diff options
Diffstat (limited to 'app/src/main/java')
3 files changed, 13 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 b0f6fd44..0a768fd0 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt @@ -66,6 +66,7 @@ import com.zeapo.pwdstore.utils.PasswordRepository.Companion.initialize import com.zeapo.pwdstore.utils.PasswordRepository.Companion.isInitialized import com.zeapo.pwdstore.utils.PasswordRepository.PasswordSortOrder.Companion.getSortOrder import com.zeapo.pwdstore.utils.commitChange +import com.zeapo.pwdstore.utils.isInsideRepository import com.zeapo.pwdstore.utils.listFilesRecursively import com.zeapo.pwdstore.utils.requestInputFocusOnView import kotlinx.coroutines.Dispatchers @@ -666,15 +667,11 @@ class PasswordStore : AppCompatActivity(R.layout.activity_pwdstore) { }.launch(intent) } - private fun isInsideRepository(file: File): Boolean { - return file.canonicalPath.contains(getRepositoryDirectory(this).canonicalPath) - } - enum class CategoryRenameError(val resource: Int) { None(0), EmptyField(R.string.message_category_error_empty_field), CategoryExists(R.string.message_category_error_category_exists), - DestinationOutsideRepo(R.string.message_category_error_destination_outside_repo), + DestinationOutsideRepo(R.string.message_error_destination_outside_repo), } /** diff --git a/app/src/main/java/com/zeapo/pwdstore/crypto/PasswordCreationActivity.kt b/app/src/main/java/com/zeapo/pwdstore/crypto/PasswordCreationActivity.kt index 1fdeafe9..c34d1a8a 100644 --- a/app/src/main/java/com/zeapo/pwdstore/crypto/PasswordCreationActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/crypto/PasswordCreationActivity.kt @@ -18,6 +18,7 @@ import androidx.lifecycle.lifecycleScope import com.github.ajalt.timberkt.e import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.zeapo.pwdstore.PasswordEntry +import com.zeapo.pwdstore.utils.isInsideRepository import com.zeapo.pwdstore.R import com.zeapo.pwdstore.autofill.oreo.AutofillPreferences import com.zeapo.pwdstore.autofill.oreo.DirectoryStructure @@ -235,6 +236,11 @@ class PasswordCreationActivity : BasePgpActivity(), OpenPgpServiceConnection.OnB snackbar(message = getString(R.string.password_creation_duplicate_error)) return@executeApiAsync } + + if (!isInsideRepository(file)) { + snackbar(message = getString(R.string.message_error_destination_outside_repo)) + return@executeApiAsync + } try { file.outputStream().use { it.write(outputStream.toByteArray()) 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 fa22b75e..c84465e9 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt +++ b/app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt @@ -23,6 +23,7 @@ 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 @@ -123,3 +124,7 @@ fun <T : View> AlertDialog.requestInputFocusOnView(@IdRes id: Int) { val Context.autofillManager: AutofillManager? @RequiresApi(Build.VERSION_CODES.O) get() = getSystemService() + +fun Activity.isInsideRepository(file: File): Boolean { + return file.canonicalPath.contains(getRepositoryDirectory(this).canonicalPath) +} |