fix(home): clear recent activity permanently

This commit is contained in:
zarzet committed 2026-08-22 22:45:06 +07:00
1 parent b1180a70a7
commit 75e1cf17b8
19 files changed
+173 -22

No files matched your search

+21 -3
View File
@@ -5,6 +5,13 @@ import 'package:spotiflac_android/services/app_state_database.dart';
const _maxRecentItems = 20;
bool isRecentDownloadAfterClear(
DateTime downloadedAt,
DateTime? downloadsClearedAt,
) {
return downloadsClearedAt == null || downloadedAt.isAfter(downloadsClearedAt);
}
enum RecentAccessType { artist, album, track, playlist }
class RecentAccessItem {
@@ -67,22 +74,26 @@ class RecentAccessItem {
class RecentAccessState {
final List<RecentAccessItem> items;
final Set<String> hiddenDownloadIds;
final DateTime? downloadsClearedAt;
final bool isLoaded;
const RecentAccessState({
this.items = const [],
this.hiddenDownloadIds = const {},
this.downloadsClearedAt,
this.isLoaded = false,
});
RecentAccessState copyWith({
List<RecentAccessItem>? items,
Set<String>? hiddenDownloadIds,
DateTime? downloadsClearedAt,
bool? isLoaded,
}) {
return RecentAccessState(
items: items ?? this.items,
hiddenDownloadIds: hiddenDownloadIds ?? this.hiddenDownloadIds,
downloadsClearedAt: downloadsClearedAt ?? this.downloadsClearedAt,
isLoaded: isLoaded ?? this.isLoaded,
);
}
@@ -104,6 +115,8 @@ class RecentAccessNotifier extends Notifier<RecentAccessState> {
limit: _maxRecentItems,
);
final hiddenIds = await _appStateDb.getHiddenRecentDownloadIds();
final downloadsClearedAt = await _appStateDb
.getRecentDownloadsClearedAt();
final items = <RecentAccessItem>[];
for (final row in rows) {
@@ -123,6 +136,7 @@ class RecentAccessNotifier extends Notifier<RecentAccessState> {
state = state.copyWith(
items: items,
hiddenDownloadIds: hiddenIds,
downloadsClearedAt: downloadsClearedAt,
isLoaded: true,
);
} catch (_) {
@@ -251,9 +265,13 @@ class RecentAccessNotifier extends Notifier<RecentAccessState> {
return state.hiddenDownloadIds.contains(downloadId);
}
void clearHistory() {
state = state.copyWith(items: []);
unawaited(_appStateDb.clearRecentAccessRows());
Future<void> clearHistory() async {
final clearedAt = await _appStateDb.clearAllRecentAccess();
state = state.copyWith(
items: [],
hiddenDownloadIds: {},
downloadsClearedAt: clearedAt,
);
}
void clearHiddenDownloads() {