Merge branch 'refs/heads/dev'

This commit is contained in:
nyne
2024-11-02 20:31:43 +08:00
24 changed files with 576 additions and 122 deletions

View File

@@ -261,8 +261,14 @@ class LocalManager with ChangeNotifier {
notifyListeners();
}
List<LocalComic> getComics() {
final res = _db.select('SELECT * FROM comics;');
List<LocalComic> getComics(LocalSortType sortType) {
var res = _db.select('''
SELECT * FROM comics
ORDER BY
${sortType.value == 'name' ? 'title' : 'created_at'}
${sortType.value == 'time_asc' ? 'ASC' : 'DESC'}
;
''');
return res.map((row) => LocalComic.fromRow(row)).toList();
}
@@ -310,6 +316,15 @@ class LocalManager with ChangeNotifier {
return LocalComic.fromRow(res.first);
}
List<LocalComic> search(String keyword) {
final res = _db.select('''
SELECT * FROM comics
WHERE title LIKE ? OR tags LIKE ? OR subtitle LIKE ?
ORDER BY created_at DESC;
''', ['%$keyword%', '%$keyword%', '%$keyword%']);
return res.map((row) => LocalComic.fromRow(row)).toList();
}
Future<List<String>> getImages(String id, ComicType type, Object ep) async {
if(ep is! String && ep is! int) {
throw "Invalid ep";
@@ -429,3 +444,22 @@ class LocalManager with ChangeNotifier {
notifyListeners();
}
}
enum LocalSortType {
name("name"),
timeAsc("time_asc"),
timeDesc("time_desc");
final String value;
const LocalSortType(this.value);
static LocalSortType fromString(String value) {
for (var type in values) {
if (type.value == value) {
return type;
}
}
return name;
}
}