Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Add location album covers and Hero transitions

r4khul43ea85af4f31
diff --git a/mobile/apps/photos/changes/location-album-covers.md b/mobile/apps/photos/changes/location-album-covers.md
new file mode 100644
index 0000000000..29d52146ce
--- /dev/null
+++ b/mobile/apps/photos/changes/location-album-covers.md
@@ -0,0 +1 @@
+- Added album cover headers and smooth transitions to locations.
diff --git a/mobile/apps/photos/lib/models/search/generic_search_result.dart b/mobile/apps/photos/lib/models/search/generic_search_result.dart
index e38442c6ad..04148b32c7 100644
--- a/mobile/apps/photos/lib/models/search/generic_search_result.dart
+++ b/mobile/apps/photos/lib/models/search/generic_search_result.dart
@@ -1,6 +1,7 @@
import "package:flutter/cupertino.dart";
import 'package:photos/models/file/file.dart';
import "package:photos/models/search/hierarchical/hierarchical_search_filter.dart";
+import "package:photos/models/search/search_constants.dart";
import 'package:photos/models/search/search_result.dart';
import "package:photos/models/search/search_types.dart";
@@ -31,6 +32,12 @@ class GenericSearchResult extends SearchResult {
return _type;
}
+ @override
+ String heroTag() {
+ final locationID = params[kLocationParamID];
+ return locationID != null ? '${type()}_$locationID' : super.heroTag();
+ }
+
@override
EnteFile? previewThumbnail() {
if (type() == ResultType.shared) {
diff --git a/mobile/apps/photos/lib/models/search/search_constants.dart b/mobile/apps/photos/lib/models/search/search_constants.dart
index d6de4ee3d2..671d5b0bba 100644
--- a/mobile/apps/photos/lib/models/search/search_constants.dart
+++ b/mobile/apps/photos/lib/models/search/search_constants.dart
@@ -2,6 +2,7 @@ const kPersonParamID = 'person_id';
const kPersonWidgetKey = 'person_widget_key';
const kPersonPinned = 'person_pinned';
const kClusterParamId = 'cluster_id';
+const kLocationParamID = 'location_id';
const kFileID = 'file_id';
const kContactUserId = 'contact_user_id';
const kContactEmail = 'contact_email';
diff --git a/mobile/apps/photos/lib/services/search_service.dart b/mobile/apps/photos/lib/services/search_service.dart
index 2865117423..386ee97d77 100644
--- a/mobile/apps/photos/lib/services/search_service.dart
+++ b/mobile/apps/photos/lib/services/search_service.dart
@@ -1141,10 +1141,18 @@ class SearchService {
ResultType.location,
name,
entry.value,
+ params: {kLocationParamID: entry.key.id},
onResultTap: (ctx) {
routeToPage(
ctx,
- LocationScreenStateProvider(entry.key, const LocationScreen()),
+ LocationScreenStateProvider(
+ entry.key,
+ LocationScreen(
+ initialFiles: entry.value,
+ coverHeroTag: "${ResultType.location}_${entry.key.id}",
+ ),
+ ),
+ useFadeTransition: true,
);
},
hierarchicalSearchFilter: LocationFilter(
@@ -1206,6 +1214,9 @@ class SearchService {
ResultType.location,
city.city,
results[city]!,
+ params: {
+ kLocationParamID: "${city.country}_${city.lat}_${city.lng}",
+ },
hierarchicalSearchFilter: TopLevelGenericFilter(
filterName: city.city,
occurrence: kMostRelevantFilter,
@@ -1670,16 +1681,19 @@ class SearchService {
ResultType.location,
entry.key.item.name,
entry.value,
+ params: {kLocationParamID: entry.key.id},
onResultTap: (ctx) {
routeToPage(
ctx,
LocationScreenStateProvider(
entry.key,
LocationScreen(
- tagPrefix:
- "${ResultType.location.toString()}_${entry.key.item.name}",
+ initialFiles: entry.value,
+ coverHeroTag: "${ResultType.location}_${entry.key.id}",
+ tagPrefix: "${ResultType.location}_${entry.key.id}",
),
),
+ useFadeTransition: true,
);
},
hierarchicalSearchFilter: LocationFilter(
@@ -1707,6 +1721,9 @@ class SearchService {
ResultType.locationSuggestion,
city.city,
results[city]!,
+ params: {
+ kLocationParamID: "${city.country}_${city.lat}_${city.lng}",
+ },
hierarchicalSearchFilter: TopLevelGenericFilter(
filterName: city.city,
occurrence: kMostRelevantFilter,
diff --git a/mobile/apps/photos/lib/ui/viewer/location/location_screen.dart b/mobile/apps/photos/lib/ui/viewer/location/location_screen.dart
index 4a76dd50e5..bd389fc6fb 100644
--- a/mobile/apps/photos/lib/ui/viewer/location/location_screen.dart
+++ b/mobile/apps/photos/lib/ui/viewer/location/location_screen.dart
@@ -31,7 +31,14 @@ import "package:photos/ui/viewer/gallery/state/selection_state.dart";
class LocationScreen extends StatefulWidget {
final String tagPrefix;
- const LocationScreen({this.tagPrefix = "", super.key});
+ final List<EnteFile>? initialFiles;
+ final String? coverHeroTag;
+ const LocationScreen({
+ this.tagPrefix = "",
+ this.initialFiles,
+ this.coverHeroTag,
+ super.key,
+ });
@override
State<LocationScreen> createState() => _LocationScreenState();
@@ -59,6 +66,8 @@ class _LocationScreenState extends State<LocationScreen> {
body: LocationGalleryWidget(
tagPrefix: widget.tagPrefix,
selectedFiles: selectedFiles,
+ initialFiles: widget.initialFiles,
+ coverHeroTag: widget.coverHeroTag,
),
),
),
@@ -69,10 +78,14 @@ class _LocationScreenState extends State<LocationScreen> {
class LocationGalleryWidget extends StatefulWidget {
final String tagPrefix;
+ final List<EnteFile>? initialFiles;
+ final String? coverHeroTag;
final SelectedFiles selectedFiles;
const LocationGalleryWidget({
required this.tagPrefix,
required this.selectedFiles,
+ this.initialFiles,
+ this.coverHeroTag,
super.key,
});
@@ -85,7 +98,8 @@ class _LocationGalleryWidgetState extends State<LocationGalleryWidget> {
late final List<EnteFile> allFilesWithLocation;
final _selectedFiles = SelectedFiles();
- late final StreamSubscription<LocalPhotosUpdatedEvent> _filesUpdateEvent;
+ final _coverAppBarKey = GlobalKey();
+ StreamSubscription<LocalPhotosUpdatedEvent>? _filesUpdateEvent;
@override
void initState() {
super.initState();
@@ -105,6 +119,7 @@ class _LocationGalleryWidgetState extends State<LocationGalleryWidget> {
)
.then((value) {
allFilesWithLocation = value.files;
+ if (!mounted) return value;
_filesUpdateEvent = Bus.instance.on<LocalPhotosUpdatedEvent>().listen(
(event) {
if (event.type == EventType.deletedFromDevice ||
@@ -127,7 +142,7 @@ class _LocationGalleryWidgetState extends State<LocationGalleryWidget> {
@override
void dispose() {
InheritedLocationScreenState.memoryCountNotifier.value = null;
- _filesUpdateEvent.cancel();
+ _filesUpdateEvent?.cancel();
super.dispose();
}
@@ -142,14 +157,9 @@ class _LocationGalleryWidgetState extends State<LocationGalleryWidget> {
final centerPoint = InheritedLocationScreenState.of(
context,
).locationTagEntity.item.centerPoint;
- final appBar = GalleryAppBarWidget.sliverConfig(
- GalleryType.locationTag,
- locationTag.name,
- _selectedFiles,
- );
-
Future<FileLoadResult> filterFiles() async {
await fileLoadResult;
+ if (!mounted) return FileLoadResult([], false);
final stopWatch = Stopwatch()..start();
final filesInLocation = allFilesWithLocation;
filesInLocation.removeWhere((f) {
@@ -169,9 +179,21 @@ class _LocationGalleryWidgetState extends State<LocationGalleryWidget> {
return Future.value(FileLoadResult(filesInLocation, false));
}
- return FutureBuilder(
+ return FutureBuilder<FileLoadResult>(
key: ValueKey("$centerPoint$selectedRadius"),
builder: (context, snapshot) {
+ final files = snapshot.data?.files;
+ final appBar = GalleryAppBarWidget.sliverConfig(
+ GalleryType.locationTag,
+ locationTag.name,
+ _selectedFiles,
+ coverAppBarKey: _coverAppBarKey,
+ cover: files == null
+ ? widget.initialFiles?.firstOrNull
+ : files.firstOrNull,
+ coverHeroTag: widget.coverHeroTag,
+ files: files ?? widget.initialFiles,
+ );
if (snapshot.hasData) {
return SelectionState(
selectedFiles: _selectedFiles,
@@ -187,7 +209,7 @@ class _LocationGalleryWidgetState extends State<LocationGalleryWidget> {
builder: (context, value, _) {
return value
? HierarchicalSearchGallery(
- tagPrefix: widget.tagPrefix,
+ tagPrefix: "${widget.tagPrefix}_files",
selectedFiles: _selectedFiles,
appBar: appBar,
)
@@ -209,7 +231,7 @@ class _LocationGalleryWidgetState extends State<LocationGalleryWidget> {
limit,
asc,
}) async {
- return snapshot.data as FileLoadResult;
+ return snapshot.data!;
},
reloadEvent: Bus.instance
.on<LocalPhotosUpdatedEvent>(),
@@ -218,7 +240,7 @@ class _LocationGalleryWidgetState extends State<LocationGalleryWidget> {
EventType.deletedFromEverywhere,
},
selectedFiles: _selectedFiles,
- tagPrefix: widget.tagPrefix,
+ tagPrefix: "${widget.tagPrefix}_files",
);
},
);
diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/search_result_page.dart b/mobile/apps/photos/lib/ui/viewer/search/result/search_result_page.dart
index b995668524..9c3915fe82 100644
--- a/mobile/apps/photos/lib/ui/viewer/search/result/search_result_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search/result/search_result_page.dart
@@ -8,6 +8,7 @@ import 'package:photos/models/file/file.dart';
import 'package:photos/models/file_load_result.dart';
import 'package:photos/models/gallery_type.dart';
import 'package:photos/models/search/search_result.dart';
+import 'package:photos/models/search/search_types.dart';
import 'package:photos/models/selected_files.dart';
import 'package:photos/ui/viewer/actions/file_selection_overlay_bar.dart';
import 'package:photos/ui/viewer/gallery/gallery.dart';
@@ -40,6 +41,7 @@ class SearchResultPage extends StatefulWidget {
class _SearchResultPageState extends State<SearchResultPage> {
final _selectedFiles = SelectedFiles();
+ final _coverAppBarKey = GlobalKey();
late final List<EnteFile> files;
late final StreamSubscription<LocalPhotosUpdatedEvent> _filesUpdatedEvent;
late final SearchFilterDataProvider _searchFilterDataProvider;
@@ -74,10 +76,19 @@ class _SearchResultPageState extends State<SearchResultPage> {
@override
Widget build(BuildContext context) {
+ final isLocation =
+ widget.searchResult.type() == ResultType.location ||
+ widget.searchResult.type() == ResultType.locationSuggestion;
+ final heroTag = widget.tagPrefix + widget.searchResult.heroTag();
+ final filesTagPrefix = isLocation ? "${heroTag}_files" : heroTag;
final appBar = GalleryAppBarWidget.sliverConfig(
SearchResultPage.appBarType,
widget.searchResult.name(),
_selectedFiles,
+ coverAppBarKey: _coverAppBarKey,
+ cover: isLocation ? files.firstOrNull : null,
+ coverHeroTag: isLocation ? heroTag : null,
+ files: isLocation ? files : null,
);
final gallery = Gallery(
appBar: appBar,
@@ -99,7 +110,7 @@ class _SearchResultPageState extends State<SearchResultPage> {
EventType.deletedFromEverywhere,
EventType.hide,
},
- tagPrefix: widget.tagPrefix + widget.searchResult.heroTag(),
+ tagPrefix: filesTagPrefix,
selectedFiles: _selectedFiles,
enableFileGrouping: widget.enableGrouping,
initialFiles: widget.searchResult.resultFiles().isNotEmpty
@@ -126,7 +137,9 @@ class _SearchResultPageState extends State<SearchResultPage> {
builder: (context, value, _) {
return value
? HierarchicalSearchGallery(
- tagPrefix: widget.tagPrefix,
+ tagPrefix: isLocation
+ ? filesTagPrefix
+ : widget.tagPrefix,
selectedFiles: _selectedFiles,
appBar: appBar,
)
diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/search_result_widget.dart b/mobile/apps/photos/lib/ui/viewer/search/result/search_result_widget.dart
index ed6e50bf52..a38a313522 100644
--- a/mobile/apps/photos/lib/ui/viewer/search/result/search_result_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search/result/search_result_widget.dart
@@ -49,7 +49,13 @@ class SearchResultWidget extends StatelessWidget {
if (searchResult.type() == ResultType.shared) {
routeToPage(context, ContactResultPage(searchResult));
} else {
- routeToPage(context, SearchResultPage(searchResult));
+ routeToPage(
+ context,
+ SearchResultPage(searchResult),
+ useFadeTransition:
+ searchResult.type() == ResultType.location ||
+ searchResult.type() == ResultType.locationSuggestion,
+ );
}
}
},
diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/search_section_all_page.dart b/mobile/apps/photos/lib/ui/viewer/search/result/search_section_all_page.dart
index 6cec58f9fb..d243e64cfd 100644
--- a/mobile/apps/photos/lib/ui/viewer/search/result/search_section_all_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search/result/search_section_all_page.dart
@@ -9,16 +9,21 @@ import "package:ente_ui/components/loading_widget.dart";
import "package:flutter/material.dart";
import "package:hugeicons/hugeicons.dart";
import "package:photos/events/event.dart";
+import "package:photos/models/local_entity_data.dart";
import "package:photos/models/search/album_search_result.dart";
import "package:photos/models/search/generic_search_result.dart";
+import "package:photos/models/search/hierarchical/location_filter.dart";
import "package:photos/models/search/hierarchical/magic_filter.dart";
import "package:photos/models/search/recent_searches.dart";
+import "package:photos/models/search/search_constants.dart";
import "package:photos/models/search/search_result.dart";
import "package:photos/models/search/search_types.dart";
import "package:photos/services/collections_service.dart";
+import "package:photos/states/location_screen_state.dart";
import "package:photos/ui/components/thumbnail_list_item.dart";
import "package:photos/ui/viewer/gallery/collection_page.dart";
import "package:photos/ui/viewer/gallery/gallery_app_bar_actions.dart";
+import "package:photos/ui/viewer/location/location_screen.dart";
import "package:photos/ui/viewer/search/result/magic_result_screen.dart";
import "package:photos/ui/viewer/search/result/searchable_item.dart";
@@ -256,6 +261,26 @@ class _SearchSectionAllPageState extends State<SearchSectionAllPage> {
},
);
} else if (result is GenericSearchResult) {
+ final filter = result.getHierarchicalSearchFilter();
+ final locationID = result.params[kLocationParamID];
+ if (filter is LocationFilter && locationID is String) {
+ final tagPrefix = "searchable_item" + result.heroTag();
+ return SearchableItemWidget(
+ result,
+ onResultTap: () => routeToPage(
+ context,
+ LocationScreenStateProvider(
+ LocalEntity(filter.locationTag, locationID),
+ LocationScreen(
+ initialFiles: result.resultFiles(),
+ coverHeroTag: tagPrefix,
+ tagPrefix: tagPrefix,
+ ),
+ ),
+ useFadeTransition: true,
+ ),
+ );
+ }
return SearchableItemWidget(
result,
onResultTap: result.onResultTap != null
diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/search_thumbnail_widget.dart b/mobile/apps/photos/lib/ui/viewer/search/result/search_thumbnail_widget.dart
index b843c18742..9c9f012266 100644
--- a/mobile/apps/photos/lib/ui/viewer/search/result/search_thumbnail_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search/result/search_thumbnail_widget.dart
@@ -27,8 +27,15 @@ class SearchThumbnailWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
+ final isLocation =
+ searchResult?.type() == ResultType.location ||
+ searchResult?.type() == ResultType.locationSuggestion;
return Hero(
- tag: tagPrefix + (file?.tag ?? ""),
+ tag: isLocation ? tagPrefix : tagPrefix + (file?.tag ?? ""),
+ createRectTween: isLocation
+ ? (begin, end) => RectTween(begin: begin, end: end)
+ : null,
+ transitionOnUserGestures: isLocation,
child: SizedBox(
height: size,
width: size,
diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/searchable_item.dart b/mobile/apps/photos/lib/ui/viewer/search/result/searchable_item.dart
index b9184cbcfc..2b03e3a39b 100644
--- a/mobile/apps/photos/lib/ui/viewer/search/result/searchable_item.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search/result/searchable_item.dart
@@ -55,6 +55,9 @@ class SearchableItemWidget extends StatelessWidget {
routeToPage(
context,
SearchResultPage(searchResult, tagPrefix: additionalPrefix),
+ useFadeTransition:
+ searchResult.type() == ResultType.location ||
+ searchResult.type() == ResultType.locationSuggestion,
);
}
}
diff --git a/mobile/apps/photos/lib/ui/viewer/search_tab/locations_section.dart b/mobile/apps/photos/lib/ui/viewer/search_tab/locations_section.dart
index 32e867acc0..a5f7233e65 100644
--- a/mobile/apps/photos/lib/ui/viewer/search_tab/locations_section.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search_tab/locations_section.dart
@@ -147,9 +147,7 @@ class LocationRecommendation extends StatelessWidget {
@override
Widget build(BuildContext context) {
- final heroTag =
- locationSearchResult.heroTag() +
- (locationSearchResult.previewThumbnail()?.tag ?? "");
+ final heroTag = locationSearchResult.heroTag();
final textTheme = getEnteTextTheme(context);
return GestureDetector(
onTap: () {
@@ -157,7 +155,11 @@ class LocationRecommendation extends StatelessWidget {
if (locationSearchResult.onResultTap != null) {
locationSearchResult.onResultTap!(context);
} else {
- routeToPage(context, SearchResultPage(locationSearchResult));
+ routeToPage(
+ context,
+ SearchResultPage(locationSearchResult),
+ useFadeTransition: true,
+ );
}
},
child: RepaintBoundary(
@@ -169,24 +171,27 @@ class LocationRecommendation extends StatelessWidget {
children: [
Stack(
children: [
- ClipSmoothRect(
- radius: SmoothBorderRadius(
- cornerRadius: outerCornerRadius,
- cornerSmoothing: cornerSmoothing,
- ),
- child: SizedBox(
- width: sideOfThumbnail,
- height: sideOfThumbnail,
- child: locationSearchResult.previewThumbnail() != null
- ? Hero(
- tag: heroTag,
- child: ThumbnailWidget(
+ Hero(
+ tag: heroTag,
+ createRectTween: (begin, end) =>
+ RectTween(begin: begin, end: end),
+ transitionOnUserGestures: true,
+ child: ClipSmoothRect(
+ radius: SmoothBorderRadius(
+ cornerRadius: outerCornerRadius,
+ cornerSmoothing: cornerSmoothing,
+ ),
+ child: SizedBox(
+ width: sideOfThumbnail,
+ height: sideOfThumbnail,
+ child: locationSearchResult.previewThumbnail() != null
+ ? ThumbnailWidget(
locationSearchResult.previewThumbnail()!,
shouldShowSyncStatus: false,
shouldShowFavoriteIcon: false,
- ),
- )
- : const NoThumbnailWidget(),
+ )
+ : const NoThumbnailWidget(),
+ ),
),
),
Positioned(