mirror of
https://github.com/mihonapp/mihon.git
synced 2025-03-01 18:34:13 +01:00
Remove alphabetical category sort option (#1781)
This commit is contained in:
parent
4db3817782
commit
2b0c28938b
@ -35,6 +35,9 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
|
|||||||
- Fix App's preferences referencing deleted categories ([@cuong-tran](https://github.com/cuong-tran)) ([#1734](https://github.com/mihonapp/mihon/pull/1734))
|
- Fix App's preferences referencing deleted categories ([@cuong-tran](https://github.com/cuong-tran)) ([#1734](https://github.com/mihonapp/mihon/pull/1734))
|
||||||
- Fix backup/restore of category related preferences ([@cuong-tran](https://github.com/cuong-tran)) ([#1726](https://github.com/mihonapp/mihon/pull/1726))
|
- Fix backup/restore of category related preferences ([@cuong-tran](https://github.com/cuong-tran)) ([#1726](https://github.com/mihonapp/mihon/pull/1726))
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
- Remove alphabetical category sort option
|
||||||
|
|
||||||
### Other
|
### Other
|
||||||
- Add zoned "Current time" to debug info and include year & timezone in logcat output ([@MajorTanya](https://github.com/MajorTanya)) ([#1672](https://github.com/mihonapp/mihon/pull/1672))
|
- Add zoned "Current time" to debug info and include year & timezone in logcat output ([@MajorTanya](https://github.com/MajorTanya)) ([#1672](https://github.com/mihonapp/mihon/pull/1672))
|
||||||
|
|
||||||
|
@ -8,8 +8,6 @@ import androidx.compose.foundation.lazy.LazyColumn
|
|||||||
import androidx.compose.foundation.lazy.LazyListState
|
import androidx.compose.foundation.lazy.LazyListState
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.material.icons.Icons
|
|
||||||
import androidx.compose.material.icons.outlined.SortByAlpha
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
@ -19,9 +17,7 @@ import androidx.compose.ui.Modifier
|
|||||||
import eu.kanade.presentation.category.components.CategoryFloatingActionButton
|
import eu.kanade.presentation.category.components.CategoryFloatingActionButton
|
||||||
import eu.kanade.presentation.category.components.CategoryListItem
|
import eu.kanade.presentation.category.components.CategoryListItem
|
||||||
import eu.kanade.presentation.components.AppBar
|
import eu.kanade.presentation.components.AppBar
|
||||||
import eu.kanade.presentation.components.AppBarActions
|
|
||||||
import eu.kanade.tachiyomi.ui.category.CategoryScreenState
|
import eu.kanade.tachiyomi.ui.category.CategoryScreenState
|
||||||
import kotlinx.collections.immutable.persistentListOf
|
|
||||||
import sh.calvin.reorderable.ReorderableItem
|
import sh.calvin.reorderable.ReorderableItem
|
||||||
import sh.calvin.reorderable.rememberReorderableLazyListState
|
import sh.calvin.reorderable.rememberReorderableLazyListState
|
||||||
import tachiyomi.domain.category.model.Category
|
import tachiyomi.domain.category.model.Category
|
||||||
@ -37,7 +33,6 @@ import tachiyomi.presentation.core.util.plus
|
|||||||
fun CategoryScreen(
|
fun CategoryScreen(
|
||||||
state: CategoryScreenState.Success,
|
state: CategoryScreenState.Success,
|
||||||
onClickCreate: () -> Unit,
|
onClickCreate: () -> Unit,
|
||||||
onClickSortAlphabetically: () -> Unit,
|
|
||||||
onClickRename: (Category) -> Unit,
|
onClickRename: (Category) -> Unit,
|
||||||
onClickDelete: (Category) -> Unit,
|
onClickDelete: (Category) -> Unit,
|
||||||
onChangeOrder: (Category, Int) -> Unit,
|
onChangeOrder: (Category, Int) -> Unit,
|
||||||
@ -49,17 +44,6 @@ fun CategoryScreen(
|
|||||||
AppBar(
|
AppBar(
|
||||||
title = stringResource(MR.strings.action_edit_categories),
|
title = stringResource(MR.strings.action_edit_categories),
|
||||||
navigateUp = navigateUp,
|
navigateUp = navigateUp,
|
||||||
actions = {
|
|
||||||
AppBarActions(
|
|
||||||
persistentListOf(
|
|
||||||
AppBar.Action(
|
|
||||||
title = stringResource(MR.strings.action_sort),
|
|
||||||
icon = Icons.Outlined.SortByAlpha,
|
|
||||||
onClick = onClickSortAlphabetically,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
},
|
|
||||||
scrollBehavior = scrollBehavior,
|
scrollBehavior = scrollBehavior,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
@ -193,35 +193,6 @@ fun CategoryDeleteDialog(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun CategorySortAlphabeticallyDialog(
|
|
||||||
onDismissRequest: () -> Unit,
|
|
||||||
onSort: () -> Unit,
|
|
||||||
) {
|
|
||||||
AlertDialog(
|
|
||||||
onDismissRequest = onDismissRequest,
|
|
||||||
confirmButton = {
|
|
||||||
TextButton(onClick = {
|
|
||||||
onSort()
|
|
||||||
onDismissRequest()
|
|
||||||
}) {
|
|
||||||
Text(text = stringResource(MR.strings.action_ok))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
dismissButton = {
|
|
||||||
TextButton(onClick = onDismissRequest) {
|
|
||||||
Text(text = stringResource(MR.strings.action_cancel))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
title = {
|
|
||||||
Text(text = stringResource(MR.strings.action_sort_category))
|
|
||||||
},
|
|
||||||
text = {
|
|
||||||
Text(text = stringResource(MR.strings.sort_category_confirmation))
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ChangeCategoryDialog(
|
fun ChangeCategoryDialog(
|
||||||
initialSelection: ImmutableList<CheckboxState<Category>>,
|
initialSelection: ImmutableList<CheckboxState<Category>>,
|
||||||
|
@ -13,7 +13,6 @@ import eu.kanade.presentation.category.CategoryScreen
|
|||||||
import eu.kanade.presentation.category.components.CategoryCreateDialog
|
import eu.kanade.presentation.category.components.CategoryCreateDialog
|
||||||
import eu.kanade.presentation.category.components.CategoryDeleteDialog
|
import eu.kanade.presentation.category.components.CategoryDeleteDialog
|
||||||
import eu.kanade.presentation.category.components.CategoryRenameDialog
|
import eu.kanade.presentation.category.components.CategoryRenameDialog
|
||||||
import eu.kanade.presentation.category.components.CategorySortAlphabeticallyDialog
|
|
||||||
import eu.kanade.presentation.util.Screen
|
import eu.kanade.presentation.util.Screen
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
import kotlinx.collections.immutable.toImmutableList
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
@ -40,7 +39,6 @@ class CategoryScreen : Screen() {
|
|||||||
CategoryScreen(
|
CategoryScreen(
|
||||||
state = successState,
|
state = successState,
|
||||||
onClickCreate = { screenModel.showDialog(CategoryDialog.Create) },
|
onClickCreate = { screenModel.showDialog(CategoryDialog.Create) },
|
||||||
onClickSortAlphabetically = { screenModel.showDialog(CategoryDialog.SortAlphabetically) },
|
|
||||||
onClickRename = { screenModel.showDialog(CategoryDialog.Rename(it)) },
|
onClickRename = { screenModel.showDialog(CategoryDialog.Rename(it)) },
|
||||||
onClickDelete = { screenModel.showDialog(CategoryDialog.Delete(it)) },
|
onClickDelete = { screenModel.showDialog(CategoryDialog.Delete(it)) },
|
||||||
onChangeOrder = screenModel::changeOrder,
|
onChangeOrder = screenModel::changeOrder,
|
||||||
@ -71,12 +69,6 @@ class CategoryScreen : Screen() {
|
|||||||
category = dialog.category.name,
|
category = dialog.category.name,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
is CategoryDialog.SortAlphabetically -> {
|
|
||||||
CategorySortAlphabeticallyDialog(
|
|
||||||
onDismissRequest = screenModel::dismissDialog,
|
|
||||||
onSort = { screenModel.sortAlphabetically() },
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
|
@ -65,18 +65,9 @@ class CategoryScreenModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sortAlphabetically() {
|
|
||||||
screenModelScope.launch {
|
|
||||||
when (reorderCategory.sortAlphabetically()) {
|
|
||||||
is ReorderCategory.Result.InternalError -> _events.send(CategoryEvent.InternalError)
|
|
||||||
else -> {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun changeOrder(category: Category, newIndex: Int) {
|
fun changeOrder(category: Category, newIndex: Int) {
|
||||||
screenModelScope.launch {
|
screenModelScope.launch {
|
||||||
when (reorderCategory.changeOrder(category, newIndex)) {
|
when (reorderCategory.await(category, newIndex)) {
|
||||||
is ReorderCategory.Result.InternalError -> _events.send(CategoryEvent.InternalError)
|
is ReorderCategory.Result.InternalError -> _events.send(CategoryEvent.InternalError)
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
@ -113,7 +104,6 @@ class CategoryScreenModel(
|
|||||||
|
|
||||||
sealed interface CategoryDialog {
|
sealed interface CategoryDialog {
|
||||||
data object Create : CategoryDialog
|
data object Create : CategoryDialog
|
||||||
data object SortAlphabetically : CategoryDialog
|
|
||||||
data class Rename(val category: Category) : CategoryDialog
|
data class Rename(val category: Category) : CategoryDialog
|
||||||
data class Delete(val category: Category) : CategoryDialog
|
data class Delete(val category: Category) : CategoryDialog
|
||||||
}
|
}
|
||||||
|
@ -12,10 +12,9 @@ import tachiyomi.domain.category.repository.CategoryRepository
|
|||||||
class ReorderCategory(
|
class ReorderCategory(
|
||||||
private val categoryRepository: CategoryRepository,
|
private val categoryRepository: CategoryRepository,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val mutex = Mutex()
|
private val mutex = Mutex()
|
||||||
|
|
||||||
suspend fun changeOrder(category: Category, newIndex: Int) = withNonCancellableContext {
|
suspend fun await(category: Category, newIndex: Int) = withNonCancellableContext {
|
||||||
mutex.withLock {
|
mutex.withLock {
|
||||||
val categories = categoryRepository.getAll()
|
val categories = categoryRepository.getAll()
|
||||||
.filterNot(Category::isSystemCategory)
|
.filterNot(Category::isSystemCategory)
|
||||||
@ -45,27 +44,6 @@ class ReorderCategory(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun sortAlphabetically() = withNonCancellableContext {
|
|
||||||
mutex.withLock {
|
|
||||||
val updates = categoryRepository.getAll()
|
|
||||||
.sortedBy { category -> category.name }
|
|
||||||
.mapIndexed { index, category ->
|
|
||||||
CategoryUpdate(
|
|
||||||
id = category.id,
|
|
||||||
order = index.toLong(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
categoryRepository.updatePartial(updates)
|
|
||||||
Result.Success
|
|
||||||
} catch (e: Exception) {
|
|
||||||
logcat(LogPriority.ERROR, e)
|
|
||||||
Result.InternalError(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sealed interface Result {
|
sealed interface Result {
|
||||||
data object Success : Result
|
data object Success : Result
|
||||||
data object Unchanged : Result
|
data object Unchanged : Result
|
||||||
|
@ -97,8 +97,6 @@
|
|||||||
<string name="action_move_category">Set categories</string>
|
<string name="action_move_category">Set categories</string>
|
||||||
<string name="delete_category_confirmation">Do you wish to delete the category \"%s\"?</string>
|
<string name="delete_category_confirmation">Do you wish to delete the category \"%s\"?</string>
|
||||||
<string name="delete_category">Delete category</string>
|
<string name="delete_category">Delete category</string>
|
||||||
<string name="action_sort_category">Sort categories</string>
|
|
||||||
<string name="sort_category_confirmation">Would you like to sort the categories alphabetically?</string>
|
|
||||||
<string name="action_edit_cover">Edit cover</string>
|
<string name="action_edit_cover">Edit cover</string>
|
||||||
<string name="action_view_chapters">View chapters</string>
|
<string name="action_view_chapters">View chapters</string>
|
||||||
<string name="action_pause">Pause</string>
|
<string name="action_pause">Pause</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user