mirror of
https://github.com/mihonapp/mihon.git
synced 2026-10-16 13:48:09 -07:00
Keep category orders unique while reordering
Reordering first moves every category to a temporary negative position, then assigns the final ones, so two categories never share a position mid-update. Deleting a category no longer renumbers the system category.
This commit is contained in:
@@ -77,6 +77,9 @@ class CategoryRepositoryImpl(
|
|||||||
|
|
||||||
override suspend fun updateAllOrders(orderedIds: List<Long>) {
|
override suspend fun updateAllOrders(orderedIds: List<Long>) {
|
||||||
database.transaction {
|
database.transaction {
|
||||||
|
orderedIds.forEachIndexed { index, categoryId ->
|
||||||
|
database.categoriesQueries.updateOrder(order = -index - 2L, categoryId = categoryId)
|
||||||
|
}
|
||||||
orderedIds.forEachIndexed { index, categoryId ->
|
orderedIds.forEachIndexed { index, categoryId ->
|
||||||
database.categoriesQueries.updateOrder(order = index.toLong(), categoryId = categoryId)
|
database.categoriesQueries.updateOrder(order = index.toLong(), categoryId = categoryId)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import dev.zacsweers.metro.Inject
|
|||||||
import logcat.LogPriority
|
import logcat.LogPriority
|
||||||
import tachiyomi.core.common.util.lang.withNonCancellableContext
|
import tachiyomi.core.common.util.lang.withNonCancellableContext
|
||||||
import tachiyomi.core.common.util.system.logcat
|
import tachiyomi.core.common.util.system.logcat
|
||||||
|
import tachiyomi.domain.category.model.Category
|
||||||
import tachiyomi.domain.category.repository.CategoryRepository
|
import tachiyomi.domain.category.repository.CategoryRepository
|
||||||
import tachiyomi.domain.download.service.DownloadPreferences
|
import tachiyomi.domain.download.service.DownloadPreferences
|
||||||
import tachiyomi.domain.library.service.LibraryPreferences
|
import tachiyomi.domain.library.service.LibraryPreferences
|
||||||
@@ -23,7 +24,9 @@ class DeleteCategory(
|
|||||||
return@withNonCancellableContext Result.InternalError(e)
|
return@withNonCancellableContext Result.InternalError(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
val orderedIds = categoryRepository.getAll().map { it.id }
|
val orderedIds = categoryRepository.getAll()
|
||||||
|
.filterNot(Category::isSystemCategory)
|
||||||
|
.map { it.id }
|
||||||
|
|
||||||
val defaultCategory = libraryPreferences.defaultCategory.get()
|
val defaultCategory = libraryPreferences.defaultCategory.get()
|
||||||
if (defaultCategory == categoryId.toInt()) {
|
if (defaultCategory == categoryId.toInt()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user