From 2833daa51afa93b51864566f2acb1ca7ad98a0cd Mon Sep 17 00:00:00 2001 From: violet-dev Date: Sat, 3 Feb 2024 14:15:48 +0900 Subject: [PATCH 1/3] Apply rightToLeft settings --- lib/pages/viewer/horizontal_viewer_page.dart | 72 ++++++++++++-------- 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/lib/pages/viewer/horizontal_viewer_page.dart b/lib/pages/viewer/horizontal_viewer_page.dart index f0c8a30ee..48b454b95 100644 --- a/lib/pages/viewer/horizontal_viewer_page.dart +++ b/lib/pages/viewer/horizontal_viewer_page.dart @@ -146,29 +146,38 @@ class _HorizontalViewerPageState extends State { if (c.provider.useFileSystem) { if (onTwoPageMode()) { + var firstIndex = index * 2; + var secondIndex = index * 2 + 1; + + if (c.rightToLeft.value) { + firstIndex += 1; + secondIndex -= 1; + } + viewWidget = Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Image( - image: FileImage(File(c.provider.uris[index * 2])) - ..resolve(ImageConfiguration.empty) - .addListener(ImageStreamListener((imageInfo, _) { - final width = sizes[index ~/ 2].value.width + - imageInfo.image.width / imageInfo.image.height * height; - sizes[index].value = Size( - width, - height, - ); - })), - ), - if (c.maxPage > index * 2 + 1) + if (c.maxPage > firstIndex) Image( - image: FileImage(File(c.provider.uris[index * 2 + 1])) + image: FileImage(File(c.provider.uris[firstIndex])) ..resolve(ImageConfiguration.empty) .addListener(ImageStreamListener((imageInfo, _) { - final width = sizes[index].value.width + + final width = sizes[firstIndex].value.width + imageInfo.image.width / imageInfo.image.height * height; - sizes[index].value = Size( + sizes[firstIndex].value = Size( + width, + height, + ); + })), + ), + if (c.maxPage > secondIndex) + Image( + image: FileImage(File(c.provider.uris[secondIndex])) + ..resolve(ImageConfiguration.empty) + .addListener(ImageStreamListener((imageInfo, _) { + final width = sizes[secondIndex].value.width + + imageInfo.image.width / imageInfo.image.height * height; + sizes[secondIndex].value = Size( width, height, ); @@ -192,24 +201,33 @@ class _HorizontalViewerPageState extends State { builder: (context, snapshot) { if (c.urlCache[index] != null && c.headerCache[index] != null) { if (onTwoPageMode()) { + var firstIndex = index * 2; + var secondIndex = index * 2 + 1; + + if (c.rightToLeft.value) { + firstIndex += 1; + secondIndex -= 1; + } + return Obx( () => Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Image( - image: ExtendedNetworkImageProvider( - c.urlCache[index * 2]!.value, - headers: c.headerCache[index * 2], - cache: true, - retries: 10, - timeRetry: const Duration(milliseconds: 300), + if (c.maxPage > firstIndex) + Image( + image: ExtendedNetworkImageProvider( + c.urlCache[firstIndex]!.value, + headers: c.headerCache[firstIndex], + cache: true, + retries: 10, + timeRetry: const Duration(milliseconds: 300), + ), ), - ), - if (c.maxPage > index * 2 + 1) + if (c.maxPage > secondIndex) Image( image: ExtendedNetworkImageProvider( - c.urlCache[index * 2 + 1]!.value, - headers: c.headerCache[index * 2 + 1], + c.urlCache[secondIndex]!.value, + headers: c.headerCache[secondIndex], cache: true, retries: 10, timeRetry: const Duration(milliseconds: 300), From c6d5e06d9c3a86c6e7fc32ec129e76de18450d69 Mon Sep 17 00:00:00 2001 From: violet-dev Date: Sat, 3 Feb 2024 14:17:43 +0900 Subject: [PATCH 2/3] Fix provider wait target --- lib/pages/viewer/horizontal_viewer_page.dart | 4 +++- lib/pages/viewer/viewer_controller.dart | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/pages/viewer/horizontal_viewer_page.dart b/lib/pages/viewer/horizontal_viewer_page.dart index 48b454b95..92d8c3cdf 100644 --- a/lib/pages/viewer/horizontal_viewer_page.dart +++ b/lib/pages/viewer/horizontal_viewer_page.dart @@ -197,7 +197,9 @@ class _HorizontalViewerPageState extends State { } } else if (c.provider.useProvider) { viewWidget = FutureBuilder( - future: c.load(index), + future: onTwoPageMode() + ? Future.wait([c.load(index * 2), c.load(index * 2 + 1)]) + : c.load(index), builder: (context, snapshot) { if (c.urlCache[index] != null && c.headerCache[index] != null) { if (onTwoPageMode()) { diff --git a/lib/pages/viewer/viewer_controller.dart b/lib/pages/viewer/viewer_controller.dart index bb09c51a2..ab895c6a3 100644 --- a/lib/pages/viewer/viewer_controller.dart +++ b/lib/pages/viewer/viewer_controller.dart @@ -182,8 +182,12 @@ class ViewerController extends GetxController { prev() => move(page.value - (onTwoPage ? 2 : 1)); next() => move(page.value + (onTwoPage ? 2 : 1)); - load(int index) async { + Future load(int index) async { if (provider.useProvider) { + if (index >= maxPage) { + return; + } + if (headerCache[index] == null) { var header = await provider.provider!.getHeader(index); headerCache[index] = header; From ee290f6594116f5f2817ef2c7065b32d63676f2e Mon Sep 17 00:00:00 2001 From: violet-dev Date: Sat, 3 Feb 2024 14:55:01 +0900 Subject: [PATCH 3/3] Fix slider jump pagination --- lib/pages/viewer/horizontal_viewer_page.dart | 10 +++++++++- lib/pages/viewer/overlay/viewer_overlay.dart | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/pages/viewer/horizontal_viewer_page.dart b/lib/pages/viewer/horizontal_viewer_page.dart index 92d8c3cdf..fb0bd3605 100644 --- a/lib/pages/viewer/horizontal_viewer_page.dart +++ b/lib/pages/viewer/horizontal_viewer_page.dart @@ -201,7 +201,15 @@ class _HorizontalViewerPageState extends State { ? Future.wait([c.load(index * 2), c.load(index * 2 + 1)]) : c.load(index), builder: (context, snapshot) { - if (c.urlCache[index] != null && c.headerCache[index] != null) { + final checkLoad = onTwoPageMode() + ? c.urlCache[index * 2] != null && + c.headerCache[index * 2] != null && + (c.maxPage <= index * 2 + 1 || + (c.urlCache[index * 2 + 1] != null && + c.headerCache[index * 2 + 1] != null)) + : c.urlCache[index] != null && c.headerCache[index] != null; + + if (checkLoad) { if (onTwoPageMode()) { var firstIndex = index * 2; var secondIndex = index * 2 + 1; diff --git a/lib/pages/viewer/overlay/viewer_overlay.dart b/lib/pages/viewer/overlay/viewer_overlay.dart index 0b9620576..3d7bff818 100644 --- a/lib/pages/viewer/overlay/viewer_overlay.dart +++ b/lib/pages/viewer/overlay/viewer_overlay.dart @@ -560,7 +560,8 @@ class _ViewerOverlayState extends State { alignment: 0.12, ); } else { - c.horizontalPageController.jumpToPage(value.toInt() - 1); + c.horizontalPageController.jumpToPage( + c.onTwoPage ? value.toInt() ~/ 2 : value.toInt() - 1); } } },