π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[auth] Add support for adding notes
Neeraj Gupta05200878f20a
diff --git a/auth/lib/l10n/arb/app_en.arb b/auth/lib/l10n/arb/app_en.arbindex 6f5ea14088..10d2711adb 100644--- a/auth/lib/l10n/arb/app_en.arb+++ b/auth/lib/l10n/arb/app_en.arb@@ -21,6 +21,19 @@"codeSecretKeyHint": "Secret Key","secret": "Secret","account": "Account",+ "advance": "Advance",+ "notes": "Notes",+ "notesLengthLimit": "Notes can be at most {count} characters long",+ "@notesLengthLimit": {+ "description": "Text to indicate the maximum number of characters allowed for notes",+ "placeholders": {+ "count": {+ "description": "The maximum number of characters allowed for notes",+ "type": "int",+ "example": "100"+ }+ }+ },"codeAccountHint": "Account ([email protected])","codeTagHint": "Tag","accountKeyType": "Type of key",diff --git a/auth/lib/models/code_display.dart b/auth/lib/models/code_display.dartindex 6bbf78f1fc..50c4767eaf 100644--- a/auth/lib/models/code_display.dart+++ b/auth/lib/models/code_display.dart@@ -9,6 +9,7 @@ class CodeDisplay {final bool trashed;final int lastUsedAt;final int tapCount;+ String note;final List<String> tags;CodeDisplay({@@ -17,6 +18,7 @@ class CodeDisplay {this.lastUsedAt = 0,this.tapCount = 0,this.tags = const [],+ this.note = '',});// copyWith@@ -26,12 +28,14 @@ class CodeDisplay {int? lastUsedAt,int? tapCount,List<String>? tags,+ String? note,}) {final bool updatedPinned = pinned ?? this.pinned;final bool updatedTrashed = trashed ?? this.trashed;final int updatedLastUsedAt = lastUsedAt ?? this.lastUsedAt;final int updatedTapCount = tapCount ?? this.tapCount;final List<String> updatedTags = tags ?? this.tags;+ final String updatedNote = note ?? this.note;return CodeDisplay(pinned: updatedPinned,@@ -39,6 +43,7 @@ class CodeDisplay {lastUsedAt: updatedLastUsedAt,tapCount: updatedTapCount,tags: updatedTags,+ note: updatedNote,);}@@ -52,6 +57,7 @@ class CodeDisplay {lastUsedAt: json['lastUsedAt'] ?? 0,tapCount: json['tapCount'] ?? 0,tags: List<String>.from(json['tags'] ?? []),+ note: json['note'] ?? '',);}@@ -92,6 +98,7 @@ class CodeDisplay {'lastUsedAt': lastUsedAt,'tapCount': tapCount,'tags': tags,+ 'note': note,};}@@ -104,6 +111,7 @@ class CodeDisplay {other.trashed == trashed &&other.lastUsedAt == lastUsedAt &&other.tapCount == tapCount &&+ other.note == note &&listEquals(other.tags, tags);}@@ -113,6 +121,7 @@ class CodeDisplay {trashed.hashCode ^lastUsedAt.hashCode ^tapCount.hashCode ^+ note.hashCode ^tags.hashCode;}}diff --git a/auth/lib/onboarding/view/setup_enter_secret_key_page.dart b/auth/lib/onboarding/view/setup_enter_secret_key_page.dartindex df3c102750..4a7570d1ec 100644--- a/auth/lib/onboarding/view/setup_enter_secret_key_page.dart+++ b/auth/lib/onboarding/view/setup_enter_secret_key_page.dart@@ -15,6 +15,7 @@ import 'package:ente_auth/theme/ente_theme.dart';import 'package:ente_auth/ui/components/buttons/button_widget.dart';import 'package:ente_auth/ui/components/models/button_result.dart';import 'package:ente_auth/utils/dialog_util.dart';+import 'package:ente_auth/utils/toast_util.dart';import 'package:ente_auth/utils/totp_util.dart';import "package:flutter/material.dart";@@ -34,6 +35,7 @@ class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {late TextEditingController _issuerController;late TextEditingController _accountController;late TextEditingController _secretController;+ late TextEditingController _notesController;late bool _secretKeyObscured;late List<String> tags = [...?widget.code?.display.tags];List<String> allTags = [];@@ -51,11 +53,23 @@ class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {_secretController = TextEditingController(text: widget.code?.secret,);+ _notesController = TextEditingController(+ text: widget.code?.display.note,+ );_secretKeyObscured = widget.code != null;_loadTags();_streamSubscription = Bus.instance.on<CodesUpdatedEvent>().listen((event) {_loadTags();});+ _notesController.addListener(() {+ if (_notesController.text.length > _notesLimit) {+ _notesController.text = _notesController.text.substring(0, _notesLimit);+ _notesController.selection = TextSelection.fromPosition(+ TextPosition(offset: _notesController.text.length),+ );+ showToast(context, context.l10n.notesLengthLimit(_notesLimit));+ }+ });if (widget.code == null ||(widget.code!.issuer.length < _otherTextLimit &&@@ -82,6 +96,10 @@ class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {@overridevoid dispose() {_streamSubscription?.cancel();+ _issuerController.dispose();+ _accountController.dispose();+ _accountController.dispose();+ _notesController.dispose();super.dispose();}@@ -188,10 +206,57 @@ class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {),],),- const SizedBox(height: 40),- const SizedBox(- height: 20,+ const SizedBox(height: 12),+ Row(+ children: [+ Expanded(+ child: Theme(+ data: Theme.of(context).copyWith(+ dividerColor: Colors+ .transparent, // Removes the default divider color+ ),+ child: ExpansionTile(+ title: Text(+ l10n.advance,+ style: getEnteTextTheme(context).bodyMuted,+ ),+ children: <Widget>[+ Row(+ children: [+ FieldLabel(l10n.notes),+ Expanded(+ child: TextFormField(+ // The validator receives the text that the user has entered.+ validator: (value) {+ if (value == null || value.isEmpty) {+ return "Please enter some text";+ }+ if (value.length > _notesLimit) {+ return "Notes can't be more than 1000 characters";+ }+ return null;+ },+ maxLength: _notesLimit,+ minLines: 1,+ maxLines: 5,+ decoration: const InputDecoration(+ contentPadding:+ EdgeInsets.symmetric(vertical: 12.0),+ ),+ style: getEnteTextTheme(context).small,+ controller: _notesController,+ ),+ ),+ ],+ ),+ const SizedBox(height: 12),+ ],+ ),+ ),+ ),+ ],),+ const SizedBox(height: 24),Text(l10n.tags,style: const TextStyle(@@ -281,6 +346,7 @@ class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {final account = _accountController.text.trim();final issuer = _issuerController.text.trim();final secret = _secretController.text.trim().replaceAll(' ', '');+ final notes = _notesController.text.trim();final isStreamCode = issuer.toLowerCase() == "steam" ||issuer.toLowerCase().contains('steampowered.com');if (widget.code != null && widget.code!.secret != secret) {@@ -299,6 +365,7 @@ class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {}final CodeDisplay display =widget.code?.display.copyWith(tags: tags) ?? CodeDisplay(tags: tags);+ display.note = notes;final Code newCode = widget.code == null? Code.fromAccountAndSecret(isStreamCode ? Type.steam : Type.totp,