Skip to content

Commit

Permalink
Don't automatically disable filters after editing or on creation.
Browse files Browse the repository at this point in the history
Might be a bit more dangerous but it's super frustrating.
(and if we create one via analyzer, then the user needs to navigate and extra round-trip just to enable it.
  • Loading branch information
d4rken committed Aug 17, 2023
1 parent 424b8df commit 8f3f06a
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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")
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class EditorOptionsCreator @Inject constructor(
label = label,
areas = targetAreas,
pathCriteria = pathCriteria,
saveAsEnabled = true,
).also { log(TAG, INFO) { "Editor options are : $it" } }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ data class CustomFilterEditorOptions(
val label: String? = null,
val pathCriteria: Set<SegmentCriterium>? = null,
val nameCriteria: Set<NameCriterium>? = null,
val saveAsEnabled: Boolean = false,
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<CustomFilterEditorFragmentArgs>()
Expand Down Expand Up @@ -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()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) }
Expand Down

0 comments on commit 8f3f06a

Please sign in to comment.