refactor: debug settings
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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<Pair<String, () -> 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<ImageButton>(R.id.back_button).setOnClickListener {
|
||||
parent.removeView(settingsView)
|
||||
debugSettingsLayout.findViewById<ImageButton>(R.id.back_button).setOnClickListener {
|
||||
parent.removeView(debugSettingsLayout)
|
||||
}
|
||||
|
||||
settingsView.findViewById<TextView>(R.id.title).text = activity.translation["settings"]
|
||||
debugSettingsLayout.findViewById<TextView>(R.id.title).text = activity.translation["debug_settings"]
|
||||
|
||||
settingsView.findViewById<ListView>(R.id.setting_page_list).apply {
|
||||
adapter = SettingAdapter(activity, R.layout.debug_setting_item, mutableListOf<Pair<String, () -> Unit>>().apply {
|
||||
add(settingTranslation["clear_cache_title"] to {
|
||||
debugSettingsLayout.findViewById<ListView>(R.id.setting_page_list).apply {
|
||||
adapter = ActionListAdapter(activity, R.layout.debug_setting_item, mutableListOf<Pair<String, () -> 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)
|
||||
}
|
||||
}
|
||||
@@ -74,8 +74,8 @@ class DownloadManagerActivity : Activity() {
|
||||
|
||||
findViewById<TextView>(R.id.title).text = resources.getString(R.string.app_name) + " " + BuildConfig.VERSION_NAME
|
||||
|
||||
findViewById<ImageButton>(R.id.settings_button).setOnClickListener {
|
||||
SettingLayoutInflater(this).inflate(findViewById(android.R.id.content))
|
||||
findViewById<ImageButton>(R.id.debug_settings_button).setOnClickListener {
|
||||
DebugSettingsLayoutInflater(this).inflate(findViewById(android.R.id.content))
|
||||
}
|
||||
|
||||
with(findViewById<RecyclerView>(R.id.download_list)) {
|
||||
|
||||
4
app/src/main/res/drawable/debug_settings_icon.xml
Normal file
4
app/src/main/res/drawable/debug_settings_icon.xml
Normal file
@@ -0,0 +1,4 @@
|
||||
<vector android:height="30dp" android:viewportHeight="960"
|
||||
android:viewportWidth="960" android:width="30dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FFFFFF" android:pathData="M480,840q-65,0 -121,-31t-83,-89L160,720v-60h92q-7,-26 -7,-52.5L245,554h-86v-60h86q0,-29 0.5,-57.5T254,380h-94v-60h120q14,-28 37,-49t51,-35l-77,-76 40,-40 94,94q28,-10 56.5,-10t56.5,10l94,-94 40,40 -76,76q28,14 49.5,35.5T683,320h118v60h-95q9,28 8.5,56.5T714,494h87v60h-87q0,27 0.5,53.5T708,660h93v60L685,720q-26,59 -82.5,89.5T480,840ZM480,780q72,0 123,-50.5T654,607v-167q0,-72 -51,-122.5T480,267q-72,0 -123,50.5T306,440v167q0,72 51,122.5T480,780ZM400,640h160v-60L400,580v60ZM400,467h160v-60L400,407v60ZM480,524h0.5,-0.5 0.5,-0.5 0.5,-0.5 0.5,-0.5Z"/>
|
||||
</vector>
|
||||
@@ -27,11 +27,11 @@
|
||||
android:fontFamily="@font/avenir_next_bold" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/settings_button"
|
||||
android:id="@+id/debug_settings_button"
|
||||
android:layout_width="45dp"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@null"
|
||||
android:src="@drawable/settings_icon"
|
||||
android:src="@drawable/debug_settings_icon"
|
||||
android:layout_gravity="center_vertical|end"
|
||||
android:padding="8dp"
|
||||
android:contentDescription="@null" />
|
||||
|
||||
Reference in New Issue
Block a user