From 8cc3702e1ad7566621442ef46cc20359fe2038cc Mon Sep 17 00:00:00 2001 From: nyne Date: Wed, 23 Apr 2025 15:38:10 +0800 Subject: [PATCH] Add an option to display single image on the first reader page. Close #244 --- assets/translation.json | 6 +++-- lib/foundation/appdata.dart | 1 + lib/pages/reader/images.dart | 42 +++++++++++++++++++++++++++------- lib/pages/settings/reader.dart | 14 ++++++++++++ 4 files changed, 53 insertions(+), 10 deletions(-) diff --git a/assets/translation.json b/assets/translation.json index 9749fc6..62654b7 100644 --- a/assets/translation.json +++ b/assets/translation.json @@ -387,7 +387,8 @@ "Screen center": "屏幕中心", "Suggestions": "建议", "Do not report any issues related to sources to App repo.": "请不要向App仓库报告任何与源相关的问题", - "Click the setting icon to change the source list url.": "点击设置图标更改源列表URL" + "Click the setting icon to change the source list url.": "点击设置图标更改源列表URL", + "Show single image on first page": "在首页显示单张图片" }, "zh_TW": { "Home": "首頁", @@ -777,6 +778,7 @@ "Screen center": "螢幕中心", "Suggestions": "建議", "Do not report any issues related to sources to App repo.": "請不要向App倉庫報告任何與源相關的問題", - "Click the setting icon to change the source list url.": "點擊設定圖示更改源列表URL" + "Click the setting icon to change the source list url.": "點擊設定圖示更改源列表URL", + "Show single image on first page": "在首頁顯示單張圖片" } } diff --git a/lib/foundation/appdata.dart b/lib/foundation/appdata.dart index ecb64cc..434681b 100644 --- a/lib/foundation/appdata.dart +++ b/lib/foundation/appdata.dart @@ -185,6 +185,7 @@ class Settings with ChangeNotifier { 'initialPage': '0', 'comicListDisplayMode': 'paging', // paging, continuous 'showPageNumberInReader': true, + 'showSingleImageOnFirstPage': false, }; operator [](String key) { diff --git a/lib/pages/reader/images.dart b/lib/pages/reader/images.dart index 728b9b4..2591ba0 100644 --- a/lib/pages/reader/images.dart +++ b/lib/pages/reader/images.dart @@ -118,7 +118,14 @@ class _GalleryModeState extends State<_GalleryMode> /// [totalPages] is the total number of pages in the current chapter. /// More than one images can be displayed on one page. - int get totalPages => (reader.images!.length / reader.imagesPerPage).ceil(); + int get totalPages { + if (!showSingleImageOnFirstPage) { + return (reader.images!.length / reader.imagesPerPage).ceil(); + } else { + return 1 + + ((reader.images!.length - 1) / reader.imagesPerPage).ceil(); + } + } var imageStates = >{}; @@ -137,6 +144,27 @@ class _GalleryModeState extends State<_GalleryMode> super.initState(); } + bool get showSingleImageOnFirstPage => appdata.settings["showSingleImageOnFirstPage"]; + + /// Get the range of images for the given page. [page] is 1-based. + (int start, int end) getPageImagesRange(int page) { + if (showSingleImageOnFirstPage) { + if (page == 1) { + return (0, 1); + } else { + int startIndex = (page - 2) * reader.imagesPerPage + 1; + int endIndex = math.min( + startIndex + reader.imagesPerPage, reader.images!.length); + return (startIndex, endIndex); + } + } else { + int startIndex = (page - 1) * reader.imagesPerPage; + int endIndex = math.min( + startIndex + reader.imagesPerPage, reader.images!.length); + return (startIndex, endIndex); + } + } + /// [cache] is used to cache the images. /// The count of images to cache is determined by the [preCacheCount] setting. /// For previous page and next page, it will do a memory cache. @@ -151,9 +179,7 @@ class _GalleryModeState extends State<_GalleryMode> } void _cachePage(int page, bool shouldPreCache) { - int startIndex = (page - 1) * reader.imagesPerPage; - int endIndex = - math.min(startIndex + reader.imagesPerPage, reader.images!.length); + var (startIndex, endIndex) = getPageImagesRange(page); for (int i = startIndex; i < endIndex; i++) { if (shouldPreCache) { _precacheImage(i+1, context); @@ -201,10 +227,7 @@ class _GalleryModeState extends State<_GalleryMode> child: const SizedBox(), ); } else { - int pageIndex = index - 1; - int startIndex = pageIndex * reader.imagesPerPage; - int endIndex = math.min( - startIndex + reader.imagesPerPage, reader.images!.length); + var (startIndex, endIndex) = getPageImagesRange(index); List pageImages = reader.images!.sublist(startIndex, endIndex); @@ -1081,6 +1104,9 @@ void _preDownloadImage(int page, BuildContext context) { } var reader = context.reader; var imageKey = reader.images![page - 1]; + if (imageKey.startsWith("file://")) { + return; + } var cid = reader.cid; var eid = reader.eid; var sourceKey = reader.type.comicSource?.key; diff --git a/lib/pages/settings/reader.dart b/lib/pages/settings/reader.dart index ea04a78..cce23e6 100644 --- a/lib/pages/settings/reader.dart +++ b/lib/pages/settings/reader.dart @@ -66,6 +66,7 @@ class _ReaderSettingsState extends State { min: 1, max: 20, onChanged: () { + setState(() {}); widget.onChanged?.call("autoPageTurningInterval"); }, ).toSliver(), @@ -80,6 +81,7 @@ class _ReaderSettingsState extends State { min: 1, max: 5, onChanged: () { + setState(() {}); widget.onChanged?.call("readerScreenPicNumberForLandscape"); }, ), @@ -99,6 +101,18 @@ class _ReaderSettingsState extends State { }, ), ), + SliverAnimatedVisibility( + visible: appdata.settings['readerMode']!.startsWith('gallery') && + (appdata.settings['readerScreenPicNumberForLandscape'] > 1 || + appdata.settings['readerScreenPicNumberForPortrait'] > 1), + child: _SwitchSetting( + title: "Show single image on first page".tl, + settingKey: "showSingleImageOnFirstPage", + onChanged: () { + widget.onChanged?.call("showSingleImageOnFirstPage"); + }, + ), + ), _SwitchSetting( title: 'Long press to zoom'.tl, settingKey: 'enableLongPressToZoom',