From 7c2bbb7c00e2cb248ee55a43d083e04360aba792 Mon Sep 17 00:00:00 2001 From: Jobobby04 Date: Sun, 24 Jul 2022 15:29:48 -0400 Subject: [PATCH] Minor cleanup --- app/src/main/java/exh/GalleryAdder.kt | 9 +- .../java/exh/debug/SettingsDebugController.kt | 182 +++++++++--------- .../java/exh/ui/batchadd/BatchAddPresenter.kt | 4 +- 3 files changed, 100 insertions(+), 95 deletions(-) diff --git a/app/src/main/java/exh/GalleryAdder.kt b/app/src/main/java/exh/GalleryAdder.kt index 710c833f4..2924180b8 100755 --- a/app/src/main/java/exh/GalleryAdder.kt +++ b/app/src/main/java/exh/GalleryAdder.kt @@ -34,6 +34,11 @@ class GalleryAdder( enabledLanguages().get() to disabledSources().get().map { it.toLong() }.toSet() } + private val Pair, Set>.enabledLangs + get() = first + private val Pair, Set>.disabledSources + get() = second + private val logger = xLogStack() fun pickSource(url: String): List { @@ -41,7 +46,7 @@ class GalleryAdder( return sourceManager.getVisibleCatalogueSources() .mapNotNull { it.getMainSource() } .filter { - it.lang in filters.first && it.id !in filters.second && try { + it.lang in filters.enabledLangs && it.id !in filters.disabledSources && try { it.matchesUri(uri) } catch (e: Exception) { false @@ -73,7 +78,7 @@ class GalleryAdder( sourceManager.getVisibleCatalogueSources() .mapNotNull { it.getMainSource() } .find { - it.lang in filters.first && it.id !in filters.second && try { + it.lang in filters.enabledLangs && it.id !in filters.disabledSources && try { it.matchesUri(uri) } catch (e: Exception) { false diff --git a/app/src/main/java/exh/debug/SettingsDebugController.kt b/app/src/main/java/exh/debug/SettingsDebugController.kt index 4ae1f0bf0..6537d577b 100644 --- a/app/src/main/java/exh/debug/SettingsDebugController.kt +++ b/app/src/main/java/exh/debug/SettingsDebugController.kt @@ -42,6 +42,7 @@ import androidx.compose.ui.unit.dp import eu.kanade.core.prefs.PreferenceMutableState 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.SwitchPreference import eu.kanade.tachiyomi.ui.base.controller.BasicComposeController @@ -80,100 +81,99 @@ class SettingsDebugController : BasicComposeController() { DebugToggles.values().map { DebugToggle(it.name, it.asPref(viewScope), it.default) } } } - if (functions != null) { - val scope = rememberCoroutineScope() - Box( - Modifier - .fillMaxSize() - .nestedScroll(nestedScrollInterop), - ) { - var running by remember { mutableStateOf(false) } - var result by remember { mutableStateOf?>(null) } - LazyColumn(Modifier.fillMaxSize()) { - item { - Text( - text = "Functions", - color = MaterialTheme.colorScheme.primary, - style = MaterialTheme.typography.bodyMedium, - modifier = Modifier.padding(16.dp), - ) - } - items(functions.orEmpty()) { (func, name) -> - PreferenceRow( - title = name, - onClick = { - scope.launch(Dispatchers.Default) { - val text = try { - running = true - "Function returned result:\n\n${func.call(DebugFunctions)}" - } catch (e: Exception) { - "Function threw exception:\n\n${Log.getStackTraceString(e)}" - } finally { - running = false - } - result = name to text - } - }, - ) - } - item { - Divider() - } - item { - Text( - text = "Toggles", - color = MaterialTheme.colorScheme.primary, - style = MaterialTheme.typography.bodyMedium, - modifier = Modifier.padding(16.dp), - ) - } - items(toggles) { (name, pref, default) -> - SwitchPreference( - preference = pref, - title = name.replace('_', ' ') - .lowercase(Locale.getDefault()) - .capitalize(Locale.getDefault()), - subtitleAnnotated = if (pref.value != default) { - AnnotatedString("MODIFIED", SpanStyle(color = Color.Red)) - } else null, - ) - } - item { - Spacer(modifier = Modifier.windowInsetsBottomHeight(WindowInsets.navigationBars)) - } - } - AnimatedVisibility( - running && result == null, - enter = fadeIn(), - exit = fadeOut(), - modifier = Modifier.fillMaxSize(), - ) { - Box( - Modifier - .fillMaxSize() - .background(color = Color.White.copy(alpha = 0.3F)) - .pointerInput(running && result == null) { - forEachGesture { - awaitPointerEventScope { - waitForUpOrCancellation()?.consume() - } - } - }, - contentAlignment = Alignment.Center, - ) { - CircularProgressIndicator() - } - } + if (functions == null) { + LoadingScreen() + return + } - ResultTextDialog( - result = result, - onDismissRequest = { result = null } - ) + val scope = rememberCoroutineScope() + Box( + Modifier + .fillMaxSize() + .nestedScroll(nestedScrollInterop), + ) { + var running by remember { mutableStateOf(false) } + var result by remember { mutableStateOf?>(null) } + LazyColumn(Modifier.fillMaxSize()) { + item { + Text( + text = "Functions", + color = MaterialTheme.colorScheme.primary, + style = MaterialTheme.typography.bodyMedium, + modifier = Modifier.padding(16.dp), + ) + } + items(functions.orEmpty()) { (func, name) -> + PreferenceRow( + title = name, + onClick = { + scope.launch(Dispatchers.Default) { + val text = try { + running = true + "Function returned result:\n\n${func.call(DebugFunctions)}" + } catch (e: Exception) { + "Function threw exception:\n\n${Log.getStackTraceString(e)}" + } finally { + running = false + } + result = name to text + } + }, + ) + } + item { + Divider() + } + item { + Text( + text = "Toggles", + color = MaterialTheme.colorScheme.primary, + style = MaterialTheme.typography.bodyMedium, + modifier = Modifier.padding(16.dp), + ) + } + items(toggles) { (name, pref, default) -> + SwitchPreference( + preference = pref, + title = name.replace('_', ' ') + .lowercase(Locale.getDefault()) + .capitalize(Locale.getDefault()), + subtitleAnnotated = if (pref.value != default) { + AnnotatedString("MODIFIED", SpanStyle(color = Color.Red)) + } else null, + ) + } + item { + Spacer(modifier = Modifier.windowInsetsBottomHeight(WindowInsets.navigationBars)) + } } - } else { - Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { - CircularProgressIndicator() + AnimatedVisibility( + running && result == null, + enter = fadeIn(), + exit = fadeOut(), + modifier = Modifier.fillMaxSize(), + ) { + Box( + Modifier + .fillMaxSize() + .background(color = Color.White.copy(alpha = 0.3F)) + .pointerInput(running && result == null) { + forEachGesture { + awaitPointerEventScope { + waitForUpOrCancellation()?.consume() + } + } + }, + contentAlignment = Alignment.Center, + ) { + CircularProgressIndicator() + } } + + ResultTextDialog( + result = result, + onDismissRequest = { result = null }, + ) } } diff --git a/app/src/main/java/exh/ui/batchadd/BatchAddPresenter.kt b/app/src/main/java/exh/ui/batchadd/BatchAddPresenter.kt index befe8e5d4..46b19dfec 100644 --- a/app/src/main/java/exh/ui/batchadd/BatchAddPresenter.kt +++ b/app/src/main/java/exh/ui/batchadd/BatchAddPresenter.kt @@ -3,11 +3,11 @@ package exh.ui.batchadd import android.content.Context import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.util.lang.withIOContext import exh.GalleryAddEvent import exh.GalleryAdder import exh.log.xLogE +import exh.ui.base.CoroutinePresenter import exh.util.trimOrNull import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.Dispatchers @@ -17,7 +17,7 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.launch import uy.kohesive.injekt.injectLazy -class BatchAddPresenter : BasePresenter() { +class BatchAddPresenter : CoroutinePresenter() { private val preferences: PreferencesHelper by injectLazy() private val galleryAdder by lazy { GalleryAdder() }