Replace preference getter functions with properties (#3091)
This commit is contained in:
+7
-7
@@ -17,17 +17,17 @@ class CategoryPreferencesCleanupMigration : Migration {
|
||||
val getCategories = migrationContext.get<GetCategories>() ?: return@withIOContext false
|
||||
val allCategories = getCategories.await().map { it.id.toString() }.toSet()
|
||||
|
||||
val defaultCategory = libraryPreferences.defaultCategory().get()
|
||||
val defaultCategory = libraryPreferences.defaultCategory.get()
|
||||
if (defaultCategory.toString() !in allCategories) {
|
||||
libraryPreferences.defaultCategory().delete()
|
||||
libraryPreferences.defaultCategory.delete()
|
||||
}
|
||||
|
||||
val categoryPreferences = listOf(
|
||||
libraryPreferences.updateCategories(),
|
||||
libraryPreferences.updateCategoriesExclude(),
|
||||
downloadPreferences.removeExcludeCategories(),
|
||||
downloadPreferences.downloadNewChapterCategories(),
|
||||
downloadPreferences.downloadNewChapterCategoriesExclude(),
|
||||
libraryPreferences.updateCategories,
|
||||
libraryPreferences.updateCategoriesExclude,
|
||||
downloadPreferences.removeExcludeCategories,
|
||||
downloadPreferences.downloadNewChapterCategories,
|
||||
downloadPreferences.downloadNewChapterCategoriesExclude,
|
||||
)
|
||||
categoryPreferences.forEach { preference ->
|
||||
val ids = preference.get()
|
||||
|
||||
@@ -11,7 +11,7 @@ class InstallationIdMigration : Migration {
|
||||
|
||||
@OptIn(ExperimentalUuidApi::class)
|
||||
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
|
||||
val installationId = migrationContext.get<BasePreferences>()?.installationId() ?: return false
|
||||
val installationId = migrationContext.get<BasePreferences>()?.installationId ?: return false
|
||||
if (!installationId.isSet()) installationId.set(FeatureFlags.newInstallationId())
|
||||
return true
|
||||
}
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@ class TrustExtensionRepositoryMigration : Migration {
|
||||
val sourcePreferences = migrationContext.get<SourcePreferences>() ?: return@withIOContext false
|
||||
val extensionRepositoryRepository =
|
||||
migrationContext.get<ExtensionRepoRepository>() ?: return@withIOContext false
|
||||
for ((index, source) in sourcePreferences.extensionRepos().get().withIndex()) {
|
||||
for ((index, source) in sourcePreferences.extensionRepos.get().withIndex()) {
|
||||
try {
|
||||
extensionRepositoryRepository.upsertRepo(
|
||||
source,
|
||||
@@ -29,7 +29,7 @@ class TrustExtensionRepositoryMigration : Migration {
|
||||
logcat(LogPriority.ERROR, e) { "Error Migrating Extension Repo with baseUrl: $source" }
|
||||
}
|
||||
}
|
||||
sourcePreferences.extensionRepos().delete()
|
||||
sourcePreferences.extensionRepos.delete()
|
||||
return@withIOContext true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ class MigrateMangaUseCase(
|
||||
suspend operator fun invoke(current: Manga, target: Manga, replace: Boolean) {
|
||||
val targetSource = sourceManager.get(target.source) ?: return
|
||||
val currentSource = sourceManager.get(current.source)
|
||||
val flags = sourcePreferences.migrationFlags().get()
|
||||
val flags = sourcePreferences.migrationFlags.get()
|
||||
|
||||
try {
|
||||
val chapters = targetSource.getChapterList(target.toSManga())
|
||||
|
||||
@@ -340,10 +340,10 @@ class MigrationConfigScreen(private val mangaIds: Collection<Long>) : Screen() {
|
||||
}
|
||||
|
||||
private fun initSources() {
|
||||
val languages = sourcePreferences.enabledLanguages().get()
|
||||
val pinnedSources = sourcePreferences.pinnedSources().get().mapNotNull { it.toLongOrNull() }
|
||||
val includedSources = sourcePreferences.migrationSources().get()
|
||||
val disabledSources = sourcePreferences.disabledSources().get()
|
||||
val languages = sourcePreferences.enabledLanguages.get()
|
||||
val pinnedSources = sourcePreferences.pinnedSources.get().mapNotNull { it.toLongOrNull() }
|
||||
val includedSources = sourcePreferences.migrationSources.get()
|
||||
val disabledSources = sourcePreferences.disabledSources.get()
|
||||
.mapNotNull { it.toLongOrNull() }
|
||||
val sources = sourceManager.getCatalogueSources()
|
||||
.asSequence()
|
||||
@@ -382,8 +382,8 @@ class MigrationConfigScreen(private val mangaIds: Collection<Long>) : Screen() {
|
||||
}
|
||||
|
||||
fun toggleSelection(config: SelectionConfig) {
|
||||
val pinnedSources = sourcePreferences.pinnedSources().get().mapNotNull { it.toLongOrNull() }
|
||||
val disabledSources = sourcePreferences.disabledSources().get().mapNotNull { it.toLongOrNull() }
|
||||
val pinnedSources = sourcePreferences.pinnedSources.get().mapNotNull { it.toLongOrNull() }
|
||||
val disabledSources = sourcePreferences.disabledSources.get().mapNotNull { it.toLongOrNull() }
|
||||
val isSelected: (Long) -> Boolean = {
|
||||
when (config) {
|
||||
SelectionConfig.All -> true
|
||||
@@ -413,7 +413,7 @@ class MigrationConfigScreen(private val mangaIds: Collection<Long>) : Screen() {
|
||||
state.value.sources
|
||||
.filter { source -> source.isSelected }
|
||||
.map { source -> source.source.id }
|
||||
.let { sources -> sourcePreferences.migrationSources().set(sources) }
|
||||
.let { sources -> sourcePreferences.migrationSources.set(sources) }
|
||||
}
|
||||
|
||||
data class State(
|
||||
|
||||
@@ -53,7 +53,7 @@ fun MigrationConfigScreenSheet(
|
||||
onStartMigration: (extraSearchQuery: String?) -> Unit,
|
||||
) {
|
||||
var extraSearchQuery by rememberSaveable { mutableStateOf("") }
|
||||
val migrationFlags by preferences.migrationFlags().collectAsState()
|
||||
val migrationFlags by preferences.migrationFlags.collectAsState()
|
||||
AdaptiveSheet(onDismissRequest = onDismissRequest) {
|
||||
Column(modifier = Modifier.fillMaxWidth()) {
|
||||
Column(
|
||||
@@ -86,7 +86,7 @@ fun MigrationConfigScreenSheet(
|
||||
FilterChip(
|
||||
selected = selected,
|
||||
onClick = {
|
||||
preferences.migrationFlags().getAndSet { currentFlags ->
|
||||
preferences.migrationFlags.getAndSet { currentFlags ->
|
||||
if (flag in currentFlags) {
|
||||
currentFlags - flag
|
||||
} else {
|
||||
@@ -112,7 +112,7 @@ fun MigrationConfigScreenSheet(
|
||||
subtitle = null,
|
||||
checked = removeDownloads,
|
||||
onClick = {
|
||||
preferences.migrationFlags().getAndSet {
|
||||
preferences.migrationFlags.getAndSet {
|
||||
if (removeDownloads) {
|
||||
it - MigrationFlag.REMOVE_DOWNLOAD
|
||||
} else {
|
||||
@@ -140,24 +140,24 @@ fun MigrationConfigScreenSheet(
|
||||
MigrationSheetSwitchItem(
|
||||
title = stringResource(MR.strings.migrationConfigScreen_hideUnmatchedTitle),
|
||||
subtitle = null,
|
||||
preference = preferences.migrationHideUnmatched(),
|
||||
preference = preferences.migrationHideUnmatched,
|
||||
)
|
||||
MigrationSheetSwitchItem(
|
||||
title = stringResource(MR.strings.migrationConfigScreen_hideWithoutUpdatesTitle),
|
||||
subtitle = stringResource(MR.strings.migrationConfigScreen_hideWithoutUpdatesSubtitle),
|
||||
preference = preferences.migrationHideWithoutUpdates(),
|
||||
preference = preferences.migrationHideWithoutUpdates,
|
||||
)
|
||||
MigrationSheetDividerItem()
|
||||
MigrationSheetWarningItem(stringResource(MR.strings.migrationConfigScreen_enhancedOptionsWarning))
|
||||
MigrationSheetSwitchItem(
|
||||
title = stringResource(MR.strings.migrationConfigScreen_deepSearchModeTitle),
|
||||
subtitle = stringResource(MR.strings.migrationConfigScreen_deepSearchModeSubtitle),
|
||||
preference = preferences.migrationDeepSearchMode(),
|
||||
preference = preferences.migrationDeepSearchMode,
|
||||
)
|
||||
MigrationSheetSwitchItem(
|
||||
title = stringResource(MR.strings.migrationConfigScreen_prioritizeByChaptersTitle),
|
||||
subtitle = stringResource(MR.strings.migrationConfigScreen_prioritizeByChaptersSubtitle),
|
||||
preference = preferences.migrationPrioritizeByChapters(),
|
||||
preference = preferences.migrationPrioritizeByChapters,
|
||||
)
|
||||
}
|
||||
HorizontalDivider()
|
||||
|
||||
@@ -143,7 +143,7 @@ private class MigrateDialogScreenModel(
|
||||
if (applicable) add(it)
|
||||
}
|
||||
}
|
||||
val selectedFlags = sourcePreference.migrationFlags().get()
|
||||
val selectedFlags = sourcePreference.migrationFlags.get()
|
||||
mutableState.update {
|
||||
State(
|
||||
current = current,
|
||||
@@ -167,7 +167,7 @@ private class MigrateDialogScreenModel(
|
||||
val state = state.value
|
||||
val current = state.current ?: return
|
||||
val target = state.target ?: return
|
||||
sourcePreference.migrationFlags().set(state.selectedFlags)
|
||||
sourcePreference.migrationFlags.set(state.selectedFlags)
|
||||
mutableState.update { it.copy(isMigrating = true) }
|
||||
migrateManga(current, target, replace)
|
||||
mutableState.update { it.copy(isMigrating = false, isMigrated = true) }
|
||||
|
||||
@@ -60,8 +60,8 @@ class MigrationListScreenModel(
|
||||
val items
|
||||
inline get() = state.value.items
|
||||
|
||||
private val hideUnmatched = preferences.migrationHideUnmatched().get()
|
||||
private val hideWithoutUpdates = preferences.migrationHideWithoutUpdates().get()
|
||||
private val hideUnmatched = preferences.migrationHideUnmatched.get()
|
||||
private val hideWithoutUpdates = preferences.migrationHideWithoutUpdates.get()
|
||||
|
||||
private val navigateBackChannel = Channel<Unit>()
|
||||
val navigateBackEvent = navigateBackChannel.receiveAsFlow()
|
||||
@@ -110,10 +110,10 @@ class MigrationListScreenModel(
|
||||
}
|
||||
|
||||
private suspend fun runMigrations(mangas: List<MigratingManga>) {
|
||||
val prioritizeByChapters = preferences.migrationPrioritizeByChapters().get()
|
||||
val deepSearchMode = preferences.migrationDeepSearchMode().get()
|
||||
val prioritizeByChapters = preferences.migrationPrioritizeByChapters.get()
|
||||
val deepSearchMode = preferences.migrationDeepSearchMode.get()
|
||||
|
||||
val sources = preferences.migrationSources().get()
|
||||
val sources = preferences.migrationSources.get()
|
||||
.mapNotNull { sourceManager.get(it) as? CatalogueSource }
|
||||
|
||||
for (manga in mangas) {
|
||||
|
||||
Reference in New Issue
Block a user