2023-03-29 11:16:07 +00:00
|
|
|
import 'dart:developer' as dev;
|
2023-03-28 07:16:35 +00:00
|
|
|
import "package:flutter/material.dart";
|
2023-04-10 04:30:30 +00:00
|
|
|
import "package:photos/core/constants.dart";
|
2023-04-10 05:11:10 +00:00
|
|
|
import "package:photos/core/event_bus.dart";
|
2023-04-10 04:30:30 +00:00
|
|
|
import "package:photos/db/files_db.dart";
|
2023-04-10 05:11:10 +00:00
|
|
|
import "package:photos/events/files_updated_event.dart";
|
|
|
|
import "package:photos/events/local_photos_updated_event.dart";
|
2023-03-29 11:16:07 +00:00
|
|
|
import "package:photos/models/file.dart";
|
2023-03-28 11:45:26 +00:00
|
|
|
import "package:photos/models/file_load_result.dart";
|
2023-04-10 04:51:58 +00:00
|
|
|
import "package:photos/models/gallery_type.dart";
|
2023-04-10 04:30:30 +00:00
|
|
|
import "package:photos/models/selected_files.dart";
|
|
|
|
import "package:photos/services/collections_service.dart";
|
2023-03-29 11:16:07 +00:00
|
|
|
import "package:photos/services/files_service.dart";
|
|
|
|
import "package:photos/services/location_service.dart";
|
2023-03-31 10:20:45 +00:00
|
|
|
import "package:photos/states/location_screen_state.dart";
|
2023-04-06 05:17:47 +00:00
|
|
|
import "package:photos/theme/colors.dart";
|
2023-03-28 07:16:35 +00:00
|
|
|
import "package:photos/theme/ente_theme.dart";
|
2023-03-29 13:31:22 +00:00
|
|
|
import "package:photos/ui/common/loading_widget.dart";
|
2023-04-06 05:17:47 +00:00
|
|
|
import "package:photos/ui/components/buttons/icon_button_widget.dart";
|
2023-03-28 07:16:35 +00:00
|
|
|
import "package:photos/ui/components/title_bar_title_widget.dart";
|
|
|
|
import "package:photos/ui/components/title_bar_widget.dart";
|
2023-04-10 04:51:58 +00:00
|
|
|
import "package:photos/ui/viewer/actions/file_selection_overlay_bar.dart";
|
2023-03-28 11:45:26 +00:00
|
|
|
import "package:photos/ui/viewer/gallery/gallery.dart";
|
2023-03-31 06:02:30 +00:00
|
|
|
import "package:photos/ui/viewer/location/edit_location_sheet.dart";
|
2023-04-06 05:38:21 +00:00
|
|
|
import "package:photos/utils/dialog_util.dart";
|
2023-03-28 07:16:35 +00:00
|
|
|
|
|
|
|
class LocationScreen extends StatelessWidget {
|
|
|
|
const LocationScreen({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-03-31 05:54:09 +00:00
|
|
|
return Scaffold(
|
2023-04-06 05:17:47 +00:00
|
|
|
appBar: const PreferredSize(
|
|
|
|
preferredSize: Size(double.infinity, 48),
|
2023-03-31 05:54:09 +00:00
|
|
|
child: TitleBarWidget(
|
|
|
|
isSliver: false,
|
|
|
|
isFlexibleSpaceDisabled: true,
|
2023-04-06 05:17:47 +00:00
|
|
|
actionIcons: [LocationScreenPopUpMenu()],
|
2023-03-28 11:45:26 +00:00
|
|
|
),
|
|
|
|
),
|
2023-03-31 05:54:09 +00:00
|
|
|
body: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
SizedBox(
|
|
|
|
height: MediaQuery.of(context).size.height - 102,
|
|
|
|
width: double.infinity,
|
2023-03-31 06:02:30 +00:00
|
|
|
child: const LocationGalleryWidget(),
|
2023-03-28 07:16:35 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2023-03-28 11:45:26 +00:00
|
|
|
|
2023-04-06 05:17:47 +00:00
|
|
|
class LocationScreenPopUpMenu extends StatelessWidget {
|
|
|
|
const LocationScreenPopUpMenu({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final textTheme = getEnteTextTheme(context);
|
|
|
|
final colorScheme = getEnteColorScheme(context);
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 4),
|
|
|
|
child: Theme(
|
|
|
|
data: Theme.of(context).copyWith(
|
|
|
|
highlightColor: Colors.transparent,
|
|
|
|
splashColor: Colors.transparent,
|
|
|
|
),
|
|
|
|
child: PopupMenuButton(
|
2023-04-06 05:38:21 +00:00
|
|
|
elevation: 2,
|
2023-04-06 05:17:47 +00:00
|
|
|
offset: const Offset(10, 50),
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
),
|
|
|
|
color: colorScheme.backgroundElevated2,
|
|
|
|
child: const IconButtonWidget(
|
|
|
|
icon: Icons.more_horiz,
|
|
|
|
iconButtonType: IconButtonType.primary,
|
|
|
|
disableGestureDetector: true,
|
|
|
|
),
|
|
|
|
itemBuilder: (context) {
|
|
|
|
return [
|
|
|
|
PopupMenuItem(
|
|
|
|
value: "edit",
|
|
|
|
child: Text(
|
|
|
|
"Edit",
|
|
|
|
style: textTheme.bodyBold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
onTap: () {},
|
|
|
|
value: "delete",
|
|
|
|
child: Text(
|
|
|
|
"Delete Location",
|
|
|
|
style: textTheme.bodyBold.copyWith(color: warning500),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
},
|
2023-04-06 05:38:21 +00:00
|
|
|
onSelected: (value) async {
|
2023-04-06 05:17:47 +00:00
|
|
|
if (value == "edit") {
|
|
|
|
showEditLocationSheet(
|
|
|
|
context,
|
|
|
|
InheritedLocationScreenState.of(context).locationTagEntity,
|
|
|
|
);
|
|
|
|
} else if (value == "delete") {
|
2023-04-06 05:38:21 +00:00
|
|
|
try {
|
|
|
|
await LocationService.instance.deleteLocationTag(
|
|
|
|
InheritedLocationScreenState.of(context).locationTagEntity.id,
|
|
|
|
);
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
} catch (e) {
|
|
|
|
showGenericErrorDialog(context: context);
|
|
|
|
}
|
2023-04-06 05:17:47 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-29 11:16:07 +00:00
|
|
|
class LocationGalleryWidget extends StatefulWidget {
|
2023-03-31 06:02:30 +00:00
|
|
|
const LocationGalleryWidget({super.key});
|
2023-03-28 11:45:26 +00:00
|
|
|
|
2023-03-29 11:16:07 +00:00
|
|
|
@override
|
|
|
|
State<LocationGalleryWidget> createState() => _LocationGalleryWidgetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _LocationGalleryWidgetState extends State<LocationGalleryWidget> {
|
|
|
|
late final Future<FileLoadResult> fileLoadResult;
|
|
|
|
late Future<void> removeIgnoredFiles;
|
2023-03-29 13:31:22 +00:00
|
|
|
late Widget galleryHeaderWidget;
|
2023-04-10 04:30:30 +00:00
|
|
|
final _selectedFiles = SelectedFiles();
|
2023-03-29 11:16:07 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
2023-04-10 04:30:30 +00:00
|
|
|
final collectionsToHide =
|
|
|
|
CollectionsService.instance.collectionsHiddenFromTimeline();
|
|
|
|
fileLoadResult = FilesDB.instance.getAllUploadedAndSharedFiles(
|
|
|
|
galleryLoadStartTime,
|
|
|
|
galleryLoadEndTime,
|
|
|
|
limit: null,
|
2023-04-10 04:37:58 +00:00
|
|
|
asc: false,
|
2023-04-10 04:30:30 +00:00
|
|
|
ignoredCollectionIDs: collectionsToHide,
|
|
|
|
);
|
2023-03-29 11:16:07 +00:00
|
|
|
removeIgnoredFiles =
|
|
|
|
FilesService.instance.removeIgnoredFiles(fileLoadResult);
|
2023-03-31 05:54:09 +00:00
|
|
|
galleryHeaderWidget = const GalleryHeaderWidget();
|
2023-03-29 11:16:07 +00:00
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
2023-03-31 10:34:58 +00:00
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
InheritedLocationScreenState.memoryCountNotifier.value = null;
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
2023-03-28 11:45:26 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-03-31 10:20:45 +00:00
|
|
|
final selectedRadius =
|
2023-04-05 04:00:18 +00:00
|
|
|
InheritedLocationScreenState.of(context).locationTagEntity.item.radius;
|
2023-04-06 04:19:21 +00:00
|
|
|
final centerPoint = InheritedLocationScreenState.of(context)
|
|
|
|
.locationTagEntity
|
|
|
|
.item
|
|
|
|
.centerPoint;
|
2023-03-29 11:16:07 +00:00
|
|
|
Future<FileLoadResult> filterFiles() async {
|
|
|
|
final FileLoadResult result = await fileLoadResult;
|
|
|
|
//wait for ignored files to be removed after init
|
|
|
|
await removeIgnoredFiles;
|
|
|
|
final stopWatch = Stopwatch()..start();
|
|
|
|
final copyOfFiles = List<File>.from(result.files);
|
|
|
|
copyOfFiles.removeWhere((f) {
|
|
|
|
return !LocationService.instance.isFileInsideLocationTag(
|
2023-04-06 04:19:21 +00:00
|
|
|
centerPoint,
|
2023-04-03 01:50:14 +00:00
|
|
|
f.location!,
|
2023-03-29 11:16:07 +00:00
|
|
|
selectedRadius,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
dev.log(
|
|
|
|
"Time taken to get all files in a location tag: ${stopWatch.elapsedMilliseconds} ms",
|
|
|
|
);
|
|
|
|
stopWatch.stop();
|
2023-03-31 10:34:58 +00:00
|
|
|
InheritedLocationScreenState.memoryCountNotifier.value =
|
|
|
|
copyOfFiles.length;
|
2023-03-29 11:16:07 +00:00
|
|
|
|
|
|
|
return Future.value(
|
|
|
|
FileLoadResult(
|
|
|
|
copyOfFiles,
|
|
|
|
result.hasMore,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FutureBuilder(
|
2023-04-06 04:19:21 +00:00
|
|
|
//rebuild gallery only when there is change in radius or center point
|
|
|
|
key: ValueKey("$centerPoint$selectedRadius"),
|
2023-03-29 11:16:07 +00:00
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
2023-04-10 04:30:30 +00:00
|
|
|
return Stack(
|
|
|
|
children: [
|
|
|
|
Gallery(
|
|
|
|
loadingWidget: Column(
|
|
|
|
children: [
|
|
|
|
galleryHeaderWidget,
|
|
|
|
EnteLoadingWidget(
|
|
|
|
color: getEnteColorScheme(context).strokeMuted,
|
|
|
|
),
|
|
|
|
],
|
2023-03-31 15:18:45 +00:00
|
|
|
),
|
2023-04-10 04:30:30 +00:00
|
|
|
header: galleryHeaderWidget,
|
|
|
|
asyncLoader: (
|
|
|
|
creationStartTime,
|
|
|
|
creationEndTime, {
|
|
|
|
limit,
|
|
|
|
asc,
|
|
|
|
}) async {
|
|
|
|
return snapshot.data as FileLoadResult;
|
|
|
|
},
|
2023-04-10 05:11:10 +00:00
|
|
|
reloadEvent: Bus.instance.on<LocalPhotosUpdatedEvent>(),
|
|
|
|
removalEventTypes: const {
|
|
|
|
EventType.deletedFromRemote,
|
|
|
|
EventType.deletedFromEverywhere,
|
|
|
|
},
|
2023-04-10 04:30:30 +00:00
|
|
|
selectedFiles: _selectedFiles,
|
|
|
|
tagPrefix: "location_gallery",
|
|
|
|
),
|
2023-04-10 04:51:58 +00:00
|
|
|
FileSelectionOverlayBar(
|
|
|
|
GalleryType.locationTag,
|
|
|
|
_selectedFiles,
|
|
|
|
)
|
2023-04-10 04:30:30 +00:00
|
|
|
],
|
2023-03-28 11:45:26 +00:00
|
|
|
);
|
|
|
|
} else {
|
2023-03-31 15:18:45 +00:00
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
galleryHeaderWidget,
|
|
|
|
const Expanded(
|
|
|
|
child: EnteLoadingWidget(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
2023-03-28 11:45:26 +00:00
|
|
|
}
|
|
|
|
},
|
2023-03-29 11:16:07 +00:00
|
|
|
future: filterFiles(),
|
2023-03-28 11:45:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2023-03-28 13:33:08 +00:00
|
|
|
|
2023-03-29 13:31:22 +00:00
|
|
|
class GalleryHeaderWidget extends StatefulWidget {
|
2023-03-31 05:54:09 +00:00
|
|
|
const GalleryHeaderWidget({super.key});
|
2023-03-28 13:33:08 +00:00
|
|
|
|
2023-03-29 13:31:22 +00:00
|
|
|
@override
|
|
|
|
State<GalleryHeaderWidget> createState() => _GalleryHeaderWidgetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _GalleryHeaderWidgetState extends State<GalleryHeaderWidget> {
|
2023-03-28 13:33:08 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-03-31 10:20:45 +00:00
|
|
|
final locationName =
|
2023-04-05 04:00:18 +00:00
|
|
|
InheritedLocationScreenState.of(context).locationTagEntity.item.name;
|
2023-03-29 13:31:22 +00:00
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.only(bottom: 20),
|
2023-03-31 15:18:45 +00:00
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 16),
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
key: ValueKey(locationName),
|
|
|
|
width: double.infinity,
|
|
|
|
child: TitleBarTitleWidget(
|
|
|
|
title: locationName,
|
|
|
|
),
|
2023-03-29 13:31:22 +00:00
|
|
|
),
|
2023-03-31 15:18:45 +00:00
|
|
|
ValueListenableBuilder(
|
|
|
|
valueListenable: InheritedLocationScreenState.memoryCountNotifier,
|
|
|
|
builder: (context, value, _) {
|
|
|
|
if (value == null) {
|
|
|
|
return RepaintBoundary(
|
|
|
|
child: EnteLoadingWidget(
|
2023-04-06 06:39:35 +00:00
|
|
|
size: 12,
|
2023-03-31 15:18:45 +00:00
|
|
|
color: getEnteColorScheme(context).strokeMuted,
|
|
|
|
alignment: Alignment.centerLeft,
|
2023-04-06 06:39:35 +00:00
|
|
|
padding: 2.5,
|
2023-03-31 15:18:45 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return Text(
|
|
|
|
value == 1 ? "1 memory" : "$value memories",
|
|
|
|
style: getEnteTextTheme(context).smallMuted,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2023-03-29 13:31:22 +00:00
|
|
|
),
|
2023-03-28 13:33:08 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|