From 14c44bf584cb7d13ada46b264419efca923ed65c Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Wed, 5 Aug 2020 19:02:24 +0530 Subject: Remove GitAsyncTask and replace with non-blocking coroutines (#865) Co-authored-by: Fabian Henneke --- .../java/com/zeapo/pwdstore/git/BaseGitActivity.kt | 25 +++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt') diff --git a/app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt b/app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt index 7a818bcf..706592fe 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt @@ -12,6 +12,7 @@ import androidx.annotation.CallSuper import androidx.appcompat.app.AppCompatActivity import androidx.core.content.edit import androidx.core.text.isDigitsOnly +import androidx.lifecycle.lifecycleScope import androidx.preference.PreferenceManager import com.github.ajalt.timberkt.Timber.tag import com.github.ajalt.timberkt.e @@ -20,11 +21,19 @@ import com.zeapo.pwdstore.R import com.zeapo.pwdstore.git.config.ConnectionMode import com.zeapo.pwdstore.git.config.Protocol import com.zeapo.pwdstore.git.config.SshApiSessionFactory +import com.zeapo.pwdstore.git.operation.BreakOutOfDetached +import com.zeapo.pwdstore.git.operation.CloneOperation +import com.zeapo.pwdstore.git.operation.GitOperation +import com.zeapo.pwdstore.git.operation.PullOperation +import com.zeapo.pwdstore.git.operation.PushOperation +import com.zeapo.pwdstore.git.operation.ResetToRemoteOperation +import com.zeapo.pwdstore.git.operation.SyncOperation import com.zeapo.pwdstore.utils.PasswordRepository import com.zeapo.pwdstore.utils.PreferenceKeys import com.zeapo.pwdstore.utils.getEncryptedPrefs import java.io.File import java.net.URI +import kotlinx.coroutines.launch /** * Abstract AppCompatActivity that holds some information that is commonly shared across git-related @@ -166,7 +175,7 @@ abstract class BaseGitActivity : AppCompatActivity() { * * @param operation The type of git operation to launch */ - fun launchGitOperation(operation: Int) { + suspend fun launchGitOperation(operation: Int) { if (url == null) { setResult(RESULT_CANCELED) finish() @@ -190,12 +199,12 @@ abstract class BaseGitActivity : AppCompatActivity() { val localDir = requireNotNull(PasswordRepository.getRepositoryDirectory(this)) val op = when (operation) { - REQUEST_CLONE, GitOperation.GET_SSH_KEY_FROM_CLONE -> CloneOperation(localDir, this).setCommand(url!!) - REQUEST_PULL -> PullOperation(localDir, this).setCommand() - REQUEST_PUSH -> PushOperation(localDir, this).setCommand() - REQUEST_SYNC -> SyncOperation(localDir, this).setCommands() - BREAK_OUT_OF_DETACHED -> BreakOutOfDetached(localDir, this).setCommands() - REQUEST_RESET -> ResetToRemoteOperation(localDir, this).setCommands() + REQUEST_CLONE, GitOperation.GET_SSH_KEY_FROM_CLONE -> CloneOperation(localDir, url!!, this) + REQUEST_PULL -> PullOperation(localDir, this) + REQUEST_PUSH -> PushOperation(localDir, this) + REQUEST_SYNC -> SyncOperation(localDir, this) + BREAK_OUT_OF_DETACHED -> BreakOutOfDetached(localDir, this) + REQUEST_RESET -> ResetToRemoteOperation(localDir, this) SshApiSessionFactory.POST_SIGNATURE -> return else -> { tag(TAG).e { "Operation not recognized : $operation" } @@ -239,7 +248,7 @@ abstract class BaseGitActivity : AppCompatActivity() { if (identityBuilder != null) { identityBuilder!!.consume(data) } - launchGitOperation(requestCode) + lifecycleScope.launch { launchGitOperation(requestCode) } } super.onActivityResult(requestCode, resultCode, data) } -- cgit v1.2.3