diff --git a/app/src/main/java/eu/kanade/presentation/category/CategoryScreen.kt b/app/src/main/java/eu/kanade/presentation/category/CategoryScreen.kt index eb3259143..e644678e5 100644 --- a/app/src/main/java/eu/kanade/presentation/category/CategoryScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/category/CategoryScreen.kt @@ -41,7 +41,7 @@ fun CategoryScreen( onClickSortAlphabetically: () -> Unit, onClickRename: (Category) -> Unit, onClickDelete: (Category) -> Unit, - moveTo: (Category, Int) -> Unit, + changeOrder: (Category, Int) -> Unit, navigateUp: () -> Unit, ) { val lazyListState = rememberLazyListState() @@ -87,7 +87,7 @@ fun CategoryScreen( PaddingValues(horizontal = MaterialTheme.padding.medium), onClickRename = onClickRename, onClickDelete = onClickDelete, - moveTo = moveTo, + changeOrder = changeOrder, ) } } @@ -99,12 +99,12 @@ private fun CategoryContent( paddingValues: PaddingValues, onClickRename: (Category) -> Unit, onClickDelete: (Category) -> Unit, - moveTo: (Category, Int) -> Unit, + changeOrder: (Category, Int) -> Unit, ) { var reorderableList by remember { mutableStateOf(categories.toList()) } val reorderableLazyColumnState = rememberReorderableLazyListState(lazyListState) { from, to -> reorderableList = reorderableList.toMutableList().apply { - moveTo(reorderableList[from.index], to.index - from.index) + changeOrder(reorderableList[from.index], to.index - from.index) add(to.index, removeAt(from.index)) } } @@ -122,9 +122,9 @@ private fun CategoryContent( ) { items( items = reorderableList, - key = { category -> category.key() }, + key = { category -> category.key }, ) { category -> - ReorderableItem(reorderableLazyColumnState, category.key()) { + ReorderableItem(reorderableLazyColumnState, category.key) { CategoryListItem( modifier = Modifier.animateItem(), category = category, @@ -136,4 +136,4 @@ private fun CategoryContent( } } -fun Category.key() = "category-$id" +private val Category.key get() = "category-$id" diff --git a/app/src/main/java/eu/kanade/presentation/category/components/CategoryListItem.kt b/app/src/main/java/eu/kanade/presentation/category/components/CategoryListItem.kt index da0cdf461..af4265352 100644 --- a/app/src/main/java/eu/kanade/presentation/category/components/CategoryListItem.kt +++ b/app/src/main/java/eu/kanade/presentation/category/components/CategoryListItem.kt @@ -6,8 +6,8 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.Delete +import androidx.compose.material.icons.outlined.DragHandle import androidx.compose.material.icons.outlined.Edit -import androidx.compose.material.icons.rounded.DragHandle import androidx.compose.material3.ElevatedCard import androidx.compose.material3.Icon import androidx.compose.material3.IconButton @@ -36,21 +36,24 @@ fun ReorderableCollectionItemScope.CategoryListItem( modifier = Modifier .fillMaxWidth() .clickable { onRename() } - .padding(MaterialTheme.padding.small), + .padding(vertical = MaterialTheme.padding.small) + .padding( + start = MaterialTheme.padding.small, + end = MaterialTheme.padding.medium, + ), verticalAlignment = Alignment.CenterVertically, ) { - IconButton( + Icon( + imageVector = Icons.Outlined.DragHandle, + contentDescription = null, modifier = Modifier + .padding(MaterialTheme.padding.medium) .draggableHandle(), - onClick = {}, - ) { - Icon(Icons.Rounded.DragHandle, contentDescription = "Reorder") - } + ) Text( text = category.name, modifier = Modifier - .weight(1f) - .padding(start = MaterialTheme.padding.small), + .weight(1f), ) IconButton(onClick = onRename) { Icon( diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryScreen.kt index abaabfc3c..1aa79d736 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryScreen.kt @@ -43,7 +43,7 @@ class CategoryScreen : Screen() { onClickSortAlphabetically = { screenModel.showDialog(CategoryDialog.SortAlphabetically) }, onClickRename = { screenModel.showDialog(CategoryDialog.Rename(it)) }, onClickDelete = { screenModel.showDialog(CategoryDialog.Delete(it)) }, - moveTo = screenModel::moveTo, + changeOrder = screenModel::changeOrder, navigateUp = navigator::pop, ) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryScreenModel.kt index 5aed5fddb..991893a48 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryScreenModel.kt @@ -74,9 +74,9 @@ class CategoryScreenModel( } } - fun moveTo(category: Category, offset: Int) { + fun changeOrder(category: Category, newOrder: Int) { screenModelScope.launch { - when (reorderCategory.await(category, offset)) { + when (reorderCategory.changeOrder(category, newOrder)) { is ReorderCategory.Result.InternalError -> _events.send(CategoryEvent.InternalError) else -> {} } diff --git a/domain/src/main/java/tachiyomi/domain/category/interactor/ReorderCategory.kt b/domain/src/main/java/tachiyomi/domain/category/interactor/ReorderCategory.kt index e89ad08dd..b0f299953 100644 --- a/domain/src/main/java/tachiyomi/domain/category/interactor/ReorderCategory.kt +++ b/domain/src/main/java/tachiyomi/domain/category/interactor/ReorderCategory.kt @@ -15,7 +15,7 @@ class ReorderCategory( private val mutex = Mutex() - suspend fun await(category: Category, offset: Int) = withNonCancellableContext { + suspend fun changeOrder(category: Category, newOrder: Int) = withNonCancellableContext { mutex.withLock { val categories = categoryRepository.getAll() .filterNot(Category::isSystemCategory) @@ -26,7 +26,7 @@ class ReorderCategory( return@withNonCancellableContext Result.Unchanged } - val newPosition = currentIndex + offset + val newPosition = currentIndex + newOrder try { categories.add(newPosition, categories.removeAt(currentIndex))