Skip to content

Commit

Permalink
Fixed trash size
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihai-Cristian Condrea committed Oct 22, 2024
1 parent a037831 commit d1ee539
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ class DataStore(context : Context) {
}
}

suspend fun subtractTrashSize(size: Long) {
dataStore.edit { settings ->
val currentSize = settings[trashSizeKey] ?: 0L
settings[trashSizeKey] = (currentSize - size).coerceAtLeast(0L)
}
}

private val genericFilterKey =
booleanPreferencesKey(name = DataStoreNamesConstants.DATA_STORE_GENERIC_FILTER)
val genericFilter : Flow<Boolean> = dataStore.data.map { preferences ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class HomeRepository(
}
}

suspend fun getLastScanInfo(onSuccess: (Int) -> Unit) {
suspend fun getLastScanInfo(onSuccess : (Int) -> Unit) {
withContext(Dispatchers.IO) {
dataStore.lastScanTimestamp.firstOrNull()?.let { timestamp ->
val daysFromLastScan = calculateDaysSince(timestamp)
Expand Down Expand Up @@ -140,10 +140,6 @@ class HomeRepository(
}
}

suspend fun addTrashSize(size: Long) {
dataStore.addTrashSize(size)
}

/**
* Restores the specified files from the trash directory.
* @param filesToRestore The set of files to restore from trash.
Expand All @@ -159,4 +155,12 @@ class HomeRepository(
}
}
}

suspend fun addTrashSize(size : Long) {
dataStore.addTrashSize(size)
}

suspend fun subtractTrashSize(size : Long) {
dataStore.subtractTrashSize(size)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class TrashViewModel(application : Application) : BaseViewModel(application) {
repository.restoreFromTrash(filesToRestore) {
loadTrashItems()
}
repository.subtractTrashSize(filesToRestore.sumOf { it.length() })
hideLoading()
}
}
Expand All @@ -64,6 +65,7 @@ class TrashViewModel(application : Application) : BaseViewModel(application) {
repository.deleteFiles(filesToDelete) {
loadTrashItems()
}
repository.subtractTrashSize(filesToDelete.sumOf { it.length() })
hideLoading()
println("Cleaner for Android -> Hiding loading indicator")
}
Expand Down

0 comments on commit d1ee539

Please sign in to comment.