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("git_external") val selectExternalGitRepositoryPreference = findPreference("pref_select_external") + if (!PasswordRepository.isGitRepo()) { + listOfNotNull( + gitServerPreference, gitConfigPreference, sshKeyPreference, + sshKeygenPreference, viewSshKeyPreference, clearSavedPassPreference + ).forEach { + it.parent?.removePreference(it) + } + } + // Crypto preferences val keyPreference = findPreference("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 similarity index 56% rename from app/src/main/res/menu/main_menu.xml rename to 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 @@ - - - + android:title="@string/action_search" + android:icon="@drawable/ic_search_white_24dp" + app:showAsAction="always|collapseActionView" + app:actionViewClass="androidx.appcompat.widget.SearchView" /> @@ -21,8 +18,8 @@ + android:icon="@drawable/ic_refresh_white_24dp" + app:showAsAction="never"/> + + + + + + + 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 @@ شارك كنص مجرد آخِر تعديل %s - جيت تعديل إعدادات خادوم جيت إستيراد مفتاح الـ SSH توليد مفتاحَي الـ SSH 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 @@ Sdílet v nešifrované podobě Naposled změněno %s - Git Upravit nastavení git serveru Importovat SSH klíč Generovat SSH klíč 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 @@ Als Klartext teilen Zuletzt geändert %s - Git Git-Server Einstellungen Git Konfiguration bearbeiten Importiere SSH-Key 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 @@ Recordar elección - Git Editar ajustes del servidor Git Preferencias de Git Importar llave SSH 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 @@ Se souvenir de mon choix - Git Editer les paramètres du serveur Git Éditer la configuration Importer une clef SSH 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 @@ 検索 - Git git サーバー設定を編集 SSH 鍵のインポート SSH 鍵ペアを生成 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 @@ Запомнить мой выбор - Git Изменить настройки сервера git Утилиты Git Импортировать SSH ключ 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 @@ 搜索 - Git 修改 Git 服务器设置 导入 SSH 密钥 生成 SSH 密钥对 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 @@ 搜尋 - Git 修改 Git 伺服器設定 匯入 SSH 私鑰 生成 SSH 金鑰 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 @@ Remember my choice - Git + Repository Edit git server settings Git utils Import SSH key 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"/> - +