Add Favorite multiple selections (#66)

This commit is contained in:
AnxuNA
2024-11-22 12:21:22 +08:00
committed by GitHub
parent f3aa0e9f27
commit 8b1f13cd33
5 changed files with 614 additions and 219 deletions

View File

@@ -12,10 +12,7 @@ import 'comic_source/comic_source.dart';
import 'comic_type.dart';
String _getTimeString(DateTime time) {
return time
.toIso8601String()
.replaceFirst("T", " ")
.substring(0, 19);
return time.toIso8601String().replaceFirst("T", " ").substring(0, 19);
}
class FavoriteItem implements Comic {
@@ -29,15 +26,14 @@ class FavoriteItem implements Comic {
String coverPath;
late String time;
FavoriteItem({
required this.id,
required this.name,
required this.coverPath,
required this.author,
required this.type,
required this.tags,
DateTime? favoriteTime
}) {
FavoriteItem(
{required this.id,
required this.name,
required this.coverPath,
required this.author,
required this.type,
required this.tags,
DateTime? favoriteTime}) {
var t = favoriteTime ?? DateTime.now();
time = _getTimeString(t);
}
@@ -355,7 +351,8 @@ class LocalFavoritesManager with ChangeNotifier {
""", [folder, source, networkFolder]);
}
bool isLinkedToNetworkFolder(String folder, String source, String networkFolder) {
bool isLinkedToNetworkFolder(
String folder, String source, String networkFolder) {
var res = _db.select("""
select * from folder_sync
where folder_name == ? and source_key == ? and source_folder == ?;
@@ -436,6 +433,41 @@ class LocalFavoritesManager with ChangeNotifier {
return true;
}
void moveFavorite(
String sourceFolder, String targetFolder, String id, ComicType type) {
_modifiedAfterLastCache = true;
if (!existsFolder(sourceFolder)) {
throw Exception("Source folder does not exist");
}
if (!existsFolder(targetFolder)) {
throw Exception("Target folder does not exist");
}
var res = _db.select("""
select * from "$targetFolder"
where id == ? and type == ?;
""", [id, type.value]);
if (res.isNotEmpty) {
return;
}
_db.execute("""
insert into "$targetFolder" (id, name, author, type, tags, cover_path, time, display_order)
select id, name, author, type, tags, cover_path, time, ?
from "$sourceFolder"
where id == ? and type == ?;
""", [minValue(targetFolder) - 1, id, type.value]);
_db.execute("""
delete from "$sourceFolder"
where id == ? and type == ?;
""", [id, type.value]);
notifyListeners();
}
/// delete a folder
void deleteFolder(String name) {
_modifiedAfterLastCache = true;