Add a setting for number of images preloaded. Close #192

This commit is contained in:
2025-02-14 10:58:21 +08:00
parent d179b39b64
commit 350bcf4ffc
4 changed files with 31 additions and 5 deletions

View File

@@ -105,7 +105,7 @@ class _GalleryModeState extends State<_GalleryMode>
late List<bool> cached;
int get preCacheCount => 4;
int get preCacheCount => appdata.settings["preloadImageCount"];
var photoViewControllers = <int, PhotoViewController>{};
@@ -371,6 +371,9 @@ class _ContinuousModeState extends State<_ContinuousMode>
var fingers = 0;
bool disableScroll = false;
late List<bool> cached;
int get preCacheCount => appdata.settings["preloadImageCount"];
/// Whether the user was scrolling the page.
/// The gesture detector has a delay to detect tap event.
/// To handle the tap event, we need to know if the user was scrolling before the delay.
@@ -388,6 +391,11 @@ class _ContinuousModeState extends State<_ContinuousMode>
reader = context.reader;
reader._imageViewController = this;
itemPositionsListener.itemPositions.addListener(onPositionChanged);
cached = List.filled(reader.maxPage + 2, false);
Future.delayed(
const Duration(milliseconds: 100),
() => cacheImages(reader.page),
);
super.initState();
}
@@ -404,6 +412,7 @@ class _ContinuousModeState extends State<_ContinuousMode>
reader.setPage(page);
context.readerScaffold.update();
}
cacheImages(page);
}
double? futurePosition;
@@ -443,6 +452,15 @@ class _ContinuousModeState extends State<_ContinuousMode>
}
}
void cacheImages(int current) {
for (int i = current + 1; i <= current + preCacheCount; i++) {
if (i <= reader.maxPage && !cached[i]) {
_precacheImage(i, context);
cached[i] = true;
}
}
}
@override
Widget build(BuildContext context) {
Widget widget = ScrollablePositionedList.builder(
@@ -473,8 +491,6 @@ class _ContinuousModeState extends State<_ContinuousMode>
width = double.infinity;
}
_precacheImage(index, context);
ImageProvider image = _createImageProvider(index, context);
return ComicImage(

View File

@@ -143,6 +143,13 @@ class _ReaderSettingsState extends State<ReaderSettings> {
callback: () => context.to(() => _CustomImageProcessing()),
actionTitle: "Edit".tl,
).toSliver(),
_SliderSetting(
title: "Number of images preloaded".tl,
settingsIndex: "preloadImageCount",
interval: 1,
min: 1,
max: 16,
).toSliver(),
],
);
}