Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][locker] Migrate Locker pages to shared app bar

aman-pilot969cedfaa953
diff --git a/mobile/apps/locker/lib/ui/pages/collection_page.dart b/mobile/apps/locker/lib/ui/pages/collection_page.dart
index 7614b9e798..3f26fdedd1 100644
--- a/mobile/apps/locker/lib/ui/pages/collection_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/collection_page.dart
@@ -2,7 +2,6 @@ import "dart:async";
import 'package:ente_components/ente_components.dart';
import 'package:ente_events/event_bus.dart';
-import "package:ente_ui/components/title_bar_title_widget.dart";
import "package:ente_ui/utils/dialog_util.dart";
import 'package:flutter/material.dart';
import "package:hugeicons/hugeicons.dart";
@@ -55,6 +54,7 @@ class _CollectionPageState extends UploaderPageState<CollectionPage>
final _selectedFiles = SelectedFiles();
final _scrollController = ScrollController();
+ final _keyboardFocusNode = FocusNode();
@override
void onFileUploadComplete() {
@@ -99,6 +99,7 @@ class _CollectionPageState extends UploaderPageState<CollectionPage>
@override
void dispose() {
_collectionUpdateSubscription.cancel();
+ _keyboardFocusNode.dispose();
_scrollController.dispose();
super.dispose();
}
@@ -184,26 +185,20 @@ class _CollectionPageState extends UploaderPageState<CollectionPage>
final colors = context.componentColors;
return KeyboardListener(
- focusNode: FocusNode(),
+ focusNode: _keyboardFocusNode,
onKeyEvent: handleKeyEvent,
child: Scaffold(
- appBar: AppBar(
- backgroundColor: colors.backgroundBase,
- surfaceTintColor: Colors.transparent,
- toolbarHeight: 48,
- leadingWidth: 48,
- leading: GestureDetector(
- onTap: () {
- Navigator.pop(context);
- },
- child: const Icon(Icons.arrow_back_outlined),
- ),
- ),
backgroundColor: colors.backgroundBase,
body: Stack(
alignment: Alignment.bottomCenter,
children: [
- _buildBody(colors),
+ AppBarComponent(
+ title: _collection.displayName ?? context.l10n.untitled,
+ subtitle: context.l10n.items(_displayedFiles.length),
+ actions: _buildActions(),
+ controller: _scrollController,
+ slivers: _buildSlivers(context),
+ ),
FileSelectionOverlayBar(
files: _displayedFiles,
selectedFiles: _selectedFiles,
@@ -216,129 +211,101 @@ class _CollectionPageState extends UploaderPageState<CollectionPage>
);
}
- Widget _buildShareButton(ColorTokens colors) {
- if (isFavorite) {
- return const SizedBox.shrink();
+ List<Widget> _buildActions() {
+ if (widget.isUncategorized || isFavorite) {
+ return const [];
}
+
+ final actions = <Widget>[];
+
final canShare =
collectionViewType == CollectionViewType.ownedCollection ||
collectionViewType == CollectionViewType.hiddenOwnedCollection ||
collectionViewType == CollectionViewType.sharedCollectionViewer ||
collectionViewType == CollectionViewType.sharedCollectionCollaborator ||
isQuickLink;
- if (!canShare) {
- return const SizedBox.shrink();
- }
- return GestureDetector(
- onTap: _shareCollection,
- child: Container(
- height: 44,
- width: 44,
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(12),
- color: colors.fillLight,
- ),
- padding: const EdgeInsets.all(12),
- child: HugeIcon(
- icon: HugeIcons.strokeRoundedShare08,
- color: colors.textBase,
+ if (canShare) {
+ actions.add(
+ IconButtonComponent(
+ icon: const HugeIcon(icon: HugeIcons.strokeRoundedShare08),
+ variant: IconButtonComponentVariant.primary,
+ onTap: _shareCollection,
),
- ),
- );
- }
-
- Widget _buildMenuButton(ColorTokens colors) {
- if (isFavorite) {
- return SizedBox.fromSize();
+ );
}
+
final canManageCollection =
collectionViewType == CollectionViewType.ownedCollection ||
collectionViewType == CollectionViewType.hiddenOwnedCollection ||
collectionViewType == CollectionViewType.sharedCollectionViewer ||
collectionViewType == CollectionViewType.sharedCollectionCollaborator ||
collectionViewType == CollectionViewType.quickLink;
- if (!canManageCollection) {
- return SizedBox.fromSize();
+ if (canManageCollection) {
+ actions.add(
+ CollectionPopupMenuWidget(
+ collection: _collection,
+ child: IgnorePointer(
+ child: IconButtonComponent(
+ icon: const HugeIcon(icon: HugeIcons.strokeRoundedMoreVertical),
+ variant: IconButtonComponentVariant.primary,
+ shouldSurfaceExecutionStates: false,
+ onTap: () {},
+ ),
+ ),
+ ),
+ );
}
- return CollectionPopupMenuWidget(
- collection: _collection,
- child: Container(
- height: 44,
- width: 44,
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(12),
- color: colors.fillLight,
- ),
- padding: const EdgeInsets.all(12),
- child: HugeIcon(
- icon: HugeIcons.strokeRoundedMoreVertical,
- color: colors.textBase,
- ),
- ),
- );
+ return actions;
}
- Widget _buildBody(ColorTokens colors) {
+ List<Widget> _buildSlivers(BuildContext context) {
if (isSearchActive) {
- return SearchResultView(
- collections: const [], // CollectionPage primarily shows files
- files: _filteredFiles,
- searchQuery: searchQuery,
- isHomePage: false,
- onSearchEverywhere: _searchEverywhere,
- );
+ return [
+ SliverToBoxAdapter(
+ child: SearchResultView(
+ collections: const [],
+ files: _filteredFiles,
+ searchQuery: searchQuery,
+ isHomePage: false,
+ onSearchEverywhere: _searchEverywhere,
+ ),
+ ),
+ ];
}
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Padding(
- padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 16),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- TitleBarTitleWidget(
- title: _collection.displayName ?? context.l10n.untitled,
- trailingWidgets: widget.isUncategorized
- ? const []
- : [
- _buildShareButton(colors),
- const SizedBox(width: 12),
- _buildMenuButton(colors),
- ],
- ),
- Text(
- _displayedFiles.length.toString(),
- style: TextStyles.body.copyWith(color: colors.textLight),
+ if (_displayedFiles.isEmpty) {
+ return [
+ SliverFillRemaining(
+ hasScrollBody: false,
+ child: Padding(
+ padding: const EdgeInsets.all(16.0),
+ child: Center(
+ child: EmptyStateWidget(
+ assetPath: 'assets/empty_state.png',
+ title: context.l10n.collectionEmptyStateTitle,
+ subtitle: context.l10n.collectionEmptyStateSubtitle,
+ showBorder: false,
),
- ],
+ ),
),
),
- Expanded(
- child: Padding(
- padding: const EdgeInsets.all(16.0),
- child: _displayedFiles.isEmpty
- ? Center(
- child: EmptyStateWidget(
- assetPath: 'assets/empty_state.png',
- title: context.l10n.collectionEmptyStateTitle,
- subtitle: context.l10n.collectionEmptyStateSubtitle,
- showBorder: false,
- ),
- )
- : ItemListView(
- key: ValueKey(_displayedFiles.length),
- files: _displayedFiles,
- selectedFiles: _selectedFiles,
- scrollController: _scrollController,
- physics: const BouncingScrollPhysics(),
- selectionEnabled: _isSelectionEnabled,
- ),
+ ];
+ }
+
+ return [
+ SliverPadding(
+ padding: const EdgeInsets.symmetric(horizontal: 16.0),
+ sliver: SliverToBoxAdapter(
+ child: ItemListView(
+ key: ValueKey(_displayedFiles.length),
+ files: _displayedFiles,
+ selectedFiles: _selectedFiles,
+ selectionEnabled: _isSelectionEnabled,
),
),
- ],
- );
+ ),
+ ];
}
void _searchEverywhere() {
diff --git a/mobile/apps/locker/lib/ui/pages/home_page.dart b/mobile/apps/locker/lib/ui/pages/home_page.dart
index e78d11091f..89db4c489b 100644
--- a/mobile/apps/locker/lib/ui/pages/home_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/home_page.dart
@@ -40,6 +40,7 @@ class CustomLockerAppBar extends StatelessWidget
final bool isSyncing;
final TextEditingController searchController;
final FocusNode searchFocusNode;
+ final bool isSearchActive;
final VoidCallback onClearSearch;
final ValueChanged<String>? onSearchChanged;
@@ -49,6 +50,7 @@ class CustomLockerAppBar extends StatelessWidget
this.isSyncing = false,
required this.searchController,
required this.searchFocusNode,
+ this.isSearchActive = false,
required this.onClearSearch,
this.onSearchChanged,
});
@@ -60,7 +62,7 @@ class CustomLockerAppBar extends StatelessWidget
Widget build(BuildContext context) {
final colors = context.componentColors;
final hasQuery = searchController.text.trim().isNotEmpty;
- final showClearIcon = searchFocusNode.hasFocus || hasQuery;
+ final showClearIcon = isSearchActive || hasQuery;
return Container(
decoration: BoxDecoration(
@@ -191,6 +193,7 @@ class _HomePageState extends UploaderPageState<HomePage>
final scaffoldKey = GlobalKey<ScaffoldState>();
final _selectedFiles = SelectedFiles();
final _scrollController = ScrollController();
+ final _keyboardFocusNode = FocusNode();
bool _isLoading = true;
bool _hasCompletedInitialLoad = false;
bool _isSettingsOpen = false;
@@ -211,6 +214,7 @@ class _HomePageState extends UploaderPageState<HomePage>
StreamSubscription? _mediaStreamSubscription;
StreamSubscription<Uri>? _deepLinkSubscription;
StreamSubscription<TriggerLogoutEvent>? _triggerLogoutSubscription;
+ StreamSubscription<CollectionsUpdatedEvent>? _collectionsUpdatedSubscription;
@override
void onFileUploadComplete() {
@@ -285,9 +289,11 @@ class _HomePageState extends UploaderPageState<HomePage>
});
}
- Bus.instance.on<CollectionsUpdatedEvent>().listen((event) async {
- await _loadCollections();
- });
+ _collectionsUpdatedSubscription = Bus.instance
+ .on<CollectionsUpdatedEvent>()
+ .listen((event) async {
+ await _loadCollections();
+ });
_triggerLogoutSubscription = Bus.instance.on<TriggerLogoutEvent>().listen((
event,
@@ -299,10 +305,12 @@ class _HomePageState extends UploaderPageState<HomePage>
@override
void dispose() {
searchFocusNode.removeListener(_onSearchFocusChanged);
+ _keyboardFocusNode.dispose();
_scrollController.dispose();
_displayedFilesNotifier.dispose();
_deepLinkSubscription?.cancel();
_triggerLogoutSubscription?.cancel();
+ _collectionsUpdatedSubscription?.cancel();
disposeSharing();
super.dispose();
}
@@ -571,12 +579,6 @@ class _HomePageState extends UploaderPageState<HomePage>
activateSearchWithQuery('');
return;
}
- if (!searchFocusNode.hasFocus &&
- isSearchActive &&
- searchController.text.trim().isEmpty) {
- dismissSearch();
- return;
- }
setState(() {});
}
@@ -619,7 +621,7 @@ class _HomePageState extends UploaderPageState<HomePage>
}
},
child: KeyboardListener(
- focusNode: FocusNode(),
+ focusNode: _keyboardFocusNode,
onKeyEvent: handleKeyEvent,
child: Scaffold(
key: scaffoldKey,
@@ -641,6 +643,7 @@ class _HomePageState extends UploaderPageState<HomePage>
isSyncing: _isSyncing,
searchController: searchController,
searchFocusNode: searchFocusNode,
+ isSearchActive: isSearchActive,
onClearSearch: _handleClearSearch,
onSearchChanged: _handleSearchChange,
),
diff --git a/mobile/apps/locker/lib/ui/pages/personal_note_page.dart b/mobile/apps/locker/lib/ui/pages/personal_note_page.dart
index 5b731475a3..5bd12f3a2b 100644
--- a/mobile/apps/locker/lib/ui/pages/personal_note_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/personal_note_page.dart
@@ -316,6 +316,7 @@ class _PersonalNotePageState
_titleFocusNode.canRequestFocus = isEditing;
final colors = context.componentColors;
+ final titleStyle = TextStyles.h2.copyWith(fontSize: 24);
return TextField(
controller: _nameController,
@@ -323,16 +324,13 @@ class _PersonalNotePageState
readOnly: !isEditing,
showCursor: isEditing,
enableInteractiveSelection: true,
- style: TextStyles.h2.copyWith(fontSize: 24),
+ style: titleStyle,
decoration: InputDecoration(
border: InputBorder.none,
isDense: true,
contentPadding: EdgeInsets.zero,
hintText: context.l10n.noteNameHint,
- hintStyle: TextStyles.h2.copyWith(
- fontSize: 24,
- color: colors.textLighter,
- ),
+ hintStyle: titleStyle.copyWith(color: colors.textLighter),
),
textCapitalization: TextCapitalization.sentences,
maxLines: 1,
diff --git a/mobile/apps/locker/lib/ui/pages/trash_page.dart b/mobile/apps/locker/lib/ui/pages/trash_page.dart
index d2da6bc3df..5eaca54e69 100644
--- a/mobile/apps/locker/lib/ui/pages/trash_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/trash_page.dart
@@ -3,7 +3,6 @@ import "dart:async";
import 'package:ente_components/ente_components.dart';
import "package:ente_events/event_bus.dart";
import 'package:ente_ui/components/buttons/button_widget.dart';
-import "package:ente_ui/components/title_bar_title_widget.dart";
import 'package:ente_ui/utils/dialog_util.dart';
import 'package:ente_ui/utils/toast_util.dart';
import 'package:flutter/material.dart';
@@ -108,24 +107,33 @@ class _TrashPageState extends State<TrashPage> {
@override
Widget build(BuildContext context) {
final colors = context.componentColors;
+ final hasTrashFiles = _trashFiles.isNotEmpty;
return Scaffold(
backgroundColor: colors.backgroundBase,
- appBar: AppBar(
- backgroundColor: colors.backgroundBase,
- surfaceTintColor: Colors.transparent,
- toolbarHeight: 48,
- leadingWidth: 48,
- leading: GestureDetector(
- onTap: () {
- Navigator.pop(context);
- },
- child: const Icon(Icons.arrow_back_outlined, semanticLabel: "Back"),
- ),
- ),
body: Stack(
children: [
- _buildBody(context, colors),
+ AppBarComponent(
+ title: context.l10n.trash,
+ subtitle: hasTrashFiles
+ ? context.l10n.items(_trashFiles.length)
+ : null,
+ actions: hasTrashFiles
+ ? [
+ IconButtonComponent(
+ icon: HugeIcon(
+ icon: HugeIcons.strokeRoundedDelete02,
+ color: colors.warning,
+ ),
+ variant: IconButtonComponentVariant.primary,
+ shouldSurfaceExecutionStates: false,
+ onTap: _emptyTrash,
+ ),
+ ]
+ : const [],
+ controller: _scrollController,
+ slivers: _buildSlivers(context),
+ ),
FileSelectionOverlayBar(
selectedFiles: _selectedFiles,
files: _trashFiles.cast<EnteFile>(),
@@ -137,49 +145,30 @@ class _TrashPageState extends State<TrashPage> {
);
}
- Widget _buildBody(BuildContext context, ColorTokens colors) {
- return Padding(
- padding: const EdgeInsets.all(16.0),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- TitleBarTitleWidget(
- title: context.l10n.trash,
- trailingWidgets: [
- if (_trashFiles.isNotEmpty)
- GestureDetector(
- onTap: _emptyTrash,
- child: Container(
- height: 44,
- width: 44,
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(12),
- color: colors.fillLight,
- ),
- padding: const EdgeInsets.all(12),
- child: HugeIcon(
- icon: HugeIcons.strokeRoundedDelete02,
- color: colors.textBase,
- ),
- ),
- ),
- ],
- ),
- const SizedBox(height: 24),
- Expanded(
- child: _trashFiles.isEmpty
- ? _TrashEmptyState(title: context.l10n.yourTrashIsEmpty)
- : ItemListView(
- files: _trashFiles.cast<EnteFile>(),
- physics: const BouncingScrollPhysics(),
- scrollController: _scrollController,
- selectedFiles: _selectedFiles,
- selectionEnabled: true,
- ),
+ List<Widget> _buildSlivers(BuildContext context) {
+ if (_trashFiles.isEmpty) {
+ return [
+ SliverFillRemaining(
+ hasScrollBody: false,
+ child: _TrashEmptyState(title: context.l10n.yourTrashIsEmpty),
+ ),
+ ];
+ }
+
+ final safeBottomInset = MediaQuery.of(context).padding.bottom;
+ final bottomPadding = safeBottomInset + 24.0;
+ return [
+ SliverPadding(
+ padding: EdgeInsets.fromLTRB(16.0, 0, 16.0, bottomPadding),
+ sliver: SliverToBoxAdapter(
+ child: ItemListView(
+ files: _trashFiles.cast<EnteFile>(),
+ selectedFiles: _selectedFiles,
+ selectionEnabled: true,
),
- ],
+ ),
),
- );
+ ];
}
}