Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Make the scrollbar divisions meant for years actually show years

ashilkn880594398db6
diff --git a/mobile/apps/photos/lib/models/gallery/gallery_sections.dart b/mobile/apps/photos/lib/models/gallery/gallery_sections.dart
index 9438fe685e..5b418d4365 100644
--- a/mobile/apps/photos/lib/models/gallery/gallery_sections.dart
+++ b/mobile/apps/photos/lib/models/gallery/gallery_sections.dart
@@ -11,6 +11,7 @@ import "package:photos/service_locator.dart";
import "package:photos/ui/viewer/gallery/component/gallery_file_widget.dart";
import "package:photos/ui/viewer/gallery/component/group/group_header_widget.dart";
import "package:photos/ui/viewer/gallery/component/group/type.dart";
+import "package:photos/ui/viewer/gallery/scrollbar/custom_scroll_bar_2.dart";
import "package:uuid/uuid.dart";
class GalleryGroups {
@@ -49,7 +50,9 @@ class GalleryGroups {
final Map<String, List<EnteFile>> _groupIdToFilesMap = {};
final Map<String, GroupHeaderData> _groupIdToHeaderDataMap = {};
final Map<double, String> _scrollOffsetToGroupIdMap = {};
+ final Map<String, double> _groupIdToScrollOffsetMap = {};
final List<double> _groupScrollOffsets = [];
+ final List<ScrollbarDivision> _scrollbarDivisions = [];
final currentUserID = Configuration.instance.getUserID();
final _uuid = const Uuid();
@@ -58,8 +61,10 @@ class GalleryGroups {
Map<String, GroupHeaderData> get groupIdToheaderDataMap =>
_groupIdToHeaderDataMap;
Map<double, String> get scrollOffsetToGroupIdMap => _scrollOffsetToGroupIdMap;
+ Map<String, double> get groupIdToScrollOffsetMap => _groupIdToScrollOffsetMap;
List<FixedExtentSectionLayout> get groupLayouts => _groupLayouts;
List<double> get groupScrollOffsets => _groupScrollOffsets;
+ List<ScrollbarDivision> get scrollbarDivisions => _scrollbarDivisions;
void init() {
_buildGroups();
@@ -70,6 +75,9 @@ class GalleryGroups {
assert(
groupIDs.length == _scrollOffsetToGroupIdMap.length,
);
+ assert(
+ groupIDs.length == _groupIdToScrollOffsetMap.length,
+ );
assert(groupIDs.length == _groupScrollOffsets.length);
}
@@ -179,6 +187,7 @@ class GalleryGroups {
);
_scrollOffsetToGroupIdMap[currentOffset] = groupID;
+ _groupIdToScrollOffsetMap[groupID] = currentOffset;
_groupScrollOffsets.add(currentOffset);
currentIndex = lastIndex;
@@ -199,17 +208,18 @@ class GalleryGroups {
// TODO: compute this in isolate
void _buildGroups() {
final stopwatch = Stopwatch()..start();
+ final years = <int>{};
List<EnteFile> groupFiles = [];
for (int index = 0; index < allFiles.length; index++) {
if (index > 0 &&
!groupType.areFromSameGroup(allFiles[index - 1], allFiles[index])) {
- _createNewGroup(groupFiles);
+ _createNewGroup(groupFiles, years);
groupFiles = [];
}
groupFiles.add(allFiles[index]);
}
if (groupFiles.isNotEmpty) {
- _createNewGroup(groupFiles);
+ _createNewGroup(groupFiles, years);
}
_logger.info(
"Built ${_groupIds.length} groups in ${stopwatch.elapsedMilliseconds} ms",
@@ -222,6 +232,7 @@ class GalleryGroups {
void _createNewGroup(
List<EnteFile> groupFiles,
+ Set<int> years,
) {
final uuid = _uuid.v1();
_groupIds.add(uuid);
@@ -229,6 +240,19 @@ class GalleryGroups {
_groupIdToHeaderDataMap[uuid] = GroupHeaderData(
groupType: groupType,
);
+
+ final yearOfGroup = DateTime.fromMicrosecondsSinceEpoch(
+ groupFiles.first.creationTime!,
+ ).year;
+ if (!years.contains(yearOfGroup)) {
+ years.add(yearOfGroup);
+ _scrollbarDivisions.add(
+ ScrollbarDivision(
+ groupID: uuid,
+ title: yearOfGroup.toString(),
+ ),
+ );
+ }
}
}
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
index 8d4364573d..8536b24617 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
@@ -479,6 +479,7 @@ class GalleryState extends State<Gallery> {
// ),
child: CustomScrollBar2(
scrollController: _scrollController,
+ galleryGroups: galleryGroups,
child: Stack(
key: _stackKey,
clipBehavior: Clip.none,
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/scrollbar/custom_scroll_bar_2.dart b/mobile/apps/photos/lib/ui/viewer/gallery/scrollbar/custom_scroll_bar_2.dart
index 968196013d..06ea9ca698 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/scrollbar/custom_scroll_bar_2.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/scrollbar/custom_scroll_bar_2.dart
@@ -1,21 +1,102 @@
+import "dart:async";
import "package:flutter/material.dart";
+import "package:logging/logging.dart";
+import "package:photos/models/gallery/gallery_sections.dart";
import "package:photos/ui/viewer/gallery/scrollbar/scroll_bar_with_use_notifier.dart";
+import "package:photos/utils/misc_util.dart";
class CustomScrollBar2 extends StatefulWidget {
final Widget child;
final ScrollController scrollController;
+ final GalleryGroups galleryGroups;
const CustomScrollBar2({
super.key,
required this.child,
required this.scrollController,
+ required this.galleryGroups,
});
@override
State<CustomScrollBar2> createState() => _CustomScrollBar2State();
}
+/*
+Create a new variable that stores Position to title mapping which will be used
+to show scrollbar divisions.
+
+List of scrollbar divisions can be obtained from galleryGroups.scrollbarDivisions.
+And the scroll positions of each division can be obtained from
+galleryGroups.groupIdToScrollOffsetMap[groupID] where groupID.
+
+Can ignore adding the top offset of the header for accuracy.
+
+Get the height of the scrollbar and create a normalized position for each
+division and populate position to title mapping.
+*/
+
class _CustomScrollBar2State extends State<CustomScrollBar2> {
+ final _logger = Logger("CustomScrollBar2");
+ final _key = GlobalKey();
final inUseNotifier = ValueNotifier<bool>(false);
+ List<({double position, String title})>? positionToTitleMap;
+
+ @override
+ void initState() {
+ super.initState();
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ _computePositionToTitleMap();
+ });
+ }
+
+ @override
+ void didUpdateWidget(covariant CustomScrollBar2 oldWidget) {
+ super.didUpdateWidget(oldWidget);
+ _computePositionToTitleMap();
+ }
+
+ @override
+ void dispose() {
+ inUseNotifier.dispose();
+ super.dispose();
+ }
+
+ Future<void> _computePositionToTitleMap() async {
+ _logger.info("computing postition to title map");
+ final result = <({double position, String title})>[];
+ final heightOfScrollTrack = await _getHeightOfScrollTrack();
+ final maxScrollExtent = widget.scrollController.position.maxScrollExtent;
+
+ for (ScrollbarDivision scrollbarDivision
+ in widget.galleryGroups.scrollbarDivisions) {
+ final scrollOffsetOfGroup = widget
+ .galleryGroups.groupIdToScrollOffsetMap[scrollbarDivision.groupID]!;
+
+ final groupScrollOffsetToUse = scrollOffsetOfGroup - heightOfScrollTrack;
+ if (groupScrollOffsetToUse < 0) {
+ result.add((position: 0, title: scrollbarDivision.title));
+ } else {
+ final normalizedPosition =
+ (groupScrollOffsetToUse / maxScrollExtent) * heightOfScrollTrack;
+ result.add(
+ (position: normalizedPosition, title: scrollbarDivision.title),
+ );
+ }
+ }
+ setState(() {
+ positionToTitleMap = result;
+ });
+ }
+
+ Future<double> _getHeightOfScrollTrack() {
+ final renderBox = _key.currentContext?.findRenderObject() as RenderBox?;
+ assert(renderBox != null, "RenderBox is null");
+ // Retry for : https://github.com/flutter/flutter/issues/25827
+ return MiscUtil().getNonZeroDoubleWithRetry(
+ () => renderBox!.size.height,
+ id: "getHeightOfScrollTrack",
+ );
+ }
+
@override
Widget build(BuildContext context) {
return Stack(
@@ -23,80 +104,56 @@ class _CustomScrollBar2State extends State<CustomScrollBar2> {
alignment: Alignment.centerLeft,
children: [
ScrollbarWithUseNotifer(
+ key: _key,
controller: widget.scrollController,
interactive: true,
inUseNotifier: inUseNotifier,
child: widget.child,
),
- ValueListenableBuilder<bool>(
- valueListenable: inUseNotifier,
- builder: (context, inUse, _) {
- return AnimatedSwitcher(
- duration: const Duration(milliseconds: 250),
- switchInCurve: Curves.easeInOut,
- switchOutCurve: Curves.easeInOut,
- child: !inUse
- ? const SizedBox.shrink()
- : Stack(
- children: [
- Positioned(
- top: 50,
- right: 24,
- child: Container(
- color: Colors.teal,
- child: const Center(
- child: Text(
- 'Item 1',
- style: TextStyle(color: Colors.white),
- ),
- ),
- ),
- ),
- Positioned(
- top: 100,
- right: 24,
- child: Container(
- color: Colors.teal,
- child: const Center(
- child: Text(
- 'Item 2',
- style: TextStyle(color: Colors.white),
- ),
- ),
+ positionToTitleMap == null
+ ? const SizedBox.shrink()
+ : ValueListenableBuilder<bool>(
+ valueListenable: inUseNotifier,
+ builder: (context, inUse, _) {
+ return AnimatedSwitcher(
+ duration: const Duration(milliseconds: 250),
+ switchInCurve: Curves.easeInOut,
+ switchOutCurve: Curves.easeInOut,
+ child: !inUse
+ ? const SizedBox.shrink()
+ : Stack(
+ children: positionToTitleMap!.map((record) {
+ return Positioned(
+ top: record.position,
+ right: 24,
+ child: Container(
+ color: Colors.teal,
+ child: Center(
+ child: Text(
+ record.title,
+ style: const TextStyle(
+ color: Colors.white,
+ ),
+ ),
+ ),
+ ),
+ );
+ }).toList(),
),
- ),
- Positioned(
- top: 250,
- right: 24,
- child: Container(
- color: Colors.teal,
- child: const Center(
- child: Text(
- 'Item 3',
- style: TextStyle(color: Colors.white),
- ),
- ),
- ),
- ),
- Positioned(
- top: 400,
- right: 24,
- child: Container(
- color: Colors.teal,
- child: const Center(
- child: Text(
- 'Item 4',
- style: TextStyle(color: Colors.white),
- ),
- ),
- ),
- ),
- ],
- ),
- );
- },
- ),
+ );
+ },
+ ),
],
);
}
}
+
+class ScrollbarDivision {
+ final String groupID;
+ final String title;
+
+ ScrollbarDivision({
+ required this.groupID,
+ required this.title,
+ });
+}