@@ -12,13 +12,9 @@ import com.d4rk.cleaner.app.clean.scanner.domain.usecases.GetEmptyFoldersUseCase
1212import com.d4rk.cleaner.app.clean.scanner.domain.usecases.GetFileTypesUseCase
1313import com.d4rk.cleaner.app.images.utils.ImageHashUtils
1414import com.d4rk.cleaner.app.settings.cleaning.utils.constants.ExtensionsConstants
15- import com.d4rk.cleaner.core.utils.constants.datastore.AppDataStoreConstants
1615import com.d4rk.cleaner.core.data.datastore.DataStore
1716import com.d4rk.cleaner.core.utils.extensions.partialMd5
1817import com.d4rk.cleaner.core.utils.helpers.CleaningEventBus
19- import androidx.datastore.preferences.core.booleanPreferencesKey
20- import androidx.datastore.preferences.core.intPreferencesKey
21- import androidx.datastore.preferences.core.longPreferencesKey
2218import kotlinx.coroutines.flow.first
2319import org.koin.core.component.KoinComponent
2420import org.koin.core.component.inject
@@ -38,19 +34,11 @@ class AutoCleanWorker(
3834 private val repository: ScannerRepositoryInterface by inject()
3935
4036 override suspend fun doWork (): Result {
41- val preferences = dataStore.data.first()
42-
43- val autoCleanEnabled =
44- preferences[booleanPreferencesKey(AppDataStoreConstants .DATA_STORE_AUTO_CLEAN_ENABLED )]
45- ? : false
37+ val autoCleanEnabled = dataStore.autoCleanEnabled.first()
4638 if (! autoCleanEnabled) return Result .success()
4739
48- val frequency =
49- preferences[intPreferencesKey(AppDataStoreConstants .DATA_STORE_AUTO_CLEAN_FREQUENCY_DAYS )]
50- ? : 7
51- val lastScan =
52- preferences[longPreferencesKey(AppDataStoreConstants .DATA_STORE_LAST_SCAN_TIMESTAMP )]
53- ? : 0L
40+ val frequency = dataStore.autoCleanFrequencyDays.first()
41+ val lastScan = dataStore.lastScanTimestamp.first() ? : 0L
5442 val now = System .currentTimeMillis()
5543 if (frequency <= 0 || now - lastScan < frequency.days.inWholeMilliseconds) {
5644 return Result .success()
@@ -88,22 +76,20 @@ class AutoCleanWorker(
8876 val types = if (typesState is DataState .Success ) typesState.data else FileTypesData ()
8977
9078 val prefs = mapOf (
91- ExtensionsConstants .IMAGE_EXTENSIONS to (preferences[booleanPreferencesKey( AppDataStoreConstants . DATA_STORE_DELETE_IMAGE_FILES )] != false ),
92- ExtensionsConstants .VIDEO_EXTENSIONS to (preferences[booleanPreferencesKey( AppDataStoreConstants . DATA_STORE_DELETE_VIDEO_FILES )] != false ),
93- ExtensionsConstants .AUDIO_EXTENSIONS to (preferences[booleanPreferencesKey( AppDataStoreConstants . DATA_STORE_DELETE_AUDIO_FILES )] != false ),
94- ExtensionsConstants .OFFICE_EXTENSIONS to (preferences[booleanPreferencesKey( AppDataStoreConstants . DATA_STORE_DELETE_OFFICE_FILES )] != false ),
95- ExtensionsConstants .ARCHIVE_EXTENSIONS to (preferences[booleanPreferencesKey( AppDataStoreConstants . DATA_STORE_DELETE_ARCHIVES )] == true ),
96- ExtensionsConstants .APK_EXTENSIONS to (preferences[booleanPreferencesKey( AppDataStoreConstants . DATA_STORE_DELETE_APK_FILES )] == true ),
97- ExtensionsConstants .FONT_EXTENSIONS to (preferences[booleanPreferencesKey( AppDataStoreConstants . DATA_STORE_DELETE_FONT_FILES )] != false ),
98- ExtensionsConstants .WINDOWS_EXTENSIONS to (preferences[booleanPreferencesKey( AppDataStoreConstants . DATA_STORE_DELETE_WINDOWS_FILES )] != false ),
99- ExtensionsConstants .EMPTY_FOLDERS to (preferences[booleanPreferencesKey( AppDataStoreConstants . DATA_STORE_DELETE_EMPTY_FOLDERS )] == true ),
100- ExtensionsConstants .OTHER_EXTENSIONS to (preferences[booleanPreferencesKey( AppDataStoreConstants . DATA_STORE_OTHER_EXTENSIONS )] != false )
79+ ExtensionsConstants .IMAGE_EXTENSIONS to dataStore.deleteImageFiles.first( ),
80+ ExtensionsConstants .VIDEO_EXTENSIONS to dataStore.deleteVideoFiles.first( ),
81+ ExtensionsConstants .AUDIO_EXTENSIONS to dataStore.deleteAudioFiles.first( ),
82+ ExtensionsConstants .OFFICE_EXTENSIONS to dataStore.deleteOfficeFiles.first( ),
83+ ExtensionsConstants .ARCHIVE_EXTENSIONS to dataStore.deleteArchives.first( ),
84+ ExtensionsConstants .APK_EXTENSIONS to dataStore.deleteApkFiles.first( ),
85+ ExtensionsConstants .FONT_EXTENSIONS to dataStore.deleteFontFiles.first( ),
86+ ExtensionsConstants .WINDOWS_EXTENSIONS to dataStore.deleteWindowsFiles.first( ),
87+ ExtensionsConstants .EMPTY_FOLDERS to dataStore.deleteEmptyFolders.first( ),
88+ ExtensionsConstants .OTHER_EXTENSIONS to dataStore.deleteOtherFiles.first( )
10189 )
10290 val includeDuplicates =
103- (preferences[booleanPreferencesKey(AppDataStoreConstants .DATA_STORE_DELETE_DUPLICATE_FILES )] == true ) &&
104- (preferences[booleanPreferencesKey(AppDataStoreConstants .DATA_STORE_ENABLE_DUPLICATE_SCAN )] ? : true )
105- val deepDuplicateSearch =
106- preferences[booleanPreferencesKey(AppDataStoreConstants .DATA_STORE_DEEP_DUPLICATE_SEARCH )] == true
91+ dataStore.deleteDuplicateFiles.first() && dataStore.duplicateScanEnabled.first()
92+ val deepDuplicateSearch = dataStore.deepDuplicateSearch.first()
10793 val toDelete = computeFilesToClean(
10894 files,
10995 emptyFolders,
0 commit comments