Fix App's preferences referencing deleted categories (mihonapp/mihon#1734)
This commit is contained in:
parent
3dded3568a
commit
2f33754c20
6 changed files with 104 additions and 39 deletions
|
|
@ -24,6 +24,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
|
|||
- Fix MAL `main_picture` nullability breaking search if a result doesn't have a cover set ([@MajorTanya](https://github.com/MajorTanya)) ([#1618](https://github.com/mihonapp/mihon/pull/1618))
|
||||
- Fix Bangumi and MAL tracking 401 errors due to Mihon sending expired credentials ([@MajorTanya](https://github.com/MajorTanya)) ([#1681](https://github.com/mihonapp/mihon/pull/1681), [#1682](https://github.com/mihonapp/mihon/pull/1682))
|
||||
- Fix certain Infinix devices being unable to use any "Open link in browser" actions, including tracker setup ([@MajorTanya](https://github.com/MajorTanya)) ([#1684](https://github.com/mihonapp/mihon/pull/1684))
|
||||
- Fix App's preferences referencing deleted categories ([@cuong-tran](https://github.com/cuong-tran)) ([#1734](https://github.com/mihonapp/mihon/pull/1734))
|
||||
|
||||
### 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))
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ android {
|
|||
defaultConfig {
|
||||
applicationId = "app.komikku"
|
||||
|
||||
versionCode = 72
|
||||
versionCode = 73
|
||||
versionName = "1.13.0"
|
||||
|
||||
buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"")
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ class DomainModule : InjektModule {
|
|||
addFactory { RenameCategory(get()) }
|
||||
addFactory { ReorderCategory(get()) }
|
||||
addFactory { UpdateCategory(get()) }
|
||||
addFactory { DeleteCategory(get()) }
|
||||
addFactory { DeleteCategory(get(), get(), get()) }
|
||||
// KMK -->
|
||||
addFactory { HideCategory(get()) }
|
||||
// KMK <--
|
||||
|
|
|
|||
|
|
@ -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 = 73f
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
@ -8,46 +8,47 @@ val migrations: List<Migration>
|
|||
SetupLibraryUpdateMigration(),
|
||||
SetupEHentaiUpdateMigration(),
|
||||
SetupSyncDataMigration(),
|
||||
DelegateHBrowseMigration(),
|
||||
DelegateNHentaiMigration(),
|
||||
MergedMangaRewriteMigration(),
|
||||
LogoutFromMALMigration(),
|
||||
MoveDOHSettingMigration(),
|
||||
ResetRotationSettingMigration(),
|
||||
ResetReaderSettingsMigration(),
|
||||
DeleteOldMangaDexTracksMigration(),
|
||||
RemoveOldReaderThemeMigration(),
|
||||
RemoveShorterLibraryUpdatesMigration(),
|
||||
MoveLibrarySortingSettingsMigration(),
|
||||
RemoveShortLibraryUpdatesMigration(),
|
||||
MoveLibraryNonCompleteSettingMigration(),
|
||||
DeleteOldEhFavoritesDatabaseMigration(),
|
||||
MoveSecureScreenSettingMigration(),
|
||||
ChangeMiuiExtensionInstallerMigration(),
|
||||
MoveCoverOnlyGridSettingMigration(),
|
||||
MoveCatalogueCoverOnlyGridSettingMigration(),
|
||||
MoveLatestToFeedMigration(),
|
||||
MoveReaderTapSettingMigration(),
|
||||
MoveSortingModeSettingsMigration(),
|
||||
MoveSortingModeSettingMigration(),
|
||||
AlwaysBackupMigration(),
|
||||
ResetFilterAndSortSettingsMigration(),
|
||||
ChangeThemeModeToUppercaseMigration(),
|
||||
MoveReadingButtonSettingMigration(),
|
||||
ChangeTrackingQueueTypeMigration(),
|
||||
LogoutFromMangaDexMigration(),
|
||||
RemoveUpdateCheckerJobsMigration(),
|
||||
RemoveBatteryNotLowRestrictionMigration(),
|
||||
MoveRelativeTimeSettingMigration(),
|
||||
ClearBrokenPagePreviewCacheMigration(),
|
||||
MoveSettingsToPrivateOrAppStateMigration(),
|
||||
MoveExtensionRepoSettingsMigration(),
|
||||
MoveCacheToDiskSettingMigration(),
|
||||
MoveEncryptionSettingsToAppStateMigration(),
|
||||
TrustExtensionRepositoryMigration(),
|
||||
// DelegateHBrowseMigration(),
|
||||
// DelegateNHentaiMigration(),
|
||||
// MergedMangaRewriteMigration(),
|
||||
// LogoutFromMALMigration(),
|
||||
// MoveDOHSettingMigration(),
|
||||
// ResetRotationSettingMigration(),
|
||||
// ResetReaderSettingsMigration(),
|
||||
// DeleteOldMangaDexTracksMigration(),
|
||||
// RemoveOldReaderThemeMigration(),
|
||||
// RemoveShorterLibraryUpdatesMigration(),
|
||||
// MoveLibrarySortingSettingsMigration(),
|
||||
// RemoveShortLibraryUpdatesMigration(),
|
||||
// MoveLibraryNonCompleteSettingMigration(),
|
||||
// DeleteOldEhFavoritesDatabaseMigration(),
|
||||
// MoveSecureScreenSettingMigration(),
|
||||
// ChangeMiuiExtensionInstallerMigration(),
|
||||
// MoveCoverOnlyGridSettingMigration(),
|
||||
// MoveCatalogueCoverOnlyGridSettingMigration(),
|
||||
// MoveLatestToFeedMigration(),
|
||||
// MoveReaderTapSettingMigration(),
|
||||
// MoveSortingModeSettingsMigration(),
|
||||
// MoveSortingModeSettingMigration(),
|
||||
// AlwaysBackupMigration(),
|
||||
// ResetFilterAndSortSettingsMigration(),
|
||||
// ChangeThemeModeToUppercaseMigration(),
|
||||
// MoveReadingButtonSettingMigration(),
|
||||
// ChangeTrackingQueueTypeMigration(),
|
||||
// LogoutFromMangaDexMigration(),
|
||||
// RemoveUpdateCheckerJobsMigration(),
|
||||
// RemoveBatteryNotLowRestrictionMigration(),
|
||||
// MoveRelativeTimeSettingMigration(),
|
||||
// ClearBrokenPagePreviewCacheMigration(),
|
||||
// MoveSettingsToPrivateOrAppStateMigration(),
|
||||
// MoveExtensionRepoSettingsMigration(),
|
||||
// MoveCacheToDiskSettingMigration(),
|
||||
// MoveEncryptionSettingsToAppStateMigration(),
|
||||
// KMK -->
|
||||
IntegratedHentaiMigration(),
|
||||
SetupAppUpdateMigration(),
|
||||
EHentaiMigration(),
|
||||
// KMK <--
|
||||
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…
Reference in a new issue