Skip to content

armgit / ente

Public Imported from GitHub
0

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

Update notes

vishnukvmd8bba7839abe6
diff --git a/mobile/apps/locker/lib/l10n/app_en.arb b/mobile/apps/locker/lib/l10n/app_en.arb
index 13b2185fba..9b2511e360 100644
--- a/mobile/apps/locker/lib/l10n/app_en.arb
+++ b/mobile/apps/locker/lib/l10n/app_en.arb
@@ -380,6 +380,10 @@
"noteNameHint": "Hint text",
"noteContent": "Content",
"noteContentHint": "Write down important thoughts, instructions, or memories you want to preserve",
+ "unsavedNoteChangesTitle": "Discard changes?",
+ "unsavedNoteChangesDescription": "You have unsaved changes in this note. If you go back now, they will be lost.",
+ "keepEditing": "Keep editing",
+ "discardChanges": "Discard",
"recordName": "Record name",
"recordNameHint": "Name of the real-world item",
"recordLocation": "Location",
diff --git a/mobile/apps/locker/lib/l10n/app_localizations.dart b/mobile/apps/locker/lib/l10n/app_localizations.dart
index 0d2863e17f..7daa5bb69a 100644
--- a/mobile/apps/locker/lib/l10n/app_localizations.dart
+++ b/mobile/apps/locker/lib/l10n/app_localizations.dart
@@ -1144,6 +1144,30 @@ abstract class AppLocalizations {
/// **'Write down important thoughts, instructions, or memories you want to preserve'**
String get noteContentHint;
+ /// No description provided for @unsavedNoteChangesTitle.
+ ///
+ /// In en, this message translates to:
+ /// **'Discard changes?'**
+ String get unsavedNoteChangesTitle;
+
+ /// No description provided for @unsavedNoteChangesDescription.
+ ///
+ /// In en, this message translates to:
+ /// **'You have unsaved changes in this note. If you go back now, they will be lost.'**
+ String get unsavedNoteChangesDescription;
+
+ /// No description provided for @keepEditing.
+ ///
+ /// In en, this message translates to:
+ /// **'Keep editing'**
+ String get keepEditing;
+
+ /// No description provided for @discardChanges.
+ ///
+ /// In en, this message translates to:
+ /// **'Discard'**
+ String get discardChanges;
+
/// No description provided for @recordName.
///
/// In en, this message translates to:
diff --git a/mobile/apps/locker/lib/l10n/app_localizations_en.dart b/mobile/apps/locker/lib/l10n/app_localizations_en.dart
index 1625b85d2f..871d5d0bc1 100644
--- a/mobile/apps/locker/lib/l10n/app_localizations_en.dart
+++ b/mobile/apps/locker/lib/l10n/app_localizations_en.dart
@@ -603,6 +603,19 @@ class AppLocalizationsEn extends AppLocalizations {
String get noteContentHint =>
'Write down important thoughts, instructions, or memories you want to preserve';
+ @override
+ String get unsavedNoteChangesTitle => 'Discard changes?';
+
+ @override
+ String get unsavedNoteChangesDescription =>
+ 'You have unsaved changes in this note. If you go back now, they will be lost.';
+
+ @override
+ String get keepEditing => 'Keep editing';
+
+ @override
+ String get discardChanges => 'Discard';
+
@override
String get recordName => 'Record name';
diff --git a/mobile/apps/locker/lib/ui/pages/base_info_page.dart b/mobile/apps/locker/lib/ui/pages/base_info_page.dart
index 372f94f64b..9ebcf467c4 100644
--- a/mobile/apps/locker/lib/ui/pages/base_info_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/base_info_page.dart
@@ -80,10 +80,87 @@ abstract class BaseInfoPageState<T extends InfoData, W extends BaseInfoPage<T>>
bool validateForm();
bool get showCollectionSelectionTitle => true;
+ double get collectionSpacing => 24;
@protected
bool get isSaveEnabled => !_isLoading;
+ @protected
+ Future<bool> onEditModeBackPressed() async {
+ return true;
+ }
+
+ @protected
+ Future<bool> onPopRequested() async {
+ return true;
+ }
+
+ @protected
+ Widget buildAppBarTitle(BuildContext context) {
+ return TitleBarTitleWidget(
+ title: pageTitle,
+ );
+ }
+
+ @protected
+ List<Collection> get availableCollections => _availableCollections;
+
+ @protected
+ Set<int> get selectedCollectionIds => _selectedCollectionIds;
+
+ @protected
+ void toggleCollectionSelection(int collectionId) {
+ _onToggleCollection(collectionId);
+ }
+
+ @protected
+ void updateAvailableCollections(List<Collection> collections) {
+ _onCollectionsUpdated(collections);
+ }
+
+ @protected
+ Widget buildEditModeContent(
+ BuildContext context,
+ BoxConstraints constraints,
+ ) {
+ return SingleChildScrollView(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(vertical: 20),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ ...buildFormFields(),
+ SizedBox(height: collectionSpacing),
+ CollectionSelectionWidget(
+ collections: _availableCollections,
+ selectedCollectionIds: _selectedCollectionIds,
+ onToggleCollection: _onToggleCollection,
+ onCollectionsUpdated: _onCollectionsUpdated,
+ titleWidget:
+ showCollectionSelectionTitle ? null : const SizedBox.shrink(),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+
+ @protected
+ Widget buildViewModeContent(
+ BuildContext context,
+ BoxConstraints constraints,
+ ) {
+ return SingleChildScrollView(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(vertical: 20),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: buildViewFields(),
+ ),
+ ),
+ );
+ }
+
@override
void initState() {
super.initState();
@@ -363,17 +440,37 @@ abstract class BaseInfoPageState<T extends InfoData, W extends BaseInfoPage<T>>
);
}
+ Future<void> _handleBackNavigation() async {
+ if (isInEditMode) {
+ final canLeaveEdit = await onEditModeBackPressed();
+ if (!canLeaveEdit) {
+ return;
+ }
+
+ if (currentData != null) {
+ _toggleMode();
+ return;
+ }
+ }
+
+ final shouldPop = await onPopRequested();
+ if (!shouldPop || !mounted) {
+ return;
+ }
+
+ Navigator.of(context).pop();
+ }
+
@override
Widget build(BuildContext context) {
final isViewMode = _currentMode == InfoPageMode.view;
final isEditMode = _currentMode == InfoPageMode.edit;
final colorScheme = getEnteColorScheme(context);
return PopScope(
- canPop: isViewMode,
+ canPop: false,
onPopInvokedWithResult: (didPop, result) {
- if (!didPop && isEditMode) {
- // If in edit mode and trying to go back, switch to view mode instead
- _toggleMode();
+ if (!didPop) {
+ _handleBackNavigation();
}
},
child: Scaffold(
@@ -384,22 +481,20 @@ abstract class BaseInfoPageState<T extends InfoData, W extends BaseInfoPage<T>>
leadingWidth: 48,
centerTitle: false,
titleSpacing: 0,
- title: TitleBarTitleWidget(
- title: pageTitle,
- ),
+ title: buildAppBarTitle(context),
leading: isEditMode && currentData != null
? IconButton(
icon: const Icon(
Icons.arrow_back_outlined,
),
- onPressed: _toggleMode,
+ onPressed: _handleBackNavigation,
tooltip: context.l10n.backToView,
)
: IconButton(
icon: const Icon(
Icons.arrow_back_outlined,
),
- onPressed: () => Navigator.of(context).pop(),
+ onPressed: _handleBackNavigation,
tooltip: context.l10n.back,
),
automaticallyImplyLeading: false,
@@ -421,34 +516,13 @@ abstract class BaseInfoPageState<T extends InfoData, W extends BaseInfoPage<T>>
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
- child: SingleChildScrollView(
- child: Padding(
- padding: const EdgeInsets.symmetric(vertical: 20),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- // Fields based on current mode
- if (isViewMode)
- ...buildViewFields()
- else
- ...buildFormFields(),
-
- // Collection selection only in edit mode
- if (isEditMode) ...[
- const SizedBox(height: 24),
- CollectionSelectionWidget(
- collections: _availableCollections,
- selectedCollectionIds: _selectedCollectionIds,
- onToggleCollection: _onToggleCollection,
- onCollectionsUpdated: _onCollectionsUpdated,
- titleWidget: showCollectionSelectionTitle
- ? null
- : const SizedBox.shrink(),
- ),
- ],
- ],
- ),
- ),
+ child: LayoutBuilder(
+ builder: (context, constraints) {
+ if (isViewMode) {
+ return buildViewModeContent(context, constraints);
+ }
+ return buildEditModeContent(context, constraints);
+ },
),
),
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 e64d4ca564..fabf74de45 100644
--- a/mobile/apps/locker/lib/ui/pages/personal_note_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/personal_note_page.dart
@@ -1,7 +1,10 @@
+import 'package:ente_ui/theme/ente_theme.dart';
import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:intl/intl.dart';
import 'package:locker/l10n/l10n.dart';
import 'package:locker/models/info/info_item.dart';
-import 'package:locker/ui/components/form_text_input_widget.dart';
+import 'package:locker/ui/components/collection_selection_widget.dart';
import 'package:locker/ui/pages/base_info_page.dart';
class PersonalNotePage extends BaseInfoPage<PersonalNoteData> {
@@ -17,37 +20,48 @@ class PersonalNotePage extends BaseInfoPage<PersonalNoteData> {
class _PersonalNotePageState
extends BaseInfoPageState<PersonalNoteData, PersonalNotePage> {
+ static const String _defaultTitle = 'Note title';
final TextEditingController _nameController = TextEditingController();
final TextEditingController _contentController = TextEditingController();
+ final FocusNode _titleFocusNode = FocusNode();
+ bool _isControllerSyncInProgress = false;
+ String _initialContent = '';
@override
void initState() {
super.initState();
- _nameController.addListener(_onFieldChanged);
- _contentController.addListener(_onFieldChanged);
- _loadExistingData();
+ _nameController.addListener(_onTitleChanged);
+ _contentController.addListener(_onContentChanged);
+ _titleFocusNode.addListener(_onTitleFocusChanged);
}
- void _loadExistingData() {
- final data = currentData;
- if (data != null) {
- _nameController.text = data.title;
- _contentController.text = data.content;
- }
+ @override
+ void loadExistingData() {
+ _syncControllers(
+ selectAllTitle: true,
+ triggerSetState: false,
+ updateInitial: true,
+ );
}
@override
void refreshUIWithCurrentData() {
super.refreshUIWithCurrentData();
- _loadExistingData();
+ _syncControllers(
+ selectAllTitle: false,
+ triggerSetState: true,
+ updateInitial: true,
+ );
}
@override
void dispose() {
- _nameController.removeListener(_onFieldChanged);
- _contentController.removeListener(_onFieldChanged);
+ _nameController.removeListener(_onTitleChanged);
+ _contentController.removeListener(_onContentChanged);
+ _titleFocusNode.removeListener(_onTitleFocusChanged);
_nameController.dispose();
_contentController.dispose();
+ _titleFocusNode.dispose();
super.dispose();
}
@@ -93,46 +107,360 @@ class _PersonalNotePageState
}
@override
- List<Widget> buildFormFields() {
- return [
- FormTextInputWidget(
- labelText: context.l10n.noteName,
- hintText: context.l10n.noteNameHint,
- controller: _nameController,
- shouldUseTextInputWidget: false,
- validator: (_) => null,
- ),
- const SizedBox(height: 24),
- FormTextInputWidget(
- labelText: context.l10n.noteContent,
- hintText: context.l10n.noteContentHint,
- controller: _contentController,
- maxLines: 5,
- validator: (value) {
- if (value == null || value.trim().isEmpty) {
- return context.l10n.pleaseEnterNoteContent;
- }
- return null;
- },
- ),
- const SizedBox(height: 24),
- ];
- }
+ List<Widget> buildFormFields() => const <Widget>[];
@override
List<Widget> buildViewFields() {
- return [
- buildViewField(
- label: context.l10n.noteContent,
- value: _contentController.text,
- maxLines: 5,
+ return const <Widget>[];
+ }
+
+ @override
+ double get collectionSpacing => 12;
+
+ @override
+ Widget buildEditModeContent(
+ BuildContext context,
+ BoxConstraints constraints,
+ ) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Expanded(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(vertical: 20),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ context.l10n.note,
+ style: textTheme.body,
+ ),
+ const SizedBox(height: 8),
+ Expanded(
+ child: ClipRRect(
+ borderRadius: const BorderRadius.all(Radius.circular(8)),
+ child: Material(
+ color: Colors.transparent,
+ child: TextFormField(
+ controller: _contentController,
+ validator: (value) {
+ if (value == null || value.trim().isEmpty) {
+ return context.l10n.pleaseEnterNoteContent;
+ }
+ return null;
+ },
+ keyboardType: TextInputType.multiline,
+ textCapitalization: TextCapitalization.sentences,
+ maxLines: null,
+ minLines: null,
+ expands: true,
+ textAlignVertical: TextAlignVertical.top,
+ style: textTheme.body,
+ decoration: InputDecoration(
+ hintText: context.l10n.noteContentHint,
+ hintStyle: textTheme.body.copyWith(
+ color: colorScheme.textFaint,
+ ),
+ filled: true,
+ fillColor: colorScheme.fillFaint,
+ contentPadding:
+ const EdgeInsets.fromLTRB(12, 12, 12, 12),
+ border: const UnderlineInputBorder(
+ borderSide: BorderSide.none,
+ ),
+ enabledBorder: OutlineInputBorder(
+ borderSide: BorderSide.none,
+ borderRadius: BorderRadius.circular(8),
+ ),
+ focusedBorder: OutlineInputBorder(
+ borderSide: BorderSide(
+ color: colorScheme.strokeFaint,
+ width: 2,
+ ),
+ borderRadius: BorderRadius.circular(8),
+ ),
+ errorBorder: OutlineInputBorder(
+ borderSide: BorderSide(
+ color: colorScheme.warning500,
+ width: 1,
+ ),
+ borderRadius: BorderRadius.circular(8),
+ ),
+ focusedErrorBorder: OutlineInputBorder(
+ borderSide: BorderSide(
+ color: colorScheme.warning500,
+ width: 2,
+ ),
+ borderRadius: BorderRadius.circular(8),
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ SizedBox(height: collectionSpacing),
+ CollectionSelectionWidget(
+ collections: availableCollections,
+ selectedCollectionIds: selectedCollectionIds,
+ onToggleCollection: toggleCollectionSelection,
+ onCollectionsUpdated: updateAvailableCollections,
+ titleWidget:
+ showCollectionSelectionTitle ? null : const SizedBox.shrink(),
+ ),
+ ],
+ );
+ }
+
+ @override
+ Widget buildViewModeContent(
+ BuildContext context,
+ BoxConstraints constraints,
+ ) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ final contentText = _contentController.text;
+
+ return Padding(
+ padding: const EdgeInsets.only(top: 20, bottom: 100),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Expanded(
+ child: ClipRRect(
+ borderRadius: const BorderRadius.all(Radius.circular(8)),
+ child: Material(
+ color: Colors.transparent,
+ child: Stack(
+ children: [
+ Container(
+ decoration: BoxDecoration(
+ color: colorScheme.fillFaint,
+ borderRadius: BorderRadius.circular(8),
+ ),
+ ),
+ Padding(
+ padding: const EdgeInsets.only(bottom: 48, right: 4),
+ child: Scrollbar(
+ child: SingleChildScrollView(
+ padding: const EdgeInsets.fromLTRB(12, 12, 12, 12),
+ child: contentText.isEmpty
+ ? Text(
+ context.l10n.noteContentHint,
+ style: textTheme.body.copyWith(
+ color: colorScheme.textFaint,
+ ),
+ )
+ : SelectableText(
+ contentText,
+ style: textTheme.body,
+ ),
+ ),
+ ),
+ ),
+ if (contentText.trim().isNotEmpty)
+ Positioned(
+ bottom: 12,
+ right: 12,
+ child: InkWell(
+ onTap: _copyContentToClipboard,
+ borderRadius: BorderRadius.circular(4),
+ child: Container(
+ padding: const EdgeInsets.all(4),
+ child: Icon(
+ Icons.copy,
+ size: 16,
+ color: colorScheme.textMuted,
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ ],
),
- ];
+ );
+ }
+
+ @override
+ Widget buildAppBarTitle(BuildContext context) {
+ if (isInEditMode) {
+ final textTheme = getEnteTextTheme(context);
+ return TextField(
+ controller: _nameController,
+ focusNode: _titleFocusNode,
+ style: textTheme.h3Bold,
+ decoration: const InputDecoration(
+ border: InputBorder.none,
+ isDense: true,
+ contentPadding: EdgeInsets.zero,
+ ),
+ textCapitalization: TextCapitalization.sentences,
+ maxLines: 1,
+ );
+ }
+ return super.buildAppBarTitle(context);
+ }
+
+ void _syncControllers({
+ bool selectAllTitle = false,
+ bool triggerSetState = true,
+ bool updateInitial = false,
+ }) {
+ _isControllerSyncInProgress = true;
+ try {
+ final data = currentData;
+ final trimmedTitle = data?.title.trim() ?? '';
+ final effectiveTitle =
+ trimmedTitle.isEmpty ? _defaultTitle : trimmedTitle;
+ final shouldSelectAll = selectAllTitle && trimmedTitle.isEmpty;
+ _updateTitleController(
+ effectiveTitle,
+ selectAll: shouldSelectAll,
+ );
+ _contentController.text = data?.content ?? '';
+ if (updateInitial) {
+ _initialContent = _contentController.text;
+ }
+ } finally {
+ _isControllerSyncInProgress = false;
+ }
+
+ if (triggerSetState && mounted) {
+ setState(() {});
+ }
+ }
+
+ void _onTitleChanged() {
+ if (_isControllerSyncInProgress) {
+ return;
+ }
+ _notifyFormChanged();
}
- void _onFieldChanged() {
+ void _onContentChanged() {
+ if (_isControllerSyncInProgress) {
+ return;
+ }
+
+ final titleText = _nameController.text.trim();
+ final contentText = _contentController.text.trim();
+ if (titleText == _defaultTitle && contentText.isNotEmpty) {
+ final generatedTitle = _formatCurrentTimestamp();
+ _updateTitleController(generatedTitle);
+ }
+
+ _notifyFormChanged();
+ }
+
+ void _notifyFormChanged() {
if (mounted) {
setState(() {});
}
}
+
+ bool get _hasUnsavedContentChanges {
+ return _contentController.text.trim() != _initialContent.trim();
+ }
+
+ void _updateTitleController(String value, {bool selectAll = false}) {
+ _nameController.value = TextEditingValue(
+ text: value,
+ selection: selectAll
+ ? TextSelection(baseOffset: 0, extentOffset: value.length)
+ : TextSelection.collapsed(offset: value.length),
+ );
+ }
+
+ String _formatCurrentTimestamp() {
+ final now = DateTime.now();
+ final monthAbbreviation = DateFormat('MMM').format(now);
+ final day = DateFormat('d').format(now);
+ final year = DateFormat('yyyy').format(now);
+ final time = DateFormat('h:mma').format(now).toLowerCase();
+ return '$monthAbbreviation $day, $year - $time';
+ }
+
+ void _onTitleFocusChanged() {
+ if (_isControllerSyncInProgress) {
+ return;
+ }
+
+ if (_titleFocusNode.hasFocus) {
+ if (_nameController.text.trim() == _defaultTitle) {
+ _updateTitleController('');
+ }
+ } else {
+ if (_nameController.text.trim().isEmpty) {
+ _updateTitleController(_defaultTitle);
+ }
+ }
+ }
+
+ void _copyContentToClipboard() {
+ final contentText = _contentController.text;
+ if (contentText.trim().isEmpty) {
+ return;
+ }
+ Clipboard.setData(ClipboardData(text: contentText));
+ ScaffoldMessenger.of(context).showSnackBar(
+ SnackBar(
+ content: Text(context.l10n.copiedToClipboard(context.l10n.note)),
+ duration: const Duration(seconds: 2),
+ backgroundColor: Colors.green,
+ ),
+ );
+ }
+
+ @override
+ Future<bool> onEditModeBackPressed() async {
+ if (!_hasUnsavedContentChanges) {
+ return true;
+ }
+
+ final shouldDiscard = await _showDiscardChangesDialog();
+ if (!shouldDiscard) {
+ return false;
+ }
+
+ _syncControllers(
+ selectAllTitle: false,
+ triggerSetState: true,
+ updateInitial: false,
+ );
+ return true;
+ }
+
+ Future<bool> _showDiscardChangesDialog() async {
+ final result = await showDialog<bool>(
+ context: context,
+ builder: (context) {
+ return AlertDialog(
+ title: Text(context.l10n.unsavedNoteChangesTitle),
+ content: Text(context.l10n.unsavedNoteChangesDescription),
+ actions: [
+ TextButton(
+ onPressed: () => Navigator.of(context).pop(false),
+ child: Text(context.l10n.keepEditing),
+ ),
+ TextButton(
+ onPressed: () => Navigator.of(context).pop(true),
+ child: Text(context.l10n.discardChanges),
+ ),
+ ],
+ );
+ },
+ );
+
+ return result ?? false;
+ }
}
diff --git a/mobile/packages/ui/lib/components/buttons/gradient_button.dart b/mobile/packages/ui/lib/components/buttons/gradient_button.dart
index bebd7b3687..09fe4bea2c 100644
--- a/mobile/packages/ui/lib/components/buttons/gradient_button.dart
+++ b/mobile/packages/ui/lib/components/buttons/gradient_button.dart
@@ -30,7 +30,8 @@ class GradientButton extends StatelessWidget {
final Color backgroundColor =
isEnabled ? colorScheme.primary700 : colorScheme.fillFaint;
final TextStyle effectiveTextStyle = _textStyle.copyWith(
- color: isEnabled ? Colors.white : colorScheme.textMuted);
+ color: isEnabled ? Colors.white : colorScheme.textMuted,
+ );
final Widget textWidget = Text(text, style: effectiveTextStyle);