[mob][photos] Stop using async loader in details page. Instead use the list of files in gallery from the GalleryState inherited widget
This commit is contained in:
@@ -139,10 +139,10 @@ class HomeWidgetService {
|
||||
iOSName: 'SlideshowWidget',
|
||||
);
|
||||
_logger.info(
|
||||
">>> OG size of SlideshowWidget image: ${width} x $height",
|
||||
">>> OG size of SlideshowWidget image: $width x $height",
|
||||
);
|
||||
_logger.info(
|
||||
">>> SlideshowWidget image rendered with size ${cacheWidth} x $cacheHeight",
|
||||
">>> SlideshowWidget image rendered with size $cacheWidth x $cacheHeight",
|
||||
);
|
||||
} catch (e) {
|
||||
_logger.severe("Error rendering widget", e);
|
||||
@@ -217,7 +217,7 @@ class HomeWidgetService {
|
||||
if (res == null) return;
|
||||
|
||||
final page = DetailPage(
|
||||
DetailPageConfiguration(List.unmodifiable([res]), null, 0, "collection"),
|
||||
DetailPageConfiguration(List.unmodifiable([res]), 0, "collection"),
|
||||
);
|
||||
routeToPage(context, page, forceCustomPageRoute: true).ignore();
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ class SaveCollageButton extends StatelessWidget {
|
||||
replacePage(
|
||||
context,
|
||||
DetailPage(
|
||||
DetailPageConfiguration([newFile], null, 0, "collage"),
|
||||
DetailPageConfiguration([newFile], 0, "collage"),
|
||||
),
|
||||
result: true,
|
||||
);
|
||||
|
||||
@@ -22,7 +22,7 @@ import 'package:photos/utils/navigation_util.dart';
|
||||
class DeduplicatePage extends StatefulWidget {
|
||||
final List<DuplicateFiles> duplicates;
|
||||
|
||||
const DeduplicatePage(this.duplicates, {Key? key}) : super(key: key);
|
||||
const DeduplicatePage(this.duplicates, {super.key});
|
||||
|
||||
@override
|
||||
State<DeduplicatePage> createState() => _DeduplicatePageState();
|
||||
@@ -442,7 +442,6 @@ class _DeduplicatePageState extends State<DeduplicatePage> {
|
||||
DetailPage(
|
||||
DetailPageConfiguration(
|
||||
files,
|
||||
null,
|
||||
files.indexOf(file),
|
||||
"deduplicate_",
|
||||
mode: DetailPageMode.minimalistic,
|
||||
@@ -459,7 +458,6 @@ class _DeduplicatePageState extends State<DeduplicatePage> {
|
||||
DetailPage(
|
||||
DetailPageConfiguration(
|
||||
files,
|
||||
null,
|
||||
files.indexOf(file),
|
||||
"deduplicate_",
|
||||
mode: DetailPageMode.minimalistic,
|
||||
|
||||
@@ -378,11 +378,14 @@ class _ImageEditorPageState extends State<ImageEditorPage> {
|
||||
_logger.info("Original file " + widget.originalFile.toString());
|
||||
_logger.info("Saved edits to file " + newFile.toString());
|
||||
final existingFiles = widget.detailPageConfig.files;
|
||||
final files = (await widget.detailPageConfig.asyncLoader!(
|
||||
existingFiles[existingFiles.length - 1].creationTime!,
|
||||
existingFiles[0].creationTime!,
|
||||
))
|
||||
.files;
|
||||
|
||||
final files = existingFiles;
|
||||
// final files = (await widget.detailPageConfig.asyncLoader!(
|
||||
// existingFiles[existingFiles.length - 1].creationTime!,
|
||||
// existingFiles[0].creationTime!,
|
||||
// ))
|
||||
// .files;
|
||||
|
||||
// the index could be -1 if the files fetched doesn't contain the newly
|
||||
// edited files
|
||||
int selectionIndex =
|
||||
|
||||
@@ -263,11 +263,13 @@ class _VideoEditorPageState extends State<VideoEditorPage> {
|
||||
_logger.info("Original file " + widget.file.toString());
|
||||
_logger.info("Saved edits to file " + newFile.toString());
|
||||
final existingFiles = widget.detailPageConfig.files;
|
||||
final files = (await widget.detailPageConfig.asyncLoader!(
|
||||
existingFiles[existingFiles.length - 1].creationTime!,
|
||||
existingFiles[0].creationTime!,
|
||||
))
|
||||
.files;
|
||||
final files = existingFiles;
|
||||
// final files = (await widget.detailPageConfig.asyncLoader!(
|
||||
// existingFiles[existingFiles.length - 1].creationTime!,
|
||||
// existingFiles[0].creationTime!,
|
||||
// ))
|
||||
// .files;
|
||||
|
||||
// the index could be -1 if the files fetched doesn't contain the newly
|
||||
// edited files
|
||||
int selectionIndex = files
|
||||
|
||||
@@ -577,7 +577,6 @@ class _FileSelectionActionsWidgetState
|
||||
final page = DetailPage(
|
||||
DetailPageConfiguration(
|
||||
selectedFiles,
|
||||
null,
|
||||
0,
|
||||
"guest_view",
|
||||
),
|
||||
|
||||
@@ -7,7 +7,6 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:photos/core/configuration.dart';
|
||||
import 'package:photos/core/constants.dart';
|
||||
import 'package:photos/core/errors.dart';
|
||||
import "package:photos/core/event_bus.dart";
|
||||
import "package:photos/events/guest_view_event.dart";
|
||||
@@ -38,7 +37,6 @@ enum DetailPageMode {
|
||||
|
||||
class DetailPageConfiguration {
|
||||
final List<EnteFile> files;
|
||||
final GalleryLoader? asyncLoader;
|
||||
final int selectedIndex;
|
||||
final String tagPrefix;
|
||||
final DetailPageMode mode;
|
||||
@@ -46,7 +44,6 @@ class DetailPageConfiguration {
|
||||
|
||||
DetailPageConfiguration(
|
||||
this.files,
|
||||
this.asyncLoader,
|
||||
this.selectedIndex,
|
||||
this.tagPrefix, {
|
||||
this.mode = DetailPageMode.full,
|
||||
@@ -62,7 +59,6 @@ class DetailPageConfiguration {
|
||||
}) {
|
||||
return DetailPageConfiguration(
|
||||
files ?? this.files,
|
||||
asyncLoader ?? this.asyncLoader,
|
||||
selectedIndex ?? this.selectedIndex,
|
||||
tagPrefix ?? this.tagPrefix,
|
||||
sortOrderAsc: sortOrderAsc ?? this.sortOrderAsc,
|
||||
@@ -80,14 +76,11 @@ class DetailPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _DetailPageState extends State<DetailPage> {
|
||||
static const kLoadLimit = 100;
|
||||
final _logger = Logger("DetailPageState");
|
||||
bool _shouldDisableScroll = false;
|
||||
List<EnteFile>? _files;
|
||||
late PageController _pageController;
|
||||
final _selectedIndexNotifier = ValueNotifier(0);
|
||||
bool _hasLoadedTillStart = false;
|
||||
bool _hasLoadedTillEnd = false;
|
||||
final _enableFullScreenNotifier = ValueNotifier(false);
|
||||
bool _isFirstOpened = true;
|
||||
bool isGuestView = false;
|
||||
@@ -97,11 +90,8 @@ class _DetailPageState extends State<DetailPage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_files = [
|
||||
...widget.config.files,
|
||||
]; // Make a copy since we append preceding and succeeding entries to this
|
||||
_files = widget.config.files;
|
||||
_selectedIndexNotifier.value = widget.config.selectedIndex;
|
||||
_preloadEntries();
|
||||
_pageController = PageController(initialPage: _selectedIndexNotifier.value);
|
||||
_guestViewEventSubscription =
|
||||
Bus.instance.on<GuestViewEvent>().listen((event) {
|
||||
@@ -311,7 +301,6 @@ class _DetailPageState extends State<DetailPage> {
|
||||
_selectedIndexNotifier.value = index;
|
||||
}
|
||||
Bus.instance.fire(GuestViewEvent(isGuestView, swipeLocked));
|
||||
_preloadEntries();
|
||||
},
|
||||
physics: _shouldDisableScroll || swipeLocked
|
||||
? const NeverScrollableScrollPhysics()
|
||||
@@ -349,74 +338,6 @@ class _DetailPageState extends State<DetailPage> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _preloadEntries() async {
|
||||
final isSortOrderAsc = widget.config.sortOrderAsc;
|
||||
|
||||
if (widget.config.asyncLoader == null) return;
|
||||
|
||||
if (_selectedIndexNotifier.value == 0 && !_hasLoadedTillStart) {
|
||||
await _loadStartEntries(isSortOrderAsc);
|
||||
}
|
||||
|
||||
if (_selectedIndexNotifier.value == _files!.length - 1 &&
|
||||
!_hasLoadedTillEnd) {
|
||||
await _loadEndEntries(isSortOrderAsc);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadStartEntries(bool isSortOrderAsc) async {
|
||||
final result = isSortOrderAsc
|
||||
? await widget.config.asyncLoader!(
|
||||
galleryLoadStartTime,
|
||||
_files![_selectedIndexNotifier.value].creationTime! - 1,
|
||||
limit: kLoadLimit,
|
||||
)
|
||||
: await widget.config.asyncLoader!(
|
||||
_files![_selectedIndexNotifier.value].creationTime! + 1,
|
||||
DateTime.now().microsecondsSinceEpoch,
|
||||
limit: kLoadLimit,
|
||||
asc: true,
|
||||
);
|
||||
|
||||
setState(() {
|
||||
_logger.fine('setState loadStartEntries');
|
||||
// Returned result could be a subtype of File
|
||||
// ignore: unnecessary_cast
|
||||
final files = result.files.reversed.map((e) => e as EnteFile).toList();
|
||||
if (!result.hasMore) {
|
||||
_hasLoadedTillStart = true;
|
||||
}
|
||||
final length = files.length;
|
||||
files.addAll(_files!);
|
||||
_files = files;
|
||||
_pageController.jumpToPage(length);
|
||||
_selectedIndexNotifier.value = length;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _loadEndEntries(bool isSortOrderAsc) async {
|
||||
final result = isSortOrderAsc
|
||||
? await widget.config.asyncLoader!(
|
||||
_files![_selectedIndexNotifier.value].creationTime! + 1,
|
||||
DateTime.now().microsecondsSinceEpoch,
|
||||
limit: kLoadLimit,
|
||||
asc: true,
|
||||
)
|
||||
: await widget.config.asyncLoader!(
|
||||
galleryLoadStartTime,
|
||||
_files![_selectedIndexNotifier.value].creationTime! - 1,
|
||||
limit: kLoadLimit,
|
||||
);
|
||||
|
||||
setState(() {
|
||||
if (!result.hasMore) {
|
||||
_hasLoadedTillEnd = true;
|
||||
}
|
||||
_logger.fine('setState loadEndEntries hasMore ${result.hasMore}');
|
||||
_files!.addAll(result.files);
|
||||
});
|
||||
}
|
||||
|
||||
void _preloadFiles(int index) {
|
||||
if (index > 0) {
|
||||
preloadFile(_files![index - 1]);
|
||||
|
||||
@@ -11,6 +11,7 @@ import "package:photos/ui/viewer/file/detail_page.dart";
|
||||
import "package:photos/ui/viewer/file/thumbnail_widget.dart";
|
||||
import "package:photos/ui/viewer/gallery/gallery.dart";
|
||||
import "package:photos/ui/viewer/gallery/state/gallery_context_state.dart";
|
||||
import "package:photos/ui/viewer/gallery/state/gallery_files_inherited_widget.dart";
|
||||
import "package:photos/utils/file_util.dart";
|
||||
import "package:photos/utils/navigation_util.dart";
|
||||
|
||||
@@ -165,11 +166,11 @@ class GalleryFileWidget extends StatelessWidget {
|
||||
}
|
||||
|
||||
void _routeToDetailPage(EnteFile file, BuildContext context) {
|
||||
final galleryFiles = GalleryFilesState.of(context).galleryFiles;
|
||||
final page = DetailPage(
|
||||
DetailPageConfiguration(
|
||||
List.unmodifiable(filesInGroup),
|
||||
asyncLoader,
|
||||
filesInGroup.indexOf(file),
|
||||
galleryFiles,
|
||||
galleryFiles.indexOf(file),
|
||||
tag,
|
||||
sortOrderAsc: GalleryContextState.of(context)!.sortOrderAsc,
|
||||
),
|
||||
|
||||
@@ -68,7 +68,6 @@ class FileSearchResultWidget extends StatelessWidget {
|
||||
final page = DetailPage(
|
||||
DetailPageConfiguration(
|
||||
List.unmodifiable([file]),
|
||||
null,
|
||||
0,
|
||||
"file_details",
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user