When adding a favorite, also add the update time.

This commit is contained in:
2025-02-15 16:32:51 +08:00
parent 5c162d2800
commit 3ff2f6aa36
3 changed files with 36 additions and 12 deletions

View File

@@ -462,7 +462,8 @@ class LocalFavoritesManager with ChangeNotifier {
/// add comic to a folder.
/// return true if success, false if already exists
bool addComic(String folder, FavoriteItem comic, [int? order]) {
bool addComic(String folder, FavoriteItem comic,
[int? order, String? updateTime]) {
_modifiedAfterLastCache = true;
if (!existsFolder(folder)) {
throw Exception("Folder does not exists");
@@ -501,6 +502,18 @@ class LocalFavoritesManager with ChangeNotifier {
values (?, ?, ?, ?, ?, ?, ?, ?, ?);
""", [...params, minValue(folder) - 1]);
}
if (updateTime != null) {
var columns = _db.select("""
pragma table_info("$folder");
""");
if (columns.any((element) => element["name"] == "last_update_time")) {
_db.execute("""
update "$folder"
set last_update_time = ?
where id == ? and type == ?;
""", [updateTime, comic.id, comic.type.value]);
}
}
notifyListeners();
return true;
}

View File

@@ -61,6 +61,7 @@ abstract mixin class _ComicPageActions {
update();
},
favoriteItem: _toFavoriteItem(),
updateTime: comic.findUpdateTime(),
),
);
}
@@ -73,6 +74,8 @@ abstract mixin class _ComicPageActions {
LocalFavoritesManager().addComic(
folder,
_toFavoriteItem(),
null,
comic.findUpdateTime(),
);
isAddToLocalFav = true;
update();

View File

@@ -7,6 +7,7 @@ class _FavoritePanel extends StatefulWidget {
required this.isFavorite,
required this.onFavorite,
required this.favoriteItem,
this.updateTime,
});
final String cid;
@@ -22,6 +23,8 @@ class _FavoritePanel extends StatefulWidget {
final FavoriteItem favoriteItem;
final String? updateTime;
@override
State<_FavoritePanel> createState() => _FavoritePanelState();
}
@@ -190,7 +193,12 @@ class _FavoritePanelState extends State<_FavoritePanel>
widget.onFavorite(false, null);
} else {
for (var folder in selectedLocalFolders) {
LocalFavoritesManager().addComic(folder, widget.favoriteItem);
LocalFavoritesManager().addComic(
folder,
widget.favoriteItem,
null,
widget.updateTime,
);
}
widget.onFavorite(true, null);
}