Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix two page viewer #384

Merged
merged 3 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 57 additions & 29 deletions lib/pages/viewer/horizontal_viewer_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,29 +146,38 @@ class _HorizontalViewerPageState extends State<HorizontalViewerPage> {

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[firstIndex]))
..resolve(ImageConfiguration.empty)
.addListener(ImageStreamListener((imageInfo, _) {
final width = sizes[firstIndex].value.width +
imageInfo.image.width / imageInfo.image.height * height;
sizes[firstIndex].value = Size(
width,
height,
);
})),
),
if (c.maxPage > secondIndex)
Image(
image: FileImage(File(c.provider.uris[index * 2 + 1]))
image: FileImage(File(c.provider.uris[secondIndex]))
..resolve(ImageConfiguration.empty)
.addListener(ImageStreamListener((imageInfo, _) {
final width = sizes[index].value.width +
final width = sizes[secondIndex].value.width +
imageInfo.image.width / imageInfo.image.height * height;
sizes[index].value = Size(
sizes[secondIndex].value = Size(
width,
height,
);
Expand All @@ -188,28 +197,47 @@ class _HorizontalViewerPageState extends State<HorizontalViewerPage> {
}
} 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) {
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;

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),
Expand Down
3 changes: 2 additions & 1 deletion lib/pages/viewer/overlay/viewer_overlay.dart
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,8 @@ class _ViewerOverlayState extends State<ViewerOverlay> {
alignment: 0.12,
);
} else {
c.horizontalPageController.jumpToPage(value.toInt() - 1);
c.horizontalPageController.jumpToPage(
c.onTwoPage ? value.toInt() ~/ 2 : value.toInt() - 1);
}
}
},
Expand Down
6 changes: 5 additions & 1 deletion lib/pages/viewer/viewer_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> 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;
Expand Down
Loading