mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 07:47:24 +00:00
Merge branch 'refs/heads/dev'
This commit is contained in:
@@ -10,7 +10,7 @@ export "widget_utils.dart";
|
||||
export "context.dart";
|
||||
|
||||
class _App {
|
||||
final version = "1.0.0";
|
||||
final version = "1.0.1";
|
||||
|
||||
bool get isAndroid => Platform.isAndroid;
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:venera/foundation/app.dart';
|
||||
import 'package:venera/utils/io.dart';
|
||||
@@ -85,7 +86,7 @@ class _Appdata {
|
||||
|
||||
final appdata = _Appdata();
|
||||
|
||||
class _Settings {
|
||||
class _Settings with ChangeNotifier {
|
||||
_Settings();
|
||||
|
||||
final _data = <String, dynamic>{
|
||||
@@ -117,6 +118,7 @@ class _Settings {
|
||||
|
||||
operator []=(String key, dynamic value) {
|
||||
_data[key] = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
|
@@ -83,7 +83,9 @@ class FavoriteItem implements Comic {
|
||||
int? get maxPage => null;
|
||||
|
||||
@override
|
||||
String get sourceKey => type == ComicType.local ? 'local' : type.comicSource?.key ?? "Unknown:${type.value}";
|
||||
String get sourceKey => type == ComicType.local
|
||||
? 'local'
|
||||
: type.comicSource?.key ?? "Unknown:${type.value}";
|
||||
|
||||
@override
|
||||
double? get stars => null;
|
||||
@@ -108,17 +110,17 @@ class FavoriteItem implements Comic {
|
||||
|
||||
static FavoriteItem fromJson(Map<String, dynamic> json) {
|
||||
var type = json["type"] as int;
|
||||
if(type == 0 && json['coverPath'].toString().startsWith('http')) {
|
||||
if (type == 0 && json['coverPath'].toString().startsWith('http')) {
|
||||
type = 'picacg'.hashCode;
|
||||
} else if(type == 1) {
|
||||
} else if (type == 1) {
|
||||
type = 'ehentai'.hashCode;
|
||||
} else if(type == 2) {
|
||||
} else if (type == 2) {
|
||||
type = 'jm'.hashCode;
|
||||
} else if(type == 3) {
|
||||
} else if (type == 3) {
|
||||
type = 'hitomi'.hashCode;
|
||||
} else if(type == 4) {
|
||||
} else if (type == 4) {
|
||||
type = 'wnacg'.hashCode;
|
||||
} else if(type == 6) {
|
||||
} else if (type == 6) {
|
||||
type = 'nhentai'.hashCode;
|
||||
}
|
||||
return FavoriteItem(
|
||||
@@ -132,21 +134,18 @@ class FavoriteItem implements Comic {
|
||||
}
|
||||
}
|
||||
|
||||
class FavoriteItemWithFolderInfo {
|
||||
FavoriteItem comic;
|
||||
class FavoriteItemWithFolderInfo extends FavoriteItem {
|
||||
String folder;
|
||||
|
||||
FavoriteItemWithFolderInfo(this.comic, this.folder);
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is FavoriteItemWithFolderInfo &&
|
||||
other.comic == comic &&
|
||||
other.folder == folder;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => comic.hashCode ^ folder.hashCode;
|
||||
FavoriteItemWithFolderInfo(FavoriteItem item, this.folder)
|
||||
: super(
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
coverPath: item.coverPath,
|
||||
author: item.author,
|
||||
type: item.type,
|
||||
tags: item.tags,
|
||||
);
|
||||
}
|
||||
|
||||
class LocalFavoritesManager {
|
||||
@@ -498,11 +497,11 @@ class LocalFavoritesManager {
|
||||
}
|
||||
|
||||
bool test(FavoriteItemWithFolderInfo comic, String keyword) {
|
||||
if (comic.comic.name.contains(keyword)) {
|
||||
if (comic.name.contains(keyword)) {
|
||||
return true;
|
||||
} else if (comic.comic.author.contains(keyword)) {
|
||||
} else if (comic.author.contains(keyword)) {
|
||||
return true;
|
||||
} else if (comic.comic.tags.any((element) => element.contains(keyword))) {
|
||||
} else if (comic.tags.any((element) => element.contains(keyword))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -577,7 +576,7 @@ class LocalFavoritesManager {
|
||||
void fromJson(String json) {
|
||||
var data = jsonDecode(json);
|
||||
var folder = data["name"];
|
||||
if(folder == null || folder is! String) {
|
||||
if (folder == null || folder is! String) {
|
||||
throw "Invalid data";
|
||||
}
|
||||
if (folderNames.contains(folder)) {
|
||||
@@ -591,10 +590,13 @@ class LocalFavoritesManager {
|
||||
for (var comic in data["comics"]) {
|
||||
try {
|
||||
addComic(folder, FavoriteItem.fromJson(comic));
|
||||
}
|
||||
catch(e) {
|
||||
} catch (e) {
|
||||
Log.error("Import Data", e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void close() {
|
||||
_db.dispose();
|
||||
}
|
||||
}
|
||||
|
@@ -172,6 +172,8 @@ class HistoryManager with ChangeNotifier {
|
||||
max_page int
|
||||
);
|
||||
""");
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// add history. if exists, update time.
|
||||
@@ -275,4 +277,8 @@ class HistoryManager with ChangeNotifier {
|
||||
""");
|
||||
return res.first[0] as int;
|
||||
}
|
||||
|
||||
void close() {
|
||||
_db.dispose();
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user