diff --git a/app-release.apk b/app-release.apk index fd6d0a7..efcb6fd 100644 Binary files a/app-release.apk and b/app-release.apk differ diff --git a/lib/methods/excursion_db_helper.dart b/lib/methods/excursion_db_helper.dart index 58b053a..09da04c 100644 --- a/lib/methods/excursion_db_helper.dart +++ b/lib/methods/excursion_db_helper.dart @@ -48,21 +48,21 @@ class ExcursionDBHelper implements IDb { @override Future addMainEntry(Map excursion) async { var excursionDBClient = await dB; - final existingID = await excursionDBClient.query( - 'excursion', - where: 'ID = ?', - whereArgs: [excursion['ID']], - ); + // final existingID = await excursionDBClient.query( + // 'excursion', + // where: 'ID = ?', + // whereArgs: [excursion['ID']], + // ); - if (existingID.isNotEmpty) { - updateMainEntry(excursion); - return existingID.first['ID'] as int; // Return existing ID - } + // if (existingID.isNotEmpty) { + // updateMainEntry(excursion); + // return existingID.first['ID'] as int; // Return existing ID + // } int id = await excursionDBClient.insert( 'excursion', excursion, - //conflictAlgorithm: ConflictAlgorithm.replace, + conflictAlgorithm: ConflictAlgorithm.replace, ); return id; // Return the ID of the newly inserted entry diff --git a/lib/screens/addCam/add_cam_main.dart b/lib/screens/addCam/add_cam_main.dart index ae50733..5282269 100644 --- a/lib/screens/addCam/add_cam_main.dart +++ b/lib/screens/addCam/add_cam_main.dart @@ -620,13 +620,14 @@ class _AddCamMainState extends State { } bool empty = CheckRequired.checkRequired(rmap); - // TODO for debugging always false - empty = false; + // for debugging always false + // empty = false; if (empty == true) { AddEntriesDialogHelper.showTemplateDialog( context, getFieldsText(), + DatabasesEnum.place ); return; } else if (empty == false) { diff --git a/lib/screens/excursion/exceptions/file_dialog_cancelled.dart b/lib/screens/excursion/exceptions/file_dialog_cancelled.dart new file mode 100644 index 0000000..4414152 --- /dev/null +++ b/lib/screens/excursion/exceptions/file_dialog_cancelled.dart @@ -0,0 +1 @@ +class FileDialogCancelled implements Exception {} diff --git a/lib/screens/excursion/excursion_main.dart b/lib/screens/excursion/excursion_main.dart index 0272800..11818b6 100644 --- a/lib/screens/excursion/excursion_main.dart +++ b/lib/screens/excursion/excursion_main.dart @@ -462,16 +462,17 @@ class _ExcursionMainState extends State { } bool empty = CheckRequired.checkRequired(rmap); - // TODO for debugging always false - empty = false; + // for debugging always false + // empty = false; - if (empty == true) { + if (empty) { AddEntriesDialogHelper.showTemplateDialog( context, getFieldsText(), + DatabasesEnum.excursion ); return; - } else if (empty == false) { + } else if (!empty) { await AddEntriesDialogHelper.showSaveOptionsDialog( context, getFieldsText(), diff --git a/lib/screens/excursion/widgets/tracking.dart b/lib/screens/excursion/widgets/tracking.dart index f35d068..5c39e6c 100644 --- a/lib/screens/excursion/widgets/tracking.dart +++ b/lib/screens/excursion/widgets/tracking.dart @@ -31,7 +31,7 @@ class _TrackingState extends State { @override void initState() { - // TODO debugging (i guess) + // debugging (i guess) // pathList.add( // LatLng(widget.startPosition.latitude, widget.startPosition.longitude), // ); @@ -113,6 +113,7 @@ class _TrackingState extends State { if (position != null) { setState(() { pathList.add(LatLng(position.latitude, position.longitude)); + // Random value for debugging // pathList.add(LatLng(rand.nextInt(5) + 40, position.longitude)); locationMarkerPosition = LocationMarkerPosition( @@ -141,7 +142,9 @@ class _TrackingState extends State { return Scaffold( appBar: AppBar( title: Text(AppLocalizations.of(context)!.tracking), - // leading: IconButton(onPressed: () {}, icon: Icon(Icons.arrow_back_rounded)), + leading: IconButton(onPressed: () { + Navigator.pop(context); + }, icon: Icon(Icons.arrow_back_rounded)), actions: [ if (!positionStreamRunning) IconButton( diff --git a/lib/screens/helper/add_entries_dialog_helper.dart b/lib/screens/helper/add_entries_dialog_helper.dart index edf5f59..ea32faa 100644 --- a/lib/screens/helper/add_entries_dialog_helper.dart +++ b/lib/screens/helper/add_entries_dialog_helper.dart @@ -4,6 +4,7 @@ import 'package:fforte/screens/sharedMethods/http_request.dart'; import 'package:fforte/screens/sharedMethods/save_file.dart'; import 'package:fforte/screens/sharedMethods/save_template.dart'; import 'package:fforte/screens/sharedMethods/save_main_entry.dart'; +import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; import 'package:fforte/l10n/app_localizations.dart'; import 'package:geolocator/geolocator.dart'; @@ -13,6 +14,7 @@ class AddEntriesDialogHelper { static Future showTemplateDialog( BuildContext context, Map saveData, + DatabasesEnum dbType, ) async { return showDialog( context: context, @@ -29,7 +31,7 @@ class AddEntriesDialogHelper { ), TextButton( onPressed: () { - saveTemplate(saveData, DatabasesEnum.place); + saveTemplate(saveData, dbType); Navigator.pushNamedAndRemoveUntil( context, '/home', @@ -114,8 +116,7 @@ class AddEntriesDialogHelper { return showDialog( context: context, - barrierDismissible: - false, // Verhindert das Schließen des Dialogs durch den Benutzer + barrierDismissible: false, builder: (BuildContext context) { return StatefulBuilder( builder: (context, setState) { @@ -136,7 +137,7 @@ class AddEntriesDialogHelper { TextButton( onPressed: () async { setState(() => isLoading = true); - saveTemplate(saveData, DatabasesEnum.place); + saveTemplate(saveData, dbType); Navigator.pushNamedAndRemoveUntil( context, '/home', @@ -191,17 +192,29 @@ class AddEntriesDialogHelper { isTemplate: isTemplate, dbType: dbType, ); - SaveFileMethod.saveFile( - saveData, - AppLocalizations.of(context)!.savefilefailed, - saveData["CID"]!, - ); + try { + if (context.mounted) { + await SaveFileMethod.saveFile( + saveData, + dbType == DatabasesEnum.place + ? AppLocalizations.of(context)!.justplace + : AppLocalizations.of(context)!.excursion, + dbType, + ); + if (context.mounted) Navigator.of(context).pop(); + } + } catch (_) { + // User cancelled the dialog + } setState(() => isLoading = false); } catch (e) { - SnackBarHelper.showSnackBarMessage( - context, - AppLocalizations.of(context)!.savefilefailed, - ); + if (context.mounted) { + Navigator.pop(context); + SnackBarHelper.showSnackBarMessage( + context, + AppLocalizations.of(context)!.savefilefailed, + ); + } } }, child: Text(AppLocalizations.of(context)!.saveasfile), @@ -209,16 +222,20 @@ class AddEntriesDialogHelper { if (!isLoading) TextButton( onPressed: () { - SaveMainEntryMethod.saveEntry( - entryData: saveData, - isTemplate: isTemplate, - dbType: dbType, - ); - Navigator.pushNamedAndRemoveUntil( - context, - '/home', - (route) => false, - ); + try { + SaveMainEntryMethod.saveEntry( + entryData: saveData, + isTemplate: isTemplate, + dbType: dbType, + ); + Navigator.pushNamedAndRemoveUntil( + context, + '/home', + (route) => false, + ); + } catch (e) { + debugPrint(e.toString()); + } }, child: Text(AppLocalizations.of(context)!.justsave), ), @@ -276,7 +293,9 @@ class AddEntriesDialogHelper { child: Text("Ok"), ), TextButton( - onPressed: () {}, + onPressed: () { + Navigator.of(context).pop(); + }, child: Text(AppLocalizations.of(context)!.cancel), ), ], @@ -310,9 +329,7 @@ class AddEntriesDialogHelper { child: Text("Ok"), ), TextButton( - onPressed: () => { - Navigator.of(context).pop() - }, + onPressed: () => {Navigator.of(context).pop()}, child: Text(AppLocalizations.of(context)!.cancel), ), ], diff --git a/lib/screens/sharedMethods/save_file.dart b/lib/screens/sharedMethods/save_file.dart index 8c351d8..7cfbbb3 100644 --- a/lib/screens/sharedMethods/save_file.dart +++ b/lib/screens/sharedMethods/save_file.dart @@ -1,22 +1,37 @@ import 'dart:convert'; import 'dart:io'; +import 'package:fforte/enums/databases.dart'; +import 'package:fforte/screens/excursion/exceptions/file_dialog_cancelled.dart'; import 'package:file_picker/file_picker.dart'; +import 'package:flutter/foundation.dart'; import 'package:shared_preferences/shared_preferences.dart'; class SaveFileMethod { - static Future saveFile(Map place, String fileNameLocalization, String placeID) async { - String? selectedDirectory = await FilePicker.platform.getDirectoryPath(); - SharedPreferences prefs = await SharedPreferences.getInstance(); - String jsonPlace = jsonEncode(place); + static Future saveFile( + Map place, + String fileNameLocalization, + DatabasesEnum dbType, + ) async { + try { + String? selectedDirectory = await FilePicker.platform.getDirectoryPath(); - if (selectedDirectory == null) { - return; + if (selectedDirectory == null) { + throw FileDialogCancelled(); + } + + SharedPreferences prefs = await SharedPreferences.getInstance(); + String jsonPlace = jsonEncode(place); + + await prefs.setString('saveDir', selectedDirectory); + + File file = File( + '$selectedDirectory/$fileNameLocalization-${dbType == DatabasesEnum.place ? place["CID"] : place["LogDat"]}.txt', + ); + + await file.writeAsString(jsonPlace); + } catch (e) { + debugPrint(e.toString()); } - await prefs.setString('saveDir', selectedDirectory); - - File file = File('$selectedDirectory/$fileNameLocalization-$placeID.txt'); - - await file.writeAsString(jsonPlace); } } diff --git a/lib/screens/viewEntries/view_cams.dart b/lib/screens/viewEntries/view_cams.dart index 8021c09..4777d0d 100644 --- a/lib/screens/viewEntries/view_cams.dart +++ b/lib/screens/viewEntries/view_cams.dart @@ -89,7 +89,7 @@ class _ViewEntriesState extends State { Tab(text: AppLocalizations.of(context)!.map), ], ), - title: Text(AppLocalizations.of(context)!.viewplacesappbar), + title: widget.dbType == DatabasesEnum.place ? Text(AppLocalizations.of(context)!.viewplacesappbar) : Text(AppLocalizations.of(context)!.viewExcursionen) , ), body: TabBarView( children: [ diff --git a/pubspec.lock b/pubspec.lock index 722be7a..baa3c91 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -133,10 +133,10 @@ packages: dependency: "direct main" description: name: file_picker - sha256: a222f231db4f822fc49e3b753674bda630e981873c84bf8604bceeb77fce0b24 + sha256: "77f8e81d22d2a07d0dee2c62e1dda71dc1da73bf43bb2d45af09727406167964" url: "https://pub.dev" source: hosted - version: "10.1.7" + version: "10.1.9" fixnum: dependency: transitive description: @@ -174,14 +174,6 @@ packages: url: "https://pub.dev" source: hosted version: "4.5.2" - flutter_file_dialog: - dependency: "direct main" - description: - name: flutter_file_dialog - sha256: "9344b8f07be6a1b6f9854b723fb0cf84a8094ba94761af1d213589d3cb087488" - url: "https://pub.dev" - source: hosted - version: "3.0.2" flutter_lints: dependency: "direct dev" description: diff --git a/pubspec.yaml b/pubspec.yaml index 0e0e9ee..604e2e9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -27,8 +27,7 @@ dependencies: animations: ^2.0.11 flutter_popup_card: ^0.0.5 shared_preferences: ^2.2.2 - flutter_file_dialog: ^3.0.2 - file_picker: ^10.1.7 + file_picker: ^10.1.9 http: ^1.2.1 dio: ^5.4.1 geocoding: ^3.0.0 diff --git a/time.txt b/time.txt index 1f91244..a760877 100644 --- a/time.txt +++ b/time.txt @@ -86,3 +86,4 @@ 17.mai 1h 30min 18.mai 35min 19.mai 2h 15min +20.mai 1h 15min