Consolidate password list refresh (#887)
This commit is contained in:
parent
9fc5d337b8
commit
535ad1dbb1
9 changed files with 31 additions and 34 deletions
|
@ -179,6 +179,11 @@ class PasswordStore : AppCompatActivity(R.layout.activity_pwdstore) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override fun onStart() {
|
||||||
|
super.onStart()
|
||||||
|
refreshPasswordList()
|
||||||
|
}
|
||||||
|
|
||||||
public override fun onResume() {
|
public override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
// do not attempt to checkLocalRepository() if no storage permission: immediate crash
|
// 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))
|
item.file.toRelativeString(getRepositoryDirectory(this))
|
||||||
}
|
}
|
||||||
))
|
))
|
||||||
refreshPasswordList()
|
|
||||||
}
|
}
|
||||||
.setNegativeButton(resources.getString(R.string.dialog_no), null)
|
.setNegativeButton(resources.getString(R.string.dialog_no), null)
|
||||||
.show()
|
.show()
|
||||||
|
@ -662,7 +666,7 @@ class PasswordStore : AppCompatActivity(R.layout.activity_pwdstore) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resetPasswordList()
|
refreshPasswordList()
|
||||||
plist?.dismissActionMode()
|
plist?.dismissActionMode()
|
||||||
}.launch(intent)
|
}.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.
|
* 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,
|
||||||
* Use this rather than [refreshPasswordList] after major file system operations that may remove
|
* navigation is reset to the repository root.
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
fun refreshPasswordList() {
|
fun refreshPasswordList() {
|
||||||
model.forceRefresh()
|
if (model.currentDir.value?.isDirectory == true) {
|
||||||
|
model.forceRefresh()
|
||||||
|
} else {
|
||||||
|
model.reset()
|
||||||
|
supportActionBar!!.setDisplayHomeAsUpEnabled(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val currentDir: File
|
private val currentDir: File
|
||||||
|
@ -763,15 +760,13 @@ class PasswordStore : AppCompatActivity(R.layout.activity_pwdstore) {
|
||||||
data.extras!!.getString("LONG_NAME")))
|
data.extras!!.getString("LONG_NAME")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
refreshPasswordList()
|
|
||||||
}
|
}
|
||||||
REQUEST_CODE_ENCRYPT -> {
|
REQUEST_CODE_ENCRYPT -> {
|
||||||
commitChange(resources.getString(R.string.git_commit_add_text,
|
commitChange(resources.getString(R.string.git_commit_add_text,
|
||||||
data!!.extras!!.getString("LONG_NAME")))
|
data!!.extras!!.getString("LONG_NAME")))
|
||||||
refreshPasswordList()
|
|
||||||
}
|
}
|
||||||
BaseGitActivity.REQUEST_INIT, NEW_REPO_BUTTON -> initializeRepositoryInfo()
|
BaseGitActivity.REQUEST_INIT, NEW_REPO_BUTTON -> initializeRepositoryInfo()
|
||||||
BaseGitActivity.REQUEST_SYNC, BaseGitActivity.REQUEST_PULL -> resetPasswordList()
|
BaseGitActivity.REQUEST_SYNC, BaseGitActivity.REQUEST_PULL -> refreshPasswordList()
|
||||||
HOME -> checkLocalRepository()
|
HOME -> checkLocalRepository()
|
||||||
// duplicate code
|
// duplicate code
|
||||||
CLONE_REPO_BUTTON -> {
|
CLONE_REPO_BUTTON -> {
|
||||||
|
@ -793,6 +788,14 @@ class PasswordStore : AppCompatActivity(R.layout.activity_pwdstore) {
|
||||||
intent.putExtra(BaseGitActivity.REQUEST_ARG_OP, BaseGitActivity.REQUEST_CLONE)
|
intent.putExtra(BaseGitActivity.REQUEST_ARG_OP, BaseGitActivity.REQUEST_CLONE)
|
||||||
startActivityForResult(intent, 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)
|
super.onActivityResult(requestCode, resultCode, data)
|
||||||
|
|
|
@ -58,7 +58,7 @@ class BreakOutOfDetached(fileDir: File, callingActivity: Activity) : GitOperatio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GitAsyncTask(callingActivity, true, this, null)
|
GitAsyncTask(callingActivity, this, null)
|
||||||
.execute(*this.commands.toTypedArray())
|
.execute(*this.commands.toTypedArray())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ class CloneOperation(fileDir: File, callingActivity: Activity) : GitOperation(fi
|
||||||
|
|
||||||
override fun execute() {
|
override fun execute() {
|
||||||
(this.command as? CloneCommand)?.setCredentialsProvider(this.provider)
|
(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) {
|
override fun onError(err: Exception) {
|
||||||
|
|
|
@ -10,7 +10,6 @@ import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.AsyncTask
|
import android.os.AsyncTask
|
||||||
import com.github.ajalt.timberkt.e
|
import com.github.ajalt.timberkt.e
|
||||||
import com.zeapo.pwdstore.PasswordStore
|
|
||||||
import com.zeapo.pwdstore.R
|
import com.zeapo.pwdstore.R
|
||||||
import com.zeapo.pwdstore.git.config.SshjSessionFactory
|
import com.zeapo.pwdstore.git.config.SshjSessionFactory
|
||||||
import net.schmizz.sshj.common.DisconnectReason
|
import net.schmizz.sshj.common.DisconnectReason
|
||||||
|
@ -30,7 +29,6 @@ import java.lang.ref.WeakReference
|
||||||
|
|
||||||
class GitAsyncTask(
|
class GitAsyncTask(
|
||||||
activity: Activity,
|
activity: Activity,
|
||||||
private val refreshListOnEnd: Boolean,
|
|
||||||
private val operation: GitOperation,
|
private val operation: GitOperation,
|
||||||
private val finishWithResultOnEnd: Intent?,
|
private val finishWithResultOnEnd: Intent?,
|
||||||
private val silentlyExecute: Boolean = false
|
private val silentlyExecute: Boolean = false
|
||||||
|
@ -170,9 +168,6 @@ class GitAsyncTask(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (refreshListOnEnd) {
|
|
||||||
(activity as? PasswordStore)?.resetPasswordList()
|
|
||||||
}
|
|
||||||
(SshSessionFactory.getInstance() as? SshjSessionFactory)?.clearCredentials()
|
(SshSessionFactory.getInstance() as? SshjSessionFactory)?.clearCredentials()
|
||||||
SshSessionFactory.setInstance(null)
|
SshSessionFactory.setInstance(null)
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ class PullOperation(fileDir: File, callingActivity: Activity) : GitOperation(fil
|
||||||
|
|
||||||
override fun execute() {
|
override fun execute() {
|
||||||
(this.command as? PullCommand)?.setCredentialsProvider(this.provider)
|
(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) {
|
override fun onError(err: Exception) {
|
||||||
|
|
|
@ -35,7 +35,7 @@ class PushOperation(fileDir: File, callingActivity: Activity) : GitOperation(fil
|
||||||
|
|
||||||
override fun execute() {
|
override fun execute() {
|
||||||
(this.command as? PushCommand)?.setCredentialsProvider(this.provider)
|
(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) {
|
override fun onError(err: Exception) {
|
||||||
|
|
|
@ -41,7 +41,7 @@ class ResetToRemoteOperation(fileDir: File, callingActivity: Activity) : GitOper
|
||||||
|
|
||||||
override fun execute() {
|
override fun execute() {
|
||||||
this.fetchCommand?.setCredentialsProvider(this.provider)
|
this.fetchCommand?.setCredentialsProvider(this.provider)
|
||||||
GitAsyncTask(callingActivity, false, this, Intent())
|
GitAsyncTask(callingActivity, this, Intent())
|
||||||
.execute(this.addCommand, this.fetchCommand, this.resetCommand)
|
.execute(this.addCommand, this.fetchCommand, this.resetCommand)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ class SyncOperation(fileDir: File, callingActivity: Activity) : GitOperation(fil
|
||||||
this.pullCommand?.setCredentialsProvider(this.provider)
|
this.pullCommand?.setCredentialsProvider(this.provider)
|
||||||
this.pushCommand?.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) {
|
override fun onError(err: Exception) {
|
||||||
|
|
|
@ -23,7 +23,6 @@ import androidx.security.crypto.EncryptedSharedPreferences
|
||||||
import androidx.security.crypto.MasterKey
|
import androidx.security.crypto.MasterKey
|
||||||
import com.github.ajalt.timberkt.d
|
import com.github.ajalt.timberkt.d
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import com.zeapo.pwdstore.PasswordStore
|
|
||||||
import com.zeapo.pwdstore.git.GitAsyncTask
|
import com.zeapo.pwdstore.git.GitAsyncTask
|
||||||
import com.zeapo.pwdstore.git.GitOperation
|
import com.zeapo.pwdstore.git.GitOperation
|
||||||
import com.zeapo.pwdstore.utils.PasswordRepository.Companion.getRepositoryDirectory
|
import com.zeapo.pwdstore.utils.PasswordRepository.Companion.getRepositoryDirectory
|
||||||
|
@ -92,7 +91,7 @@ fun Activity.commitChange(message: String, finishWithResultOnEnd: Intent? = null
|
||||||
override fun execute() {
|
override fun execute() {
|
||||||
d { "Comitting with message: '$message'" }
|
d { "Comitting with message: '$message'" }
|
||||||
val git = Git(repository)
|
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(
|
task.execute(
|
||||||
git.add().addFilepattern("."),
|
git.add().addFilepattern("."),
|
||||||
git.commit().setAll(true).setMessage(message)
|
git.commit().setAll(true).setMessage(message)
|
||||||
|
|
Loading…
Reference in a new issue