diff options
Diffstat (limited to 'app/src/main/java')
9 files changed, 46 insertions, 37 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt index f1283538..964fb323 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt @@ -796,12 +796,12 @@ class PasswordStore : AppCompatActivity() { block != null && block !== UnicodeBlock.SPECIALS) } - fun commitChange(activity: Activity, message: String) { + fun commitChange(activity: Activity, message: String, finishWithResultOnEnd: Intent? = null) { object : GitOperation(getRepositoryDirectory(activity), activity) { override fun execute() { Timber.tag(TAG).d("Committing with message $message") val git = Git(repository) - val tasks = GitAsyncTask(activity, false, true, this) + val tasks = GitAsyncTask(activity, true, this, finishWithResultOnEnd) tasks.execute( git.add().addFilepattern("."), git.commit().setAll(true).setMessage(message) diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillSaveActivity.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillSaveActivity.kt index 3a4831d6..c3132a79 100644 --- a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillSaveActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillSaveActivity.kt @@ -120,31 +120,34 @@ class AutofillSaveActivity : Activity() { AutofillMatcher.addMatchFor(this, it, File(createdPath)) } val longName = data.getStringExtra("LONG_NAME")!! - // PgpActivity delegates committing the added file to PasswordStore. Since PasswordStore - // is not involved in an AutofillScenario, we have to commit the file ourself. - PasswordStore.commitChange(this, getString(R.string.git_commit_add_text, longName)) - - val password = data.getStringExtra("PASSWORD") + val password = data.getStringExtra("PASSWORD")!! val username = data.getStringExtra("USERNAME") - if (password != null) { - val clientState = - intent?.getBundleExtra(AutofillManager.EXTRA_CLIENT_STATE) ?: run { - e { "AutofillDecryptActivity started without EXTRA_CLIENT_STATE" } - finish() - return - } - val credentials = Credentials(username, password) - val fillInDataset = FillableForm.makeFillInDataset( - this, - credentials, - clientState, - AutofillAction.Generate - ) - setResult(RESULT_OK, Intent().apply { - putExtra(AutofillManager.EXTRA_AUTHENTICATION_RESULT, fillInDataset) - }) + val clientState = + intent?.getBundleExtra(AutofillManager.EXTRA_CLIENT_STATE) ?: run { + e { "AutofillDecryptActivity started without EXTRA_CLIENT_STATE" } + finish() + return + } + val credentials = Credentials(username, password) + val fillInDataset = FillableForm.makeFillInDataset( + this, + credentials, + clientState, + AutofillAction.Generate + ) + val result = Intent().apply { + putExtra(AutofillManager.EXTRA_AUTHENTICATION_RESULT, fillInDataset) } + // PgpActivity delegates committing the added file to PasswordStore. Since PasswordStore + // is not involved in an AutofillScenario, we have to commit the file ourselves. + PasswordStore.commitChange( + this, + getString(R.string.git_commit_add_text, longName), + finishWithResultOnEnd = result + ) + // GitAsyncTask will finish the activity for us. + } else { + finish() } - finish() } } diff --git a/app/src/main/java/com/zeapo/pwdstore/git/BreakOutOfDetached.kt b/app/src/main/java/com/zeapo/pwdstore/git/BreakOutOfDetached.kt index 80387688..4edd9e38 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/BreakOutOfDetached.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/BreakOutOfDetached.kt @@ -58,7 +58,7 @@ class BreakOutOfDetached(fileDir: File, callingActivity: Activity) : GitOperatio } } } - GitAsyncTask(callingActivity, false, true, this) + GitAsyncTask(callingActivity, true, this, null) .execute(*this.commands.toTypedArray()) } diff --git a/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.kt b/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.kt index 18cff01c..2bfcd491 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.kt @@ -5,6 +5,7 @@ package com.zeapo.pwdstore.git import android.app.Activity +import android.content.Intent import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.zeapo.pwdstore.R import java.io.File @@ -60,7 +61,7 @@ class CloneOperation(fileDir: File, callingActivity: Activity) : GitOperation(fi override fun execute() { (this.command as? CloneCommand)?.setCredentialsProvider(this.provider) - GitAsyncTask(callingActivity, true, false, this).execute(this.command) + GitAsyncTask(callingActivity, false, this, Intent()).execute(this.command) } override fun onError(errorMessage: String) { diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java b/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java index a33ec221..d07bd791 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java @@ -6,6 +6,7 @@ package com.zeapo.pwdstore.git; import android.app.Activity; import android.app.ProgressDialog; +import android.content.Intent; import android.os.AsyncTask; import com.zeapo.pwdstore.PasswordStore; import com.zeapo.pwdstore.R; @@ -22,20 +23,20 @@ import org.eclipse.jgit.transport.RemoteRefUpdate; public class GitAsyncTask extends AsyncTask<GitCommand, Integer, String> { private WeakReference<Activity> activityWeakReference; - private boolean finishOnEnd; private boolean refreshListOnEnd; private ProgressDialog dialog; private GitOperation operation; + private Intent finishWithResultOnEnd; public GitAsyncTask( Activity activity, - boolean finishOnEnd, boolean refreshListOnEnd, - GitOperation operation) { + GitOperation operation, + Intent finishWithResultOnEnd) { this.activityWeakReference = new WeakReference<>(activity); - this.finishOnEnd = finishOnEnd; this.refreshListOnEnd = refreshListOnEnd; this.operation = operation; + this.finishWithResultOnEnd = finishWithResultOnEnd; dialog = new ProgressDialog(getActivity()); } @@ -124,8 +125,8 @@ public class GitAsyncTask extends AsyncTask<GitCommand, Integer, String> { } else { this.operation.onSuccess(); - if (finishOnEnd) { - this.getActivity().setResult(Activity.RESULT_OK); + if (finishWithResultOnEnd != null) { + this.getActivity().setResult(Activity.RESULT_OK, finishWithResultOnEnd); this.getActivity().finish(); } diff --git a/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.kt b/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.kt index 6fdae937..554b76af 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.kt @@ -5,6 +5,7 @@ package com.zeapo.pwdstore.git import android.app.Activity +import android.content.Intent import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.zeapo.pwdstore.R import java.io.File @@ -34,7 +35,7 @@ class PullOperation(fileDir: File, callingActivity: Activity) : GitOperation(fil override fun execute() { (this.command as? PullCommand)?.setCredentialsProvider(this.provider) - GitAsyncTask(callingActivity, true, false, this).execute(this.command) + GitAsyncTask(callingActivity, false, this, Intent()).execute(this.command) } override fun onError(errorMessage: String) { diff --git a/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.kt b/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.kt index f3629ba7..1f40e615 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.kt @@ -5,6 +5,7 @@ package com.zeapo.pwdstore.git import android.app.Activity +import android.content.Intent import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.zeapo.pwdstore.R import java.io.File @@ -34,7 +35,7 @@ class PushOperation(fileDir: File, callingActivity: Activity) : GitOperation(fil override fun execute() { (this.command as? PushCommand)?.setCredentialsProvider(this.provider) - GitAsyncTask(callingActivity, true, false, this).execute(this.command) + GitAsyncTask(callingActivity, false, this, Intent()).execute(this.command) } override fun onError(errorMessage: String) { diff --git a/app/src/main/java/com/zeapo/pwdstore/git/ResetToRemoteOperation.kt b/app/src/main/java/com/zeapo/pwdstore/git/ResetToRemoteOperation.kt index 5bddcad5..44cd75a0 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/ResetToRemoteOperation.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/ResetToRemoteOperation.kt @@ -5,6 +5,7 @@ package com.zeapo.pwdstore.git import android.app.Activity +import android.content.Intent import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.zeapo.pwdstore.R import java.io.File @@ -39,7 +40,7 @@ class ResetToRemoteOperation(fileDir: File, callingActivity: Activity) : GitOper override fun execute() { this.fetchCommand?.setCredentialsProvider(this.provider) - GitAsyncTask(callingActivity, true, false, this) + GitAsyncTask(callingActivity, false, this, Intent()) .execute(this.addCommand, this.fetchCommand, this.resetCommand) } diff --git a/app/src/main/java/com/zeapo/pwdstore/git/SyncOperation.kt b/app/src/main/java/com/zeapo/pwdstore/git/SyncOperation.kt index 16267fc1..73e2d875 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/SyncOperation.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/SyncOperation.kt @@ -5,6 +5,7 @@ package com.zeapo.pwdstore.git import android.app.Activity +import android.content.Intent import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.zeapo.pwdstore.R import java.io.File @@ -48,7 +49,7 @@ class SyncOperation(fileDir: File, callingActivity: Activity) : GitOperation(fil this.pullCommand?.setCredentialsProvider(this.provider) this.pushCommand?.setCredentialsProvider(this.provider) } - GitAsyncTask(callingActivity, true, false, this).execute(this.addCommand, this.statusCommand, this.commitCommand, this.pullCommand, this.pushCommand) + GitAsyncTask(callingActivity, false, this, Intent()).execute(this.addCommand, this.statusCommand, this.commitCommand, this.pullCommand, this.pushCommand) } override fun onError(errorMessage: String) { |