Skip to content

armgit / ente

Public Imported from GitHub
0

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

Refactor to move info button to app bar's popup menu

ashilkndb31a7f452c7
diff --git a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart
index 4b1723e87f..940003a18c 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart
@@ -191,9 +191,9 @@ class _BodyState extends State<_Body> {
_files![selectedIndex],
_onFileRemoved,
_onEditFileRequested,
- widget.config.mode == DetailPageMode.full,
enableFullScreenNotifier: InheritedDetailPageState.of(context)
.enableFullScreenNotifier,
+ mode: widget.config.mode,
);
},
valueListenable: _selectedIndexNotifier,
@@ -208,34 +208,32 @@ class _BodyState extends State<_Body> {
_buildPageView(),
ValueListenableBuilder(
builder: (BuildContext context, int selectedIndex, _) {
- return FileBottomBar(
- _files![selectedIndex],
- widget.config.mode == DetailPageMode.minimalistic &&
- !isGuestView,
- onFileRemoved: _onFileRemoved,
- userID: Configuration.instance.getUserID(),
- enableFullScreenNotifier:
- InheritedDetailPageState.of(context)
- .enableFullScreenNotifier,
- isLocalOnlyContext: widget.config.isLocalOnlyContext,
- );
+ return widget.config.mode == DetailPageMode.minimalistic
+ ? const SizedBox()
+ : FileBottomBar(
+ _files![selectedIndex],
+ onFileRemoved: _onFileRemoved,
+ userID: Configuration.instance.getUserID(),
+ enableFullScreenNotifier:
+ InheritedDetailPageState.of(context)
+ .enableFullScreenNotifier,
+ isLocalOnlyContext: widget.config.isLocalOnlyContext,
+ );
},
valueListenable: _selectedIndexNotifier,
),
ValueListenableBuilder(
valueListenable: _selectedIndexNotifier,
builder: (BuildContext context, int selectedIndex, _) {
- return TextDetectionOverlayButton(
- file: _files![selectedIndex],
- enableFullScreenNotifier:
- InheritedDetailPageState.of(context)
- .enableFullScreenNotifier,
- isGuestView: isGuestView,
- showOnlyInfoButton:
- widget.config.mode == DetailPageMode.minimalistic &&
- !isGuestView,
- userID: Configuration.instance.getUserID(),
- );
+ return widget.config.mode == DetailPageMode.minimalistic
+ ? const SizedBox.shrink()
+ : TextDetectionOverlayButton(
+ file: _files![selectedIndex],
+ enableFullScreenNotifier:
+ InheritedDetailPageState.of(context)
+ .enableFullScreenNotifier,
+ isGuestView: isGuestView,
+ );
},
),
ValueListenableBuilder(
diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart b/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart
index 982eed1322..a71858d991 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart
@@ -1,6 +1,7 @@
import "dart:async";
import 'dart:io';
+import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import "package:flutter_svg/flutter_svg.dart";
import "package:local_auth/local_auth.dart";
@@ -14,7 +15,7 @@ import "package:photos/l10n/l10n.dart";
import "package:photos/models/file/extensions/file_props.dart";
import 'package:photos/models/file/file.dart';
import 'package:photos/models/file/file_type.dart';
-import 'package:photos/models/file/trash_file.dart';
+import "package:photos/models/file/trash_file.dart";
import "package:photos/models/metadata/common_keys.dart";
import 'package:photos/models/selected_files.dart';
import "package:photos/service_locator.dart";
@@ -23,9 +24,11 @@ import 'package:photos/services/hidden_service.dart';
import "package:photos/services/local_authentication_service.dart";
import "package:photos/services/video_preview_service.dart";
import "package:photos/theme/ente_theme.dart";
+import "package:photos/ui/actions/file/file_actions.dart";
import 'package:photos/ui/collections/collection_action_sheet.dart';
import "package:photos/ui/common/popup_item.dart";
import 'package:photos/ui/notification/toast.dart';
+import "package:photos/ui/viewer/file/detail_page.dart";
import "package:photos/ui/viewer/file_details/favorite_widget.dart";
import "package:photos/ui/viewer/file_details/upload_icon_widget.dart";
import 'package:photos/utils/dialog_util.dart';
@@ -37,15 +40,15 @@ class FileAppBar extends StatefulWidget {
final EnteFile file;
final Function(EnteFile) onFileRemoved;
final Function(EnteFile) onEditRequested;
- final bool shouldShowActions;
final ValueNotifier<bool> enableFullScreenNotifier;
+ final DetailPageMode mode;
const FileAppBar(
this.file,
this.onFileRemoved,
- this.onEditRequested,
- this.shouldShowActions, {
+ this.onEditRequested, {
required this.enableFullScreenNotifier,
+ this.mode = DetailPageMode.full,
super.key,
});
@@ -96,9 +99,7 @@ class FileAppBarState extends State<FileAppBar> {
_getActions();
_reloadActions = false;
}
-
- final isTrashedFile = widget.file is TrashFile;
- final shouldShowActions = widget.shouldShowActions && !isTrashedFile;
+ final shouldShowActions = !isGuestView;
return PreferredSize(
preferredSize: const Size.fromHeight(kToolbarHeight),
child: ValueListenableBuilder(
@@ -145,7 +146,7 @@ class FileAppBarState extends State<FileAppBar> {
: Navigator.of(context).pop();
},
),
- actions: shouldShowActions && !isGuestView ? _actions : [],
+ actions: shouldShowActions ? _actions : [],
elevation: 0,
backgroundColor: const Color(0x00000000),
),
@@ -180,7 +181,7 @@ class FileAppBarState extends State<FileAppBar> {
),
);
}
- if (!isFileHidden && isFileUploaded) {
+ if (!isFileHidden && isFileUploaded && widget.file is! TrashFile) {
_actions.add(
Center(child: FavoriteWidget(widget.file)),
);
@@ -195,106 +196,129 @@ class FileAppBarState extends State<FileAppBar> {
}
final List<PopupMenuItem> items = [];
- if (widget.file.isRemoteFile) {
- items.add(
- EntePopupMenuItem(
- AppLocalizations.of(context).download,
- value: 1,
- icon: Platform.isAndroid
- ? Icons.download
- : Icons.cloud_download_outlined,
- iconColor: Theme.of(context).iconTheme.color,
- ),
- );
- }
- // Edit option for images, live photos, and videos
- if (widget.file.fileType == FileType.image ||
- widget.file.fileType == FileType.livePhoto ||
- widget.file.fileType == FileType.video) {
- items.add(
- EntePopupMenuItem(
- AppLocalizations.of(context).edit,
- value: 11,
- icon: Icons.tune_outlined,
- iconColor: Theme.of(context).iconTheme.color,
- ),
- );
- }
- // options for files owned by the user
- if (isOwnedByUser && !isFileHidden && isFileUploaded) {
- final bool isArchived =
- widget.file.magicMetadata.visibility == archiveVisibility;
- items.add(
- EntePopupMenuItem(
- isArchived
- ? AppLocalizations.of(context).unarchive
- : AppLocalizations.of(context).archive,
- value: 2,
- icon: isArchived ? Icons.unarchive : Icons.archive_outlined,
- iconColor: Theme.of(context).iconTheme.color,
- ),
- );
- }
+ final bool restrictFileActions =
+ widget.mode == DetailPageMode.minimalistic || widget.file is TrashFile;
- if (widget.file.isUploaded && !isFileHidden) {
- items.add(
- EntePopupMenuItem(
- AppLocalizations.of(context).addToAlbum,
- value: 10,
- icon: Icons.add,
- iconColor: Theme.of(context).iconTheme.color,
- ),
- );
- }
- if ((widget.file.fileType == FileType.image ||
- widget.file.fileType == FileType.livePhoto) &&
- Platform.isAndroid) {
+ if (restrictFileActions) {
items.add(
EntePopupMenuItem(
- AppLocalizations.of(context).setAs,
- value: 3,
- icon: Icons.wallpaper_outlined,
+ AppLocalizations.of(context).info,
+ value: 12,
+ icon: Platform.isAndroid ? Icons.info_outline : CupertinoIcons.info,
iconColor: Theme.of(context).iconTheme.color,
),
);
- }
- if (isOwnedByUser && widget.file.isUploaded) {
- if (!isFileHidden) {
+ } else {
+ if (widget.file.isRemoteFile) {
items.add(
EntePopupMenuItem(
- AppLocalizations.of(context).hide,
- value: 4,
- icon: Icons.visibility_off,
+ AppLocalizations.of(context).download,
+ value: 1,
+ icon: Platform.isAndroid
+ ? Icons.download
+ : Icons.cloud_download_outlined,
iconColor: Theme.of(context).iconTheme.color,
),
);
- } else {
+ }
+ // Edit option for images, live photos, and videos
+ if (widget.file.fileType == FileType.image ||
+ widget.file.fileType == FileType.livePhoto ||
+ widget.file.fileType == FileType.video) {
items.add(
EntePopupMenuItem(
- AppLocalizations.of(context).unhide,
- value: 5,
- icon: Icons.visibility,
+ AppLocalizations.of(context).edit,
+ value: 11,
+ icon: Icons.tune_outlined,
+ iconColor: Theme.of(context).iconTheme.color,
+ ),
+ );
+ }
+ // options for files owned by the user
+ if (isOwnedByUser && !isFileHidden && isFileUploaded) {
+ final bool isArchived =
+ widget.file.magicMetadata.visibility == archiveVisibility;
+ items.add(
+ EntePopupMenuItem(
+ isArchived
+ ? AppLocalizations.of(context).unarchive
+ : AppLocalizations.of(context).archive,
+ value: 2,
+ icon: isArchived ? Icons.unarchive : Icons.archive_outlined,
iconColor: Theme.of(context).iconTheme.color,
),
);
}
- }
- items.add(
- EntePopupMenuItem(
- AppLocalizations.of(context).guestView,
- value: 6,
- iconWidget: SvgPicture.asset(
- "assets/icons/guest_view_icon.svg",
- colorFilter: ColorFilter.mode(
- getEnteColorScheme(context).textBase,
- BlendMode.srcIn,
+ if (widget.file.isUploaded && !isFileHidden) {
+ items.add(
+ EntePopupMenuItem(
+ AppLocalizations.of(context).addToAlbum,
+ value: 10,
+ icon: Icons.add,
+ iconColor: Theme.of(context).iconTheme.color,
+ ),
+ );
+ }
+ if ((widget.file.fileType == FileType.image ||
+ widget.file.fileType == FileType.livePhoto) &&
+ Platform.isAndroid) {
+ items.add(
+ EntePopupMenuItem(
+ AppLocalizations.of(context).setAs,
+ value: 3,
+ icon: Icons.wallpaper_outlined,
+ iconColor: Theme.of(context).iconTheme.color,
+ ),
+ );
+ }
+ if (isOwnedByUser && widget.file.isUploaded) {
+ if (!isFileHidden) {
+ items.add(
+ EntePopupMenuItem(
+ AppLocalizations.of(context).hide,
+ value: 4,
+ icon: Icons.visibility_off,
+ iconColor: Theme.of(context).iconTheme.color,
+ ),
+ );
+ } else {
+ items.add(
+ EntePopupMenuItem(
+ AppLocalizations.of(context).unhide,
+ value: 5,
+ icon: Icons.visibility,
+ iconColor: Theme.of(context).iconTheme.color,
+ ),
+ );
+ }
+ }
+
+ items.add(
+ EntePopupMenuItem(
+ AppLocalizations.of(context).guestView,
+ value: 6,
+ iconWidget: SvgPicture.asset(
+ "assets/icons/guest_view_icon.svg",
+ colorFilter: ColorFilter.mode(
+ getEnteColorScheme(context).textBase,
+ BlendMode.srcIn,
+ ),
),
),
- ),
- );
+ );
+
+ items.add(
+ EntePopupMenuItem(
+ AppLocalizations.of(context).info,
+ value: 12,
+ icon: Platform.isAndroid ? Icons.info_outline : CupertinoIcons.info,
+ iconColor: Theme.of(context).iconTheme.color,
+ ),
+ );
+ }
- if (widget.file.isVideo) {
+ if (widget.file.isVideo && !restrictFileActions) {
// Video streaming options
if (_shouldShowCreateStreamOption()) {
items.add(
@@ -391,6 +415,8 @@ class FileAppBarState extends State<FileAppBar> {
await _handleAddToAlbum();
} else if (value == 11) {
widget.onEditRequested(widget.file);
+ } else if (value == 12) {
+ await showDetailsSheet(context, widget.file);
}
},
),
diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart b/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart
index 41f1bd9e16..2befca8b74 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart
@@ -11,7 +11,6 @@ import "package:photos/models/file/extensions/file_props.dart";
import 'package:photos/models/file/file.dart';
import 'package:photos/models/file/trash_file.dart';
import 'package:photos/models/selected_files.dart';
-
import "package:photos/ui/actions/file/file_actions.dart";
import 'package:photos/ui/collections/collection_action_sheet.dart';
import 'package:photos/utils/delete_file_util.dart';
@@ -21,14 +20,12 @@ import 'package:photos/utils/share_util.dart';
class FileBottomBar extends StatefulWidget {
final EnteFile file;
final Function(EnteFile) onFileRemoved;
- final bool showOnlyInfoButton;
final int? userID;
final ValueNotifier<bool> enableFullScreenNotifier;
final bool isLocalOnlyContext;
const FileBottomBar(
- this.file,
- this.showOnlyInfoButton, {
+ this.file, {
required this.onFileRemoved,
required this.enableFullScreenNotifier,
this.userID,
@@ -84,31 +81,15 @@ class FileBottomBarState extends State<FileBottomBar> {
Widget _getBottomBar() {
Logger("FileBottomBar")
.fine("building bottom bar ${widget.file.generatedID}");
+
final List<Widget> children = [];
final bool isOwnedByUser =
widget.file.ownerID == null || widget.file.ownerID == widget.userID;
- children.add(
- Tooltip(
- message: AppLocalizations.of(context).info,
- child: Padding(
- padding: const EdgeInsets.only(top: 12),
- child: IconButton(
- icon: Icon(
- Platform.isAndroid ? Icons.info_outline : CupertinoIcons.info,
- color: Colors.white,
- ),
- onPressed: () async {
- await _displayDetails(widget.file);
- },
- ),
- ),
- ),
- );
if (widget.file is TrashFile) {
_addTrashOptions(children);
}
- if (!widget.showOnlyInfoButton && widget.file is! TrashFile) {
+ if (widget.file is! TrashFile) {
if (isOwnedByUser) {
children.add(
Tooltip(
@@ -249,8 +230,4 @@ class FileBottomBarState extends State<FileBottomBar> {
),
);
}
-
- Future<void> _displayDetails(EnteFile file) async {
- await showDetailsSheet(context, file);
- }
}
diff --git a/mobile/apps/photos/lib/ui/viewer/file/text_detection_overlay_button.dart b/mobile/apps/photos/lib/ui/viewer/file/text_detection_overlay_button.dart
index 2a749b0a2e..d18374ee90 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/text_detection_overlay_button.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/text_detection_overlay_button.dart
@@ -17,15 +17,11 @@ class TextDetectionOverlayButton extends StatefulWidget {
final EnteFile file;
final ValueListenable<bool> enableFullScreenNotifier;
final bool isGuestView;
- final bool showOnlyInfoButton;
- final int? userID;
const TextDetectionOverlayButton({
required this.file,
required this.enableFullScreenNotifier,
required this.isGuestView,
- required this.showOnlyInfoButton,
- required this.userID,
super.key,
});
@@ -37,7 +33,6 @@ class TextDetectionOverlayButton extends StatefulWidget {
class _TextDetectionOverlayButtonState
extends State<TextDetectionOverlayButton> {
static const double _buttonSize = 40.0;
- static const double _barSlotExtent = 48.0;
static final Map<String, _DetectionResult> _cache = {};
final Logger _logger = Logger("TextDetectionOverlayButton");
final MobileOcr _mobileOcr = MobileOcr();
@@ -185,54 +180,22 @@ class _TextDetectionOverlayButtonState
return ValueListenableBuilder<bool>(
valueListenable: widget.enableFullScreenNotifier,
builder: (context, isFullScreen, _) {
- final bool shouldHide = isFullScreen || widget.isGuestView;
+ final bool shouldHide =
+ isFullScreen || widget.isGuestView || widget.file is TrashFile;
if (shouldHide) {
return const SizedBox.shrink();
}
- if (!_hasShareSlot()) {
- return const SizedBox.shrink();
- }
- final double bottomOffset = MediaQuery.paddingOf(context).bottom + 96.0;
- final int slotCount = _bottomBarSlotCount();
- if (slotCount <= 0) {
- return const SizedBox.shrink();
- }
- final List<Widget> rowChildren = List<Widget>.generate(
- slotCount,
- (int index) => _buildPlaceholderSlot(
- context: context,
- isShareSlot: index == slotCount - 1,
- ),
- );
+ final double bottomOffset = MediaQuery.paddingOf(context).bottom + 60.0;
return Positioned(
bottom: bottomOffset,
left: 0,
right: 0,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceAround,
- children: rowChildren,
- ),
+ child: Center(child: _buildButton(context)),
);
},
);
}
- Widget _buildPlaceholderSlot({
- required BuildContext context,
- required bool isShareSlot,
- }) {
- return Padding(
- padding: const EdgeInsets.only(top: 12),
- child: SizedBox(
- width: _barSlotExtent,
- height: _barSlotExtent,
- child: isShareSlot
- ? Center(child: _buildButton(context))
- : const SizedBox.shrink(),
- ),
- );
- }
-
Widget _buildButton(BuildContext context) {
const String detectTextLabel = "Detect Text";
return Tooltip(
@@ -286,48 +249,6 @@ class _TextDetectionOverlayButtonState
}
return localFile.path;
}
-
- bool _hasShareSlot() {
- if (widget.showOnlyInfoButton) {
- return false;
- }
- if (widget.file is TrashFile) {
- return false;
- }
- return true;
- }
-
- int _bottomBarSlotCount() {
- if (!_hasShareSlot()) {
- return 0;
- }
- int count = 1; // Info button
- if (_supportsEdit(widget.file)) {
- count++;
- }
- if (_isOwnedByUser()) {
- count++;
- }
- return count + 1; // Share slot
- }
-
- bool _isOwnedByUser() {
- final int? ownerID = widget.file.ownerID;
- if (ownerID == null) {
- return true;
- }
- final int? userID = widget.userID;
- if (userID == null) {
- return false;
- }
- return ownerID == userID;
- }
-
- bool _supportsEdit(EnteFile file) {
- return file.fileType == FileType.image ||
- file.fileType == FileType.livePhoto ||
- file.fileType == FileType.video;
- }
}
class _DetectionResult {