Add clear unfavorited history functionality. Close #372

This commit is contained in:
nyne
2025-05-22 19:59:42 +08:00
parent 8f357b3e6c
commit 88f093f7e5
3 changed files with 29 additions and 3 deletions

View File

@@ -10,6 +10,7 @@ import 'package:flutter/widgets.dart' show ChangeNotifier;
import 'package:sqlite3/sqlite3.dart';
import 'package:venera/foundation/comic_source/comic_source.dart';
import 'package:venera/foundation/comic_type.dart';
import 'package:venera/foundation/favorites.dart';
import 'package:venera/foundation/image_provider/image_favorites_provider.dart';
import 'package:venera/foundation/log.dart';
import 'package:venera/utils/ext.dart';
@@ -305,6 +306,22 @@ class HistoryManager with ChangeNotifier {
notifyListeners();
}
void clearUnfavoritedHistory() {
final idAndTypes = _db.select("""
select id, type from history;
""");
for (var element in idAndTypes) {
final id = element["id"] as String;
final type = ComicType(element["type"] as int);
if (!LocalFavoritesManager().isExist(id, type)) {
_db.execute("""
delete from history
where id == ? and type == ?;
""", [id, type.value]);
}
}
}
void remove(String id, ComicType type) async {
_db.execute("""
delete from history

View File

@@ -140,6 +140,13 @@ class _HistoryPageState extends State<HistoryPage> {
title: 'Clear History'.tl,
content: Text('Are you sure you want to clear your history?'.tl),
actions: [
Button.outlined(
onPressed: () {
HistoryManager().clearUnfavoritedHistory();
context.pop();
},
child: Text('Clear Unfavorited'.tl),
),
Button.filled(
color: context.colorScheme.error,
onPressed: () {