diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2021-02-03 01:25:34 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-03 01:25:34 +0530 |
commit | 318aeae50072d575c975bbf1f708d526c41adc20 (patch) | |
tree | 794dd596f67e14956b0cf8351f151121db723fca /app/src | |
parent | 4694c5ac8575a7e85e6b950eaed99049719b6151 (diff) |
Rework clear clipboard feature (#1295)
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app/src')
12 files changed, 39 insertions, 17 deletions
diff --git a/app/src/androidTest/java/dev/msfjarvis/aps/util/settings/MigrationsTest.kt b/app/src/androidTest/java/dev/msfjarvis/aps/util/settings/MigrationsTest.kt index d27b4c1c..0c3afebe 100644 --- a/app/src/androidTest/java/dev/msfjarvis/aps/util/settings/MigrationsTest.kt +++ b/app/src/androidTest/java/dev/msfjarvis/aps/util/settings/MigrationsTest.kt @@ -13,6 +13,7 @@ import dev.msfjarvis.aps.Application import dev.msfjarvis.aps.util.extensions.getString import dev.msfjarvis.aps.util.extensions.sharedPrefs import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse import org.junit.Assert.assertNull import org.junit.Test @@ -104,4 +105,16 @@ class MigrationsTest { assertEquals(false, context.sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_FOLDERS, false)) assertEquals(true, context.sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_CONTENTS, false)) } + + @Test + fun verifyClearClipboardHistoryMigration() { + val context = Application.instance.applicationContext + context.sharedPrefs.edit { + clear() + putBoolean(PreferenceKeys.CLEAR_CLIPBOARD_20X, true) + } + runMigrations(context) + assertEquals(true, context.sharedPrefs.getBoolean(PreferenceKeys.CLEAR_CLIPBOARD_HISTORY, false)) + assertFalse(context.sharedPrefs.contains(PreferenceKeys.CLEAR_CLIPBOARD_20X)) + } } diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/settings/MiscSettings.kt b/app/src/main/java/dev/msfjarvis/aps/ui/settings/MiscSettings.kt index cb03878d..30a5db86 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/settings/MiscSettings.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/settings/MiscSettings.kt @@ -60,7 +60,7 @@ class MiscSettings(activity: FragmentActivity) : SettingsProvider { true } } - checkBox(PreferenceKeys.CLEAR_CLIPBOARD_20X) { + checkBox(PreferenceKeys.CLEAR_CLIPBOARD_HISTORY) { defaultValue = false titleRes = R.string.pref_clear_clipboard_title summaryRes = R.string.pref_clear_clipboard_summary diff --git a/app/src/main/java/dev/msfjarvis/aps/util/services/ClipboardService.kt b/app/src/main/java/dev/msfjarvis/aps/util/services/ClipboardService.kt index c0130ff1..bf62b506 100644 --- a/app/src/main/java/dev/msfjarvis/aps/util/services/ClipboardService.kt +++ b/app/src/main/java/dev/msfjarvis/aps/util/services/ClipboardService.kt @@ -80,7 +80,7 @@ class ClipboardService : Service() { } private fun clearClipboard() { - val deepClear = sharedPrefs.getBoolean(PreferenceKeys.CLEAR_CLIPBOARD_20X, false) + val deepClear = sharedPrefs.getBoolean(PreferenceKeys.CLEAR_CLIPBOARD_HISTORY, false) val clipboard = clipboard if (clipboard != null) { @@ -90,7 +90,7 @@ class ClipboardService : Service() { clipboard.setPrimaryClip(clip) if (deepClear) { withContext(Dispatchers.IO) { - repeat(20) { + repeat(CLIPBOARD_CLEAR_COUNT) { val count = (it * 500).toString() clipboard.setPrimaryClip(ClipData.newPlainText(count, count)) } @@ -179,5 +179,8 @@ class ClipboardService : Service() { const val EXTRA_NOTIFICATION_TIME = "EXTRA_NOTIFICATION_TIME" private const val ACTION_CLEAR = "ACTION_CLEAR_CLIPBOARD" private const val CHANNEL_ID = "NotificationService" + // Newest Samsung phones now feature a history of up to 30 items. To err on the side of caution, + // push 35 fake ones. + private const val CLIPBOARD_CLEAR_COUNT = 35 } } diff --git a/app/src/main/java/dev/msfjarvis/aps/util/settings/Migrations.kt b/app/src/main/java/dev/msfjarvis/aps/util/settings/Migrations.kt index fe855f3f..157a2665 100644 --- a/app/src/main/java/dev/msfjarvis/aps/util/settings/Migrations.kt +++ b/app/src/main/java/dev/msfjarvis/aps/util/settings/Migrations.kt @@ -24,6 +24,7 @@ fun runMigrations(context: Context) { migrateToGitUrlBasedConfig(sharedPrefs) migrateToHideAll(sharedPrefs) migrateToSshKey(context, sharedPrefs) + migrateToClipboardHistory(sharedPrefs) } private fun migrateToGitUrlBasedConfig(sharedPrefs: SharedPreferences) { @@ -112,3 +113,15 @@ private fun migrateToSshKey(context: Context, sharedPrefs: SharedPreferences) { } } } + +private fun migrateToClipboardHistory(sharedPrefs: SharedPreferences) { + if (sharedPrefs.contains(PreferenceKeys.CLEAR_CLIPBOARD_20X)) { + sharedPrefs.edit { + putBoolean( + PreferenceKeys.CLEAR_CLIPBOARD_HISTORY, + sharedPrefs.getBoolean(PreferenceKeys.CLEAR_CLIPBOARD_20X, false) + ) + remove(PreferenceKeys.CLEAR_CLIPBOARD_20X) + } + } +} diff --git a/app/src/main/java/dev/msfjarvis/aps/util/settings/PreferenceKeys.kt b/app/src/main/java/dev/msfjarvis/aps/util/settings/PreferenceKeys.kt index 930a5427..084b70c2 100644 --- a/app/src/main/java/dev/msfjarvis/aps/util/settings/PreferenceKeys.kt +++ b/app/src/main/java/dev/msfjarvis/aps/util/settings/PreferenceKeys.kt @@ -11,7 +11,12 @@ object PreferenceKeys { const val APP_VERSION = "app_version" const val AUTOFILL_ENABLE = "autofill_enable" const val BIOMETRIC_AUTH = "biometric_auth" + @Deprecated( + message = "Use CLEAR_CLIPBOARD_HISTORY instead", + replaceWith = ReplaceWith("PreferenceKeys.CLEAR_CLIPBOARD_HISTORY"), + ) const val CLEAR_CLIPBOARD_20X = "clear_clipboard_20x" + const val CLEAR_CLIPBOARD_HISTORY = "clear_clipboard_history" const val CLEAR_SAVED_PASS = "clear_saved_pass" const val COPY_ON_DECRYPT = "copy_on_decrypt" const val ENABLE_DEBUG_LOGGING = "enable_debug_logging" diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 50de1a02..119b1ed6 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -117,8 +117,6 @@ <string name="pref_category_autofill_title">Automatisch ausfüllen</string> <string name="pref_autofill_enable_title">Autofill aktivieren</string> <string name="pref_category_misc_title">Verschiedenes</string> - <string name="pref_clear_clipboard_title">Lösche die Zwischenablage 20-mal</string> - <string name="pref_clear_clipboard_summary">Speichert Nonsense 20-mal anstatt 1-mal in der Zwischenablage. Nützlich bspw. auf Samsung-Geräten, die den Verlauf der Zwischenablage speichern.</string> <string name="pref_git_delete_repo_summary">Lösche das lokale (versteckte) Repository</string> <string name="pref_external_repository_title">Externes Repository</string> <string name="pref_external_repository_summary">Nutze ein externes Repository</string> diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 73008ecf..16c85794 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -119,8 +119,6 @@ <string name="pref_category_autofill_title">Saisie automatique</string> <string name="pref_autofill_enable_title">Saisie automatique</string> <string name="pref_category_misc_title">Divers</string> - <string name="pref_clear_clipboard_title">Effacer le presse-papier 20 fois</string> - <string name="pref_clear_clipboard_summary">Enregistre des informations absurdes dans le presse-papier 20 fois à la place d\'une seule. Utile sur les téléphones Samsung qui disposent d\'un historique du presse-papier.</string> <string name="pref_git_delete_repo_summary">Supprime le dépot local (caché)</string> <string name="pref_external_repository_title">Dépôt externe</string> <string name="pref_external_repository_summary">Utilise un dépôt externe pour les mots de passe</string> diff --git a/app/src/main/res/values-gl/strings.xml b/app/src/main/res/values-gl/strings.xml index aec320b8..fd4d8734 100644 --- a/app/src/main/res/values-gl/strings.xml +++ b/app/src/main/res/values-gl/strings.xml @@ -121,8 +121,6 @@ <string name="pref_category_autofill_title">Completado automático</string> <string name="pref_autofill_enable_title">Activar completado automático</string> <string name="pref_category_misc_title">Varios</string> - <string name="pref_clear_clipboard_title">Baleirar portapapeis 20 veces</string> - <string name="pref_clear_clipboard_summary">Gardar números consecutivos no portapapeis 20 veces. Resulta útil nos móbiles Samsung que gardan historial no portapapeis.</string> <string name="pref_git_delete_repo_summary">Elimina repositorio local (oculto).</string> <string name="pref_external_repository_title">Repositorio externo</string> <string name="pref_external_repository_summary">Usar un repositorio externo de contrasinais</string> diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index ccce743c..8ae40951 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -121,8 +121,6 @@ <string name="pref_category_autofill_title">Auto-compilazione</string> <string name="pref_autofill_enable_title">Abilita Auto-Compilazione</string> <string name="pref_category_misc_title">Varie</string> - <string name="pref_clear_clipboard_title">Cancella 20 volte gli appunti</string> - <string name="pref_clear_clipboard_summary">Archivia i numeri consecutivi negli appunti per 20 volte. Utile sui telefoni Samsung che presentano la cronologia degli appunti.</string> <string name="pref_git_delete_repo_summary">Elimina repository locale (nascosta)</string> <string name="pref_external_repository_title">Repository Esterna</string> <string name="pref_external_repository_summary">Usa una repository di password esterna</string> diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 27094d17..7d616839 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -121,8 +121,6 @@ <string name="pref_category_autofill_title">Preenchimento Automático</string> <string name="pref_autofill_enable_title">Ativar preenchimento automático</string> <string name="pref_category_misc_title">Outros</string> - <string name="pref_clear_clipboard_title">Limpar área de transferência 20 vezes</string> - <string name="pref_clear_clipboard_summary">Armazene números consecutivos na área de transferência 20 vezes. Útil em telefones Samsung que apresentam o histórico da área de transferência.</string> <string name="pref_git_delete_repo_summary">Exclui o repositório local (oculto)</string> <string name="pref_external_repository_title">Repositório externo</string> <string name="pref_external_repository_summary">Use um repositório de senha externo</string> diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 39701817..ba5745fb 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -125,8 +125,6 @@ <string name="pref_category_autofill_title">Автозаполнение</string> <string name="pref_autofill_enable_title">Включить автозаполнение</string> <string name="pref_category_misc_title">Другое</string> - <string name="pref_clear_clipboard_title">Очистить буфер 20 раз</string> - <string name="pref_clear_clipboard_summary">Вставлять чепуху в буфер обмена 20 раз вместо одного. Полезно на некоторых моделях телефонов с запоминанием истории буфера обмена</string> <string name="pref_git_delete_repo_summary">Удалить локальный (скрытый) репозиторий</string> <string name="pref_external_repository_title">Внешний репозиторий</string> <string name="pref_external_repository_summary">Использовать внешний репозиторий</string> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 57af2db3..230be155 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -138,8 +138,8 @@ <string name="pref_category_autofill_title">Autofill</string> <string name="pref_autofill_enable_title">Enable Autofill</string> <string name="pref_category_misc_title">Misc</string> - <string name="pref_clear_clipboard_title">Clear clipboard 20 times</string> - <string name="pref_clear_clipboard_summary">Store consecutive numbers in the clipboard 20 times. Useful on Samsung phones that feature clipboard history.</string> + <string name="pref_clear_clipboard_title">Workaround clipboard history feature</string> + <string name="pref_clear_clipboard_summary">Enable to flood clipboard history on devices that include such a feature with consecutive numbers, flushing out any passwords</string> <string name="pref_git_delete_repo_summary">Deletes local (hidden) repository</string> <string name="pref_external_repository_title">External repository</string> <string name="pref_external_repository_summary">Use an external password repository</string> |