Use Voyager on Sort Tags screen
This commit is contained in:
@@ -1,31 +1,29 @@
|
||||
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.genre.SortTagContent
|
||||
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.genre.SortTagPresenter
|
||||
import eu.kanade.tachiyomi.ui.category.genre.SortTagPresenter.Dialog
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import eu.kanade.tachiyomi.ui.category.genre.SortTagScreenState
|
||||
|
||||
@Composable
|
||||
fun SortTagScreen(
|
||||
presenter: SortTagPresenter,
|
||||
state: SortTagScreenState.Success,
|
||||
onClickCreate: () -> Unit,
|
||||
onClickDelete: (String) -> Unit,
|
||||
onClickMoveUp: (String, Int) -> Unit,
|
||||
onClickMoveDown: (String, Int) -> Unit,
|
||||
navigateUp: () -> Unit,
|
||||
) {
|
||||
val lazyListState = rememberLazyListState()
|
||||
@@ -40,56 +38,25 @@ fun SortTagScreen(
|
||||
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 -> {
|
||||
SortTagContent(
|
||||
state = presenter,
|
||||
lazyListState = lazyListState,
|
||||
paddingValues = paddingValues + topPaddingValues + PaddingValues(horizontal = horizontalPadding),
|
||||
onMoveUp = { tag, index -> presenter.moveUp(tag, index) },
|
||||
onMoveDown = { tag, index -> presenter.moveDown(tag, index) },
|
||||
)
|
||||
}
|
||||
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.createTag(it) },
|
||||
title = stringResource(R.string.add_tag),
|
||||
extraMessage = stringResource(R.string.action_add_tags_message),
|
||||
)
|
||||
}
|
||||
is Dialog.Delete -> {
|
||||
CategoryDeleteDialog(
|
||||
onDismissRequest = onDismissRequest,
|
||||
onDelete = { presenter.delete(dialog.tag) },
|
||||
title = stringResource(R.string.delete_tag),
|
||||
text = stringResource(R.string.delete_tag_confirmation, dialog.tag),
|
||||
)
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
LaunchedEffect(Unit) {
|
||||
presenter.events.collectLatest { event ->
|
||||
when (event) {
|
||||
is SortTagPresenter.Event.TagExists -> {
|
||||
context.toast(R.string.error_tag_exists)
|
||||
}
|
||||
is SortTagPresenter.Event.InternalError -> {
|
||||
context.toast(R.string.internal_error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SortTagContent(
|
||||
tags = state.tags,
|
||||
lazyListState = lazyListState,
|
||||
paddingValues = paddingValues + topPaddingValues + PaddingValues(horizontal = horizontalPadding),
|
||||
onClickDelete = onClickDelete,
|
||||
onMoveUp = onClickMoveUp,
|
||||
onMoveDown = onClickMoveDown,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.genre.SortTagPresenter
|
||||
|
||||
@Stable
|
||||
interface SortTagState {
|
||||
val isLoading: Boolean
|
||||
var dialog: SortTagPresenter.Dialog?
|
||||
val tags: List<String>
|
||||
val isEmpty: Boolean
|
||||
}
|
||||
|
||||
fun SortTagState(): SortTagState {
|
||||
return SortTagStateImpl()
|
||||
}
|
||||
|
||||
class SortTagStateImpl : SortTagState {
|
||||
override var isLoading: Boolean by mutableStateOf(true)
|
||||
override var dialog: SortTagPresenter.Dialog? by mutableStateOf(null)
|
||||
override var tags: List<String> by mutableStateOf(emptyList())
|
||||
override val isEmpty: Boolean by derivedStateOf { tags.isEmpty() }
|
||||
}
|
||||
+4
-6
@@ -7,25 +7,23 @@ import androidx.compose.foundation.lazy.itemsIndexed
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import eu.kanade.presentation.category.SortTagState
|
||||
import eu.kanade.presentation.components.LazyColumn
|
||||
import eu.kanade.tachiyomi.ui.category.genre.SortTagPresenter
|
||||
|
||||
@Composable
|
||||
fun SortTagContent(
|
||||
state: SortTagState,
|
||||
tags: List<String>,
|
||||
lazyListState: LazyListState,
|
||||
paddingValues: PaddingValues,
|
||||
onClickDelete: (String) -> Unit,
|
||||
onMoveUp: (String, Int) -> Unit,
|
||||
onMoveDown: (String, Int) -> Unit,
|
||||
) {
|
||||
val tags = state.tags
|
||||
LazyColumn(
|
||||
state = lazyListState,
|
||||
contentPadding = paddingValues,
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
itemsIndexed(tags) { index, tag ->
|
||||
itemsIndexed(tags, key = { _, tag -> tag }) { index, tag ->
|
||||
SortTagListItem(
|
||||
modifier = Modifier.animateItemPlacement(),
|
||||
tag = tag,
|
||||
@@ -33,7 +31,7 @@ fun SortTagContent(
|
||||
canMoveDown = index != tags.lastIndex,
|
||||
onMoveUp = { onMoveUp(tag, index) },
|
||||
onMoveDown = { onMoveDown(tag, index) },
|
||||
onDelete = { state.dialog = SortTagPresenter.Dialog.Delete(tag) },
|
||||
onDelete = { onClickDelete(tag) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user