Confirm password move if it will replace an existing one (#757)
* Confirm password move if it will replace an existing one Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * CHANGELOG: update Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
9696af4024
commit
ced8bcca01
2 changed files with 39 additions and 28 deletions
|
@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Allow user to abort password move when it is replacing an existing file
|
||||||
|
|
||||||
## [1.7.2] - 2020-04-29
|
## [1.7.2] - 2020-04-29
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -126,7 +129,8 @@ All notable changes to this project will be documented in this file.
|
||||||
- Fix elements overlapping.
|
- 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.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.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
|
[1.6.0]: https://github.com/android-password-store/Android-Password-Store/compare/v1.5.0..v1.6.0
|
||||||
|
|
|
@ -729,18 +729,34 @@ class PasswordStore : AppCompatActivity() {
|
||||||
val sourceLongName = getLongName(requireNotNull(source.parent), repositoryPath, basename)
|
val sourceLongName = getLongName(requireNotNull(source.parent), repositoryPath, basename)
|
||||||
val destinationLongName = getLongName(target.absolutePath, repositoryPath, basename)
|
val destinationLongName = getLongName(target.absolutePath, repositoryPath, basename)
|
||||||
if (destinationFile.exists()) {
|
if (destinationFile.exists()) {
|
||||||
tag(TAG).e { "Trying to move a file that already exists." }
|
e { "Trying to move a file that already exists." }
|
||||||
// TODO: Add option to cancel overwrite. Will be easier once this is an async task.
|
|
||||||
MaterialAlertDialogBuilder(this)
|
MaterialAlertDialogBuilder(this)
|
||||||
.setTitle(resources.getString(R.string.password_exists_title))
|
.setTitle(resources.getString(R.string.password_exists_title))
|
||||||
.setMessage(resources
|
.setMessage(resources.getString(
|
||||||
.getString(
|
|
||||||
R.string.password_exists_message,
|
R.string.password_exists_message,
|
||||||
destinationLongName,
|
destinationLongName,
|
||||||
sourceLongName))
|
sourceLongName)
|
||||||
.setPositiveButton("Okay", null)
|
)
|
||||||
.show()
|
.setPositiveButton(R.string.dialog_ok) { _, _ ->
|
||||||
|
movePasswords(source, destinationFile, sourceLongName, destinationLongName)
|
||||||
}
|
}
|
||||||
|
.setNegativeButton(R.string.dialog_cancel, null)
|
||||||
|
.show()
|
||||||
|
} else {
|
||||||
|
movePasswords(source, destinationFile, sourceLongName, destinationLongName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resetPasswordList()
|
||||||
|
if (plist != null) {
|
||||||
|
plist!!.dismissActionMode()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.onActivityResult(requestCode, resultCode, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun movePasswords(source: File, destinationFile: File, sourceLongName: String, destinationLongName: String) {
|
||||||
val sourceDestinationMap = if (source.isDirectory) {
|
val sourceDestinationMap = if (source.isDirectory) {
|
||||||
// Recursively list all files (not directories) below `source`, then
|
// Recursively list all files (not directories) below `source`, then
|
||||||
// obtain the corresponding target file by resolving the relative path
|
// obtain the corresponding target file by resolving the relative path
|
||||||
|
@ -752,7 +768,7 @@ class PasswordStore : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
if (!source.renameTo(destinationFile)) {
|
if (!source.renameTo(destinationFile)) {
|
||||||
// TODO this should show a warning to the user
|
// TODO this should show a warning to the user
|
||||||
tag(TAG).e { "Something went wrong while moving." }
|
e { "Something went wrong while moving." }
|
||||||
} else {
|
} else {
|
||||||
AutofillMatcher.updateMatches(this, sourceDestinationMap)
|
AutofillMatcher.updateMatches(this, sourceDestinationMap)
|
||||||
commitChange(this.resources
|
commitChange(this.resources
|
||||||
|
@ -762,15 +778,6 @@ class PasswordStore : AppCompatActivity() {
|
||||||
destinationLongName))
|
destinationLongName))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resetPasswordList()
|
|
||||||
if (plist != null) {
|
|
||||||
plist!!.dismissActionMode()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
super.onActivityResult(requestCode, resultCode, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun initRepository(operation: Int) {
|
private fun initRepository(operation: Int) {
|
||||||
closeRepository()
|
closeRepository()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue