Fix App's preferences referencing deleted categories (#1734)
(cherry picked from commit eeb683069a3a0be7e769ac9273b5accc582e03ec) # Conflicts: # CHANGELOG.md # app/build.gradle.kts
This commit is contained in:
parent
9c22e7fcb7
commit
ce6b847c8b
@ -31,7 +31,7 @@ android {
|
||||
defaultConfig {
|
||||
applicationId = "eu.kanade.tachiyomi.sy"
|
||||
|
||||
versionCode = 71
|
||||
versionCode = 72
|
||||
versionName = "1.11.0"
|
||||
|
||||
buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"")
|
||||
|
@ -110,7 +110,7 @@ class DomainModule : InjektModule {
|
||||
addFactory { RenameCategory(get()) }
|
||||
addFactory { ReorderCategory(get()) }
|
||||
addFactory { UpdateCategory(get()) }
|
||||
addFactory { DeleteCategory(get()) }
|
||||
addFactory { DeleteCategory(get(), get(), get()) }
|
||||
|
||||
addSingletonFactory<MangaRepository> { MangaRepositoryImpl(get()) }
|
||||
addFactory { GetDuplicateLibraryManga(get()) }
|
||||
|
@ -0,0 +1,40 @@
|
||||
package mihon.core.migration.migrations
|
||||
|
||||
import mihon.core.migration.Migration
|
||||
import mihon.core.migration.MigrationContext
|
||||
import tachiyomi.core.common.util.lang.withIOContext
|
||||
import tachiyomi.domain.category.interactor.GetCategories
|
||||
import tachiyomi.domain.download.service.DownloadPreferences
|
||||
import tachiyomi.domain.library.service.LibraryPreferences
|
||||
|
||||
class CategoryPreferencesCleanupMigration : Migration {
|
||||
override val version: Float = 72f
|
||||
|
||||
override suspend fun invoke(migrationContext: MigrationContext): Boolean = withIOContext {
|
||||
val libraryPreferences = migrationContext.get<LibraryPreferences>() ?: return@withIOContext false
|
||||
val downloadPreferences = migrationContext.get<DownloadPreferences>() ?: return@withIOContext false
|
||||
|
||||
val getCategories = migrationContext.get<GetCategories>() ?: return@withIOContext false
|
||||
val allCategories = getCategories.await().map { it.id.toString() }.toSet()
|
||||
|
||||
val defaultCategory = libraryPreferences.defaultCategory().get()
|
||||
if (defaultCategory.toString() !in allCategories) {
|
||||
libraryPreferences.defaultCategory().delete()
|
||||
}
|
||||
|
||||
val categoryPreferences = listOf(
|
||||
libraryPreferences.updateCategories(),
|
||||
libraryPreferences.updateCategoriesExclude(),
|
||||
downloadPreferences.removeExcludeCategories(),
|
||||
downloadPreferences.downloadNewChapterCategories(),
|
||||
downloadPreferences.downloadNewChapterCategoriesExclude(),
|
||||
)
|
||||
categoryPreferences.forEach { preference ->
|
||||
val ids = preference.get()
|
||||
val garbageIds = ids.minus(allCategories)
|
||||
if (garbageIds.isEmpty()) return@forEach
|
||||
preference.set(ids.minus(garbageIds))
|
||||
}
|
||||
return@withIOContext true
|
||||
}
|
||||
}
|
@ -45,4 +45,5 @@ val migrations: List<Migration>
|
||||
MoveCacheToDiskSettingMigration(),
|
||||
MoveEncryptionSettingsToAppStateMigration(),
|
||||
TrustExtensionRepositoryMigration(),
|
||||
CategoryPreferencesCleanupMigration(),
|
||||
)
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user