2019-04-06 13:35:36 +02:00
|
|
|
package exh.debug
|
|
|
|
|
|
2019-04-14 18:12:58 +02:00
|
|
|
import android.annotation.SuppressLint
|
2019-04-06 13:35:36 +02:00
|
|
|
import android.support.v7.preference.PreferenceScreen
|
|
|
|
|
import android.util.Log
|
2019-04-14 18:12:58 +02:00
|
|
|
import android.widget.HorizontalScrollView
|
|
|
|
|
import android.widget.TextView
|
2019-04-06 13:35:36 +02:00
|
|
|
import com.afollestad.materialdialogs.MaterialDialog
|
|
|
|
|
import eu.kanade.tachiyomi.ui.setting.SettingsController
|
|
|
|
|
import eu.kanade.tachiyomi.ui.setting.onClick
|
|
|
|
|
import eu.kanade.tachiyomi.ui.setting.preference
|
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-04-14 18:12:58 +02:00
|
|
|
DebugFunctions::class.declaredFunctions.filter {
|
|
|
|
|
it.visibility == KVisibility.PUBLIC
|
|
|
|
|
}.forEach {
|
2019-04-06 13:35:36 +02:00
|
|
|
preference {
|
|
|
|
|
title = it.name.replace(Regex("(.)(\\p{Upper})"), "$1 $2").toLowerCase().capitalize()
|
|
|
|
|
isPersistent = false
|
|
|
|
|
|
|
|
|
|
onClick {
|
2019-04-14 18:12:58 +02:00
|
|
|
val view = TextView(context)
|
|
|
|
|
view.setHorizontallyScrolling(true)
|
|
|
|
|
view.setTextIsSelectable(true)
|
|
|
|
|
|
|
|
|
|
val hView = HorizontalScrollView(context)
|
|
|
|
|
hView.addView(view)
|
|
|
|
|
|
2019-04-06 13:35:36 +02:00
|
|
|
try {
|
|
|
|
|
val result = it.call(DebugFunctions)
|
2019-04-14 18:12:58 +02:00
|
|
|
view.text = "Function returned result:\n\n$result"
|
2019-04-06 13:35:36 +02:00
|
|
|
MaterialDialog.Builder(context)
|
2019-04-14 18:12:58 +02:00
|
|
|
.customView(hView, true)
|
2019-04-06 13:35:36 +02:00
|
|
|
} catch(t: Throwable) {
|
2019-04-14 18:12:58 +02:00
|
|
|
view.text = "Function threw exception:\n\n${Log.getStackTraceString(t)}"
|
2019-04-06 13:35:36 +02:00
|
|
|
MaterialDialog.Builder(context)
|
2019-04-14 18:12:58 +02:00
|
|
|
.customView(hView, true)
|
2019-04-06 13:35:36 +02:00
|
|
|
}.show()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|