From 0d8bf10049f0f19e6c5b96f710b5b85aeffed317 Mon Sep 17 00:00:00 2001 From: rhunk <101876869+rhunk@users.noreply.github.com> Date: Fri, 23 Jun 2023 17:53:33 +0200 Subject: [PATCH] refactor: debug settings --- app/src/main/assets/lang/en_US.json | 4 +- app/src/main/assets/lang/fr_FR.json | 4 +- ...ater.kt => DebugSettingsLayoutInflater.kt} | 37 +++++++++++-------- .../ui/download/DownloadManagerActivity.kt | 4 +- .../main/res/drawable/debug_settings_icon.xml | 4 ++ .../res/layout/download_manager_activity.xml | 4 +- 6 files changed, 33 insertions(+), 24 deletions(-) rename app/src/main/kotlin/me/rhunk/snapenhance/ui/download/{SettingLayoutInflater.kt => DebugSettingsLayoutInflater.kt} (63%) create mode 100644 app/src/main/res/drawable/debug_settings_icon.xml diff --git a/app/src/main/assets/lang/en_US.json b/app/src/main/assets/lang/en_US.json index d475f5af..ab6ff285 100644 --- a/app/src/main/assets/lang/en_US.json +++ b/app/src/main/assets/lang/en_US.json @@ -375,8 +375,8 @@ "story_category": "Stories", "spotlight_category": "Spotlight" }, - "settings": "Settings", - "settings_page": { + "debug_settings": "Debug Settings", + "debug_settings_page": { "clear_file_title": "Clear {file_name} file", "clear_file_confirmation": "Are you sure you want to clear the {file_name} file?", "clear_cache_title": "Clear Cache", diff --git a/app/src/main/assets/lang/fr_FR.json b/app/src/main/assets/lang/fr_FR.json index 7c9d085b..6516aaac 100644 --- a/app/src/main/assets/lang/fr_FR.json +++ b/app/src/main/assets/lang/fr_FR.json @@ -375,8 +375,8 @@ "story_category": "Story", "spotlight_category": "Spotlight" }, - "settings": "Paramètres", - "settings_page": { + "debug_settings": "Paramètres de débogage", + "debug_settings_page": { "clear_file_title": "Supprimer le fichier {file_name}", "clear_file_confirmation": "Êtes-vous sûr de vouloir supprimer le fichier {file_name} ?", "clear_cache_title": "Supprimer le cache", diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/download/SettingLayoutInflater.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/download/DebugSettingsLayoutInflater.kt similarity index 63% rename from app/src/main/kotlin/me/rhunk/snapenhance/ui/download/SettingLayoutInflater.kt rename to app/src/main/kotlin/me/rhunk/snapenhance/ui/download/DebugSettingsLayoutInflater.kt index 77a479d9..93f7c5c3 100644 --- a/app/src/main/kotlin/me/rhunk/snapenhance/ui/download/SettingLayoutInflater.kt +++ b/app/src/main/kotlin/me/rhunk/snapenhance/ui/download/DebugSettingsLayoutInflater.kt @@ -1,6 +1,7 @@ package me.rhunk.snapenhance.ui.download import android.app.AlertDialog +import android.content.Intent import android.view.View import android.view.ViewGroup import android.widget.ArrayAdapter @@ -11,9 +12,10 @@ import android.widget.Toast import me.rhunk.snapenhance.R import me.rhunk.snapenhance.SharedContext import me.rhunk.snapenhance.bridge.common.impl.file.BridgeFileType +import me.rhunk.snapenhance.ui.config.ConfigActivity import java.io.File -class SettingAdapter( +class ActionListAdapter( private val activity: DownloadManagerActivity, private val layoutId: Int, private val actions: Array Unit>> @@ -32,7 +34,7 @@ class SettingAdapter( } } -class SettingLayoutInflater( +class DebugSettingsLayoutInflater( private val activity: DownloadManagerActivity ) { private fun confirmAction(title: String, message: String, action: () -> Unit) { @@ -53,19 +55,22 @@ class SettingLayoutInflater( } fun inflate(parent: ViewGroup) { - val settingsView = activity.layoutInflater.inflate(R.layout.debug_settings_page, parent, false) + val debugSettingsLayout = activity.layoutInflater.inflate(R.layout.debug_settings_page, parent, false) - val settingTranslation = activity.translation.getCategory("settings_page") + val debugSettingsTranslation = activity.translation.getCategory("debug_settings_page") - settingsView.findViewById(R.id.back_button).setOnClickListener { - parent.removeView(settingsView) + debugSettingsLayout.findViewById(R.id.back_button).setOnClickListener { + parent.removeView(debugSettingsLayout) } - settingsView.findViewById(R.id.title).text = activity.translation["settings"] + debugSettingsLayout.findViewById(R.id.title).text = activity.translation["debug_settings"] - settingsView.findViewById(R.id.setting_page_list).apply { - adapter = SettingAdapter(activity, R.layout.debug_setting_item, mutableListOf Unit>>().apply { - add(settingTranslation["clear_cache_title"] to { + debugSettingsLayout.findViewById(R.id.setting_page_list).apply { + adapter = ActionListAdapter(activity, R.layout.debug_setting_item, mutableListOf Unit>>().apply { + add(SharedContext.translation["config_activity.title"] to { + activity.startActivity(Intent(activity, ConfigActivity::class.java)) + }) + add(debugSettingsTranslation["clear_cache_title"] to { context.cacheDir.listFiles()?.forEach { it.deleteRecursively() } @@ -73,17 +78,17 @@ class SettingLayoutInflater( }) BridgeFileType.values().forEach { fileType -> - val actionName = settingTranslation.format("clear_file_title", "file_name" to fileType.displayName) + val actionName = debugSettingsTranslation.format("clear_file_title", "file_name" to fileType.displayName) add(actionName to { - confirmAction(actionName, settingTranslation.format("clear_file_confirmation", "file_name" to fileType.displayName)) { + confirmAction(actionName, debugSettingsTranslation.format("clear_file_confirmation", "file_name" to fileType.displayName)) { fileType.resolve(context).deleteRecursively() showSuccessToast() } }) } - add(settingTranslation["reset_all_title"] to { - confirmAction(settingTranslation["reset_all_title"], settingTranslation["reset_all_confirmation"]) { + add(debugSettingsTranslation["reset_all_title"] to { + confirmAction(debugSettingsTranslation["reset_all_title"], debugSettingsTranslation["reset_all_confirmation"]) { arrayOf(context.cacheDir, context.filesDir, File(context.dataDir, "databases"), File(context.dataDir, "shared_prefs")).forEach { it.listFiles()?.forEach { file -> file.deleteRecursively() @@ -96,9 +101,9 @@ class SettingLayoutInflater( } activity.registerBackCallback { - parent.removeView(settingsView) + parent.removeView(debugSettingsLayout) } - parent.addView(settingsView) + parent.addView(debugSettingsLayout) } } \ No newline at end of file diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/download/DownloadManagerActivity.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/download/DownloadManagerActivity.kt index 711f5b78..0efc0427 100644 --- a/app/src/main/kotlin/me/rhunk/snapenhance/ui/download/DownloadManagerActivity.kt +++ b/app/src/main/kotlin/me/rhunk/snapenhance/ui/download/DownloadManagerActivity.kt @@ -74,8 +74,8 @@ class DownloadManagerActivity : Activity() { findViewById(R.id.title).text = resources.getString(R.string.app_name) + " " + BuildConfig.VERSION_NAME - findViewById(R.id.settings_button).setOnClickListener { - SettingLayoutInflater(this).inflate(findViewById(android.R.id.content)) + findViewById(R.id.debug_settings_button).setOnClickListener { + DebugSettingsLayoutInflater(this).inflate(findViewById(android.R.id.content)) } with(findViewById(R.id.download_list)) { diff --git a/app/src/main/res/drawable/debug_settings_icon.xml b/app/src/main/res/drawable/debug_settings_icon.xml new file mode 100644 index 00000000..c3a5c95b --- /dev/null +++ b/app/src/main/res/drawable/debug_settings_icon.xml @@ -0,0 +1,4 @@ + + + diff --git a/app/src/main/res/layout/download_manager_activity.xml b/app/src/main/res/layout/download_manager_activity.xml index f08ff4bf..d3d413e5 100644 --- a/app/src/main/res/layout/download_manager_activity.xml +++ b/app/src/main/res/layout/download_manager_activity.xml @@ -27,11 +27,11 @@ android:fontFamily="@font/avenir_next_bold" />