diff options
Diffstat (limited to 'app/src/main/java/com')
9 files changed, 31 insertions, 34 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt index 0a768fd0..c20be674 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt @@ -179,6 +179,11 @@ class PasswordStore : AppCompatActivity(R.layout.activity_pwdstore) { } } + public override fun onStart() { + super.onStart() + refreshPasswordList() + } + public override fun onResume() { super.onResume() // do not attempt to checkLocalRepository() if no storage permission: immediate crash @@ -584,7 +589,6 @@ class PasswordStore : AppCompatActivity(R.layout.activity_pwdstore) { item.file.toRelativeString(getRepositoryDirectory(this)) } )) - refreshPasswordList() } .setNegativeButton(resources.getString(R.string.dialog_no), null) .show() @@ -662,7 +666,7 @@ class PasswordStore : AppCompatActivity(R.layout.activity_pwdstore) { } } } - resetPasswordList() + refreshPasswordList() plist?.dismissActionMode() }.launch(intent) } @@ -727,24 +731,17 @@ class PasswordStore : AppCompatActivity(R.layout.activity_pwdstore) { } /** - * Resets navigation to the repository root and refreshes the password list accordingly. - * - * Use this rather than [refreshPasswordList] after major file system operations that may remove - * the current directory and thus require a full reset of the navigation stack. - */ - fun resetPasswordList() { - model.reset() - supportActionBar!!.setDisplayHomeAsUpEnabled(false) - } - - /** - * Refreshes the password list by re-executing the last navigation or search action. - * - * Use this rather than [resetPasswordList] after file system operations limited to the current - * folder since it preserves the scroll position and navigation stack. + * Refreshes the password list by re-executing the last navigation or search action, preserving + * the navigation stack and scroll position. If the current directory no longer exists, + * navigation is reset to the repository root. */ fun refreshPasswordList() { - model.forceRefresh() + if (model.currentDir.value?.isDirectory == true) { + model.forceRefresh() + } else { + model.reset() + supportActionBar!!.setDisplayHomeAsUpEnabled(false) + } } private val currentDir: File @@ -763,15 +760,13 @@ class PasswordStore : AppCompatActivity(R.layout.activity_pwdstore) { data.extras!!.getString("LONG_NAME"))) } } - refreshPasswordList() } REQUEST_CODE_ENCRYPT -> { commitChange(resources.getString(R.string.git_commit_add_text, data!!.extras!!.getString("LONG_NAME"))) - refreshPasswordList() } BaseGitActivity.REQUEST_INIT, NEW_REPO_BUTTON -> initializeRepositoryInfo() - BaseGitActivity.REQUEST_SYNC, BaseGitActivity.REQUEST_PULL -> resetPasswordList() + BaseGitActivity.REQUEST_SYNC, BaseGitActivity.REQUEST_PULL -> refreshPasswordList() HOME -> checkLocalRepository() // duplicate code CLONE_REPO_BUTTON -> { @@ -793,6 +788,14 @@ class PasswordStore : AppCompatActivity(R.layout.activity_pwdstore) { intent.putExtra(BaseGitActivity.REQUEST_ARG_OP, BaseGitActivity.REQUEST_CLONE) startActivityForResult(intent, BaseGitActivity.REQUEST_CLONE) } + else -> { + d { "Unexpected request code: $requestCode" } + // FIXME: The sync operation returns with a requestCode of 65535 instead of the + // expected 105. It is completely unclear why, but the issue might be resolved + // by switching to ActivityResultContracts. For now, we run the post-sync code + // also when encountering an unexpected request code. + refreshPasswordList() + } } } super.onActivityResult(requestCode, resultCode, data) 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 31c376eb..8533187f 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, true, this, null) + GitAsyncTask(callingActivity, 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 705566be..0e89af0f 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.kt @@ -36,7 +36,7 @@ class CloneOperation(fileDir: File, callingActivity: Activity) : GitOperation(fi override fun execute() { (this.command as? CloneCommand)?.setCredentialsProvider(this.provider) - GitAsyncTask(callingActivity, false, this, Intent()).execute(this.command) + GitAsyncTask(callingActivity, this, Intent()).execute(this.command) } override fun onError(err: Exception) { diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.kt b/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.kt index a2b4e2a8..84e08dfc 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.kt @@ -10,7 +10,6 @@ import android.content.Context import android.content.Intent import android.os.AsyncTask import com.github.ajalt.timberkt.e -import com.zeapo.pwdstore.PasswordStore import com.zeapo.pwdstore.R import com.zeapo.pwdstore.git.config.SshjSessionFactory import net.schmizz.sshj.common.DisconnectReason @@ -30,7 +29,6 @@ import java.lang.ref.WeakReference class GitAsyncTask( activity: Activity, - private val refreshListOnEnd: Boolean, private val operation: GitOperation, private val finishWithResultOnEnd: Intent?, private val silentlyExecute: Boolean = false @@ -170,9 +168,6 @@ class GitAsyncTask( } } } - if (refreshListOnEnd) { - (activity as? PasswordStore)?.resetPasswordList() - } (SshSessionFactory.getInstance() as? SshjSessionFactory)?.clearCredentials() SshSessionFactory.setInstance(null) } 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 2d5f6bbe..c543f885 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.kt @@ -35,7 +35,7 @@ class PullOperation(fileDir: File, callingActivity: Activity) : GitOperation(fil override fun execute() { (this.command as? PullCommand)?.setCredentialsProvider(this.provider) - GitAsyncTask(callingActivity, false, this, Intent()).execute(this.command) + GitAsyncTask(callingActivity, this, Intent()).execute(this.command) } override fun onError(err: Exception) { 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 52e6e537..fc58705f 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.kt @@ -35,7 +35,7 @@ class PushOperation(fileDir: File, callingActivity: Activity) : GitOperation(fil override fun execute() { (this.command as? PushCommand)?.setCredentialsProvider(this.provider) - GitAsyncTask(callingActivity, false, this, Intent()).execute(this.command) + GitAsyncTask(callingActivity, this, Intent()).execute(this.command) } override fun onError(err: Exception) { 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 c652889d..be9e929f 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/ResetToRemoteOperation.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/ResetToRemoteOperation.kt @@ -41,7 +41,7 @@ class ResetToRemoteOperation(fileDir: File, callingActivity: Activity) : GitOper override fun execute() { this.fetchCommand?.setCredentialsProvider(this.provider) - GitAsyncTask(callingActivity, false, this, Intent()) + GitAsyncTask(callingActivity, 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 1f241c64..3af6f08d 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/SyncOperation.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/SyncOperation.kt @@ -50,7 +50,7 @@ class SyncOperation(fileDir: File, callingActivity: Activity) : GitOperation(fil this.pullCommand?.setCredentialsProvider(this.provider) this.pushCommand?.setCredentialsProvider(this.provider) } - GitAsyncTask(callingActivity, false, this, Intent()).execute(this.addCommand, this.statusCommand, this.commitCommand, this.pullCommand, this.pushCommand) + GitAsyncTask(callingActivity, this, Intent()).execute(this.addCommand, this.statusCommand, this.commitCommand, this.pullCommand, this.pushCommand) } override fun onError(err: Exception) { diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt b/app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt index c84465e9..dcede7da 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt +++ b/app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt @@ -23,7 +23,6 @@ import androidx.security.crypto.EncryptedSharedPreferences import androidx.security.crypto.MasterKey import com.github.ajalt.timberkt.d import com.google.android.material.snackbar.Snackbar -import com.zeapo.pwdstore.PasswordStore import com.zeapo.pwdstore.git.GitAsyncTask import com.zeapo.pwdstore.git.GitOperation import com.zeapo.pwdstore.utils.PasswordRepository.Companion.getRepositoryDirectory @@ -92,7 +91,7 @@ fun Activity.commitChange(message: String, finishWithResultOnEnd: Intent? = null override fun execute() { d { "Comitting with message: '$message'" } val git = Git(repository) - val task = GitAsyncTask(this@commitChange, true, this, finishWithResultOnEnd, silentlyExecute = true) + val task = GitAsyncTask(this@commitChange, this, finishWithResultOnEnd, silentlyExecute = true) task.execute( git.add().addFilepattern("."), git.commit().setAll(true).setMessage(message) |