Better debug menu
This commit is contained in:
parent
6da504c999
commit
07fd3575c5
@ -4,11 +4,15 @@ import com.pushtorefresh.storio.sqlite.queries.RawQuery
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.tables.MangaTable
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import exh.EH_SOURCE_ID
|
||||
import exh.EXH_SOURCE_ID
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
||||
object DebugFunctions {
|
||||
val db: DatabaseHelper by injectLazy()
|
||||
val prefs: PreferencesHelper by injectLazy()
|
||||
val sourceManager: SourceManager by injectLazy()
|
||||
|
||||
fun addAllMangaInDatabaseToLibrary() {
|
||||
db.inTransaction {
|
||||
@ -35,4 +39,23 @@ object DebugFunctions {
|
||||
}
|
||||
|
||||
fun clearSavedSearches() = prefs.eh_savedSearches().set(emptySet())
|
||||
|
||||
fun listAllSources() = sourceManager.getCatalogueSources().map {
|
||||
"${it.id}: ${it.name} (${it.lang.toUpperCase()})"
|
||||
}.joinToString("\n")
|
||||
|
||||
fun convertAllEhentaiGalleriesToExhentai() = convertSources(EH_SOURCE_ID, EXH_SOURCE_ID)
|
||||
|
||||
fun convertAllExhentaiGalleriesToEhentai() = convertSources(EXH_SOURCE_ID, EH_SOURCE_ID)
|
||||
|
||||
private fun convertSources(from: Long, to: Long) {
|
||||
db.lowLevel().executeSQL(RawQuery.builder()
|
||||
.query("""
|
||||
UPDATE ${MangaTable.TABLE}
|
||||
SET ${MangaTable.COL_SOURCE} = $to
|
||||
WHERE ${MangaTable.COL_SOURCE} = $from
|
||||
""".trimIndent())
|
||||
.affectsTables(MangaTable.TABLE)
|
||||
.build())
|
||||
}
|
||||
}
|
@ -1,30 +1,46 @@
|
||||
package exh.debug
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.support.v7.preference.PreferenceScreen
|
||||
import android.util.Log
|
||||
import android.widget.HorizontalScrollView
|
||||
import android.widget.TextView
|
||||
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
|
||||
import kotlin.reflect.KVisibility
|
||||
import kotlin.reflect.full.declaredFunctions
|
||||
|
||||
class SettingsDebugController : SettingsController() {
|
||||
@SuppressLint("SetTextI18n")
|
||||
override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) {
|
||||
title = "DEBUG MENU"
|
||||
|
||||
DebugFunctions::class.declaredFunctions.forEach {
|
||||
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)
|
||||
.content("Function returned result:\n\n$result")
|
||||
.customView(hView, true)
|
||||
} catch(t: Throwable) {
|
||||
view.text = "Function threw exception:\n\n${Log.getStackTraceString(t)}"
|
||||
MaterialDialog.Builder(context)
|
||||
.content("Function threw exception:\n\n${Log.getStackTraceString(t)}")
|
||||
.customView(hView, true)
|
||||
}.show()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user