Add button to reorder categories alphabetically (#9369)

Closes #6459

Co-authored-by: arkon <arkon@users.noreply.github.com>
This commit is contained in:
Pauline
2023-10-09 00:55:15 +02:00
committed by GitHub
parent 8568d5d6c3
commit 77ebc362f6
6 changed files with 106 additions and 3 deletions

View File

@@ -12,6 +12,7 @@ import eu.kanade.presentation.category.CategoryScreen
import eu.kanade.presentation.category.components.CategoryCreateDialog
import eu.kanade.presentation.category.components.CategoryDeleteDialog
import eu.kanade.presentation.category.components.CategoryRenameDialog
import eu.kanade.presentation.category.components.CategorySortAlphabeticallyDialog
import eu.kanade.presentation.util.Screen
import eu.kanade.tachiyomi.util.system.toast
import kotlinx.coroutines.flow.collectLatest
@@ -37,6 +38,7 @@ class CategoryScreen : Screen() {
CategoryScreen(
state = successState,
onClickCreate = { screenModel.showDialog(CategoryDialog.Create) },
onClickSortAlphabetically = { screenModel.showDialog(CategoryDialog.SortAlphabetically) },
onClickRename = { screenModel.showDialog(CategoryDialog.Rename(it)) },
onClickDelete = { screenModel.showDialog(CategoryDialog.Delete(it)) },
onClickMoveUp = screenModel::moveUp,
@@ -68,6 +70,12 @@ class CategoryScreen : Screen() {
category = dialog.category,
)
}
is CategoryDialog.SortAlphabetically -> {
CategorySortAlphabeticallyDialog(
onDismissRequest = screenModel::dismissDialog,
onSort = { screenModel.sortAlphabetically() },
)
}
}
LaunchedEffect(Unit) {

View File

@@ -61,6 +61,15 @@ class CategoryScreenModel(
}
}
fun sortAlphabetically() {
coroutineScope.launch {
when (reorderCategory.sortAlphabetically()) {
is ReorderCategory.Result.InternalError -> _events.send(CategoryEvent.InternalError)
else -> {}
}
}
}
fun moveUp(category: Category) {
coroutineScope.launch {
when (reorderCategory.moveUp(category)) {
@@ -109,6 +118,7 @@ class CategoryScreenModel(
sealed interface CategoryDialog {
data object Create : CategoryDialog
data object SortAlphabetically : CategoryDialog
data class Rename(val category: Category) : CategoryDialog
data class Delete(val category: Category) : CategoryDialog
}