From a34f749e9ac1d6112a42b0f4ded3ae801d8c583c Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Mon, 14 Sep 2020 22:37:22 +0530 Subject: Add tentative workaround for dialog crashes and refactor Git-related code (#1100) * Ensure we're creating dialogs on the main thread Signed-off-by: Harsh Shandilya * Remove unused operation type Signed-off-by: Harsh Shandilya * Refactor launchGitOperation to use an enum Signed-off-by: Harsh Shandilya --- .../com/zeapo/pwdstore/git/GitServerConfigActivity.kt | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt') diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt b/app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt index 4bbc5965..92381384 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt @@ -4,6 +4,8 @@ */ package com.zeapo.pwdstore.git +import android.content.Context +import android.content.Intent import android.os.Bundle import android.os.Handler import android.view.MenuItem @@ -42,7 +44,7 @@ class GitServerConfigActivity : BaseGitActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - val isClone = intent?.extras?.getInt(REQUEST_ARG_OP) ?: -1 == REQUEST_CLONE + val isClone = intent?.extras?.getBoolean("cloning") ?: false if (isClone) { binding.saveButton.text = getString(R.string.clone_button) } @@ -151,7 +153,7 @@ class GitServerConfigActivity : BaseGitActivity() { localDir.deleteRecursively() } snackbar.dismiss() - launchGitOperation(REQUEST_CLONE).fold( + launchGitOperation(GitOp.CLONE).fold( success = { setResult(RESULT_OK) finish() @@ -185,14 +187,22 @@ class GitServerConfigActivity : BaseGitActivity() { MaterialAlertDialogBuilder(this).setMessage(e.message).show() } lifecycleScope.launch { - launchGitOperation(REQUEST_CLONE).fold( + launchGitOperation(GitOp.CLONE).fold( success = { setResult(RESULT_OK) finish() }, - failure = ::promptOnErrorHandler, + failure = { promptOnErrorHandler(it) }, ) } } } + + companion object { + fun createCloneIntent(context: Context): Intent { + return Intent(context, GitServerConfigActivity::class.java).apply { + putExtra("cloning", true) + } + } + } } -- cgit v1.2.3