mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
Compare commits
36 Commits
v1.0.0-bet
...
v1.0.1
Author | SHA1 | Date | |
---|---|---|---|
![]() |
28913adc86 | ||
![]() |
cd607ff337 | ||
![]() |
eecd30f77d | ||
![]() |
49174a7d8e | ||
![]() |
c4d867db89 | ||
![]() |
19a93cbbce | ||
![]() |
877e2d5e63 | ||
![]() |
98ae67a6a5 | ||
![]() |
2db3f5a72e | ||
![]() |
2d628ec9b1 | ||
![]() |
b1b516381d | ||
![]() |
048a68f76a | ||
![]() |
11bbbdca0e | ||
![]() |
d48edc6331 | ||
![]() |
13c775b7ce | ||
![]() |
d0e76dd3a0 | ||
![]() |
37997af173 | ||
![]() |
82478fa247 | ||
![]() |
a508d85ce6 | ||
![]() |
a09fb0e81c | ||
![]() |
1883c3ee5b | ||
![]() |
3518949f99 | ||
![]() |
0589e63be7 | ||
![]() |
c2d3f3e56d | ||
![]() |
3e1bb5ef5c | ||
![]() |
7ce84d095e | ||
![]() |
373411e49d | ||
![]() |
0fba86d6a0 | ||
![]() |
97a6e456a5 | ||
![]() |
363f3641fb | ||
![]() |
02bda275b1 | ||
![]() |
093a772dff | ||
![]() |
5280f26981 | ||
![]() |
cc29ff0c33 | ||
![]() |
0db633a9d9 | ||
![]() |
c4dc12e050 |
31
README.md
31
README.md
@@ -1,16 +1,29 @@
|
||||
# venera
|
||||
|
||||
A comic app.
|
||||
[](https://flutter.dev/)
|
||||
[](https://github.com/venera-app/venera/blob/master/LICENSE)
|
||||
[](https://github.com/venera-app/venera/releases)
|
||||
[](https://github.com/venera-app/venera/stargazers)
|
||||
|
||||
## Getting Started
|
||||
A comic reader that support reading local and network comics.
|
||||
|
||||
This project is a starting point for a Flutter application.
|
||||
## Features
|
||||
|
||||
A few resources to get you started if this is your first Flutter project:
|
||||
- Read local comics
|
||||
- Use javascript to create comic sources
|
||||
- Read comics from network sources
|
||||
- Manage favorite comics
|
||||
- Download comics
|
||||
- View comments, tags, and other information of comics if the source supports
|
||||
- Login to comment, rate, and other operations if the source supports
|
||||
|
||||
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
|
||||
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
|
||||
## Create a new comic source
|
||||
|
||||
For help getting started with Flutter development, view the
|
||||
[online documentation](https://docs.flutter.dev/), which offers tutorials,
|
||||
samples, guidance on mobile development, and a full API reference.
|
||||
See [venera-configs](https://github.com/venera-app/venera-configs)
|
||||
|
||||
## Thanks
|
||||
|
||||
### Tags Translation
|
||||
[](https://github.com/EhTagTranslation/Database)
|
||||
|
||||
The Chinese translation of the manga tags is from this project.
|
||||
|
@@ -144,7 +144,18 @@
|
||||
"The directory name will be used as the comic title. And the name of chapter directories will be used as the chapter titles." : "目录名称将被用作漫画标题。章节目录的名称将被用作章节标题。",
|
||||
"Export as cbz": "导出为cbz",
|
||||
"Select a cbz file." : "选择一个cbz文件",
|
||||
"A cbz file" : "一个cbz文件"
|
||||
"A cbz file" : "一个cbz文件",
|
||||
"Fullscreen": "全屏",
|
||||
"Exit": "退出",
|
||||
"View more": "查看更多",
|
||||
"Sort": "排序",
|
||||
"Name": "名称",
|
||||
"Date": "日期",
|
||||
"Date Desc": "日期降序",
|
||||
"Start": "开始",
|
||||
"Export App Data": "导出应用数据",
|
||||
"Import App Data": "导入应用数据",
|
||||
"Export": "导出"
|
||||
},
|
||||
"zh_TW": {
|
||||
"Home": "首頁",
|
||||
@@ -291,6 +302,17 @@
|
||||
"The directory name will be used as the comic title. And the name of chapter directories will be used as the chapter titles." : "目錄名稱將被用作漫畫標題。章節目錄的名稱將被用作章節標題。",
|
||||
"Export as cbz": "匯出為cbz",
|
||||
"Select a cbz file." : "選擇一個cbz文件",
|
||||
"A cbz file" : "一個cbz文件"
|
||||
"A cbz file" : "一個cbz文件",
|
||||
"Fullscreen": "全螢幕",
|
||||
"Exit": "退出",
|
||||
"View more": "查看更多",
|
||||
"Sort": "排序",
|
||||
"Name": "名稱",
|
||||
"Date": "日期",
|
||||
"Date Desc": "日期降序",
|
||||
"Start": "開始",
|
||||
"Export App Data": "匯出應用數據",
|
||||
"Import App Data": "匯入應用數據",
|
||||
"Export": "匯出"
|
||||
}
|
||||
}
|
@@ -156,7 +156,7 @@ class _ButtonState extends State<Button> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var padding = widget.padding ??
|
||||
const EdgeInsets.symmetric(horizontal: 16, vertical: 6);
|
||||
const EdgeInsets.symmetric(horizontal: 16, vertical: 4);
|
||||
var width = widget.width;
|
||||
if (width != null) {
|
||||
width = width - padding.horizontal;
|
||||
@@ -172,7 +172,7 @@ class _ButtonState extends State<Button> {
|
||||
child: DefaultTextStyle(
|
||||
style: TextStyle(
|
||||
color: textColor,
|
||||
fontSize: 16,
|
||||
fontSize: 14,
|
||||
),
|
||||
child: isLoading
|
||||
? CircularProgressIndicator(
|
||||
@@ -210,11 +210,11 @@ class _ButtonState extends State<Button> {
|
||||
decoration: BoxDecoration(
|
||||
color: buttonColor,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: (isHover && !isLoading && widget.type == ButtonType.filled)
|
||||
boxShadow: (isHover && !isLoading && (widget.type == ButtonType.filled || widget.type == ButtonType.normal))
|
||||
? [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.1),
|
||||
blurRadius: 4,
|
||||
blurRadius: 2,
|
||||
offset: const Offset(0, 1),
|
||||
)
|
||||
]
|
||||
@@ -252,6 +252,14 @@ class _ButtonState extends State<Button> {
|
||||
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) {
|
||||
return context.colorScheme.outline.withOpacity(0.2);
|
||||
}
|
||||
|
@@ -382,7 +382,7 @@ class _ComicDescription extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
title,
|
||||
title.trim(),
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 14.0,
|
||||
@@ -405,47 +405,56 @@ class _ComicDescription extends StatelessWidget {
|
||||
height: 4,
|
||||
),
|
||||
if (tags != null)
|
||||
LayoutBuilder(builder: (context, constraints) {
|
||||
return Container(
|
||||
constraints: const BoxConstraints(maxHeight: 47),
|
||||
child: Wrap(
|
||||
runAlignment: WrapAlignment.start,
|
||||
Expanded(
|
||||
child: LayoutBuilder(builder: (context, constraints) {
|
||||
if (constraints.maxHeight < 22) {
|
||||
return Container();
|
||||
}
|
||||
int cnt = (constraints.maxHeight - 22).toInt() ~/ 25;
|
||||
return Container(
|
||||
clipBehavior: Clip.antiAlias,
|
||||
crossAxisAlignment: WrapCrossAlignment.end,
|
||||
spacing: 4,
|
||||
runSpacing: 3,
|
||||
children: [
|
||||
for (var s in tags!)
|
||||
Container(
|
||||
height: 22,
|
||||
padding: const EdgeInsets.fromLTRB(3,2,3,2),
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: constraints.maxWidth * 0.45,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: s == "Unavailable"
|
||||
? Theme.of(context).colorScheme.errorContainer
|
||||
: Theme.of(context)
|
||||
.colorScheme
|
||||
.secondaryContainer,
|
||||
borderRadius:
|
||||
const BorderRadius.all(Radius.circular(8)),
|
||||
),
|
||||
child: Text(
|
||||
enableTranslate
|
||||
? TagsTranslation.translateTag(s)
|
||||
: s,
|
||||
style: const TextStyle(fontSize: 12),
|
||||
softWrap: true,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}),
|
||||
const Spacer(),
|
||||
if (rating != null) StarRating(value: rating!, size: 18),
|
||||
height: 22 + cnt * 25,
|
||||
width: double.infinity,
|
||||
decoration: const BoxDecoration(),
|
||||
child: Wrap(
|
||||
runAlignment: WrapAlignment.start,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
crossAxisAlignment: WrapCrossAlignment.end,
|
||||
spacing: 4,
|
||||
runSpacing: 3,
|
||||
children: [
|
||||
for (var s in tags!)
|
||||
Container(
|
||||
height: 22,
|
||||
padding: const EdgeInsets.fromLTRB(3, 2, 3, 2),
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: constraints.maxWidth * 0.45,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: s == "Unavailable"
|
||||
? Theme.of(context).colorScheme.errorContainer
|
||||
: Theme.of(context)
|
||||
.colorScheme
|
||||
.secondaryContainer,
|
||||
borderRadius:
|
||||
const BorderRadius.all(Radius.circular(8)),
|
||||
),
|
||||
child: Center(
|
||||
widthFactor: 1,
|
||||
child: Text(
|
||||
enableTranslate
|
||||
? TagsTranslation.translateTag(s)
|
||||
: s.split(':').last,
|
||||
style: const TextStyle(fontSize: 12),
|
||||
softWrap: true,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
))),
|
||||
],
|
||||
),
|
||||
).toAlign(Alignment.topCenter);
|
||||
}),
|
||||
),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
@@ -453,6 +462,7 @@ class _ComicDescription extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (rating != null) StarRating(value: rating!, size: 18),
|
||||
Text(
|
||||
description,
|
||||
style: const TextStyle(
|
||||
@@ -469,10 +479,12 @@ class _ComicDescription extends StatelessWidget {
|
||||
color: Theme.of(context).colorScheme.tertiaryContainer,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
||||
),
|
||||
child: Text(
|
||||
badge!,
|
||||
style: const TextStyle(fontSize: 12),
|
||||
),
|
||||
child: Center(
|
||||
child:Text(
|
||||
"${badge![0].toUpperCase()}${badge!.substring(1).toLowerCase()}",
|
||||
style: const TextStyle(fontSize: 12),
|
||||
),
|
||||
)
|
||||
),
|
||||
],
|
||||
)
|
||||
@@ -860,6 +872,7 @@ class ComicListState extends State<ComicList> {
|
||||
try {
|
||||
if (widget.loadPage != null) {
|
||||
var res = await widget.loadPage!(page);
|
||||
if(!mounted) return;
|
||||
if (res.success) {
|
||||
if (res.data.isEmpty) {
|
||||
_data[page] = const [];
|
||||
|
@@ -21,7 +21,6 @@ import 'package:venera/foundation/history.dart';
|
||||
import 'package:venera/foundation/image_provider/cached_image.dart';
|
||||
import 'package:venera/foundation/local.dart';
|
||||
import 'package:venera/foundation/res.dart';
|
||||
import 'package:venera/foundation/state_controller.dart';
|
||||
import 'package:venera/network/cloudflare.dart';
|
||||
import 'package:venera/pages/comic_page.dart';
|
||||
import 'package:venera/pages/favorites/favorites_page.dart';
|
||||
@@ -46,3 +45,4 @@ part 'select.dart';
|
||||
part 'side_bar.dart';
|
||||
part 'comic.dart';
|
||||
part 'effects.dart';
|
||||
part 'gesture.dart';
|
22
lib/components/gesture.dart
Normal file
22
lib/components/gesture.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
part of 'components.dart';
|
||||
|
||||
class MouseBackDetector extends StatelessWidget {
|
||||
const MouseBackDetector({super.key, required this.onTapDown, required this.child});
|
||||
|
||||
final Widget child;
|
||||
|
||||
final void Function() onTapDown;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Listener(
|
||||
onPointerDown: (event) {
|
||||
if (event.buttons == kBackMouseButton) {
|
||||
onTapDown();
|
||||
}
|
||||
},
|
||||
behavior: HitTestBehavior.translucent,
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
}
|
@@ -16,7 +16,14 @@ class SmoothCustomScrollView extends StatelessWidget {
|
||||
return CustomScrollView(
|
||||
controller: controller,
|
||||
physics: physics,
|
||||
slivers: slivers,
|
||||
slivers: [
|
||||
...slivers,
|
||||
SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: context.padding.bottom,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -87,7 +94,7 @@ class _SmoothScrollProviderState extends State<SmoothScrollProvider> {
|
||||
_controller.position.minScrollExtent,
|
||||
_controller.position.maxScrollExtent,
|
||||
);
|
||||
if(_futurePosition == old) return;
|
||||
if (_futurePosition == old) return;
|
||||
_controller.animateTo(_futurePosition!,
|
||||
duration: _fastAnimationDuration, curve: Curves.linear);
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ export "widget_utils.dart";
|
||||
export "context.dart";
|
||||
|
||||
class _App {
|
||||
final version = "1.0.0-beta";
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@@ -166,7 +166,7 @@ class LocalManager with ChangeNotifier {
|
||||
} catch (e) {
|
||||
return e.toString();
|
||||
}
|
||||
await Directory(path).deleteIgnoreError();
|
||||
await Directory(path).deleteIgnoreError(recursive:true);
|
||||
path = newPath;
|
||||
return null;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
@@ -20,7 +20,7 @@ void main(List<String> args) {
|
||||
runZonedGuarded(() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await init();
|
||||
if(App.isAndroid) {
|
||||
if (App.isAndroid) {
|
||||
handleLinks();
|
||||
}
|
||||
FlutterError.onError = (details) {
|
||||
@@ -73,6 +73,7 @@ class _MyAppState extends State<MyApp> {
|
||||
el.markNeedsBuild();
|
||||
el.visitChildren(rebuild);
|
||||
}
|
||||
|
||||
(context as Element).visitChildren(rebuild);
|
||||
setState(() {});
|
||||
}
|
||||
@@ -114,10 +115,10 @@ class _MyAppState extends State<MyApp> {
|
||||
],
|
||||
locale: () {
|
||||
var lang = appdata.settings['language'];
|
||||
if(lang == 'system') {
|
||||
if (lang == 'system') {
|
||||
return null;
|
||||
}
|
||||
return switch(lang) {
|
||||
return switch (lang) {
|
||||
'zh-CN' => const Locale('zh', 'CN'),
|
||||
'zh-TW' => const Locale('zh', 'TW'),
|
||||
'en-US' => const Locale('en'),
|
||||
@@ -148,7 +149,10 @@ class _MyAppState extends State<MyApp> {
|
||||
App.pop,
|
||||
),
|
||||
},
|
||||
child: WindowFrame(widget),
|
||||
child: MouseBackDetector(
|
||||
onTapDown: App.pop,
|
||||
child: WindowFrame(widget),
|
||||
),
|
||||
);
|
||||
}
|
||||
return _SystemUiProvider(Material(
|
||||
@@ -174,11 +178,13 @@ class _SystemUiProvider extends StatelessWidget {
|
||||
systemUiStyle = SystemUiOverlayStyle.dark.copyWith(
|
||||
statusBarColor: Colors.transparent,
|
||||
systemNavigationBarColor: Colors.transparent,
|
||||
systemNavigationBarIconBrightness: Brightness.dark,
|
||||
);
|
||||
} else {
|
||||
systemUiStyle = SystemUiOverlayStyle.light.copyWith(
|
||||
statusBarColor: Colors.transparent,
|
||||
systemNavigationBarColor: Colors.transparent,
|
||||
systemNavigationBarIconBrightness: Brightness.light,
|
||||
);
|
||||
}
|
||||
return AnnotatedRegion<SystemUiOverlayStyle>(
|
||||
|
@@ -2,6 +2,7 @@ import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:sqlite3/sqlite3.dart';
|
||||
import 'package:venera/foundation/log.dart';
|
||||
import 'package:venera/utils/ext.dart';
|
||||
|
||||
class CookieJarSql {
|
||||
@@ -130,9 +131,17 @@ class CookieJarSql {
|
||||
}
|
||||
|
||||
void saveFromResponseCookieHeader(Uri uri, List<String> cookieHeader) {
|
||||
var cookies = cookieHeader
|
||||
.map((header) => Cookie.fromSetCookieValue(header))
|
||||
.toList();
|
||||
var cookies = <Cookie>[];
|
||||
for (var header in cookieHeader) {
|
||||
try{
|
||||
var cookie = Cookie.fromSetCookieValue(header);
|
||||
cookies.add(cookie);
|
||||
}
|
||||
catch(_) {
|
||||
Log.warning("Network", "Invalid cookie header: $header");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
saveFromResponse(uri, cookies);
|
||||
}
|
||||
|
||||
|
@@ -197,6 +197,7 @@ class ImagesDownloadTask extends DownloadTask with _TransferSpeedMixin {
|
||||
_scheduleTasks();
|
||||
}
|
||||
});
|
||||
downloading++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -590,5 +591,7 @@ abstract mixin class _TransferSpeedMixin {
|
||||
void stopRecorder() {
|
||||
timer?.cancel();
|
||||
timer = null;
|
||||
_currentSpeed = 0;
|
||||
_bytesSinceLastSecond = 0;
|
||||
}
|
||||
}
|
||||
|
@@ -70,6 +70,7 @@ class AccountsPage extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
element.saveData();
|
||||
ComicSource.notifyListeners();
|
||||
logic.update();
|
||||
},
|
||||
);
|
||||
@@ -124,6 +125,7 @@ class AccountsPage extends StatelessWidget {
|
||||
element.data["account"] = null;
|
||||
element.account?.logout();
|
||||
element.saveData();
|
||||
ComicSource.notifyListeners();
|
||||
logic.update();
|
||||
},
|
||||
trailing: const Icon(Icons.logout),
|
||||
|
@@ -42,12 +42,41 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
||||
|
||||
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
|
||||
void initState() {
|
||||
scrollController.addListener(onScroll);
|
||||
HistoryManager().addListener(updateHistory);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
scrollController.removeListener(onScroll);
|
||||
HistoryManager().removeListener(updateHistory);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void update() {
|
||||
setState(() {});
|
||||
@@ -205,6 +234,7 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
||||
|
||||
Widget buildActions() {
|
||||
bool isMobile = context.width < changePoint;
|
||||
bool hasHistory = history != null && (history!.ep > 1 || history!.page > 1);
|
||||
return SliverToBoxAdapter(
|
||||
child: Column(
|
||||
children: [
|
||||
@@ -212,17 +242,17 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
||||
scrollDirection: Axis.horizontal,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
children: [
|
||||
if (history != null && (history!.ep > 1 || history!.page > 1))
|
||||
if (hasHistory && !isMobile)
|
||||
_ActionButton(
|
||||
icon: const Icon(Icons.menu_book),
|
||||
text: 'Continue'.tl,
|
||||
onPressed: continueRead,
|
||||
iconColor: context.useTextColor(Colors.yellow),
|
||||
),
|
||||
if (!isMobile)
|
||||
if(!isMobile || hasHistory)
|
||||
_ActionButton(
|
||||
icon: const Icon(Icons.play_circle_outline),
|
||||
text: 'Read'.tl,
|
||||
text: 'Start'.tl,
|
||||
onPressed: read,
|
||||
iconColor: context.useTextColor(Colors.orange),
|
||||
),
|
||||
@@ -278,7 +308,10 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
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),
|
||||
@@ -398,23 +431,23 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
||||
Text(comic.stars!.toStringAsFixed(2)),
|
||||
],
|
||||
).paddingLeft(16).paddingVertical(8),
|
||||
for (var e in comic.tags.entries)
|
||||
buildWrap(
|
||||
children: [
|
||||
if(e.value.isNotEmpty)
|
||||
for (var e in comic.tags.entries)
|
||||
buildWrap(
|
||||
children: [
|
||||
if (e.value.isNotEmpty)
|
||||
buildTag(text: e.key.ts(comicSource.key), isTitle: true),
|
||||
for (var tag in e.value)
|
||||
buildTag(
|
||||
text: enableTranslation
|
||||
? TagsTranslation.translationTagWithNamespace(
|
||||
tag,
|
||||
e.key.toLowerCase(),
|
||||
)
|
||||
: tag,
|
||||
onTap: () => onTapTag(tag, e.key),
|
||||
),
|
||||
],
|
||||
),
|
||||
for (var tag in e.value)
|
||||
buildTag(
|
||||
text: enableTranslation
|
||||
? TagsTranslation.translationTagWithNamespace(
|
||||
tag,
|
||||
e.key.toLowerCase(),
|
||||
)
|
||||
: tag,
|
||||
onTap: () => onTapTag(tag, e.key),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (comic.uploader != null)
|
||||
buildWrap(
|
||||
children: [
|
||||
@@ -458,7 +491,7 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
||||
}
|
||||
|
||||
Widget buildRecommend() {
|
||||
if (comic.recommend == null) {
|
||||
if (comic.recommend == null || comic.recommend!.isEmpty) {
|
||||
return const SliverPadding(padding: EdgeInsets.zero);
|
||||
}
|
||||
return SliverMainAxisGroup(slivers: [
|
||||
@@ -770,6 +803,7 @@ class _ActionButton extends StatelessWidget {
|
||||
this.isLoading,
|
||||
this.iconColor,
|
||||
});
|
||||
|
||||
final Widget icon;
|
||||
|
||||
final Widget? activeIcon;
|
||||
@@ -783,6 +817,7 @@ class _ActionButton extends StatelessWidget {
|
||||
final bool? isLoading;
|
||||
|
||||
final Color? iconColor;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
|
@@ -40,6 +40,7 @@ class ComicSourcePage extends StatefulWidget {
|
||||
}
|
||||
controller?.close();
|
||||
if (shouldUpdate.isEmpty) {
|
||||
App.rootContext.showMessage(message: "No Update Available".tl);
|
||||
return;
|
||||
}
|
||||
var msg = "";
|
||||
|
@@ -5,8 +5,12 @@ import 'package:venera/foundation/appdata.dart';
|
||||
import 'package:venera/foundation/comic_source/comic_source.dart';
|
||||
import 'package:venera/foundation/res.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 'category_comics_page.dart';
|
||||
|
||||
class ExplorePage extends StatefulWidget {
|
||||
const ExplorePage({super.key});
|
||||
|
||||
@@ -15,7 +19,7 @@ class ExplorePage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ExplorePageState extends State<ExplorePage>
|
||||
with TickerProviderStateMixin {
|
||||
with TickerProviderStateMixin, AutomaticKeepAliveClientMixin<ExplorePage> {
|
||||
late TabController controller;
|
||||
|
||||
bool showFB = true;
|
||||
@@ -24,6 +28,24 @@ class _ExplorePageState extends State<ExplorePage>
|
||||
|
||||
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
|
||||
void initState() {
|
||||
pages = List<String>.from(appdata.settings["explore_pages"]);
|
||||
@@ -36,9 +58,17 @@ class _ExplorePageState extends State<ExplorePage>
|
||||
length: pages.length,
|
||||
vsync: this,
|
||||
);
|
||||
appdata.settings.addListener(onSettingsChanged);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
controller.dispose();
|
||||
appdata.settings.removeListener(onSettingsChanged);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void refresh() {
|
||||
int page = controller.index;
|
||||
String currentPageId = pages[page];
|
||||
@@ -83,12 +113,14 @@ class _ExplorePageState extends State<ExplorePage>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
if (pages.isEmpty) {
|
||||
return buildEmpty();
|
||||
}
|
||||
|
||||
Widget tabBar = Material(
|
||||
child: FilledTabBar(
|
||||
key: Key(pages.toString()),
|
||||
tabs: pages.map((e) => buildTab(e)).toList(),
|
||||
controller: controller,
|
||||
),
|
||||
@@ -97,48 +129,50 @@ class _ExplorePageState extends State<ExplorePage>
|
||||
return Stack(
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: Column(
|
||||
children: [
|
||||
tabBar,
|
||||
Expanded(
|
||||
child: NotificationListener<ScrollNotification>(
|
||||
onNotification: (notifications) {
|
||||
if (notifications.metrics.axis == Axis.horizontal) {
|
||||
if (!showFB) {
|
||||
child: Column(
|
||||
children: [
|
||||
tabBar,
|
||||
Expanded(
|
||||
child: NotificationListener<ScrollNotification>(
|
||||
onNotification: (notifications) {
|
||||
if (notifications.metrics.axis == Axis.horizontal) {
|
||||
if (!showFB) {
|
||||
setState(() {
|
||||
showFB = true;
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
var current = notifications.metrics.pixels;
|
||||
|
||||
if ((current > location && current != 0) && showFB) {
|
||||
setState(() {
|
||||
showFB = false;
|
||||
});
|
||||
} else if ((current < location || current == 0) &&
|
||||
!showFB) {
|
||||
setState(() {
|
||||
showFB = true;
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
var current = notifications.metrics.pixels;
|
||||
|
||||
if ((current > location && current != 0) && showFB) {
|
||||
setState(() {
|
||||
showFB = false;
|
||||
});
|
||||
} else if ((current < location || current == 0) && !showFB) {
|
||||
setState(() {
|
||||
showFB = true;
|
||||
});
|
||||
}
|
||||
|
||||
location = current;
|
||||
return false;
|
||||
},
|
||||
child: MediaQuery.removePadding(
|
||||
context: context,
|
||||
removeTop: true,
|
||||
child: TabBarView(
|
||||
controller: controller,
|
||||
children: pages.map((e) => buildBody(e)).toList(),
|
||||
location = current;
|
||||
return false;
|
||||
},
|
||||
child: MediaQuery.removePadding(
|
||||
context: context,
|
||||
removeTop: true,
|
||||
child: TabBarView(
|
||||
controller: controller,
|
||||
children: pages.map((e) => buildBody(e)).toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
)),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
right: 16,
|
||||
bottom: 16,
|
||||
@@ -159,6 +193,9 @@ class _ExplorePageState extends State<ExplorePage>
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
}
|
||||
|
||||
class _SingleExplorePage extends StatefulWidget {
|
||||
@@ -170,7 +207,8 @@ class _SingleExplorePage extends StatefulWidget {
|
||||
State<_SingleExplorePage> createState() => _SingleExplorePageState();
|
||||
}
|
||||
|
||||
class _SingleExplorePageState extends StateWithController<_SingleExplorePage> {
|
||||
class _SingleExplorePageState extends StateWithController<_SingleExplorePage>
|
||||
with AutomaticKeepAliveClientMixin<_SingleExplorePage> {
|
||||
late final ExplorePageData data;
|
||||
|
||||
bool loading = true;
|
||||
@@ -183,6 +221,16 @@ class _SingleExplorePageState extends StateWithController<_SingleExplorePage> {
|
||||
|
||||
int key = 0;
|
||||
|
||||
bool _wantKeepAlive = true;
|
||||
|
||||
void onSettingsChanged() {
|
||||
var explorePages = appdata.settings["explore_pages"];
|
||||
if (!explorePages.contains(widget.title)) {
|
||||
_wantKeepAlive = false;
|
||||
updateKeepAlive();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -195,11 +243,19 @@ class _SingleExplorePageState extends StateWithController<_SingleExplorePage> {
|
||||
}
|
||||
}
|
||||
}
|
||||
appdata.settings.addListener(onSettingsChanged);
|
||||
throw "Explore Page ${widget.title} Not Found!";
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
appdata.settings.removeListener(onSettingsChanged);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
if (data.loadMultiPart != null) {
|
||||
return buildMultiPart();
|
||||
} 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 {
|
||||
@@ -367,13 +426,12 @@ Iterable<Widget> _buildExplorePagePart(
|
||||
if (part.viewMore != null)
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
// TODO: view more
|
||||
/*
|
||||
var context = App.mainNavigatorKey!.currentContext!;
|
||||
if (part.viewMore!.startsWith("search:")) {
|
||||
context.to(
|
||||
() => SearchResultPage(
|
||||
keyword: part.viewMore!.replaceFirst("search:", ""),
|
||||
() => SearchResultPage(
|
||||
text: part.viewMore!.replaceFirst("search:", ""),
|
||||
options: const [],
|
||||
sourceKey: sourceKey,
|
||||
),
|
||||
);
|
||||
@@ -385,16 +443,16 @@ Iterable<Widget> _buildExplorePagePart(
|
||||
p = null;
|
||||
}
|
||||
context.to(
|
||||
() => CategoryComicsPage(
|
||||
() => CategoryComicsPage(
|
||||
category: c,
|
||||
categoryKey:
|
||||
ComicSource.find(sourceKey)!.categoryData!.key,
|
||||
ComicSource.find(sourceKey)!.categoryData!.key,
|
||||
param: p,
|
||||
),
|
||||
);
|
||||
}*/
|
||||
}
|
||||
},
|
||||
child: Text("查看更多".tl),
|
||||
child: Text("View more".tl),
|
||||
)
|
||||
],
|
||||
),
|
||||
|
@@ -17,6 +17,7 @@ part 'favorite_actions.dart';
|
||||
part 'side_bar.dart';
|
||||
part 'local_favorites_page.dart';
|
||||
part 'network_favorites_page.dart';
|
||||
part 'local_search_page.dart';
|
||||
|
||||
const _kLeftBarWidth = 256.0;
|
||||
|
||||
|
41
lib/pages/favorites/local_search_page.dart
Normal file
41
lib/pages/favorites/local_search_page.dart
Normal 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;
|
||||
},
|
||||
),
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
@@ -88,6 +88,13 @@ class _LeftBarState extends State<_LeftBar> implements FolderList {
|
||||
const SizedBox(width: 12),
|
||||
Text("Local".tl),
|
||||
const Spacer(),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.search),
|
||||
color: context.colorScheme.primary,
|
||||
onPressed: () {
|
||||
context.to(() => const LocalSearchPage());
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add),
|
||||
color: context.colorScheme.primary,
|
||||
@@ -112,6 +119,7 @@ class _LeftBarState extends State<_LeftBar> implements FolderList {
|
||||
if (index == 0) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
margin: const EdgeInsets.only(top: 8),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
top: BorderSide(
|
||||
|
@@ -699,7 +699,7 @@ class _ImportComicsWidgetState extends State<_ImportComicsWidget> {
|
||||
subtitle: '',
|
||||
tags: [],
|
||||
directory: directory.name,
|
||||
chapters: Map.fromIterables(chapters, chapters),
|
||||
chapters: hasChapters ? Map.fromIterables(chapters, chapters) : null,
|
||||
cover: coverPath,
|
||||
comicType: ComicType.local,
|
||||
downloadedChapters: chapters,
|
||||
@@ -820,6 +820,7 @@ class _AccountsWidgetState extends State<_AccountsWidget> {
|
||||
|
||||
void onComicSourceChange() {
|
||||
setState(() {
|
||||
accounts.clear();
|
||||
for (var c in ComicSource.all()) {
|
||||
if (c.isLogged) {
|
||||
accounts.add(c.name);
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:venera/components/components.dart';
|
||||
import 'package:venera/foundation/app.dart';
|
||||
import 'package:venera/foundation/appdata.dart';
|
||||
import 'package:venera/foundation/local.dart';
|
||||
import 'package:venera/pages/downloading_page.dart';
|
||||
import 'package:venera/utils/cbz.dart';
|
||||
@@ -17,15 +18,29 @@ class LocalComicsPage extends StatefulWidget {
|
||||
class _LocalComicsPageState extends State<LocalComicsPage> {
|
||||
late List<LocalComic> comics;
|
||||
|
||||
late LocalSortType sortType;
|
||||
|
||||
String keyword = "";
|
||||
|
||||
bool searchMode = false;
|
||||
|
||||
void update() {
|
||||
setState(() {
|
||||
comics = LocalManager().getComics();
|
||||
});
|
||||
if(keyword.isEmpty) {
|
||||
setState(() {
|
||||
comics = LocalManager().getComics(sortType);
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
comics = LocalManager().search(keyword);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
comics = LocalManager().getComics();
|
||||
var sort = appdata.implicitData["local_sort"] ?? "name";
|
||||
sortType = LocalSortType.fromString(sort);
|
||||
comics = LocalManager().getComics(sortType);
|
||||
LocalManager().addListener(update);
|
||||
super.initState();
|
||||
}
|
||||
@@ -36,25 +51,129 @@ class _LocalComicsPageState extends State<LocalComicsPage> {
|
||||
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
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: SmoothCustomScrollView(
|
||||
slivers: [
|
||||
SliverAppbar(
|
||||
title: Text("Local".tl),
|
||||
actions: [
|
||||
Tooltip(
|
||||
message: "Downloading".tl,
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.download),
|
||||
if(!searchMode)
|
||||
SliverAppbar(
|
||||
title: Text("Local".tl),
|
||||
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(
|
||||
message: "Downloading".tl,
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.download),
|
||||
onPressed: () {
|
||||
showPopUpWidget(context, const DownloadingPage());
|
||||
},
|
||||
),
|
||||
)
|
||||
],
|
||||
)
|
||||
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: () {
|
||||
showPopUpWidget(context, const DownloadingPage());
|
||||
setState(() {
|
||||
searchMode = false;
|
||||
keyword = "";
|
||||
update();
|
||||
});
|
||||
},
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
SliverGridComics(
|
||||
comics: comics,
|
||||
onTap: (c) {
|
||||
@@ -80,8 +199,7 @@ class _LocalComicsPageState extends State<LocalComicsPage> {
|
||||
var file = await CBZ.export(c as LocalComic);
|
||||
await saveFile(filename: file.name, file: file);
|
||||
await file.delete();
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
context.showMessage(message: e.toString());
|
||||
}
|
||||
controller.close();
|
||||
|
@@ -12,14 +12,16 @@ class _ReaderGestureDetector extends StatefulWidget {
|
||||
class _ReaderGestureDetectorState extends State<_ReaderGestureDetector> {
|
||||
late TapGestureRecognizer _tapGestureRecognizer;
|
||||
|
||||
static const _kDoubleTapMinTime = Duration(milliseconds: 200);
|
||||
static const _kDoubleTapMaxTime = Duration(milliseconds: 200);
|
||||
|
||||
static const _kLongPressMinTime = Duration(milliseconds: 200);
|
||||
static const _kLongPressMinTime = Duration(milliseconds: 250);
|
||||
|
||||
static const _kDoubleTapMaxDistanceSquared = 20.0 * 20.0;
|
||||
|
||||
static const _kTapToTurnPagePercent = 0.3;
|
||||
|
||||
_DragListener? dragListener;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_tapGestureRecognizer = TapGestureRecognizer()
|
||||
@@ -28,6 +30,7 @@ class _ReaderGestureDetectorState extends State<_ReaderGestureDetector> {
|
||||
onSecondaryTapUp(details.globalPosition);
|
||||
};
|
||||
super.initState();
|
||||
context.readerScaffold._gestureDetectorState = this;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -38,11 +41,20 @@ class _ReaderGestureDetectorState extends State<_ReaderGestureDetector> {
|
||||
_lastTapPointer = event.pointer;
|
||||
_lastTapMoveDistance = Offset.zero;
|
||||
_tapGestureRecognizer.addPointer(event);
|
||||
if(_dragInProgress) {
|
||||
dragListener?.onEnd?.call();
|
||||
_dragInProgress = false;
|
||||
}
|
||||
Future.delayed(_kLongPressMinTime, () {
|
||||
if (_lastTapPointer == event.pointer &&
|
||||
_lastTapMoveDistance!.distanceSquared < 20.0 * 20.0) {
|
||||
onLongPressedDown(event.position);
|
||||
_longPressInProgress = true;
|
||||
if (_lastTapPointer == event.pointer) {
|
||||
if(_lastTapMoveDistance!.distanceSquared < 20.0 * 20.0) {
|
||||
onLongPressedDown(event.position);
|
||||
_longPressInProgress = true;
|
||||
} else {
|
||||
_dragInProgress = true;
|
||||
dragListener?.onStart?.call(event.position);
|
||||
dragListener?.onMove?.call(_lastTapMoveDistance!);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -50,11 +62,18 @@ class _ReaderGestureDetectorState extends State<_ReaderGestureDetector> {
|
||||
if (event.pointer == _lastTapPointer) {
|
||||
_lastTapMoveDistance = event.delta + _lastTapMoveDistance!;
|
||||
}
|
||||
if(_dragInProgress) {
|
||||
dragListener?.onMove?.call(event.delta);
|
||||
}
|
||||
},
|
||||
onPointerUp: (event) {
|
||||
if (_longPressInProgress) {
|
||||
onLongPressedUp(event.position);
|
||||
}
|
||||
if(_dragInProgress) {
|
||||
dragListener?.onEnd?.call();
|
||||
_dragInProgress = false;
|
||||
}
|
||||
_lastTapPointer = null;
|
||||
_lastTapMoveDistance = null;
|
||||
},
|
||||
@@ -89,6 +108,8 @@ class _ReaderGestureDetectorState extends State<_ReaderGestureDetector> {
|
||||
|
||||
bool _longPressInProgress = false;
|
||||
|
||||
bool _dragInProgress = false;
|
||||
|
||||
void onTapUp(TapUpDetails event) {
|
||||
if (_longPressInProgress) {
|
||||
_longPressInProgress = false;
|
||||
@@ -107,7 +128,7 @@ class _ReaderGestureDetectorState extends State<_ReaderGestureDetector> {
|
||||
}
|
||||
}
|
||||
_previousEvent = event;
|
||||
Future.delayed(_kDoubleTapMinTime, () {
|
||||
Future.delayed(_kDoubleTapMaxTime, () {
|
||||
if (_previousEvent == event) {
|
||||
onTap(location);
|
||||
_previousEvent = null;
|
||||
@@ -183,25 +204,33 @@ class _ReaderGestureDetectorState extends State<_ReaderGestureDetector> {
|
||||
location,
|
||||
[
|
||||
MenuEntry(
|
||||
text: "Settings".tl,
|
||||
onClick: () {
|
||||
context.readerScaffold.openSetting();
|
||||
}),
|
||||
icon: Icons.settings,
|
||||
text: "Settings".tl,
|
||||
onClick: () {
|
||||
context.readerScaffold.openSetting();
|
||||
},
|
||||
),
|
||||
MenuEntry(
|
||||
text: "Chapters".tl,
|
||||
onClick: () {
|
||||
context.readerScaffold.openChapterDrawer();
|
||||
}),
|
||||
icon: Icons.menu,
|
||||
text: "Chapters".tl,
|
||||
onClick: () {
|
||||
context.readerScaffold.openChapterDrawer();
|
||||
},
|
||||
),
|
||||
MenuEntry(
|
||||
text: "Fullscreen".tl,
|
||||
onClick: () {
|
||||
context.reader.fullscreen();
|
||||
}),
|
||||
icon: Icons.fullscreen,
|
||||
text: "Fullscreen".tl,
|
||||
onClick: () {
|
||||
context.reader.fullscreen();
|
||||
},
|
||||
),
|
||||
MenuEntry(
|
||||
text: "Exit".tl,
|
||||
onClick: () {
|
||||
context.pop();
|
||||
}),
|
||||
icon: Icons.exit_to_app,
|
||||
text: "Exit".tl,
|
||||
onClick: () {
|
||||
context.pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -214,3 +243,11 @@ class _ReaderGestureDetectorState extends State<_ReaderGestureDetector> {
|
||||
context.reader._imageViewController?.handleLongPressDown(location);
|
||||
}
|
||||
}
|
||||
|
||||
class _DragListener {
|
||||
void Function(Offset point)? onStart;
|
||||
void Function(Offset offset)? onMove;
|
||||
void Function()? onEnd;
|
||||
|
||||
_DragListener({this.onStart, this.onMove, this.onEnd});
|
||||
}
|
@@ -116,6 +116,9 @@ class _GalleryModeState extends State<_GalleryMode>
|
||||
controller = PageController(initialPage: reader.page);
|
||||
reader._imageViewController = this;
|
||||
cached = List.filled(reader.maxPage + 2, false);
|
||||
Future.microtask(() {
|
||||
context.readerScaffold.setFloatingButton(0);
|
||||
});
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@@ -180,11 +183,11 @@ class _GalleryModeState extends State<_GalleryMode>
|
||||
),
|
||||
onPageChanged: (i) {
|
||||
if (i == 0) {
|
||||
if (!reader.toNextChapter()) {
|
||||
if (!reader.toPrevChapter()) {
|
||||
reader.toPage(1);
|
||||
}
|
||||
} else if (i == reader.maxPage + 1) {
|
||||
if (!reader.toPrevChapter()) {
|
||||
if (!reader.toNextChapter()) {
|
||||
reader.toPage(reader.maxPage);
|
||||
}
|
||||
} else {
|
||||
|
@@ -2,6 +2,7 @@ library venera_reader;
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
@@ -105,6 +106,7 @@ class _ReaderState extends State<Reader> with _ReaderLocation, _ReaderWindow {
|
||||
Future.microtask(() {
|
||||
updateHistory();
|
||||
});
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@@ -112,6 +114,7 @@ class _ReaderState extends State<Reader> with _ReaderLocation, _ReaderWindow {
|
||||
void dispose() {
|
||||
autoPageTurningTimer?.cancel();
|
||||
focusNode.dispose();
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
@@ -20,21 +20,68 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
|
||||
int showFloatingButtonValue = 0;
|
||||
|
||||
double fABValue = 0;
|
||||
var lastValue = 0;
|
||||
|
||||
var fABValue = ValueNotifier<double>(0);
|
||||
|
||||
_ReaderGestureDetectorState? _gestureDetectorState;
|
||||
|
||||
void setFloatingButton(int value) {
|
||||
lastValue = showFloatingButtonValue;
|
||||
if (value == 0) {
|
||||
if (showFloatingButtonValue != 0) {
|
||||
showFloatingButtonValue = 0;
|
||||
fABValue = 0;
|
||||
fABValue.value = 0;
|
||||
update();
|
||||
}
|
||||
_gestureDetectorState!.dragListener = null;
|
||||
}
|
||||
var readerMode = context.reader.mode;
|
||||
if (value == 1 && showFloatingButtonValue == 0) {
|
||||
showFloatingButtonValue = 1;
|
||||
_gestureDetectorState!.dragListener = _DragListener(
|
||||
onMove: (offset) {
|
||||
if (readerMode == ReaderMode.continuousTopToBottom) {
|
||||
fABValue.value -= offset.dy;
|
||||
} else if (readerMode == ReaderMode.continuousLeftToRight) {
|
||||
fABValue.value -= offset.dx;
|
||||
} else if (readerMode == ReaderMode.continuousRightToLeft) {
|
||||
fABValue.value += offset.dx;
|
||||
}
|
||||
},
|
||||
onEnd: () {
|
||||
if (fABValue.value.abs() > 58 * 3) {
|
||||
setState(() {
|
||||
showFloatingButtonValue = 0;
|
||||
});
|
||||
context.reader.toNextChapter();
|
||||
}
|
||||
fABValue.value = 0;
|
||||
},
|
||||
);
|
||||
update();
|
||||
} else if (value == -1 && showFloatingButtonValue == 0) {
|
||||
showFloatingButtonValue = -1;
|
||||
_gestureDetectorState!.dragListener = _DragListener(
|
||||
onMove: (offset) {
|
||||
if (readerMode == ReaderMode.continuousTopToBottom) {
|
||||
fABValue.value += offset.dy;
|
||||
} else if (readerMode == ReaderMode.continuousLeftToRight) {
|
||||
fABValue.value += offset.dx;
|
||||
} else if (readerMode == ReaderMode.continuousRightToLeft) {
|
||||
fABValue.value -= offset.dx;
|
||||
}
|
||||
},
|
||||
onEnd: () {
|
||||
if (fABValue.value.abs() > 58 * 3) {
|
||||
setState(() {
|
||||
showFloatingButtonValue = 0;
|
||||
});
|
||||
context.reader.toPrevChapter();
|
||||
}
|
||||
fABValue.value = 0;
|
||||
},
|
||||
);
|
||||
update();
|
||||
}
|
||||
}
|
||||
@@ -47,6 +94,9 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
sliderFocus.nextFocus();
|
||||
}
|
||||
});
|
||||
if (rotation != null) {
|
||||
SystemChrome.setPreferredOrientations(DeviceOrientation.values);
|
||||
}
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@@ -57,6 +107,11 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
}
|
||||
|
||||
void openOrClose() {
|
||||
if(!_isOpen) {
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||
} else {
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
|
||||
}
|
||||
setState(() {
|
||||
_isOpen = !_isOpen;
|
||||
});
|
||||
@@ -76,6 +131,12 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
child: widget.child,
|
||||
),
|
||||
buildPageInfoText(),
|
||||
AnimatedPositioned(
|
||||
duration: const Duration(milliseconds: 180),
|
||||
right: 16,
|
||||
bottom: showFloatingButtonValue == 0 ? -58 : 16,
|
||||
child: buildEpChangeButton(),
|
||||
),
|
||||
AnimatedPositioned(
|
||||
duration: const Duration(milliseconds: 180),
|
||||
top: _isOpen ? 0 : -(kTopBarHeight + context.padding.top),
|
||||
@@ -86,18 +147,11 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
),
|
||||
AnimatedPositioned(
|
||||
duration: const Duration(milliseconds: 180),
|
||||
bottom: _isOpen ? 0 : -(kBottomBarHeight + context.padding.bottom),
|
||||
bottom: _isOpen ? 0 : -(kBottomBarHeight + MediaQuery.of(context).padding.bottom),
|
||||
left: 0,
|
||||
right: 0,
|
||||
height: kBottomBarHeight + context.padding.bottom,
|
||||
child: buildBottom(),
|
||||
),
|
||||
AnimatedPositioned(
|
||||
duration: const Duration(milliseconds: 180),
|
||||
right: 16,
|
||||
bottom: showFloatingButtonValue == 0 ? -58 : 16,
|
||||
child: buildEpChangeButton(),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -150,7 +204,7 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
}
|
||||
|
||||
Widget child = SizedBox(
|
||||
height: kBottomBarHeight + MediaQuery.of(context).padding.bottom,
|
||||
height: kBottomBarHeight,
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(
|
||||
@@ -160,14 +214,34 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
children: [
|
||||
const SizedBox(width: 8),
|
||||
IconButton.filledTonal(
|
||||
onPressed: context.reader.toPrevChapter,
|
||||
onPressed: () {
|
||||
if (!context.reader.toPrevChapter()) {
|
||||
context.reader.toPage(1);
|
||||
} else {
|
||||
if(showFloatingButtonValue != 0) {
|
||||
setState(() {
|
||||
showFloatingButtonValue = 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.first_page),
|
||||
),
|
||||
Expanded(
|
||||
child: buildSlider(),
|
||||
),
|
||||
IconButton.filledTonal(
|
||||
onPressed: context.reader.toNextChapter,
|
||||
onPressed: () {
|
||||
if (!context.reader.toNextChapter()) {
|
||||
context.reader.toPage(context.reader.maxPage);
|
||||
} else {
|
||||
if(showFloatingButtonValue != 0) {
|
||||
setState(() {
|
||||
showFloatingButtonValue = 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.last_page)),
|
||||
const SizedBox(
|
||||
width: 8,
|
||||
@@ -359,8 +433,8 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
if (imageKey.startsWith("file://")) {
|
||||
return await File(imageKey.substring(7)).readAsBytes();
|
||||
} else {
|
||||
return (await CacheManager()
|
||||
.findCache("$imageKey@${context.reader.type.sourceKey}@${context.reader.cid}@${context.reader.eid}"))!
|
||||
return (await CacheManager().findCache(
|
||||
"$imageKey@${context.reader.type.sourceKey}@${context.reader.cid}@${context.reader.eid}"))!
|
||||
.readAsBytes();
|
||||
}
|
||||
}
|
||||
@@ -402,11 +476,6 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
Widget buildEpChangeButton() {
|
||||
if (context.reader.widget.chapters == null) return const SizedBox();
|
||||
switch (showFloatingButtonValue) {
|
||||
case -1:
|
||||
return FloatingActionButton(
|
||||
onPressed: () => context.reader.toPrevChapter(),
|
||||
child: const Icon(Icons.arrow_back_ios_outlined),
|
||||
);
|
||||
case 0:
|
||||
return Container(
|
||||
width: 58,
|
||||
@@ -417,11 +486,14 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.arrow_forward_ios,
|
||||
lastValue == 1
|
||||
? Icons.arrow_forward_ios
|
||||
: Icons.arrow_back_ios_outlined,
|
||||
size: 24,
|
||||
color: Theme.of(context).colorScheme.onPrimaryContainer,
|
||||
),
|
||||
);
|
||||
case -1:
|
||||
case 1:
|
||||
return Container(
|
||||
width: 58,
|
||||
@@ -431,37 +503,54 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
color: Theme.of(context).colorScheme.primaryContainer,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () => context.reader.toNextChapter(),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Center(
|
||||
child: Icon(
|
||||
Icons.arrow_forward_ios,
|
||||
size: 24,
|
||||
color: Theme.of(context).colorScheme.onPrimaryContainer,
|
||||
)),
|
||||
child: ValueListenableBuilder(
|
||||
valueListenable: fABValue,
|
||||
builder: (context, value, child) {
|
||||
return Stack(
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
if (showFloatingButtonValue == 1) {
|
||||
context.reader.toNextChapter();
|
||||
} else if (showFloatingButtonValue == -1) {
|
||||
context.reader.toPrevChapter();
|
||||
}
|
||||
setFloatingButton(0);
|
||||
},
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Center(
|
||||
child: Icon(
|
||||
showFloatingButtonValue == 1
|
||||
? Icons.arrow_forward_ios
|
||||
: Icons.arrow_back_ios_outlined,
|
||||
size: 24,
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.onPrimaryContainer,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
height: fABValue,
|
||||
child: ColoredBox(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.surfaceTint
|
||||
.withOpacity(0.2),
|
||||
child: const SizedBox.expand(),
|
||||
),
|
||||
)
|
||||
],
|
||||
Positioned(
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
height: value.clamp(0, 58*3) / 3,
|
||||
child: ColoredBox(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.surfaceTint
|
||||
.withOpacity(0.2),
|
||||
child: const SizedBox.expand(),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@@ -86,6 +86,36 @@ class _AppSettingsState extends State<AppSettings> {
|
||||
},
|
||||
actionTitle: 'Set'.tl,
|
||||
).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(
|
||||
title: "Log".tl,
|
||||
icon: Icons.error_outline,
|
||||
|
@@ -21,6 +21,9 @@ class _AppearanceSettingsState extends State<AppearanceSettings> {
|
||||
"light": "Light".tl,
|
||||
"dark": "Dark".tl,
|
||||
},
|
||||
onChanged: () async {
|
||||
App.forceRebuild();
|
||||
},
|
||||
).toSliver(),
|
||||
SelectSetting(
|
||||
title: "Theme Color".tl,
|
||||
|
@@ -434,7 +434,7 @@ class _CallbackSetting extends StatelessWidget {
|
||||
return ListTile(
|
||||
title: Text(title),
|
||||
subtitle: subtitle == null ? null : Text(subtitle!),
|
||||
trailing: FilledButton(
|
||||
trailing: Button.normal(
|
||||
onPressed: callback,
|
||||
child: Text(actionTitle),
|
||||
).fixHeight(28),
|
||||
|
@@ -14,6 +14,7 @@ import 'package:venera/foundation/consts.dart';
|
||||
import 'package:venera/foundation/local.dart';
|
||||
import 'package:venera/foundation/log.dart';
|
||||
import 'package:venera/network/app_dio.dart';
|
||||
import 'package:venera/utils/data.dart';
|
||||
import 'package:venera/utils/io.dart';
|
||||
import 'package:venera/utils/translations.dart';
|
||||
import 'package:yaml/yaml.dart';
|
||||
|
71
lib/utils/data.dart
Normal file
71
lib/utils/data.dart
Normal 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();
|
||||
}
|
||||
}
|
@@ -24,6 +24,18 @@ extension ListExt<T> on List<T>{
|
||||
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{
|
||||
|
@@ -169,7 +169,8 @@ Future<file_selector.XFile?> selectFile({required List<String> ext}) async {
|
||||
acceptedTypeGroups: <file_selector.XTypeGroup>[typeGroup],
|
||||
);
|
||||
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 file;
|
||||
|
@@ -2,7 +2,7 @@ name: venera
|
||||
description: "A comic app."
|
||||
publish_to: 'none'
|
||||
|
||||
version: 1.0.0-beta+1
|
||||
version: 1.0.1+101
|
||||
|
||||
environment:
|
||||
sdk: '>=3.5.0 <4.0.0'
|
||||
|
@@ -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\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\zip_flutter.dll"; DestDir: "{app}"; Flags: ignoreversion
|
||||
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
|
||||
|
||||
|
Reference in New Issue
Block a user