Skip to content

Commit

Permalink
Dashboard: Fix task results showing inconsistently
Browse files Browse the repository at this point in the history
Improve how the task manager handles the task history.
We pruned new tasks instead of old tasks.
As SD Maid uses the last task manager results to display either scan or deletion results, this lead to new scans not displaying their results in the dashboard.
  • Loading branch information
d4rken committed Jul 25, 2024
1 parent 8cd2082 commit 30a3581
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,18 @@ class TaskManager @Inject constructor(
.distinctUntilChanged()
.onEach {
updateTasks {
this.entries
// We want to keep one result of each type
val tasksByType = this.entries
.asSequence()
.filter { it.value.isComplete }
.sortedBy { it.value.completedAt }
.groupBy { it.value.toolType }

// Keep the newest for each type
val tasksToRemove = tasksByType
.flatMap { (_, tasks) -> tasks.sortedByDescending { it.value.completedAt }.drop(1) }
.map { it.key }
.drop(10)

tasksToRemove
.onEach {
log(TAG, VERBOSE) { "Pruning old task: $it" }
remove(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class DashboardViewModel @Inject constructor(

private val titleCardItem = combine(
upgradeInfo,
taskManager.state
taskManager.state,
) { upgradeInfo, taskState ->
TitleCardVH.Item(
upgradeInfo = upgradeInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class SchedulerManagerViewModel @Inject constructor(
schedulerManager.state,
taskManager.state,
showBatteryOptimizationHint,
) { schedulerState, taskState, showBatteryHint ->
) { schedulerState, _, showBatteryHint ->
val items = mutableListOf<SchedulerAdapter.Item>()

if (hasApiLevel(31) && showBatteryHint && schedulerState.schedules.any { it.isEnabled }) {
Expand Down

0 comments on commit 30a3581

Please sign in to comment.