mirror of
https://github.com/mihonapp/mihon.git
synced 2025-10-25 12:30:41 +02:00
Fix App's preferences referencing deleted categories (#1734)
This commit is contained in:
@@ -5,9 +5,13 @@ import tachiyomi.core.common.util.lang.withNonCancellableContext
|
||||
import tachiyomi.core.common.util.system.logcat
|
||||
import tachiyomi.domain.category.model.CategoryUpdate
|
||||
import tachiyomi.domain.category.repository.CategoryRepository
|
||||
import tachiyomi.domain.download.service.DownloadPreferences
|
||||
import tachiyomi.domain.library.service.LibraryPreferences
|
||||
|
||||
class DeleteCategory(
|
||||
private val categoryRepository: CategoryRepository,
|
||||
private val libraryPreferences: LibraryPreferences,
|
||||
private val downloadPreferences: DownloadPreferences,
|
||||
) {
|
||||
|
||||
suspend fun await(categoryId: Long) = withNonCancellableContext {
|
||||
@@ -26,6 +30,25 @@ class DeleteCategory(
|
||||
)
|
||||
}
|
||||
|
||||
val defaultCategory = libraryPreferences.defaultCategory().get()
|
||||
if (defaultCategory == categoryId.toInt()) {
|
||||
libraryPreferences.defaultCategory().delete()
|
||||
}
|
||||
|
||||
val categoryPreferences = listOf(
|
||||
libraryPreferences.updateCategories(),
|
||||
libraryPreferences.updateCategoriesExclude(),
|
||||
downloadPreferences.removeExcludeCategories(),
|
||||
downloadPreferences.downloadNewChapterCategories(),
|
||||
downloadPreferences.downloadNewChapterCategoriesExclude(),
|
||||
)
|
||||
val categoryIdString = categoryId.toString()
|
||||
categoryPreferences.forEach { preference ->
|
||||
val ids = preference.get()
|
||||
if (categoryIdString !in ids) return@forEach
|
||||
preference.set(ids.minus(categoryIdString))
|
||||
}
|
||||
|
||||
try {
|
||||
categoryRepository.updatePartial(updates)
|
||||
Result.Success
|
||||
|
||||
Reference in New Issue
Block a user