komikku/app/src/main/java/exh/debug/SettingsDebugController.kt

83 lines
3.1 KiB
Kotlin
Raw Normal View History

package exh.debug
2019-04-14 18:12:58 +02:00
import android.annotation.SuppressLint
import android.app.Activity
import android.util.Log
2019-04-14 18:12:58 +02:00
import android.widget.HorizontalScrollView
import android.widget.TextView
2020-04-21 23:18:31 +02:00
import androidx.core.text.HtmlCompat
import androidx.preference.PreferenceScreen
import com.afollestad.materialdialogs.MaterialDialog
2020-04-26 23:09:40 +02:00
import com.afollestad.materialdialogs.customview.customView
import eu.kanade.tachiyomi.ui.setting.SettingsController
import eu.kanade.tachiyomi.util.preference.defaultValue
import eu.kanade.tachiyomi.util.preference.onClick
import eu.kanade.tachiyomi.util.preference.preference
import eu.kanade.tachiyomi.util.preference.preferenceCategory
import eu.kanade.tachiyomi.util.preference.switchPreference
2019-04-14 18:12:58 +02:00
import kotlin.reflect.KVisibility
import kotlin.reflect.full.declaredFunctions
class SettingsDebugController : SettingsController() {
2019-04-14 18:12:58 +02:00
@SuppressLint("SetTextI18n")
#3520 Searchable Settings (#3683) * Adding class stubs for settings search, UI elements. * - implement searchable settings - `SettingsController.setupPreferenceScreen` must return a PreferenceScreen * Remove unneeded SettingsControllerFactory. * Set query hint, clean up code smell. * Add search button to MoreController, stop infinite recursion. * - initialize SearchResultCollection once in Activity.onCreate * - implement prefernce highlighting after settings search * - Ensure all Preferences have a key set or else the highlighting effect will have no effect on it. - remove ExtensionFilterController and SourceFilterController from settingControllersList in SettingsSearchHelper, since those are related to Extensions and not Settings * Limiting search to settings menu only, localized breadcrumb string, and code cleanup after code review. * - moved call to SettingsSearchHelper.initPreferenceSearchResultCollection() into SettingsSearchController * Code review cleanup and refactoring. * Inlined non-reused key strings. * Adding more UI polish, add comments for future enhancements. * - retain search query when navigating *away* from SettingsSearchController - keep `searchItem` in `expandActionView` state until user goes back (fixes the empty view in `SettingsSearchSearchController` issue) Co-authored-by: mpm11011 <markuscicero5@gmail.com> Co-authored-by: lmj0011 <9396189+lmj0011@users.noreply.github.com> (cherry picked from commit 766f9e37b52873080c58d73dfaff42c5add24dc0) # Conflicts: # app/build.gradle # app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceFilterController.kt # app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt # app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt # app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt
2020-09-23 04:23:38 +02:00
override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply {
title = "DEBUG MENU"
preferenceCategory {
title = "Functions"
DebugFunctions::class.declaredFunctions.filter {
it.visibility == KVisibility.PUBLIC
}.forEach {
preference {
title = it.name.replace(Regex("(.)(\\p{Upper})"), "$1 $2").toLowerCase().capitalize()
isPersistent = false
onClick {
val view = TextView(context)
view.setHorizontallyScrolling(true)
view.setTextIsSelectable(true)
val hView = HorizontalScrollView(context)
hView.addView(view)
try {
val result = it.call(DebugFunctions)
view.text = "Function returned result:\n\n$result"
2020-04-26 23:09:40 +02:00
MaterialDialog(context)
2020-05-02 06:46:24 +02:00
.customView(view = hView, scrollable = true)
} catch (t: Throwable) {
view.text = "Function threw exception:\n\n${Log.getStackTraceString(t)}"
2020-04-26 23:09:40 +02:00
MaterialDialog(context)
2020-05-02 06:46:24 +02:00
.customView(view = hView, scrollable = true)
}.show()
}
}
}
}
preferenceCategory {
title = "Toggles"
DebugToggles.values().forEach {
switchPreference {
title = it.name.replace('_', ' ').toLowerCase().capitalize()
key = it.prefKey
defaultValue = it.default
summaryOn = if (it.default) "" else MODIFIED_TEXT
summaryOff = if (it.default) MODIFIED_TEXT else ""
}
}
}
}
override fun onActivityStopped(activity: Activity) {
super.onActivityStopped(activity)
router.popCurrentController()
}
companion object {
2020-04-21 23:18:31 +02:00
private val MODIFIED_TEXT = HtmlCompat.fromHtml("<font color='red'>MODIFIED</font>", HtmlCompat.FROM_HTML_MODE_LEGACY)
}
}