diff options
-rw-r--r-- | CHANGELOG.md | 6 | ||||
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt | 61 |
2 files changed, 39 insertions, 28 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 315c5ff0..4b8603df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Added +- Allow user to abort password move when it is replacing an existing file + ## [1.7.2] - 2020-04-29 ### Added @@ -126,7 +129,8 @@ All notable changes to this project will be documented in this file. - Fix elements overlapping. -[Unreleased]: https://github.com/android-password-store/Android-Password-Store/compare/v1.7.1...HEAD +[Unreleased]: https://github.com/android-password-store/Android-Password-Store/compare/v1.7.2...HEAD +[1.7.2]: https://github.com/android-password-store/Android-Password-Store/compare/v1.7.1..v1.7.2 [1.7.1]: https://github.com/android-password-store/Android-Password-Store/compare/v1.7.0..v1.7.1 [1.7.0]: https://github.com/android-password-store/Android-Password-Store/compare/v1.6.0..v1.7.0 [1.6.0]: https://github.com/android-password-store/Android-Password-Store/compare/v1.5.0..v1.6.0 diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt index fe18c6b7..c9b47582 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt @@ -729,37 +729,21 @@ class PasswordStore : AppCompatActivity() { val sourceLongName = getLongName(requireNotNull(source.parent), repositoryPath, basename) val destinationLongName = getLongName(target.absolutePath, repositoryPath, basename) if (destinationFile.exists()) { - tag(TAG).e { "Trying to move a file that already exists." } - // TODO: Add option to cancel overwrite. Will be easier once this is an async task. + e { "Trying to move a file that already exists." } MaterialAlertDialogBuilder(this) .setTitle(resources.getString(R.string.password_exists_title)) - .setMessage(resources - .getString( - R.string.password_exists_message, - destinationLongName, - sourceLongName)) - .setPositiveButton("Okay", null) + .setMessage(resources.getString( + R.string.password_exists_message, + destinationLongName, + sourceLongName) + ) + .setPositiveButton(R.string.dialog_ok) { _, _ -> + movePasswords(source, destinationFile, sourceLongName, destinationLongName) + } + .setNegativeButton(R.string.dialog_cancel, null) .show() - } - val sourceDestinationMap = if (source.isDirectory) { - // Recursively list all files (not directories) below `source`, then - // obtain the corresponding target file by resolving the relative path - // starting at the destination folder. - val sourceFiles = FileUtils.listFiles(source, null, true) - sourceFiles.associateWith { destinationFile.resolve(it.relativeTo(source)) } - } else { - mapOf(source to destinationFile) - } - if (!source.renameTo(destinationFile)) { - // TODO this should show a warning to the user - tag(TAG).e { "Something went wrong while moving." } } else { - AutofillMatcher.updateMatches(this, sourceDestinationMap) - commitChange(this.resources - .getString( - R.string.git_commit_move_text, - sourceLongName, - destinationLongName)) + movePasswords(source, destinationFile, sourceLongName, destinationLongName) } } resetPasswordList() @@ -772,6 +756,29 @@ class PasswordStore : AppCompatActivity() { super.onActivityResult(requestCode, resultCode, data) } + private fun movePasswords(source: File, destinationFile: File, sourceLongName: String, destinationLongName: String) { + val sourceDestinationMap = if (source.isDirectory) { + // Recursively list all files (not directories) below `source`, then + // obtain the corresponding target file by resolving the relative path + // starting at the destination folder. + val sourceFiles = FileUtils.listFiles(source, null, true) + sourceFiles.associateWith { destinationFile.resolve(it.relativeTo(source)) } + } else { + mapOf(source to destinationFile) + } + if (!source.renameTo(destinationFile)) { + // TODO this should show a warning to the user + e { "Something went wrong while moving." } + } else { + AutofillMatcher.updateMatches(this, sourceDestinationMap) + commitChange(this.resources + .getString( + R.string.git_commit_move_text, + sourceLongName, + destinationLongName)) + } + } + private fun initRepository(operation: Int) { closeRepository() MaterialAlertDialogBuilder(this) |