diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt | 4 | ||||
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillMatcher.kt | 12 |
2 files changed, 11 insertions, 5 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt index 4744b259..008db7af 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt @@ -499,6 +499,8 @@ class PasswordStore : AppCompatActivity() { MaterialAlertDialogBuilder(this) .setMessage(resources.getString(R.string.delete_dialog_text, item.longName)) .setPositiveButton(resources.getString(R.string.dialog_yes)) { _, _ -> + val filesToDelete = FileUtils.listFiles(item.file, null, true) + AutofillMatcher.updateMatches(applicationContext, delete = filesToDelete) item.file.deleteRecursively() adapter.remove(position) it.remove() @@ -665,7 +667,7 @@ class PasswordStore : AppCompatActivity() { // TODO this should show a warning to the user Timber.tag(TAG).e("Something went wrong while moving.") } else { - AutofillMatcher.updateMatchesFor(this, sourceDestinationMap) + AutofillMatcher.updateMatches(this, sourceDestinationMap) commitChange(this.resources .getString( R.string.git_commit_move_text, diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillMatcher.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillMatcher.kt index 5f9c081d..e6e16ef0 100644 --- a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillMatcher.kt +++ b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillMatcher.kt @@ -148,10 +148,11 @@ class AutofillMatcher { /** * Goes through all existing matches and updates their associated entries by using - * [sourceDestinationMap] as a lookup table. + * [moveFromTo] as a lookup table and deleting the matches for files in [delete]. */ - fun updateMatchesFor(context: Context, sourceDestinationMap: Map<File, File>) { - val oldNewPathMap = sourceDestinationMap.mapValues { it.value.absolutePath } + fun updateMatches(context: Context, moveFromTo: Map<File, File> = emptyMap(), delete: Collection<File> = emptyList()) { + val deletePathList = delete.map { it.absolutePath } + val oldNewPathMap = moveFromTo.mapValues { it.value.absolutePath } .mapKeys { it.key.absolutePath } for (prefs in listOf(context.autofillAppMatches, context.autofillWebMatches)) { for ((key, value) in prefs.all) { @@ -164,7 +165,10 @@ class AutofillMatcher { // Delete all matches for file locations that are going to be overwritten, then // transfer matches over to the files at their new locations. val newMatches = - oldMatches.asSequence().minus(oldNewPathMap.values).map { match -> + oldMatches.asSequence() + .minus(deletePathList) + .minus(oldNewPathMap.values) + .map { match -> val newPath = oldNewPathMap[match] ?: return@map match d { "Updating match for $key: $match --> $newPath" } newPath |