Use Voyager on Source Category screen
This commit is contained in:
@@ -1,32 +1,28 @@
|
||||
package eu.kanade.presentation.category
|
||||
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import eu.kanade.presentation.category.components.CategoryCreateDialog
|
||||
import eu.kanade.presentation.category.components.CategoryDeleteDialog
|
||||
import eu.kanade.presentation.category.components.CategoryFloatingActionButton
|
||||
import eu.kanade.presentation.category.components.CategoryRenameDialog
|
||||
import eu.kanade.presentation.category.components.sources.SourceCategoryContent
|
||||
import eu.kanade.presentation.components.AppBar
|
||||
import eu.kanade.presentation.components.EmptyScreen
|
||||
import eu.kanade.presentation.components.LoadingScreen
|
||||
import eu.kanade.presentation.components.Scaffold
|
||||
import eu.kanade.presentation.util.horizontalPadding
|
||||
import eu.kanade.presentation.util.plus
|
||||
import eu.kanade.presentation.util.topPaddingValues
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.ui.category.sources.SourceCategoryPresenter
|
||||
import eu.kanade.tachiyomi.ui.category.sources.SourceCategoryPresenter.Dialog
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import eu.kanade.tachiyomi.ui.category.sources.SourceCategoryScreenState
|
||||
|
||||
@Composable
|
||||
fun SourceCategoryScreen(
|
||||
presenter: SourceCategoryPresenter,
|
||||
state: SourceCategoryScreenState.Success,
|
||||
onClickCreate: () -> Unit,
|
||||
onClickRename: (String) -> Unit,
|
||||
onClickDelete: (String) -> Unit,
|
||||
navigateUp: () -> Unit,
|
||||
) {
|
||||
val lazyListState = rememberLazyListState()
|
||||
@@ -41,63 +37,24 @@ fun SourceCategoryScreen(
|
||||
floatingActionButton = {
|
||||
CategoryFloatingActionButton(
|
||||
lazyListState = lazyListState,
|
||||
onCreate = { presenter.dialog = Dialog.Create },
|
||||
onCreate = onClickCreate,
|
||||
)
|
||||
},
|
||||
) { paddingValues ->
|
||||
val context = LocalContext.current
|
||||
when {
|
||||
presenter.isLoading -> LoadingScreen()
|
||||
presenter.isEmpty -> EmptyScreen(textResource = R.string.information_empty_category)
|
||||
else -> {
|
||||
SourceCategoryContent(
|
||||
state = presenter,
|
||||
lazyListState = lazyListState,
|
||||
paddingValues = paddingValues + topPaddingValues + PaddingValues(horizontal = horizontalPadding),
|
||||
)
|
||||
}
|
||||
if (state.isEmpty) {
|
||||
EmptyScreen(
|
||||
textResource = R.string.information_empty_category,
|
||||
modifier = Modifier.padding(paddingValues),
|
||||
)
|
||||
return@Scaffold
|
||||
}
|
||||
|
||||
val onDismissRequest = { presenter.dialog = null }
|
||||
when (val dialog = presenter.dialog) {
|
||||
Dialog.Create -> {
|
||||
CategoryCreateDialog(
|
||||
onDismissRequest = onDismissRequest,
|
||||
onCreate = { presenter.createCategory(it) },
|
||||
title = stringResource(R.string.action_add_category),
|
||||
)
|
||||
}
|
||||
is Dialog.Rename -> {
|
||||
CategoryRenameDialog(
|
||||
onDismissRequest = onDismissRequest,
|
||||
onRename = { presenter.renameCategory(dialog.category, it) },
|
||||
category = dialog.category,
|
||||
)
|
||||
}
|
||||
is Dialog.Delete -> {
|
||||
CategoryDeleteDialog(
|
||||
onDismissRequest = onDismissRequest,
|
||||
onDelete = { presenter.deleteCategory(dialog.category) },
|
||||
title = stringResource(R.string.delete_category),
|
||||
text = stringResource(R.string.delete_category_confirmation, dialog.category),
|
||||
)
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
LaunchedEffect(Unit) {
|
||||
presenter.events.collectLatest { event ->
|
||||
when (event) {
|
||||
is SourceCategoryPresenter.Event.CategoryExists -> {
|
||||
context.toast(R.string.error_category_exists)
|
||||
}
|
||||
is SourceCategoryPresenter.Event.InternalError -> {
|
||||
context.toast(R.string.internal_error)
|
||||
}
|
||||
SourceCategoryPresenter.Event.InvalidName -> {
|
||||
context.toast(R.string.invalid_category_name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SourceCategoryContent(
|
||||
categories = state.categories,
|
||||
lazyListState = lazyListState,
|
||||
paddingValues = paddingValues + topPaddingValues + PaddingValues(horizontal = horizontalPadding),
|
||||
onClickRename = onClickRename,
|
||||
onClickDelete = onClickDelete,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package eu.kanade.presentation.category
|
||||
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.runtime.derivedStateOf
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import eu.kanade.tachiyomi.ui.category.sources.SourceCategoryPresenter
|
||||
|
||||
@Stable
|
||||
interface SourceCategoryState {
|
||||
val isLoading: Boolean
|
||||
var dialog: SourceCategoryPresenter.Dialog?
|
||||
val categories: List<String>
|
||||
val isEmpty: Boolean
|
||||
}
|
||||
|
||||
fun SourceCategoryState(): SourceCategoryState {
|
||||
return SourceCategoryStateImpl()
|
||||
}
|
||||
|
||||
class SourceCategoryStateImpl : SourceCategoryState {
|
||||
override var isLoading: Boolean by mutableStateOf(true)
|
||||
override var dialog: SourceCategoryPresenter.Dialog? by mutableStateOf(null)
|
||||
override var categories: List<String> by mutableStateOf(emptyList())
|
||||
override val isEmpty: Boolean by derivedStateOf { categories.isEmpty() }
|
||||
}
|
||||
+6
-7
@@ -7,28 +7,27 @@ import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import eu.kanade.presentation.category.SourceCategoryState
|
||||
import eu.kanade.presentation.components.LazyColumn
|
||||
import eu.kanade.tachiyomi.ui.category.sources.SourceCategoryPresenter
|
||||
|
||||
@Composable
|
||||
fun SourceCategoryContent(
|
||||
state: SourceCategoryState,
|
||||
categories: List<String>,
|
||||
lazyListState: LazyListState,
|
||||
paddingValues: PaddingValues,
|
||||
onClickRename: (String) -> Unit,
|
||||
onClickDelete: (String) -> Unit,
|
||||
) {
|
||||
val categories = state.categories
|
||||
LazyColumn(
|
||||
state = lazyListState,
|
||||
contentPadding = paddingValues,
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
items(categories) { category ->
|
||||
items(categories, key = { it }) { category ->
|
||||
SourceCategoryListItem(
|
||||
modifier = Modifier.animateItemPlacement(),
|
||||
category = category,
|
||||
onRename = { state.dialog = SourceCategoryPresenter.Dialog.Rename(category) },
|
||||
onDelete = { state.dialog = SourceCategoryPresenter.Dialog.Delete(category) },
|
||||
onRename = { onClickRename(category) },
|
||||
onDelete = { onClickDelete(category) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user