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

@@ -146,7 +146,16 @@
"Select a cbz file." : "选择一个cbz文件", "Select a cbz file." : "选择一个cbz文件",
"A cbz file" : "一个cbz文件", "A cbz file" : "一个cbz文件",
"Fullscreen": "全屏", "Fullscreen": "全屏",
"Exit": "退出" "Exit": "退出",
"View more": "查看更多",
"Sort": "排序",
"Name": "名称",
"Date": "日期",
"Date Desc": "日期降序",
"Start": "开始",
"Export App Data": "导出应用数据",
"Import App Data": "导入应用数据",
"Export": "导出"
}, },
"zh_TW": { "zh_TW": {
"Home": "首頁", "Home": "首頁",
@@ -295,6 +304,15 @@
"Select a cbz file." : "選擇一個cbz文件", "Select a cbz file." : "選擇一個cbz文件",
"A cbz file" : "一個cbz文件", "A cbz file" : "一個cbz文件",
"Fullscreen": "全螢幕", "Fullscreen": "全螢幕",
"Exit": "退出" "Exit": "退出",
"View more": "查看更多",
"Sort": "排序",
"Name": "名稱",
"Date": "日期",
"Date Desc": "日期降序",
"Start": "開始",
"Export App Data": "匯出應用數據",
"Import App Data": "匯入應用數據",
"Export": "匯出"
} }
} }

View File

@@ -156,7 +156,7 @@ class _ButtonState extends State<Button> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var padding = widget.padding ?? var padding = widget.padding ??
const EdgeInsets.symmetric(horizontal: 16, vertical: 6); const EdgeInsets.symmetric(horizontal: 16, vertical: 4);
var width = widget.width; var width = widget.width;
if (width != null) { if (width != null) {
width = width - padding.horizontal; width = width - padding.horizontal;
@@ -172,7 +172,7 @@ class _ButtonState extends State<Button> {
child: DefaultTextStyle( child: DefaultTextStyle(
style: TextStyle( style: TextStyle(
color: textColor, color: textColor,
fontSize: 16, fontSize: 14,
), ),
child: isLoading child: isLoading
? CircularProgressIndicator( ? CircularProgressIndicator(
@@ -210,11 +210,11 @@ class _ButtonState extends State<Button> {
decoration: BoxDecoration( decoration: BoxDecoration(
color: buttonColor, color: buttonColor,
borderRadius: BorderRadius.circular(16), borderRadius: BorderRadius.circular(16),
boxShadow: (isHover && !isLoading && widget.type == ButtonType.filled) boxShadow: (isHover && !isLoading && (widget.type == ButtonType.filled || widget.type == ButtonType.normal))
? [ ? [
BoxShadow( BoxShadow(
color: Colors.black.withOpacity(0.1), color: Colors.black.withOpacity(0.1),
blurRadius: 4, blurRadius: 2,
offset: const Offset(0, 1), offset: const Offset(0, 1),
) )
] ]
@@ -252,6 +252,14 @@ class _ButtonState extends State<Button> {
return color; return color;
} }
} }
if (widget.type == ButtonType.normal) {
var color = widget.color ?? context.colorScheme.surfaceContainer;
if (isHover) {
return color.withOpacity(0.9);
} else {
return color;
}
}
if (isHover) { if (isHover) {
return context.colorScheme.outline.withOpacity(0.2); return context.colorScheme.outline.withOpacity(0.2);
} }

View File

@@ -872,6 +872,7 @@ class ComicListState extends State<ComicList> {
try { try {
if (widget.loadPage != null) { if (widget.loadPage != null) {
var res = await widget.loadPage!(page); var res = await widget.loadPage!(page);
if(!mounted) return;
if (res.success) { if (res.success) {
if (res.data.isEmpty) { if (res.data.isEmpty) {
_data[page] = const []; _data[page] = const [];

View File

@@ -10,7 +10,7 @@ export "widget_utils.dart";
export "context.dart"; export "context.dart";
class _App { class _App {
final version = "1.0.0"; final version = "1.0.1";
bool get isAndroid => Platform.isAndroid; bool get isAndroid => Platform.isAndroid;

View File

@@ -1,5 +1,6 @@
import 'dart:convert'; import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
import 'package:venera/foundation/app.dart'; import 'package:venera/foundation/app.dart';
import 'package:venera/utils/io.dart'; import 'package:venera/utils/io.dart';
@@ -85,7 +86,7 @@ class _Appdata {
final appdata = _Appdata(); final appdata = _Appdata();
class _Settings { class _Settings with ChangeNotifier {
_Settings(); _Settings();
final _data = <String, dynamic>{ final _data = <String, dynamic>{
@@ -117,6 +118,7 @@ class _Settings {
operator []=(String key, dynamic value) { operator []=(String key, dynamic value) {
_data[key] = value; _data[key] = value;
notifyListeners();
} }
@override @override

View File

@@ -83,7 +83,9 @@ class FavoriteItem implements Comic {
int? get maxPage => null; int? get maxPage => null;
@override @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 @override
double? get stars => null; double? get stars => null;
@@ -108,17 +110,17 @@ class FavoriteItem implements Comic {
static FavoriteItem fromJson(Map<String, dynamic> json) { static FavoriteItem fromJson(Map<String, dynamic> json) {
var type = json["type"] as int; 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; type = 'picacg'.hashCode;
} else if(type == 1) { } else if (type == 1) {
type = 'ehentai'.hashCode; type = 'ehentai'.hashCode;
} else if(type == 2) { } else if (type == 2) {
type = 'jm'.hashCode; type = 'jm'.hashCode;
} else if(type == 3) { } else if (type == 3) {
type = 'hitomi'.hashCode; type = 'hitomi'.hashCode;
} else if(type == 4) { } else if (type == 4) {
type = 'wnacg'.hashCode; type = 'wnacg'.hashCode;
} else if(type == 6) { } else if (type == 6) {
type = 'nhentai'.hashCode; type = 'nhentai'.hashCode;
} }
return FavoriteItem( return FavoriteItem(
@@ -132,21 +134,18 @@ class FavoriteItem implements Comic {
} }
} }
class FavoriteItemWithFolderInfo { class FavoriteItemWithFolderInfo extends FavoriteItem {
FavoriteItem comic;
String folder; String folder;
FavoriteItemWithFolderInfo(this.comic, this.folder); FavoriteItemWithFolderInfo(FavoriteItem item, this.folder)
: super(
@override id: item.id,
bool operator ==(Object other) { name: item.name,
return other is FavoriteItemWithFolderInfo && coverPath: item.coverPath,
other.comic == comic && author: item.author,
other.folder == folder; type: item.type,
} tags: item.tags,
);
@override
int get hashCode => comic.hashCode ^ folder.hashCode;
} }
class LocalFavoritesManager { class LocalFavoritesManager {
@@ -498,11 +497,11 @@ class LocalFavoritesManager {
} }
bool test(FavoriteItemWithFolderInfo comic, String keyword) { bool test(FavoriteItemWithFolderInfo comic, String keyword) {
if (comic.comic.name.contains(keyword)) { if (comic.name.contains(keyword)) {
return true; return true;
} else if (comic.comic.author.contains(keyword)) { } else if (comic.author.contains(keyword)) {
return true; return true;
} else if (comic.comic.tags.any((element) => element.contains(keyword))) { } else if (comic.tags.any((element) => element.contains(keyword))) {
return true; return true;
} }
return false; return false;
@@ -577,7 +576,7 @@ class LocalFavoritesManager {
void fromJson(String json) { void fromJson(String json) {
var data = jsonDecode(json); var data = jsonDecode(json);
var folder = data["name"]; var folder = data["name"];
if(folder == null || folder is! String) { if (folder == null || folder is! String) {
throw "Invalid data"; throw "Invalid data";
} }
if (folderNames.contains(folder)) { if (folderNames.contains(folder)) {
@@ -591,10 +590,13 @@ class LocalFavoritesManager {
for (var comic in data["comics"]) { for (var comic in data["comics"]) {
try { try {
addComic(folder, FavoriteItem.fromJson(comic)); addComic(folder, FavoriteItem.fromJson(comic));
} } catch (e) {
catch(e) {
Log.error("Import Data", e.toString()); Log.error("Import Data", e.toString());
} }
} }
} }
void close() {
_db.dispose();
}
} }

View File

@@ -172,6 +172,8 @@ class HistoryManager with ChangeNotifier {
max_page int max_page int
); );
"""); """);
notifyListeners();
} }
/// add history. if exists, update time. /// add history. if exists, update time.
@@ -275,4 +277,8 @@ class HistoryManager with ChangeNotifier {
"""); """);
return res.first[0] as int; return res.first[0] as int;
} }
void close() {
_db.dispose();
}
} }

View File

@@ -261,8 +261,14 @@ class LocalManager with ChangeNotifier {
notifyListeners(); notifyListeners();
} }
List<LocalComic> getComics() { List<LocalComic> getComics(LocalSortType sortType) {
final res = _db.select('SELECT * FROM comics;'); 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(); return res.map((row) => LocalComic.fromRow(row)).toList();
} }
@@ -310,6 +316,15 @@ class LocalManager with ChangeNotifier {
return LocalComic.fromRow(res.first); 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 { Future<List<String>> getImages(String id, ComicType type, Object ep) async {
if(ep is! String && ep is! int) { if(ep is! String && ep is! int) {
throw "Invalid ep"; throw "Invalid ep";
@@ -429,3 +444,22 @@ class LocalManager with ChangeNotifier {
notifyListeners(); 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;
}
}

View File

@@ -197,6 +197,7 @@ class ImagesDownloadTask extends DownloadTask with _TransferSpeedMixin {
_scheduleTasks(); _scheduleTasks();
} }
}); });
downloading++;
} }
} }
@@ -590,5 +591,7 @@ abstract mixin class _TransferSpeedMixin {
void stopRecorder() { void stopRecorder() {
timer?.cancel(); timer?.cancel();
timer = null; timer = null;
_currentSpeed = 0;
_bytesSinceLastSecond = 0;
} }
} }

View File

@@ -42,12 +42,41 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
bool isDownloaded = false; bool isDownloaded = false;
void updateHistory() async {
var newHistory = await HistoryManager()
.find(widget.id, ComicType(widget.sourceKey.hashCode));
if(newHistory?.ep != history?.ep || newHistory?.page != history?.page) {
history = newHistory;
update();
}
}
@override
Widget buildLoading() {
return Column(
children: [
const Appbar(title: Text("")),
Expanded(
child: super.buildLoading(),
),
],
);
}
@override @override
void initState() { void initState() {
scrollController.addListener(onScroll); scrollController.addListener(onScroll);
HistoryManager().addListener(updateHistory);
super.initState(); super.initState();
} }
@override
void dispose() {
scrollController.removeListener(onScroll);
HistoryManager().removeListener(updateHistory);
super.dispose();
}
@override @override
void update() { void update() {
setState(() {}); setState(() {});
@@ -205,6 +234,7 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
Widget buildActions() { Widget buildActions() {
bool isMobile = context.width < changePoint; bool isMobile = context.width < changePoint;
bool hasHistory = history != null && (history!.ep > 1 || history!.page > 1);
return SliverToBoxAdapter( return SliverToBoxAdapter(
child: Column( child: Column(
children: [ children: [
@@ -212,17 +242,17 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
scrollDirection: Axis.horizontal, scrollDirection: Axis.horizontal,
padding: const EdgeInsets.symmetric(horizontal: 8), padding: const EdgeInsets.symmetric(horizontal: 8),
children: [ children: [
if (history != null && (history!.ep > 1 || history!.page > 1)) if (hasHistory && !isMobile)
_ActionButton( _ActionButton(
icon: const Icon(Icons.menu_book), icon: const Icon(Icons.menu_book),
text: 'Continue'.tl, text: 'Continue'.tl,
onPressed: continueRead, onPressed: continueRead,
iconColor: context.useTextColor(Colors.yellow), iconColor: context.useTextColor(Colors.yellow),
), ),
if (!isMobile) if(!isMobile || hasHistory)
_ActionButton( _ActionButton(
icon: const Icon(Icons.play_circle_outline), icon: const Icon(Icons.play_circle_outline),
text: 'Read'.tl, text: 'Start'.tl,
onPressed: read, onPressed: read,
iconColor: context.useTextColor(Colors.orange), iconColor: context.useTextColor(Colors.orange),
), ),
@@ -278,7 +308,10 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
), ),
const SizedBox(width: 16), const SizedBox(width: 16),
Expanded( Expanded(
child: FilledButton(onPressed: read, child: Text("Read".tl)), child: hasHistory
? FilledButton(
onPressed: continueRead, child: Text("Continue".tl))
: FilledButton(onPressed: read, child: Text("Read".tl)),
) )
], ],
).paddingHorizontal(16).paddingVertical(8), ).paddingHorizontal(16).paddingVertical(8),
@@ -401,7 +434,7 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
for (var e in comic.tags.entries) for (var e in comic.tags.entries)
buildWrap( buildWrap(
children: [ children: [
if(e.value.isNotEmpty) if (e.value.isNotEmpty)
buildTag(text: e.key.ts(comicSource.key), isTitle: true), buildTag(text: e.key.ts(comicSource.key), isTitle: true),
for (var tag in e.value) for (var tag in e.value)
buildTag( buildTag(
@@ -458,7 +491,7 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
} }
Widget buildRecommend() { Widget buildRecommend() {
if (comic.recommend == null||comic.recommend!.isEmpty) { if (comic.recommend == null || comic.recommend!.isEmpty) {
return const SliverPadding(padding: EdgeInsets.zero); return const SliverPadding(padding: EdgeInsets.zero);
} }
return SliverMainAxisGroup(slivers: [ return SliverMainAxisGroup(slivers: [
@@ -770,6 +803,7 @@ class _ActionButton extends StatelessWidget {
this.isLoading, this.isLoading,
this.iconColor, this.iconColor,
}); });
final Widget icon; final Widget icon;
final Widget? activeIcon; final Widget? activeIcon;
@@ -783,6 +817,7 @@ class _ActionButton extends StatelessWidget {
final bool? isLoading; final bool? isLoading;
final Color? iconColor; final Color? iconColor;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(

View File

@@ -5,8 +5,12 @@ import 'package:venera/foundation/appdata.dart';
import 'package:venera/foundation/comic_source/comic_source.dart'; import 'package:venera/foundation/comic_source/comic_source.dart';
import 'package:venera/foundation/res.dart'; import 'package:venera/foundation/res.dart';
import 'package:venera/foundation/state_controller.dart'; import 'package:venera/foundation/state_controller.dart';
import 'package:venera/pages/search_result_page.dart';
import 'package:venera/utils/ext.dart';
import 'package:venera/utils/translations.dart'; import 'package:venera/utils/translations.dart';
import 'category_comics_page.dart';
class ExplorePage extends StatefulWidget { class ExplorePage extends StatefulWidget {
const ExplorePage({super.key}); const ExplorePage({super.key});
@@ -15,7 +19,7 @@ class ExplorePage extends StatefulWidget {
} }
class _ExplorePageState extends State<ExplorePage> class _ExplorePageState extends State<ExplorePage>
with TickerProviderStateMixin { with TickerProviderStateMixin, AutomaticKeepAliveClientMixin<ExplorePage> {
late TabController controller; late TabController controller;
bool showFB = true; bool showFB = true;
@@ -24,6 +28,24 @@ class _ExplorePageState extends State<ExplorePage>
late List<String> pages; late List<String> pages;
void onSettingsChanged() {
var explorePages = List<String>.from(appdata.settings["explore_pages"]);
var all = ComicSource.all()
.map((e) => e.explorePages)
.expand((e) => e.map((e) => e.title))
.toList();
explorePages = explorePages.where((e) => all.contains(e)).toList();
if (!pages.isEqualsTo(explorePages)) {
setState(() {
pages = explorePages;
controller = TabController(
length: pages.length,
vsync: this,
);
});
}
}
@override @override
void initState() { void initState() {
pages = List<String>.from(appdata.settings["explore_pages"]); pages = List<String>.from(appdata.settings["explore_pages"]);
@@ -36,9 +58,17 @@ class _ExplorePageState extends State<ExplorePage>
length: pages.length, length: pages.length,
vsync: this, vsync: this,
); );
appdata.settings.addListener(onSettingsChanged);
super.initState(); super.initState();
} }
@override
void dispose() {
controller.dispose();
appdata.settings.removeListener(onSettingsChanged);
super.dispose();
}
void refresh() { void refresh() {
int page = controller.index; int page = controller.index;
String currentPageId = pages[page]; String currentPageId = pages[page];
@@ -83,12 +113,14 @@ class _ExplorePageState extends State<ExplorePage>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
super.build(context);
if (pages.isEmpty) { if (pages.isEmpty) {
return buildEmpty(); return buildEmpty();
} }
Widget tabBar = Material( Widget tabBar = Material(
child: FilledTabBar( child: FilledTabBar(
key: Key(pages.toString()),
tabs: pages.map((e) => buildTab(e)).toList(), tabs: pages.map((e) => buildTab(e)).toList(),
controller: controller, controller: controller,
), ),
@@ -118,7 +150,8 @@ class _ExplorePageState extends State<ExplorePage>
setState(() { setState(() {
showFB = false; showFB = false;
}); });
} else if ((current < location || current == 0) && !showFB) { } else if ((current < location || current == 0) &&
!showFB) {
setState(() { setState(() {
showFB = true; showFB = true;
}); });
@@ -138,7 +171,8 @@ class _ExplorePageState extends State<ExplorePage>
), ),
) )
], ],
)), ),
),
Positioned( Positioned(
right: 16, right: 16,
bottom: 16, bottom: 16,
@@ -159,6 +193,9 @@ class _ExplorePageState extends State<ExplorePage>
], ],
); );
} }
@override
bool get wantKeepAlive => true;
} }
class _SingleExplorePage extends StatefulWidget { class _SingleExplorePage extends StatefulWidget {
@@ -170,7 +207,8 @@ class _SingleExplorePage extends StatefulWidget {
State<_SingleExplorePage> createState() => _SingleExplorePageState(); State<_SingleExplorePage> createState() => _SingleExplorePageState();
} }
class _SingleExplorePageState extends StateWithController<_SingleExplorePage> { class _SingleExplorePageState extends StateWithController<_SingleExplorePage>
with AutomaticKeepAliveClientMixin<_SingleExplorePage> {
late final ExplorePageData data; late final ExplorePageData data;
bool loading = true; bool loading = true;
@@ -183,6 +221,16 @@ class _SingleExplorePageState extends StateWithController<_SingleExplorePage> {
int key = 0; int key = 0;
bool _wantKeepAlive = true;
void onSettingsChanged() {
var explorePages = appdata.settings["explore_pages"];
if (!explorePages.contains(widget.title)) {
_wantKeepAlive = false;
updateKeepAlive();
}
}
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@@ -195,11 +243,19 @@ class _SingleExplorePageState extends StateWithController<_SingleExplorePage> {
} }
} }
} }
appdata.settings.addListener(onSettingsChanged);
throw "Explore Page ${widget.title} Not Found!"; throw "Explore Page ${widget.title} Not Found!";
} }
@override
void dispose() {
appdata.settings.removeListener(onSettingsChanged);
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
super.build(context);
if (data.loadMultiPart != null) { if (data.loadMultiPart != null) {
return buildMultiPart(); return buildMultiPart();
} else if (data.loadPage != null || data.loadNext != null) { } else if (data.loadPage != null || data.loadNext != null) {
@@ -284,6 +340,9 @@ class _SingleExplorePageState extends StateWithController<_SingleExplorePage> {
}); });
} }
} }
@override
bool get wantKeepAlive => _wantKeepAlive;
} }
class _MixedExplorePage extends StatefulWidget { class _MixedExplorePage extends StatefulWidget {
@@ -367,13 +426,12 @@ Iterable<Widget> _buildExplorePagePart(
if (part.viewMore != null) if (part.viewMore != null)
TextButton( TextButton(
onPressed: () { onPressed: () {
// TODO: view more
/*
var context = App.mainNavigatorKey!.currentContext!; var context = App.mainNavigatorKey!.currentContext!;
if (part.viewMore!.startsWith("search:")) { if (part.viewMore!.startsWith("search:")) {
context.to( context.to(
() => SearchResultPage( () => SearchResultPage(
keyword: part.viewMore!.replaceFirst("search:", ""), text: part.viewMore!.replaceFirst("search:", ""),
options: const [],
sourceKey: sourceKey, sourceKey: sourceKey,
), ),
); );
@@ -392,9 +450,9 @@ Iterable<Widget> _buildExplorePagePart(
param: p, param: p,
), ),
); );
}*/ }
}, },
child: Text("查看更多".tl), child: Text("View more".tl),
) )
], ],
), ),

View File

@@ -17,6 +17,7 @@ part 'favorite_actions.dart';
part 'side_bar.dart'; part 'side_bar.dart';
part 'local_favorites_page.dart'; part 'local_favorites_page.dart';
part 'network_favorites_page.dart'; part 'network_favorites_page.dart';
part 'local_search_page.dart';
const _kLeftBarWidth = 256.0; const _kLeftBarWidth = 256.0;

View File

@@ -0,0 +1,41 @@
part of 'favorites_page.dart';
class LocalSearchPage extends StatefulWidget {
const LocalSearchPage({super.key});
@override
State<LocalSearchPage> createState() => _LocalSearchPageState();
}
class _LocalSearchPageState extends State<LocalSearchPage> {
String keyword = '';
var comics = <FavoriteItemWithFolderInfo>[];
late final SearchBarController controller;
@override
void initState() {
super.initState();
controller = SearchBarController(onSearch: (text) {
keyword = text;
comics = LocalFavoritesManager().search(keyword);
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SmoothCustomScrollView(slivers: [
SliverSearchBar(controller: controller),
SliverGridComics(
comics: comics,
badgeBuilder: (c) {
return (c as FavoriteItemWithFolderInfo).folder;
},
),
]),
);
}
}

View File

@@ -88,6 +88,13 @@ class _LeftBarState extends State<_LeftBar> implements FolderList {
const SizedBox(width: 12), const SizedBox(width: 12),
Text("Local".tl), Text("Local".tl),
const Spacer(), const Spacer(),
IconButton(
icon: const Icon(Icons.search),
color: context.colorScheme.primary,
onPressed: () {
context.to(() => const LocalSearchPage());
},
),
IconButton( IconButton(
icon: const Icon(Icons.add), icon: const Icon(Icons.add),
color: context.colorScheme.primary, color: context.colorScheme.primary,
@@ -112,6 +119,7 @@ class _LeftBarState extends State<_LeftBar> implements FolderList {
if (index == 0) { if (index == 0) {
return Container( return Container(
padding: const EdgeInsets.symmetric(vertical: 12), padding: const EdgeInsets.symmetric(vertical: 12),
margin: const EdgeInsets.only(top: 8),
decoration: BoxDecoration( decoration: BoxDecoration(
border: Border( border: Border(
top: BorderSide( top: BorderSide(

View File

@@ -1,6 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:venera/components/components.dart'; import 'package:venera/components/components.dart';
import 'package:venera/foundation/app.dart'; import 'package:venera/foundation/app.dart';
import 'package:venera/foundation/appdata.dart';
import 'package:venera/foundation/local.dart'; import 'package:venera/foundation/local.dart';
import 'package:venera/pages/downloading_page.dart'; import 'package:venera/pages/downloading_page.dart';
import 'package:venera/utils/cbz.dart'; import 'package:venera/utils/cbz.dart';
@@ -17,15 +18,29 @@ class LocalComicsPage extends StatefulWidget {
class _LocalComicsPageState extends State<LocalComicsPage> { class _LocalComicsPageState extends State<LocalComicsPage> {
late List<LocalComic> comics; late List<LocalComic> comics;
late LocalSortType sortType;
String keyword = "";
bool searchMode = false;
void update() { void update() {
if(keyword.isEmpty) {
setState(() { setState(() {
comics = LocalManager().getComics(); comics = LocalManager().getComics(sortType);
}); });
} else {
setState(() {
comics = LocalManager().search(keyword);
});
}
} }
@override @override
void initState() { void initState() {
comics = LocalManager().getComics(); var sort = appdata.implicitData["local_sort"] ?? "name";
sortType = LocalSortType.fromString(sort);
comics = LocalManager().getComics(sortType);
LocalManager().addListener(update); LocalManager().addListener(update);
super.initState(); super.initState();
} }
@@ -36,14 +51,92 @@ class _LocalComicsPageState extends State<LocalComicsPage> {
super.dispose(); super.dispose();
} }
void sort() {
showDialog(
context: context,
builder: (context) {
return StatefulBuilder(builder: (context, setState) {
return ContentDialog(
title: "Sort".tl,
content: Column(
children: [
RadioListTile<LocalSortType>(
title: Text("Name".tl),
value: LocalSortType.name,
groupValue: sortType,
onChanged: (v) {
setState(() {
sortType = v!;
});
},
),
RadioListTile<LocalSortType>(
title: Text("Date".tl),
value: LocalSortType.timeAsc,
groupValue: sortType,
onChanged: (v) {
setState(() {
sortType = v!;
});
},
),
RadioListTile<LocalSortType>(
title: Text("Date Desc".tl),
value: LocalSortType.timeDesc,
groupValue: sortType,
onChanged: (v) {
setState(() {
sortType = v!;
});
},
),
],
),
actions: [
FilledButton(
onPressed: () {
appdata.implicitData["local_sort"] =
sortType.value;
appdata.writeImplicitData();
Navigator.pop(context);
update();
},
child: Text("Confirm".tl),
),
],
);
});
},
);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
body: SmoothCustomScrollView( body: SmoothCustomScrollView(
slivers: [ slivers: [
if(!searchMode)
SliverAppbar( SliverAppbar(
title: Text("Local".tl), title: Text("Local".tl),
actions: [ actions: [
Tooltip(
message: "Search".tl,
child: IconButton(
icon: const Icon(Icons.search),
onPressed: () {
setState(() {
searchMode = true;
});
},
),
),
Tooltip(
message: "Sort".tl,
child: IconButton(
icon: const Icon(Icons.sort),
onPressed: sort,
),
),
Tooltip( Tooltip(
message: "Downloading".tl, message: "Downloading".tl,
child: IconButton( child: IconButton(
@@ -54,6 +147,32 @@ class _LocalComicsPageState extends State<LocalComicsPage> {
), ),
) )
], ],
)
else
SliverAppbar(
title: TextField(
autofocus: true,
decoration: InputDecoration(
hintText: "Search".tl,
border: InputBorder.none,
),
onChanged: (v) {
keyword = v;
update();
},
),
actions: [
IconButton(
icon: const Icon(Icons.close),
onPressed: () {
setState(() {
searchMode = false;
keyword = "";
update();
});
},
),
],
), ),
SliverGridComics( SliverGridComics(
comics: comics, comics: comics,
@@ -80,8 +199,7 @@ class _LocalComicsPageState extends State<LocalComicsPage> {
var file = await CBZ.export(c as LocalComic); var file = await CBZ.export(c as LocalComic);
await saveFile(filename: file.name, file: file); await saveFile(filename: file.name, file: file);
await file.delete(); await file.delete();
} } catch (e) {
catch (e) {
context.showMessage(message: e.toString()); context.showMessage(message: e.toString());
} }
controller.close(); controller.close();

View File

@@ -86,6 +86,36 @@ class _AppSettingsState extends State<AppSettings> {
}, },
actionTitle: 'Set'.tl, actionTitle: 'Set'.tl,
).toSliver(), ).toSliver(),
_CallbackSetting(
title: "Export App Data".tl,
callback: () async {
var controller = showLoadingDialog(context);
var file = await exportAppData();
await saveFile(filename: "data.venera", file: file);
controller.close();
},
actionTitle: 'Export'.tl,
).toSliver(),
_CallbackSetting(
title: "Import App Data".tl,
callback: () async {
var controller = showLoadingDialog(context);
var file = await selectFile(ext: ['venera']);
if(file != null) {
var cacheFile = File(FilePath.join(App.cachePath, "temp.venera"));
await file.saveTo(cacheFile.path);
try {
await importAppData(cacheFile);
}
catch(e, s) {
Log.error("Import data", e.toString(), s);
context.showMessage(message: "Failed to import data".tl);
}
}
controller.close();
},
actionTitle: 'Import'.tl,
).toSliver(),
_SettingPartTitle( _SettingPartTitle(
title: "Log".tl, title: "Log".tl,
icon: Icons.error_outline, icon: Icons.error_outline,

View File

@@ -21,6 +21,9 @@ class _AppearanceSettingsState extends State<AppearanceSettings> {
"light": "Light".tl, "light": "Light".tl,
"dark": "Dark".tl, "dark": "Dark".tl,
}, },
onChanged: () async {
App.forceRebuild();
},
).toSliver(), ).toSliver(),
SelectSetting( SelectSetting(
title: "Theme Color".tl, title: "Theme Color".tl,

View File

@@ -434,7 +434,7 @@ class _CallbackSetting extends StatelessWidget {
return ListTile( return ListTile(
title: Text(title), title: Text(title),
subtitle: subtitle == null ? null : Text(subtitle!), subtitle: subtitle == null ? null : Text(subtitle!),
trailing: FilledButton( trailing: Button.normal(
onPressed: callback, onPressed: callback,
child: Text(actionTitle), child: Text(actionTitle),
).fixHeight(28), ).fixHeight(28),

View File

@@ -14,6 +14,7 @@ import 'package:venera/foundation/consts.dart';
import 'package:venera/foundation/local.dart'; import 'package:venera/foundation/local.dart';
import 'package:venera/foundation/log.dart'; import 'package:venera/foundation/log.dart';
import 'package:venera/network/app_dio.dart'; import 'package:venera/network/app_dio.dart';
import 'package:venera/utils/data.dart';
import 'package:venera/utils/io.dart'; import 'package:venera/utils/io.dart';
import 'package:venera/utils/translations.dart'; import 'package:venera/utils/translations.dart';
import 'package:yaml/yaml.dart'; import 'package:yaml/yaml.dart';

71
lib/utils/data.dart Normal file
View File

@@ -0,0 +1,71 @@
import 'dart:isolate';
import 'package:venera/foundation/app.dart';
import 'package:venera/foundation/appdata.dart';
import 'package:venera/foundation/comic_source/comic_source.dart';
import 'package:venera/foundation/favorites.dart';
import 'package:venera/foundation/history.dart';
import 'package:zip_flutter/zip_flutter.dart';
import 'io.dart';
Future<File> exportAppData() async {
var time = DateTime.now().millisecondsSinceEpoch ~/ 1000;
var cacheFilePath = FilePath.join(App.cachePath, '$time.venera');
var cacheFile = File(cacheFilePath);
var dataPath = App.dataPath;
if(await cacheFile.exists()) {
await cacheFile.delete();
}
await Isolate.run(() {
var zipFile = ZipFile.open(cacheFilePath);
var historyFile = FilePath.join(dataPath, "history.db");
var localFavoriteFile = FilePath.join(dataPath, "local_favorite.db");
var appdata = FilePath.join(dataPath, "appdata.json");
zipFile.addFile("history.db", historyFile);
zipFile.addFile("local_favorite.db", localFavoriteFile);
zipFile.addFile("appdata.json", appdata);
for(var file in Directory(FilePath.join(dataPath, "comic_source")).listSync()) {
if(file is File) {
zipFile.addFile("comic_source/${file.name}", file.path);
}
}
zipFile.close();
});
return cacheFile;
}
Future<void> importAppData(File file) async {
var cacheDirPath = FilePath.join(App.cachePath, 'temp_data');
var cacheDir = Directory(cacheDirPath);
await Isolate.run(() {
ZipFile.openAndExtract(file.path, cacheDirPath);
});
var historyFile = cacheDir.joinFile("history.db");
var localFavoriteFile = cacheDir.joinFile("local_favorite.db");
var appdataFile = cacheDir.joinFile("appdata.json");
if(await historyFile.exists()) {
HistoryManager().close();
await historyFile.copy(FilePath.join(App.dataPath, "history.db"));
HistoryManager().init();
}
if(await localFavoriteFile.exists()) {
LocalFavoritesManager().close();
await localFavoriteFile.copy(FilePath.join(App.dataPath, "local_favorite.db"));
LocalFavoritesManager().init();
}
if(await appdataFile.exists()) {
await appdataFile.copy(FilePath.join(App.dataPath, "appdata.json"));
appdata.init();
}
var comicSourceDir = FilePath.join(cacheDirPath, "comic_source");
if(Directory(comicSourceDir).existsSync()) {
for(var file in Directory(comicSourceDir).listSync()) {
if(file is File) {
var targetFile = FilePath.join(App.dataPath, "comic_source", file.name);
await file.copy(targetFile);
}
}
await ComicSource.reload();
}
}

View File

@@ -24,6 +24,18 @@ extension ListExt<T> on List<T>{
add(value); add(value);
} }
} }
bool isEqualsTo(List<T> list){
if(length != list.length){
return false;
}
for(int i=0; i<length; i++){
if(this[i] != list[i]){
return false;
}
}
return true;
}
} }
extension StringExt on String{ extension StringExt on String{

View File

@@ -169,7 +169,8 @@ Future<file_selector.XFile?> selectFile({required List<String> ext}) async {
acceptedTypeGroups: <file_selector.XTypeGroup>[typeGroup], acceptedTypeGroups: <file_selector.XTypeGroup>[typeGroup],
); );
if (file == null) return null; if (file == null) return null;
if (!ext.contains(file?.path.split(".").last)) { if (!ext.contains(file.path.split(".").last)) {
App.rootContext.showMessage(message: "Invalid file type");
return null; return null;
} }
return file; return file;

View File

@@ -2,7 +2,7 @@ name: venera
description: "A comic app." description: "A comic app."
publish_to: 'none' publish_to: 'none'
version: 1.0.0+1 version: 1.0.1+101
environment: environment:
sdk: '>=3.5.0 <4.0.0' sdk: '>=3.5.0 <4.0.0'

View File

@@ -53,6 +53,7 @@ Source: "{#RootPath}\build\windows\x64\runner\Release\share_plus_plugin.dll"; De
Source: "{#RootPath}\build\windows\x64\runner\Release\url_launcher_windows_plugin.dll"; DestDir: "{app}"; Flags: ignoreversion Source: "{#RootPath}\build\windows\x64\runner\Release\url_launcher_windows_plugin.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#RootPath}\build\windows\x64\runner\Release\screen_retriever_plugin.dll"; DestDir: "{app}"; Flags: ignoreversion Source: "{#RootPath}\build\windows\x64\runner\Release\screen_retriever_plugin.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#RootPath}\build\windows\x64\runner\Release\window_manager_plugin.dll"; DestDir: "{app}"; Flags: ignoreversion Source: "{#RootPath}\build\windows\x64\runner\Release\window_manager_plugin.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#RootPath}\build\windows\x64\runner\Release\zip_flutter.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#RootPath}\build\windows\x64\runner\Release\data\*"; DestDir: "{app}\data"; Flags: ignoreversion recursesubdirs createallsubdirs Source: "{#RootPath}\build\windows\x64\runner\Release\data\*"; DestDir: "{app}\data"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files ; NOTE: Don't use "Flags: ignoreversion" on any shared system files