Minor cleanup

This commit is contained in:
Jobobby04 2022-07-24 15:29:48 -04:00
parent 87d7a47b8e
commit 7c2bbb7c00
3 changed files with 100 additions and 95 deletions

View File

@ -34,6 +34,11 @@ class GalleryAdder(
enabledLanguages().get() to disabledSources().get().map { it.toLong() }.toSet()
}
private val Pair<Set<String>, Set<Long>>.enabledLangs
get() = first
private val Pair<Set<String>, Set<Long>>.disabledSources
get() = second
private val logger = xLogStack()
fun pickSource(url: String): List<UrlImportableSource> {
@ -41,7 +46,7 @@ class GalleryAdder(
return sourceManager.getVisibleCatalogueSources()
.mapNotNull { it.getMainSource<UrlImportableSource>() }
.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<UrlImportableSource>() }
.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

View File

@ -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<Pair<String, String>?>(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<Pair<String, String>?>(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 },
)
}
}

View File

@ -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<BatchAddController>() {
class BatchAddPresenter : CoroutinePresenter<BatchAddController>() {
private val preferences: PreferencesHelper by injectLazy()
private val galleryAdder by lazy { GalleryAdder() }