diff --git a/assets/translation.json b/assets/translation.json index 974be32..bd5a745 100644 --- a/assets/translation.json +++ b/assets/translation.json @@ -251,7 +251,11 @@ "Aggregated Search": "聚合搜索", "No search results found": "未找到搜索结果", "Added @c comics to download queue." : "已添加 @c 本漫画到下载队列", - "Download started": "下载已开始" + "Download started": "下载已开始", + "Click favorite": "点击收藏", + "End": "末尾", + "None": "无", + "View Detail": "查看详情" }, "zh_TW": { "Home": "首頁", @@ -505,6 +509,10 @@ "Aggregated Search": "聚合搜索", "No search results found": "未找到搜索結果", "Added @c comics to download queue." : "已添加 @c 本漫畫到下載隊列", - "Download started": "下載已開始" + "Download started": "下載已開始", + "Click favorite": "點擊收藏", + "End": "末尾", + "None": "無", + "View Detail": "查看詳情" } } \ No newline at end of file diff --git a/lib/foundation/appdata.dart b/lib/foundation/appdata.dart index 128d0bf..dc49623 100644 --- a/lib/foundation/appdata.dart +++ b/lib/foundation/appdata.dart @@ -122,6 +122,7 @@ class _Settings with ChangeNotifier { 'enableClockAndBatteryInfoInReader': true, 'ignoreCertificateErrors': false, 'authorizationRequired': false, + 'onClickFavorite': 'viewDetail', // viewDetail, read }; operator [](String key) { diff --git a/lib/foundation/comic_type.dart b/lib/foundation/comic_type.dart index 36c8ad6..6fa31ef 100644 --- a/lib/foundation/comic_type.dart +++ b/lib/foundation/comic_type.dart @@ -28,4 +28,12 @@ class ComicType { } static const local = ComicType(0); + + factory ComicType.fromKey(String key) { + if(key == "local") { + return local; + } else { + return ComicType(key.hashCode); + } + } } \ No newline at end of file diff --git a/lib/pages/favorites/favorites_page.dart b/lib/pages/favorites/favorites_page.dart index 335b40c..47b868f 100644 --- a/lib/pages/favorites/favorites_page.dart +++ b/lib/pages/favorites/favorites_page.dart @@ -14,6 +14,7 @@ import 'package:venera/foundation/local.dart'; import 'package:venera/foundation/res.dart'; import 'package:venera/network/download.dart'; import 'package:venera/pages/comic_page.dart'; +import 'package:venera/pages/reader/reader.dart'; import 'package:venera/utils/io.dart'; import 'package:venera/utils/translations.dart'; diff --git a/lib/pages/favorites/local_favorites_page.dart b/lib/pages/favorites/local_favorites_page.dart index 44049d3..256d763 100644 --- a/lib/pages/favorites/local_favorites_page.dart +++ b/lib/pages/favorites/local_favorites_page.dart @@ -389,22 +389,29 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> { ), ]; }, - onTap: multiSelectMode - ? (c) { - setState(() { - if (selectedComics.containsKey(c as FavoriteItem)) { - selectedComics.remove(c); - _checkExitSelectMode(); - } else { - selectedComics[c] = true; - } - lastSelectedIndex = comics.indexOf(c); - }); + onTap: (c) { + if (multiSelectMode) { + setState(() { + if (selectedComics.containsKey(c as FavoriteItem)) { + selectedComics.remove(c); + _checkExitSelectMode(); + } else { + selectedComics[c] = true; } - : (c) { - App.mainNavigatorKey?.currentContext - ?.to(() => ComicPage(id: c.id, sourceKey: c.sourceKey)); - }, + lastSelectedIndex = comics.indexOf(c); + }); + } else if (appdata.settings["onClickFavorite"] == "viewDetail") { + App.mainNavigatorKey?.currentContext + ?.to(() => ComicPage(id: c.id, sourceKey: c.sourceKey)); + } else { + App.mainNavigatorKey?.currentContext?.to( + () => ReaderWithLoading( + id: c.id, + sourceKey: c.sourceKey, + ), + ); + } + }, onLongPressed: (c) { setState(() { if (!multiSelectMode) { diff --git a/lib/pages/reader/loading.dart b/lib/pages/reader/loading.dart new file mode 100644 index 0000000..682f457 --- /dev/null +++ b/lib/pages/reader/loading.dart @@ -0,0 +1,101 @@ +part of 'reader.dart'; + +class ReaderWithLoading extends StatefulWidget { + const ReaderWithLoading({ + super.key, + required this.id, + required this.sourceKey, + }); + + final String id; + + final String sourceKey; + + @override + State createState() => _ReaderWithLoadingState(); +} + +class _ReaderWithLoadingState + extends LoadingState { + @override + Widget buildContent(BuildContext context, ReaderProps data) { + return Reader( + type: data.type, + cid: data.cid, + name: data.name, + chapters: data.chapters, + history: data.history, + ); + } + + @override + Future> loadData() async { + var comicSource = ComicSource.find(widget.sourceKey); + var history = HistoryManager().findSync( + widget.id, + ComicType.fromKey(widget.sourceKey), + ); + if (comicSource == null) { + var localComic = LocalManager().find( + widget.id, + ComicType.fromKey(widget.sourceKey), + ); + if (localComic == null) { + return Res.error("comic not found"); + } + return Res( + ReaderProps( + type: ComicType.fromKey(widget.sourceKey), + cid: widget.id, + name: localComic.title, + chapters: localComic.chapters, + history: history ?? + History.fromModel( + model: localComic, + ep: 0, + page: 0, + ), + ), + ); + } else { + var comic = await comicSource.loadComicInfo!(widget.id); + if (comic.error) { + return Res.fromErrorRes(comic); + } + return Res( + ReaderProps( + type: ComicType.fromKey(widget.sourceKey), + cid: widget.id, + name: comic.data.title, + chapters: comic.data.chapters, + history: history ?? + History.fromModel( + model: comic.data, + ep: 0, + page: 0, + ), + ), + ); + } + } +} + +class ReaderProps { + final ComicType type; + + final String cid; + + final String name; + + final Map? chapters; + + final History history; + + const ReaderProps({ + required this.type, + required this.cid, + required this.name, + required this.chapters, + required this.history, + }); +} diff --git a/lib/pages/reader/reader.dart b/lib/pages/reader/reader.dart index dc03af6..ec04d06 100644 --- a/lib/pages/reader/reader.dart +++ b/lib/pages/reader/reader.dart @@ -18,11 +18,13 @@ import 'package:venera/components/custom_slider.dart'; import 'package:venera/foundation/app.dart'; import 'package:venera/foundation/appdata.dart'; import 'package:venera/foundation/cache_manager.dart'; +import 'package:venera/foundation/comic_source/comic_source.dart'; import 'package:venera/foundation/comic_type.dart'; import 'package:venera/foundation/history.dart'; import 'package:venera/foundation/image_provider/reader_image.dart'; import 'package:venera/foundation/local.dart'; import 'package:venera/foundation/log.dart'; +import 'package:venera/foundation/res.dart'; import 'package:venera/pages/settings/settings_page.dart'; import 'package:venera/utils/data_sync.dart'; import 'package:venera/utils/file_type.dart'; @@ -36,6 +38,7 @@ part 'scaffold.dart'; part 'images.dart'; part 'gesture.dart'; part 'comic_image.dart'; +part 'loading.dart'; extension _ReaderContext on BuildContext { _ReaderState get reader => findAncestorStateOfType<_ReaderState>()!; diff --git a/lib/pages/settings/local_favorites.dart b/lib/pages/settings/local_favorites.dart index c35f9a3..04511fa 100644 --- a/lib/pages/settings/local_favorites.dart +++ b/lib/pages/settings/local_favorites.dart @@ -16,18 +16,18 @@ class _LocalFavoritesSettingsState extends State { SelectSetting( title: "Add new favorite to".tl, settingKey: "newFavoriteAddTo", - optionTranslation: const { - "start": "Start", - "end": "End", + optionTranslation: { + "start": "Start".tl, + "end": "End".tl, }, ).toSliver(), SelectSetting( title: "Move favorite after reading".tl, settingKey: "moveFavoriteAfterRead", - optionTranslation: const { - "none": "None", - "end": "End", - "start": "Start", + optionTranslation: { + "none": "None".tl, + "end": "End".tl, + "start": "Start".tl, }, ).toSliver(), SelectSetting( @@ -48,6 +48,14 @@ class _LocalFavoritesSettingsState extends State { }, actionTitle: 'Delete'.tl, ).toSliver(), + SelectSetting( + title: "Click favorite".tl, + settingKey: "onClickFavorite", + optionTranslation: { + "viewDetail": "View Detail".tl, + "read": "Read".tl, + }, + ).toSliver(), ], ); } diff --git a/pubspec.lock b/pubspec.lock index af3d58c..916f35e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -446,11 +446,10 @@ packages: flutter_to_arch: dependency: "direct dev" description: - path: "." - ref: HEAD - resolved-ref: "15bfead0380fda79b0256b37c73b886b0882f1bf" - url: "https://github.com/wgh136/flutter_to_arch" - source: git + name: flutter_to_arch + sha256: "656cffc182b05af38aa96a1115931620b8865c4b0cfe00813b26fcff0875f2ab" + url: "https://pub.dev" + source: hosted version: "1.0.0" flutter_to_debian: dependency: "direct dev" @@ -1125,12 +1124,11 @@ packages: zip_flutter: dependency: "direct main" description: - path: "." - ref: "51007a0" - resolved-ref: "51007a0c1f34ee7865ef3bdededf40e5f5df85bd" - url: "https://github.com/wgh136/zip_flutter" - source: git - version: "0.0.3" + name: zip_flutter + sha256: "78c9b6053117828581346d24b07943ba6d3032a13f68d15c133bc21df2cf178a" + url: "https://pub.dev" + source: hosted + version: "0.0.4" sdks: dart: ">=3.6.0 <4.0.0" flutter: ">=3.27.1" diff --git a/pubspec.yaml b/pubspec.yaml index f50c1a7..096574d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -51,10 +51,7 @@ dependencies: sliver_tools: ^0.2.12 flutter_file_dialog: ^3.0.2 file_selector: ^1.0.3 - zip_flutter: - git: - url: https://github.com/wgh136/zip_flutter - ref: 51007a0 + zip_flutter: ^0.0.4 lodepng_flutter: git: url: https://github.com/venera-app/lodepng_flutter @@ -79,8 +76,7 @@ dev_dependencies: flutter_test: sdk: flutter flutter_lints: ^5.0.0 - flutter_to_arch: - git: https://github.com/wgh136/flutter_to_arch + flutter_to_arch: ^1.0.0 flutter_to_debian: flutter: