diff --git a/app/src/main/java/eu/darken/sdmse/systemcleaner/core/SystemCleanerSettings.kt b/app/src/main/java/eu/darken/sdmse/systemcleaner/core/SystemCleanerSettings.kt index cc7926d61..89f3dcf26 100644 --- a/app/src/main/java/eu/darken/sdmse/systemcleaner/core/SystemCleanerSettings.kt +++ b/app/src/main/java/eu/darken/sdmse/systemcleaner/core/SystemCleanerSettings.kt @@ -9,7 +9,6 @@ import dagger.hilt.android.qualifiers.ApplicationContext import eu.darken.sdmse.common.datastore.PreferenceScreenData import eu.darken.sdmse.common.datastore.PreferenceStoreMapper import eu.darken.sdmse.common.datastore.createValue -import eu.darken.sdmse.common.debug.logging.log import eu.darken.sdmse.common.debug.logging.logTag import eu.darken.sdmse.systemcleaner.core.filter.FilterIdentifier import javax.inject.Inject @@ -53,11 +52,6 @@ class SystemCleanerSettings @Inject constructor( moshi ) - suspend fun clearCustomFilter(filterId: FilterIdentifier) { - log(TAG) { "clearCustomFilter($filterId)" } - enabledCustomFilter.update { it - filterId } - } - override val mapper = PreferenceStoreMapper( filterLogFilesEnabled, filterAdvertisementsEnabled, diff --git a/app/src/main/java/eu/darken/sdmse/systemcleaner/core/filter/custom/CustomFilterExtensions.kt b/app/src/main/java/eu/darken/sdmse/systemcleaner/core/filter/custom/CustomFilterExtensions.kt new file mode 100644 index 000000000..c9b120c36 --- /dev/null +++ b/app/src/main/java/eu/darken/sdmse/systemcleaner/core/filter/custom/CustomFilterExtensions.kt @@ -0,0 +1,30 @@ +package eu.darken.sdmse.systemcleaner.core.filter.custom + +import eu.darken.sdmse.common.datastore.value +import eu.darken.sdmse.common.debug.logging.log +import eu.darken.sdmse.common.debug.logging.logTag +import eu.darken.sdmse.systemcleaner.core.SystemCleanerSettings +import eu.darken.sdmse.systemcleaner.core.filter.FilterIdentifier +import kotlinx.coroutines.flow.first + + +suspend fun CustomFilterRepo.currentConfigs() = configs.first() + + +suspend fun SystemCleanerSettings.toggleCustomFilter(filterId: FilterIdentifier, enabled: Boolean? = null) { + log(TAG) { "toggleCustomFilter($filterId, $enabled)" } + enabledCustomFilter.update { + if (it.contains(filterId) || enabled == false) it - filterId else it + filterId + } +} + +suspend fun SystemCleanerSettings.clearCustomFilter(filterId: FilterIdentifier) { + log(TAG) { "clearCustomFilter($filterId)" } + enabledCustomFilter.update { it - filterId } +} + +suspend fun SystemCleanerSettings.isCustomFilterEnabled(filterId: FilterIdentifier): Boolean { + return enabledCustomFilter.value().contains(filterId) +} + +private val TAG = logTag("SystemCleaner", "CustomFilter") \ No newline at end of file diff --git a/app/src/main/java/eu/darken/sdmse/systemcleaner/core/filter/custom/CustomFilterLoader.kt b/app/src/main/java/eu/darken/sdmse/systemcleaner/core/filter/custom/CustomFilterLoader.kt index b69507af8..a3e3b4ed3 100644 --- a/app/src/main/java/eu/darken/sdmse/systemcleaner/core/filter/custom/CustomFilterLoader.kt +++ b/app/src/main/java/eu/darken/sdmse/systemcleaner/core/filter/custom/CustomFilterLoader.kt @@ -3,7 +3,6 @@ package eu.darken.sdmse.systemcleaner.core.filter.custom import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject -import eu.darken.sdmse.common.datastore.value import eu.darken.sdmse.systemcleaner.core.SystemCleanerSettings import eu.darken.sdmse.systemcleaner.core.filter.SystemCleanerFilter @@ -13,7 +12,7 @@ class CustomFilterLoader @AssistedInject constructor( private val settings: SystemCleanerSettings, ) : SystemCleanerFilter.Factory { - override suspend fun isEnabled(): Boolean = settings.enabledCustomFilter.value().contains(filterConfig.identifier) + override suspend fun isEnabled(): Boolean = settings.isCustomFilterEnabled(filterConfig.identifier) override suspend fun create(): SystemCleanerFilter = factory.create(filterConfig) diff --git a/app/src/main/java/eu/darken/sdmse/systemcleaner/core/filter/custom/CustomFilterRepo.kt b/app/src/main/java/eu/darken/sdmse/systemcleaner/core/filter/custom/CustomFilterRepo.kt index 7752642ce..d81072625 100644 --- a/app/src/main/java/eu/darken/sdmse/systemcleaner/core/filter/custom/CustomFilterRepo.kt +++ b/app/src/main/java/eu/darken/sdmse/systemcleaner/core/filter/custom/CustomFilterRepo.kt @@ -94,8 +94,6 @@ class CustomFilterRepo @Inject constructor( val path = config.identifier.configPath configAdapter.toFile(config, path) log(TAG) { "Saved to $path" } - // Reset any previous state - settings.clearCustomFilter(config.identifier) } } refresh() diff --git a/app/src/main/java/eu/darken/sdmse/systemcleaner/core/filter/custom/CustomFilterRepoExtensions.kt b/app/src/main/java/eu/darken/sdmse/systemcleaner/core/filter/custom/CustomFilterRepoExtensions.kt deleted file mode 100644 index f5947486b..000000000 --- a/app/src/main/java/eu/darken/sdmse/systemcleaner/core/filter/custom/CustomFilterRepoExtensions.kt +++ /dev/null @@ -1,6 +0,0 @@ -package eu.darken.sdmse.systemcleaner.core.filter.custom - -import kotlinx.coroutines.flow.first - - -suspend fun CustomFilterRepo.currentConfigs() = configs.first() \ No newline at end of file diff --git a/app/src/main/java/eu/darken/sdmse/systemcleaner/core/filter/custom/EditorOptionsCreator.kt b/app/src/main/java/eu/darken/sdmse/systemcleaner/core/filter/custom/EditorOptionsCreator.kt index 8783271fe..b9acc97ce 100644 --- a/app/src/main/java/eu/darken/sdmse/systemcleaner/core/filter/custom/EditorOptionsCreator.kt +++ b/app/src/main/java/eu/darken/sdmse/systemcleaner/core/filter/custom/EditorOptionsCreator.kt @@ -67,6 +67,7 @@ class EditorOptionsCreator @Inject constructor( label = label, areas = targetAreas, pathCriteria = pathCriteria, + saveAsEnabled = true, ).also { log(TAG, INFO) { "Editor options are : $it" } } } diff --git a/app/src/main/java/eu/darken/sdmse/systemcleaner/ui/customfilter/editor/CustomFilterEditorOptions.kt b/app/src/main/java/eu/darken/sdmse/systemcleaner/ui/customfilter/editor/CustomFilterEditorOptions.kt index 2cb56bf3f..020de6689 100644 --- a/app/src/main/java/eu/darken/sdmse/systemcleaner/ui/customfilter/editor/CustomFilterEditorOptions.kt +++ b/app/src/main/java/eu/darken/sdmse/systemcleaner/ui/customfilter/editor/CustomFilterEditorOptions.kt @@ -12,4 +12,5 @@ data class CustomFilterEditorOptions( val label: String? = null, val pathCriteria: Set? = null, val nameCriteria: Set? = null, + val saveAsEnabled: Boolean = false, ) : Parcelable \ No newline at end of file diff --git a/app/src/main/java/eu/darken/sdmse/systemcleaner/ui/customfilter/editor/CustomFilterEditorViewModel.kt b/app/src/main/java/eu/darken/sdmse/systemcleaner/ui/customfilter/editor/CustomFilterEditorViewModel.kt index bd727468b..57a5c5a6b 100644 --- a/app/src/main/java/eu/darken/sdmse/systemcleaner/ui/customfilter/editor/CustomFilterEditorViewModel.kt +++ b/app/src/main/java/eu/darken/sdmse/systemcleaner/ui/customfilter/editor/CustomFilterEditorViewModel.kt @@ -17,12 +17,14 @@ import eu.darken.sdmse.common.flow.withPrevious import eu.darken.sdmse.common.navigation.navArgs import eu.darken.sdmse.common.progress.Progress import eu.darken.sdmse.common.uix.ViewModel3 +import eu.darken.sdmse.systemcleaner.core.SystemCleanerSettings import eu.darken.sdmse.systemcleaner.core.SystemCrawler import eu.darken.sdmse.systemcleaner.core.filter.FilterIdentifier import eu.darken.sdmse.systemcleaner.core.filter.custom.CustomFilter import eu.darken.sdmse.systemcleaner.core.filter.custom.CustomFilterConfig import eu.darken.sdmse.systemcleaner.core.filter.custom.CustomFilterRepo import eu.darken.sdmse.systemcleaner.core.filter.custom.currentConfigs +import eu.darken.sdmse.systemcleaner.core.filter.custom.toggleCustomFilter import eu.darken.sdmse.systemcleaner.core.sieve.NameCriterium import eu.darken.sdmse.systemcleaner.core.sieve.SegmentCriterium import eu.darken.sdmse.systemcleaner.ui.customfilter.editor.live.LiveSearchListRow @@ -47,6 +49,7 @@ class CustomFilterEditorViewModel @Inject constructor( private val dataAreaManager: DataAreaManager, private val crawler: SystemCrawler, private val filterFactory: CustomFilter.Factory, + private val settings: SystemCleanerSettings, ) : ViewModel3(dispatcherProvider) { private val navArgs by handle.navArgs() @@ -92,6 +95,9 @@ class CustomFilterEditorViewModel @Inject constructor( log(TAG) { "save()" } val toSave = currentState.value().current.copy(modifiedAt = Instant.now()) filterRepo.save(setOf(toSave)) + if (initialOptions?.saveAsEnabled == true) { + settings.toggleCustomFilter(toSave.identifier, true) + } popNavStack() } diff --git a/app/src/main/java/eu/darken/sdmse/systemcleaner/ui/customfilter/list/CustomFilterListViewModel.kt b/app/src/main/java/eu/darken/sdmse/systemcleaner/ui/customfilter/list/CustomFilterListViewModel.kt index 87020b3c5..87f10b87e 100644 --- a/app/src/main/java/eu/darken/sdmse/systemcleaner/ui/customfilter/list/CustomFilterListViewModel.kt +++ b/app/src/main/java/eu/darken/sdmse/systemcleaner/ui/customfilter/list/CustomFilterListViewModel.kt @@ -14,6 +14,7 @@ import eu.darken.sdmse.main.ui.dashboard.items.* import eu.darken.sdmse.systemcleaner.core.SystemCleanerSettings import eu.darken.sdmse.systemcleaner.core.filter.custom.CustomFilterConfig import eu.darken.sdmse.systemcleaner.core.filter.custom.CustomFilterRepo +import eu.darken.sdmse.systemcleaner.core.filter.custom.toggleCustomFilter import eu.darken.sdmse.systemcleaner.ui.customfilter.list.types.CustomFilterDefaultVH import kotlinx.coroutines.flow.* import javax.inject.Inject @@ -46,10 +47,7 @@ class CustomFilterListViewModel @Inject constructor( isEnabled = enabledFilters.contains(config.identifier), onItemClick = { launch { - systemCleanerSettings.enabledCustomFilter.update { - val newId = config.identifier - if (it.contains(newId)) it - newId else it + newId - } + systemCleanerSettings.toggleCustomFilter(config.identifier) } }, onEditClick = { edit(it) }