Convert Debug Menu to a FullComposeController

This commit is contained in:
Jobobby04 2022-08-31 17:04:10 -04:00
parent 9dad9a6551
commit aaa2a961ae
2 changed files with 50 additions and 41 deletions

View File

@ -51,28 +51,6 @@ abstract class ComposeController<P : Presenter<*>>(bundle: Bundle? = null) :
}
}
/**
* Basic Compose controller without a presenter.
*/
abstract class BasicComposeController(bundle: Bundle? = null) :
BaseController<ComposeControllerBinding>(bundle),
ComposeContentController {
override fun createBinding(inflater: LayoutInflater) =
ComposeControllerBinding.inflate(inflater)
override fun onViewCreated(view: View) {
super.onViewCreated(view)
binding.root.apply {
setComposeContent {
val nestedScrollInterop = rememberNestedScrollInteropConnection()
ComposeContent(nestedScrollInterop)
}
}
}
}
/**
* Basic Compose controller without a presenter.
*/

View File

@ -3,18 +3,24 @@ package exh.debug
import android.app.Activity
import android.util.Log
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.Crossfade
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.forEachGesture
import androidx.compose.foundation.gestures.waitForUpOrCancellation
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.windowInsetsBottomHeight
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.selection.SelectionContainer
@ -23,6 +29,8 @@ import androidx.compose.material3.AlertDialog
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.rememberTopAppBarState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
@ -33,19 +41,22 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.unit.dp
import eu.kanade.core.prefs.PreferenceMutableState
import eu.kanade.presentation.components.AppBar
import eu.kanade.presentation.components.Divider
import eu.kanade.presentation.components.LazyColumn
import eu.kanade.presentation.components.LoadingScreen
import eu.kanade.presentation.components.PreferenceRow
import eu.kanade.presentation.components.Scaffold
import eu.kanade.presentation.components.ScrollbarLazyColumn
import eu.kanade.presentation.components.SwitchPreference
import eu.kanade.tachiyomi.ui.base.controller.BasicComposeController
import eu.kanade.presentation.util.plus
import eu.kanade.presentation.util.topPaddingValues
import eu.kanade.tachiyomi.ui.base.controller.BasicFullComposeController
import exh.util.capitalize
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@ -55,16 +66,14 @@ import kotlin.reflect.KFunction
import kotlin.reflect.KVisibility
import kotlin.reflect.full.declaredFunctions
class SettingsDebugController : BasicComposeController() {
override fun getTitle(): String {
return "DEBUG MENU"
}
class SettingsDebugController : BasicFullComposeController() {
data class DebugToggle(val name: String, val pref: PreferenceMutableState<Boolean>, val default: Boolean)
@Composable
override fun ComposeContent(nestedScrollInterop: NestedScrollConnection) {
override fun ComposeContent() {
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())
val insets = WindowInsets.navigationBars.only(WindowInsetsSides.Horizontal)
val functions by produceState<List<Pair<KFunction<*>, String>>?>(initialValue = null) {
value = withContext(Dispatchers.Default) {
DebugFunctions::class.declaredFunctions.filter {
@ -81,20 +90,42 @@ class SettingsDebugController : BasicComposeController() {
DebugToggles.values().map { DebugToggle(it.name, it.asPref(viewScope), it.default) }
}
}
if (functions == null) {
LoadingScreen()
return
Scaffold(
modifier = Modifier
.windowInsetsPadding(insets)
.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
AppBar(
title = "DEBUG MENU",
scrollBehavior = scrollBehavior,
)
},
) { paddingValues ->
Crossfade(functions == null) {
when (it) {
true -> LoadingScreen()
false -> FunctionList(paddingValues, functions.orEmpty(), toggles)
}
}
}
}
@Composable
fun FunctionList(
paddingValues: PaddingValues,
functions: List<Pair<KFunction<*>, String>>,
toggles: List<DebugToggle>
) {
val scope = rememberCoroutineScope()
Box(
Modifier
.fillMaxSize()
.nestedScroll(nestedScrollInterop),
) {
Box(Modifier.fillMaxSize()) {
var running by remember { mutableStateOf(false) }
var result by remember { mutableStateOf<Pair<String, String>?>(null) }
LazyColumn(Modifier.fillMaxSize()) {
ScrollbarLazyColumn(
Modifier.fillMaxSize(),
contentPadding = paddingValues +
WindowInsets.navigationBars.only(WindowInsetsSides.Vertical).asPaddingValues() +
topPaddingValues,
) {
item {
Text(
text = "Functions",
@ -103,7 +134,7 @@ class SettingsDebugController : BasicComposeController() {
modifier = Modifier.padding(16.dp),
)
}
items(functions.orEmpty()) { (func, name) ->
items(functions) { (func, name) ->
PreferenceRow(
title = name,
onClick = {