diff options
Diffstat (limited to 'app/src/main/java')
4 files changed, 24 insertions, 3 deletions
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" |