summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorHarsh Shandilya <msfjarvis@gmail.com>2020-05-03 01:39:16 +0530
committerGitHub <noreply@github.com>2020-05-03 01:39:16 +0530
commit69e887f3d8602438389161449bdff4539c67c72e (patch)
tree79a5c235d98fbd66e9362cff7ca0719fbe3385b4 /app/src/main
parentced8bcca01dc2545edc3ef17e0cd44922dd97e61 (diff)
Better handle non-git repositories (#756)
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt65
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/UserPreference.kt9
-rw-r--r--app/src/main/res/menu/main_menu_git.xml (renamed from app/src/main/res/menu/main_menu.xml)17
-rw-r--r--app/src/main/res/menu/main_menu_non_git.xml20
-rw-r--r--app/src/main/res/values-ar/strings.xml1
-rw-r--r--app/src/main/res/values-cs/strings.xml1
-rw-r--r--app/src/main/res/values-de/strings.xml1
-rw-r--r--app/src/main/res/values-es/strings.xml1
-rw-r--r--app/src/main/res/values-fr/strings.xml1
-rw-r--r--app/src/main/res/values-ja/strings.xml1
-rw-r--r--app/src/main/res/values-ru/strings.xml1
-rw-r--r--app/src/main/res/values-zh-rCN/strings.xml1
-rw-r--r--app/src/main/res/values-zh-rTW/strings.xml1
-rw-r--r--app/src/main/res/values/strings.xml2
-rw-r--r--app/src/main/res/xml/preference.xml2
15 files changed, 68 insertions, 56 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt
index c9b47582..cba24202 100644
--- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt
@@ -201,11 +201,14 @@ class PasswordStore : AppCompatActivity() {
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
- menuInflater.inflate(R.menu.main_menu, menu)
+ menuInflater.inflate(if (PasswordRepository.isGitRepo()) R.menu.main_menu_git else R.menu.main_menu_non_git, menu)
return super.onCreateOptionsMenu(menu)
}
override fun onPrepareOptionsMenu(menu: Menu): Boolean {
+ // Invalidation forces onCreateOptionsMenu to be called again. This is cheap and quick so
+ // we can get by without any noticeable difference in performance.
+ invalidateOptionsMenu()
searchItem = menu.findItem(R.id.action_search)
searchView = searchItem.actionView as SearchView
searchView.setOnQueryTextListener(
@@ -256,8 +259,8 @@ class PasswordStore : AppCompatActivity() {
val id = item.itemId
val intent: Intent
val initBefore = MaterialAlertDialogBuilder(this)
- .setMessage(this.resources.getString(R.string.creation_dialog_text))
- .setPositiveButton(this.resources.getString(R.string.dialog_ok), null)
+ .setMessage(resources.getString(R.string.creation_dialog_text))
+ .setPositiveButton(resources.getString(R.string.dialog_ok), null)
when (id) {
R.id.user_pref -> {
try {
@@ -378,12 +381,12 @@ class PasswordStore : AppCompatActivity() {
val keyIds = settings.getStringSet("openpgp_key_ids_set", HashSet())
if (keyIds != null && keyIds.isEmpty()) {
MaterialAlertDialogBuilder(this)
- .setMessage(this.resources.getString(R.string.key_dialog_text))
- .setPositiveButton(this.resources.getString(R.string.dialog_positive)) { _, _ ->
+ .setMessage(resources.getString(R.string.key_dialog_text))
+ .setPositiveButton(resources.getString(R.string.dialog_positive)) { _, _ ->
val intent = Intent(activity, UserPreference::class.java)
startActivityForResult(intent, BaseGitActivity.REQUEST_INIT)
}
- .setNegativeButton(this.resources.getString(R.string.dialog_negative), null)
+ .setNegativeButton(resources.getString(R.string.dialog_negative), null)
.show()
}
createRepository()
@@ -540,16 +543,16 @@ class PasswordStore : AppCompatActivity() {
private fun validateState(): Boolean {
if (!isInitialized) {
MaterialAlertDialogBuilder(this)
- .setMessage(this.resources.getString(R.string.creation_dialog_text))
- .setPositiveButton(this.resources.getString(R.string.dialog_ok), null)
+ .setMessage(resources.getString(R.string.creation_dialog_text))
+ .setPositiveButton(resources.getString(R.string.dialog_ok), null)
.show()
return false
}
if (settings.getStringSet("openpgp_key_ids_set", HashSet()).isNullOrEmpty()) {
MaterialAlertDialogBuilder(this)
- .setTitle(this.resources.getString(R.string.no_key_selected_dialog_title))
- .setMessage(this.resources.getString(R.string.no_key_selected_dialog_text))
- .setPositiveButton(this.resources.getString(R.string.dialog_ok)) { _, _ ->
+ .setTitle(resources.getString(R.string.no_key_selected_dialog_title))
+ .setMessage(resources.getString(R.string.no_key_selected_dialog_text))
+ .setPositiveButton(resources.getString(R.string.dialog_ok)) { _, _ ->
val intent = Intent(activity, UserPreference::class.java)
startActivity(intent)
}
@@ -595,7 +598,7 @@ class PasswordStore : AppCompatActivity() {
commitChange(resources.getString(R.string.git_commit_remove_text, item.longName))
deletePasswords(selectedItems)
}
- .setNegativeButton(this.resources.getString(R.string.dialog_no)) { _, _ ->
+ .setNegativeButton(resources.getString(R.string.dialog_no)) { _, _ ->
deletePasswords(selectedItems)
}
.show()
@@ -637,7 +640,7 @@ class PasswordStore : AppCompatActivity() {
get() = plist?.currentDir ?: getRepositoryDirectory(applicationContext)
private fun commitChange(message: String) {
- commitChange(activity, message)
+ commitChange(this, message)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
@@ -650,32 +653,23 @@ class PasswordStore : AppCompatActivity() {
REQUEST_CODE_DECRYPT_AND_VERIFY -> {
if (data != null && data.getBooleanExtra("needCommit", false)) {
if (data.getStringExtra("OPERATION") == "EDIT") {
- commitChange(this.resources
- .getString(
- R.string.git_commit_edit_text,
- data.extras!!.getString("LONG_NAME")))
+ commitChange(resources.getString(R.string.git_commit_edit_text,
+ data.extras!!.getString("LONG_NAME")))
} else {
- commitChange(this.resources
- .getString(
- R.string.git_commit_increment_text,
- data.extras!!.getString("LONG_NAME")))
+ commitChange(resources.getString(R.string.git_commit_increment_text,
+ data.extras!!.getString("LONG_NAME")))
}
}
refreshPasswordList()
}
REQUEST_CODE_ENCRYPT -> {
- commitChange(this.resources
- .getString(
- R.string.git_commit_add_text,
- data!!.extras!!.getString("LONG_NAME")))
+ commitChange(resources.getString(R.string.git_commit_add_text,
+ data!!.extras!!.getString("LONG_NAME")))
refreshPasswordList()
}
REQUEST_CODE_EDIT -> {
- commitChange(
- this.resources
- .getString(
- R.string.git_commit_edit_text,
- data!!.extras!!.getString("LONG_NAME")))
+ commitChange(resources.getString(R.string.git_commit_edit_text,
+ data!!.extras!!.getString("LONG_NAME")))
refreshPasswordList()
}
BaseGitActivity.REQUEST_INIT, NEW_REPO_BUTTON -> initializeRepositoryInfo()
@@ -771,7 +765,7 @@ class PasswordStore : AppCompatActivity() {
e { "Something went wrong while moving." }
} else {
AutofillMatcher.updateMatches(this, sourceDestinationMap)
- commitChange(this.resources
+ commitChange(resources
.getString(
R.string.git_commit_move_text,
sourceLongName,
@@ -782,9 +776,9 @@ class PasswordStore : AppCompatActivity() {
private fun initRepository(operation: Int) {
closeRepository()
MaterialAlertDialogBuilder(this)
- .setTitle(this.resources.getString(R.string.location_dialog_title))
- .setMessage(this.resources.getString(R.string.location_dialog_text))
- .setPositiveButton(this.resources.getString(R.string.location_hidden)) { _, _ ->
+ .setTitle(resources.getString(R.string.location_dialog_title))
+ .setMessage(resources.getString(R.string.location_dialog_text))
+ .setPositiveButton(resources.getString(R.string.location_hidden)) { _, _ ->
settings.edit { putBoolean("git_external", false) }
when (operation) {
NEW_REPO_BUTTON -> initializeRepositoryInfo()
@@ -795,7 +789,7 @@ class PasswordStore : AppCompatActivity() {
}
}
}
- .setNegativeButton(this.resources.getString(R.string.location_sdcard)) { _, _ ->
+ .setNegativeButton(resources.getString(R.string.location_sdcard)) { _, _ ->
settings.edit { putBoolean("git_external", true) }
val externalRepo = settings.getString("git_external_repo", null)
if (externalRepo == null) {
@@ -865,6 +859,7 @@ class PasswordStore : AppCompatActivity() {
private const val PREFERENCE_SEEN_AUTOFILL_ONBOARDING = "seen_autofill_onboarding"
fun commitChange(activity: Activity, message: String, finishWithResultOnEnd: Intent? = null) {
+ if (!PasswordRepository.isGitRepo()) return
object : GitOperation(getRepositoryDirectory(activity), activity) {
override fun execute() {
tag(TAG).d { "Committing with message $message" }
diff --git a/app/src/main/java/com/zeapo/pwdstore/UserPreference.kt b/app/src/main/java/com/zeapo/pwdstore/UserPreference.kt
index 869ee05b..74de872d 100644
--- a/app/src/main/java/com/zeapo/pwdstore/UserPreference.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/UserPreference.kt
@@ -96,6 +96,15 @@ class UserPreference : AppCompatActivity() {
val externalGitRepositoryPreference = findPreference<Preference>("git_external")
val selectExternalGitRepositoryPreference = findPreference<Preference>("pref_select_external")
+ if (!PasswordRepository.isGitRepo()) {
+ listOfNotNull(
+ gitServerPreference, gitConfigPreference, sshKeyPreference,
+ sshKeygenPreference, viewSshKeyPreference, clearSavedPassPreference
+ ).forEach {
+ it.parent?.removePreference(it)
+ }
+ }
+
// Crypto preferences
val keyPreference = findPreference<Preference>("openpgp_key_id_pref")
diff --git a/app/src/main/res/menu/main_menu.xml b/app/src/main/res/menu/main_menu_git.xml
index 2e126d33..40c99550 100644
--- a/app/src/main/res/menu/main_menu.xml
+++ b/app/src/main/res/menu/main_menu_git.xml
@@ -1,16 +1,13 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
- xmlns:pwstore="http://schemas.android.com/apk/res-auto"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".pwdstore" >
<item android:id="@+id/action_search"
- android:title="@string/action_search"
- android:icon="@drawable/ic_search_white_24dp"
- pwstore:showAsAction="always|collapseActionView"
- pwstore:actionViewClass="androidx.appcompat.widget.SearchView" />
-
- <!--<item android:id="@+id/menu_add_category"-->
- <!--android:title="New category"/>-->
+ android:title="@string/action_search"
+ android:icon="@drawable/ic_search_white_24dp"
+ app:showAsAction="always|collapseActionView"
+ app:actionViewClass="androidx.appcompat.widget.SearchView" />
<item android:id="@+id/git_sync"
android:title="@string/git_sync"/>
@@ -21,8 +18,8 @@
<item android:id="@+id/refresh"
android:title="@string/refresh_list"
- pwstore:showAsAction="never"
- android:icon="@drawable/ic_refresh_white_24dp"/>
+ android:icon="@drawable/ic_refresh_white_24dp"
+ app:showAsAction="never"/>
<item android:id="@+id/user_pref"
android:title="@string/action_settings"
diff --git a/app/src/main/res/menu/main_menu_non_git.xml b/app/src/main/res/menu/main_menu_non_git.xml
new file mode 100644
index 00000000..dc7d20cc
--- /dev/null
+++ b/app/src/main/res/menu/main_menu_non_git.xml
@@ -0,0 +1,20 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ tools:context=".pwdstore" >
+
+ <item android:id="@+id/action_search"
+ android:title="@string/action_search"
+ android:icon="@drawable/ic_search_white_24dp"
+ app:showAsAction="always|collapseActionView"
+ app:actionViewClass="androidx.appcompat.widget.SearchView" />
+
+ <item android:id="@+id/refresh"
+ android:title="@string/refresh_list"
+ android:icon="@drawable/ic_refresh_white_24dp"
+ app:showAsAction="never"/>
+
+ <item android:id="@+id/user_pref"
+ android:title="@string/action_settings"
+ android:orderInCategory="100"/>
+</menu>
diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml
index 8f335c14..133f96a5 100644
--- a/app/src/main/res/values-ar/strings.xml
+++ b/app/src/main/res/values-ar/strings.xml
@@ -63,7 +63,6 @@
<string name="share_as_plaintext">شارك كنص مجرد</string>
<string name="last_changed">آخِر تعديل %s</string>
<!-- Preferences -->
- <string name="pref_git_title">جيت</string>
<string name="pref_edit_server_info">تعديل إعدادات خادوم جيت</string>
<string name="pref_ssh_title">إستيراد مفتاح الـ SSH</string>
<string name="pref_ssh_keygen_title">توليد مفتاحَي الـ SSH</string>
diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml
index 6b8c6f44..d29e8f82 100644
--- a/app/src/main/res/values-cs/strings.xml
+++ b/app/src/main/res/values-cs/strings.xml
@@ -102,7 +102,6 @@
<string name="share_as_plaintext">Sdílet v nešifrované podobě</string>
<string name="last_changed">Naposled změněno %s</string>
<!-- Preferences -->
- <string name="pref_git_title">Git</string>
<string name="pref_edit_server_info">Upravit nastavení git serveru</string>
<string name="pref_ssh_title">Importovat SSH klíč</string>
<string name="pref_ssh_keygen_title">Generovat SSH klíč</string>
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index c94b363c..372b3154 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -76,7 +76,6 @@
<string name="share_as_plaintext">Als Klartext teilen</string>
<string name="last_changed">Zuletzt geändert %s</string>
<!-- Preferences -->
- <string name="pref_git_title">Git</string>
<string name="pref_edit_server_info">Git-Server Einstellungen</string>
<string name="pref_edit_git_config">Git Konfiguration bearbeiten</string>
<string name="pref_ssh_title">Importiere SSH-Key</string>
diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml
index 2904e767..1916cc83 100644
--- a/app/src/main/res/values-es/strings.xml
+++ b/app/src/main/res/values-es/strings.xml
@@ -101,7 +101,6 @@
<string name="dialog_update_check">Recordar elección</string>
<!-- Preferences -->
- <string name="pref_git_title">Git</string>
<string name="pref_edit_server_info">Editar ajustes del servidor Git</string>
<string name="pref_edit_git_config">Preferencias de Git</string>
<string name="pref_ssh_title">Importar llave SSH</string>
diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml
index e8a70667..3dad40e9 100644
--- a/app/src/main/res/values-fr/strings.xml
+++ b/app/src/main/res/values-fr/strings.xml
@@ -109,7 +109,6 @@
<string name="dialog_update_check">Se souvenir de mon choix</string>
<!-- Preferences -->
- <string name="pref_git_title">Git</string>
<string name="pref_edit_server_info">Editer les paramètres du serveur Git</string>
<string name="pref_edit_git_config">Éditer la configuration</string>
<string name="pref_ssh_title">Importer une clef SSH</string>
diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml
index 4337c6d0..c8fb396b 100644
--- a/app/src/main/res/values-ja/strings.xml
+++ b/app/src/main/res/values-ja/strings.xml
@@ -63,7 +63,6 @@
<!-- DECRYPT Layout -->
<string name="action_search">検索</string>
<!-- Preferences -->
- <string name="pref_git_title">Git</string>
<string name="pref_edit_server_info">git サーバー設定を編集</string>
<string name="pref_ssh_title">SSH 鍵のインポート</string>
<string name="pref_ssh_keygen_title">SSH 鍵ペアを生成</string>
diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml
index 3859ac6b..1f578631 100644
--- a/app/src/main/res/values-ru/strings.xml
+++ b/app/src/main/res/values-ru/strings.xml
@@ -114,7 +114,6 @@
<string name="dialog_update_check">Запомнить мой выбор</string>
<!-- Preferences -->
- <string name="pref_git_title">Git</string>
<string name="pref_edit_server_info">Изменить настройки сервера git</string>
<string name="pref_edit_git_config">Утилиты Git</string>
<string name="pref_ssh_title">Импортировать SSH ключ</string>
diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml
index 1ab16b96..6b87a10c 100644
--- a/app/src/main/res/values-zh-rCN/strings.xml
+++ b/app/src/main/res/values-zh-rCN/strings.xml
@@ -63,7 +63,6 @@
<!-- DECRYPT Layout -->
<string name="action_search">搜索</string>
<!-- Preferences -->
- <string name="pref_git_title">Git</string>
<string name="pref_edit_server_info">修改 Git 服务器设置</string>
<string name="pref_ssh_title">导入 SSH 密钥</string>
<string name="pref_ssh_keygen_title">生成 SSH 密钥对</string>
diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml
index b0f5231a..db52f31b 100644
--- a/app/src/main/res/values-zh-rTW/strings.xml
+++ b/app/src/main/res/values-zh-rTW/strings.xml
@@ -60,7 +60,6 @@
<!-- DECRYPT Layout -->
<string name="action_search">搜尋</string>
<!-- Preferences -->
- <string name="pref_git_title">Git</string>
<string name="pref_edit_server_info">修改 Git 伺服器設定</string>
<string name="pref_ssh_title">匯入 SSH 私鑰</string>
<string name="pref_ssh_keygen_title">生成 SSH 金鑰</string>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 79fda215..5d77ad6a 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -131,7 +131,7 @@
<string name="dialog_update_check">Remember my choice</string>
<!-- Preferences -->
- <string name="pref_git_title">Git</string>
+ <string name="pref_repository_title">Repository</string>
<string name="pref_edit_server_info">Edit git server settings</string>
<string name="pref_edit_git_config">Git utils</string>
<string name="pref_ssh_title">Import SSH key</string>
diff --git a/app/src/main/res/xml/preference.xml b/app/src/main/res/xml/preference.xml
index 656e47f6..dcb33e3e 100644
--- a/app/src/main/res/xml/preference.xml
+++ b/app/src/main/res/xml/preference.xml
@@ -32,7 +32,7 @@
app:title="@string/pref_autofill_full_path_title"/>
</PreferenceCategory>
- <PreferenceCategory app:title="@string/pref_git_title">
+ <PreferenceCategory app:title="@string/pref_repository_title">
<Preference
app:key="git_server_info"
app:title="@string/pref_edit_server_info" />