2019-04-06 13:35:36 +02:00
|
|
|
package exh.debug
|
|
|
|
|
|
2019-04-14 18:12:58 +02:00
|
|
|
import android.annotation.SuppressLint
|
2019-08-13 03:09:39 +02:00
|
|
|
import android.app.Activity
|
2019-04-06 13:35:36 +02:00
|
|
|
import android.util.Log
|
2020-04-21 23:18:31 +02:00
|
|
|
import androidx.core.text.HtmlCompat
|
2020-01-06 09:26:31 +01:00
|
|
|
import androidx.preference.PreferenceScreen
|
2019-04-06 13:35:36 +02:00
|
|
|
import com.afollestad.materialdialogs.MaterialDialog
|
2020-04-04 22:30:05 +02:00
|
|
|
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
|
2021-06-02 06:10:36 +02:00
|
|
|
import exh.util.capitalize
|
2020-11-11 23:30:38 +01:00
|
|
|
import java.util.Locale
|
2019-04-14 18:12:58 +02:00
|
|
|
import kotlin.reflect.KVisibility
|
2019-04-06 13:35:36 +02:00
|
|
|
import kotlin.reflect.full.declaredFunctions
|
|
|
|
|
|
|
|
|
|
class SettingsDebugController : SettingsController() {
|
2019-04-14 18:12:58 +02:00
|
|
|
@SuppressLint("SetTextI18n")
|
2020-09-23 04:23:38 +02:00
|
|
|
override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply {
|
2019-04-06 13:35:36 +02:00
|
|
|
title = "DEBUG MENU"
|
|
|
|
|
|
2019-08-05 03:27:59 +02:00
|
|
|
preferenceCategory {
|
|
|
|
|
title = "Functions"
|
|
|
|
|
|
|
|
|
|
DebugFunctions::class.declaredFunctions.filter {
|
|
|
|
|
it.visibility == KVisibility.PUBLIC
|
|
|
|
|
}.forEach {
|
|
|
|
|
preference {
|
2021-06-02 03:09:03 +02:00
|
|
|
title = it.name.replace("(.)(\\p{Upper})".toRegex(), "$1 $2").lowercase(Locale.getDefault()).capitalize(Locale.getDefault())
|
2019-08-05 03:27:59 +02:00
|
|
|
isPersistent = false
|
|
|
|
|
|
|
|
|
|
onClick {
|
|
|
|
|
try {
|
|
|
|
|
val result = it.call(DebugFunctions)
|
2021-07-04 23:14:07 +02:00
|
|
|
val text = "Function returned result:\n\n$result"
|
2020-04-26 23:09:40 +02:00
|
|
|
MaterialDialog(context)
|
2021-07-04 23:14:07 +02:00
|
|
|
.title(text = title.toString())
|
|
|
|
|
.message(text = text) {
|
|
|
|
|
messageTextView.apply {
|
|
|
|
|
setHorizontallyScrolling(true)
|
|
|
|
|
setTextIsSelectable(true)
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-04 22:30:05 +02:00
|
|
|
} catch (t: Throwable) {
|
2021-07-04 23:14:07 +02:00
|
|
|
val text = "Function threw exception:\n\n${Log.getStackTraceString(t)}"
|
2020-04-26 23:09:40 +02:00
|
|
|
MaterialDialog(context)
|
2021-07-04 23:14:07 +02:00
|
|
|
.message(text = text) {
|
|
|
|
|
messageTextView.apply {
|
|
|
|
|
setHorizontallyScrolling(true)
|
|
|
|
|
setTextIsSelectable(true)
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-05 03:27:59 +02:00
|
|
|
}.show()
|
|
|
|
|
}
|
2019-04-06 13:35:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-05 03:27:59 +02:00
|
|
|
|
|
|
|
|
preferenceCategory {
|
|
|
|
|
title = "Toggles"
|
|
|
|
|
|
|
|
|
|
DebugToggles.values().forEach {
|
|
|
|
|
switchPreference {
|
2021-06-02 03:09:03 +02:00
|
|
|
title = it.name.replace('_', ' ').lowercase(Locale.getDefault()).capitalize(Locale.getDefault())
|
2019-08-05 03:27:59 +02:00
|
|
|
key = it.prefKey
|
|
|
|
|
defaultValue = it.default
|
2020-04-04 22:30:05 +02:00
|
|
|
summaryOn = if (it.default) "" else MODIFIED_TEXT
|
|
|
|
|
summaryOff = if (it.default) MODIFIED_TEXT else ""
|
2019-08-05 03:27:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-13 03:09:39 +02:00
|
|
|
override fun onActivityStopped(activity: Activity) {
|
|
|
|
|
super.onActivityStopped(activity)
|
|
|
|
|
router.popCurrentController()
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 03:27:59 +02:00
|
|
|
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)
|
2019-04-06 13:35:36 +02:00
|
|
|
}
|
2020-04-04 22:30:05 +02:00
|
|
|
}
|