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-08-05 03:27:59 +02:00
|
|
|
import android.text.Html
|
2019-04-06 13:35:36 +02:00
|
|
|
import android.util.Log
|
2019-04-14 18:12:58 +02:00
|
|
|
import android.widget.HorizontalScrollView
|
|
|
|
|
import android.widget.TextView
|
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
|
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")
|
2019-04-06 13:35:36 +02:00
|
|
|
override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) {
|
|
|
|
|
title = "DEBUG MENU"
|
|
|
|
|
|
2019-08-05 03:27:59 +02:00
|
|
|
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"
|
|
|
|
|
MaterialDialog.Builder(context)
|
|
|
|
|
.customView(hView, true)
|
2020-04-04 22:30:05 +02:00
|
|
|
} catch (t: Throwable) {
|
2019-08-05 03:27:59 +02:00
|
|
|
view.text = "Function threw exception:\n\n${Log.getStackTraceString(t)}"
|
|
|
|
|
MaterialDialog.Builder(context)
|
|
|
|
|
.customView(hView, true)
|
|
|
|
|
}.show()
|
|
|
|
|
}
|
2019-04-06 13:35:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-05 03:27:59 +02:00
|
|
|
|
|
|
|
|
preferenceCategory {
|
|
|
|
|
title = "Toggles"
|
|
|
|
|
|
|
|
|
|
DebugToggles.values().forEach {
|
|
|
|
|
switchPreference {
|
|
|
|
|
title = it.name.replace('_', ' ').toLowerCase().capitalize()
|
|
|
|
|
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 {
|
|
|
|
|
private val MODIFIED_TEXT = Html.fromHtml("<font color='red'>MODIFIED</font>")
|
2019-04-06 13:35:36 +02:00
|
|
|
}
|
2020-04-04 22:30:05 +02:00
|
|
|
}
|