Skip to content

armgit / ente

Public Imported from GitHub
0

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

Open info files directly in edit mode instead of downloading

vishnukvmd86bef07666f0
diff --git a/mobile/apps/locker/lib/ui/components/item_list_view.dart b/mobile/apps/locker/lib/ui/components/item_list_view.dart
index 5da2fe18e2..c3ab32b96a 100644
--- a/mobile/apps/locker/lib/ui/components/item_list_view.dart
+++ b/mobile/apps/locker/lib/ui/components/item_list_view.dart
@@ -8,6 +8,7 @@ import 'package:ente_utils/share_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:locker/l10n/l10n.dart';
+import 'package:locker/models/info/info_item.dart';
import 'package:locker/services/collections/collections_service.dart';
import 'package:locker/services/collections/models/collection.dart';
import 'package:locker/services/configuration.dart';
@@ -15,8 +16,13 @@ import 'package:locker/services/files/download/file_downloader.dart';
import 'package:locker/services/files/links/links_service.dart';
import 'package:locker/services/files/sync/metadata_updater_service.dart';
import 'package:locker/services/files/sync/models/file.dart';
+import 'package:locker/services/info_file_service.dart';
import 'package:locker/ui/components/file_edit_dialog.dart';
+import 'package:locker/ui/pages/account_credentials_page.dart';
import 'package:locker/ui/pages/collection_page.dart';
+import 'package:locker/ui/pages/emergency_contact_page.dart';
+import 'package:locker/ui/pages/personal_note_page.dart';
+import 'package:locker/ui/pages/physical_records_page.dart';
import 'package:locker/utils/collection_actions.dart';
import 'package:locker/utils/collection_sort_util.dart';
import 'package:locker/utils/date_time_util.dart';
@@ -1033,6 +1039,12 @@ class FileRowWidget extends StatelessWidget {
}
Future<void> _openFile(BuildContext context) async {
+ // Check if this is an info file
+ if (InfoFileService.instance.isInfoFile(file)) {
+ return _openInfoFile(context);
+ }
+
+ // Original file opening logic for non-info files
if (file.localPath != null) {
final localFile = File(file.localPath!);
if (await localFile.exists()) {
@@ -1096,6 +1108,55 @@ class FileRowWidget extends StatelessWidget {
}
}
+ Future<void> _openInfoFile(BuildContext context) async {
+ try {
+ final infoItem = InfoFileService.instance.extractInfoFromFile(file);
+ if (infoItem == null) {
+ await showErrorDialog(
+ context,
+ context.l10n.errorOpeningFile,
+ 'Unable to extract information from this file',
+ );
+ return;
+ }
+
+ // Navigate to the appropriate page based on info type
+ Widget page;
+ switch (infoItem.type) {
+ case InfoType.note:
+ page = PersonalNotePage(
+ existingData: infoItem.data as PersonalNoteData,
+ );
+ break;
+ case InfoType.accountCredential:
+ page = AccountCredentialsPage(
+ existingData: infoItem.data as AccountCredentialData,
+ );
+ break;
+ case InfoType.physicalRecord:
+ page = PhysicalRecordsPage(
+ existingData: infoItem.data as PhysicalRecordData,
+ );
+ break;
+ case InfoType.emergencyContact:
+ page = EmergencyContactPage(
+ existingData: infoItem.data as EmergencyContactData,
+ );
+ break;
+ }
+
+ await Navigator.of(context).push(
+ MaterialPageRoute(builder: (context) => page),
+ );
+ } catch (e) {
+ await showErrorDialog(
+ context,
+ context.l10n.errorOpeningFile,
+ 'Failed to open info file: ${e.toString()}',
+ );
+ }
+ }
+
Future<void> _launchFile(
BuildContext context,
File file,
diff --git a/mobile/apps/locker/lib/ui/pages/account_credentials_page.dart b/mobile/apps/locker/lib/ui/pages/account_credentials_page.dart
index 55b10335a8..c9992fe686 100644
--- a/mobile/apps/locker/lib/ui/pages/account_credentials_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/account_credentials_page.dart
@@ -10,7 +10,9 @@ import 'package:locker/ui/components/collection_selection_widget.dart';
import 'package:locker/ui/components/form_text_input_widget.dart';
class AccountCredentialsPage extends StatefulWidget {
- const AccountCredentialsPage({super.key});
+ final AccountCredentialData? existingData;
+
+ const AccountCredentialsPage({super.key, this.existingData});
@override
State<AccountCredentialsPage> createState() => _AccountCredentialsPageState();
@@ -41,6 +43,16 @@ class _AccountCredentialsPageState extends State<AccountCredentialsPage> {
});
});
_loadCollections();
+ _loadExistingData();
+ }
+
+ void _loadExistingData() {
+ if (widget.existingData != null) {
+ _nameController.text = widget.existingData!.name;
+ _usernameController.text = widget.existingData!.username;
+ _passwordController.text = widget.existingData!.password;
+ _notesController.text = widget.existingData!.notes ?? '';
+ }
}
Future<void> _loadCollections() async {
diff --git a/mobile/apps/locker/lib/ui/pages/emergency_contact_page.dart b/mobile/apps/locker/lib/ui/pages/emergency_contact_page.dart
index 7822cbb51e..7189a46d35 100644
--- a/mobile/apps/locker/lib/ui/pages/emergency_contact_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/emergency_contact_page.dart
@@ -10,7 +10,9 @@ import 'package:locker/ui/components/collection_selection_widget.dart';
import 'package:locker/ui/components/form_text_input_widget.dart';
class EmergencyContactPage extends StatefulWidget {
- const EmergencyContactPage({super.key});
+ final EmergencyContactData? existingData;
+
+ const EmergencyContactPage({super.key, this.existingData});
@override
State<EmergencyContactPage> createState() => _EmergencyContactPageState();
@@ -33,6 +35,15 @@ class _EmergencyContactPageState extends State<EmergencyContactPage> {
void initState() {
super.initState();
_loadCollections();
+ _loadExistingData();
+ }
+
+ void _loadExistingData() {
+ if (widget.existingData != null) {
+ _nameController.text = widget.existingData!.name;
+ _contactDetailsController.text = widget.existingData!.contactDetails;
+ _notesController.text = widget.existingData!.notes ?? '';
+ }
}
Future<void> _loadCollections() async {
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 e2064731dd..a6bbb754c3 100644
--- a/mobile/apps/locker/lib/ui/pages/personal_note_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/personal_note_page.dart
@@ -10,7 +10,9 @@ import 'package:locker/ui/components/collection_selection_widget.dart';
import 'package:locker/ui/components/form_text_input_widget.dart';
class PersonalNotePage extends StatefulWidget {
- const PersonalNotePage({super.key});
+ final PersonalNoteData? existingData;
+
+ const PersonalNotePage({super.key, this.existingData});
@override
State<PersonalNotePage> createState() => _PersonalNotePageState();
@@ -31,6 +33,14 @@ class _PersonalNotePageState extends State<PersonalNotePage> {
void initState() {
super.initState();
_loadCollections();
+ _loadExistingData();
+ }
+
+ void _loadExistingData() {
+ if (widget.existingData != null) {
+ _nameController.text = widget.existingData!.title;
+ _contentController.text = widget.existingData!.content;
+ }
}
Future<void> _loadCollections() async {
diff --git a/mobile/apps/locker/lib/ui/pages/physical_records_page.dart b/mobile/apps/locker/lib/ui/pages/physical_records_page.dart
index ede09c482d..f134035c1b 100644
--- a/mobile/apps/locker/lib/ui/pages/physical_records_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/physical_records_page.dart
@@ -10,7 +10,9 @@ import 'package:locker/ui/components/collection_selection_widget.dart';
import 'package:locker/ui/components/form_text_input_widget.dart';
class PhysicalRecordsPage extends StatefulWidget {
- const PhysicalRecordsPage({super.key});
+ final PhysicalRecordData? existingData;
+
+ const PhysicalRecordsPage({super.key, this.existingData});
@override
State<PhysicalRecordsPage> createState() => _PhysicalRecordsPageState();
@@ -32,6 +34,15 @@ class _PhysicalRecordsPageState extends State<PhysicalRecordsPage> {
void initState() {
super.initState();
_loadCollections();
+ _loadExistingData();
+ }
+
+ void _loadExistingData() {
+ if (widget.existingData != null) {
+ _nameController.text = widget.existingData!.name;
+ _locationController.text = widget.existingData!.location;
+ _notesController.text = widget.existingData!.notes ?? '';
+ }
}
Future<void> _loadCollections() async {