32 Commits

Author SHA1 Message Date
b3aee85a84 Merge pull request 'development' (#12) from development into main
All checks were successful
Flutter APK Build / Build Flutter APK (push) Successful in 6m42s
Reviewed-on: #12
2026-01-27 14:29:08 +01:00
a984269c15 Merge branch 'main' into development 2026-01-27 14:29:01 +01:00
600ff26016 added action bar for selected bookmark item 2026-01-27 14:16:43 +01:00
9c85d565a9 changed listtile theme 2026-01-27 13:52:14 +01:00
446ef9a57a fixed settings page not updating on storage permission granted
All checks were successful
Flutter APK Build / Build Flutter APK (push) Successful in 6m42s
2026-01-23 18:26:08 +01:00
6103d0b679 Merge branch 'development'
Some checks failed
Flutter APK Build / Build Flutter APK (push) Has been cancelled
2026-01-23 18:24:29 +01:00
5fd690197a fixed workflow running on pull request 2026-01-23 18:21:41 +01:00
31c0ade243 fixed settings page not refreshing on granting storage permission
Some checks failed
Flutter APK Build / Build Flutter APK (pull_request) Has been cancelled
2026-01-23 18:18:25 +01:00
8ec264cebe Merge pull request 'settings-feature' (#7) from settings-feature into main
Some checks failed
Flutter APK Build / Build Flutter APK (push) Has been cancelled
Reviewed-on: #7
2026-01-23 18:04:38 +01:00
83bfdf322b added persisted app settings
Some checks failed
Flutter APK Build / Build Flutter APK (pull_request) Has been cancelled
2026-01-23 18:03:46 +01:00
cad43c7664 added app settings api 2026-01-23 17:02:57 +01:00
5c44574949 created settings model 2026-01-23 16:49:26 +01:00
336be6cb72 visually changed settings page
Some checks failed
Flutter APK Build / Build Flutter APK (pull_request) Has been cancelled
2026-01-23 16:41:53 +01:00
214ae08bb9 fixed wrong return value 2026-01-23 16:41:41 +01:00
100b86d3f9 added list tile content padding 2026-01-23 16:41:29 +01:00
ff1b102047 fixed visual bug 2026-01-23 16:41:16 +01:00
d51f3d4ba7 Merge pull request 'Data import and export' (#6) from development into main
All checks were successful
Flutter APK Build / Build Flutter APK (push) Successful in 7m54s
Reviewed-on: #6
2026-01-22 18:47:02 +01:00
b4016e6e5b localized dialog
All checks were successful
Flutter APK Build / Build Flutter APK (pull_request) Successful in 7m28s
2026-01-22 18:23:05 +01:00
eae4a853e9 removed unnecessary code 2026-01-22 18:20:08 +01:00
8eb4cadc85 Merge pull request 'Json export and import feature' (#5) from json-export-feature into development
Reviewed-on: #5
2026-01-22 18:12:01 +01:00
06c5ca9910 added minimal error handling and user feedback 2026-01-22 18:09:34 +01:00
27c3804b1e removed path provider 2026-01-22 17:52:18 +01:00
debf960d70 simple working json import and export 2026-01-22 17:51:50 +01:00
1029bad20f added localization for settings 2026-01-22 17:16:37 +01:00
cef23a1c83 added constant global values 2026-01-22 17:00:23 +01:00
c4fe32e4b1 replaced file_picker with file_selector 2026-01-22 16:58:33 +01:00
893a1b558f added file picker 2026-01-22 16:44:43 +01:00
b0eebb5ee8 added permission service 2026-01-22 16:28:05 +01:00
06a76afc42 Merge pull request 'Theme changes' (#4) from development into main
All checks were successful
Flutter APK Build / Build Flutter APK (push) Successful in 6m46s
Reviewed-on: #4
2026-01-21 16:38:03 +01:00
dca8c64555 Merge pull request 'small theme changes' (#3) from development into main
All checks were successful
Flutter APK Build / Build Flutter APK (push) Successful in 6m48s
Reviewed-on: #3
2026-01-21 15:05:11 +01:00
1aaea5f6d9 Merge pull request '[fix] Added basic locatlization' (#2) from development into main
All checks were successful
Flutter APK Build / Calculate Version (push) Successful in 13s
Flutter APK Build / Build Flutter APK (push) Successful in 6m34s
Flutter APK Build / Create Release (push) Has been skipped
Reviewed-on: #2
2026-01-21 14:12:41 +01:00
3a54a077f3 Merge pull request '[fix] added bookmark count number to collections page' (#1) from development into main
All checks were successful
Flutter APK Build / Calculate Version (push) Successful in 15s
Flutter APK Build / Build Flutter APK (push) Successful in 6m37s
Flutter APK Build / Create Release (push) Has been skipped
Reviewed-on: #1
2026-01-21 13:20:49 +01:00
20 changed files with 656 additions and 180 deletions

View File

@@ -4,9 +4,6 @@ on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

View File

@@ -0,0 +1,3 @@
const String appName = 'Maps Bookmarks';
const String jsonFileName = 'MapsBookmarksData.json';
const String defaultAndroidExportDirectory = '/storage/emulated/0/Documents';

View File

@@ -25,10 +25,19 @@
"url": "Url",
"description": "Beschreibung",
"settings": "Einstellungen",
"activateJsonExport": "Json-Export aktivieren",
"appData": "App-Daten",
"export": "Exportieren",
"import": "Importieren",
"activateJsonExport": "Immer als JSON speichern",
"@@comment": "Info",
"exportSuccess": "Daten exportiert",
"importSuccess": "Daten importiert",
"@@comment": "Errors",
"errorStoragePermisson": "Zugriff auf Speicher verwehrt",
"errorCouldNotLaunchUrl": "Konnte Url nicht öffnen",
"errorInvalidUrl": "Fehlerhafte Url"
"errorInvalidUrl": "Fehlerhafte Url",
"exportFailed": "Export fehlgeschlagen",
"importFailed": "Import fehlgeschlagen"
}

View File

@@ -25,10 +25,20 @@
"url": "Url",
"description": "Description",
"settings": "Settings",
"activateJsonExport": "Activate json export",
"appData": "App data",
"export": "Export",
"import": "Import",
"activateJsonExport": "Always save to JSON",
"@@comment": "Info",
"exportSuccess": "Exported data",
"importSuccess": "Imported data",
"@@comment": "Errors",
"errorStoragePermisson": "Storage permissions denied",
"errorCouldNotLaunchUrl": "Could not launch Url",
"errorInvalidUrl": "Invalid Url"
"errorInvalidUrl": "Invalid Url",
"exportFailed": "Export failed",
"importFailed": "Import failed"
}

View File

@@ -7,6 +7,7 @@ import 'pages/collections_list_page.dart';
import 'pages/search_page.dart';
import 'pages/settings_page.dart';
import 'service/search_provider.dart';
import 'service/settings_provider.dart';
import 'service/shared_link_provider.dart';
import 'service/storage.dart';
import 'service/share_intent_service.dart';
@@ -20,6 +21,7 @@ void main() async {
providers: [
ChangeNotifierProvider(create: (_) => SharedLinkProvider()),
ChangeNotifierProvider(create: (_) => SearchProvider()),
ChangeNotifierProvider(create: (_) => SettingsProvider()),
],
child: const MapsBookmarks(),
),

39
lib/model/settings.dart Normal file
View File

@@ -0,0 +1,39 @@
import '../assets/constants.dart' as constants;
class Settings {
final String exportDirectoryPath;
final bool alwaysExportEnabled;
Settings._({
required this.exportDirectoryPath,
required this.alwaysExportEnabled,
});
Map<String, dynamic> toJson() {
return {
'exportDirectoryPath': exportDirectoryPath,
'alwaysExportEnabled': alwaysExportEnabled,
};
}
factory Settings.fromJson(Map<String, dynamic> json) {
return Settings._(
exportDirectoryPath: json['exportDirectoryPath'] as String,
alwaysExportEnabled: json['alwaysExportEnabled'] as bool,
);
}
factory Settings.defaults() {
return Settings._(
exportDirectoryPath: constants.defaultAndroidExportDirectory,
alwaysExportEnabled: false,
);
}
Settings copyWith({String? exportDirectoryPath, bool? alwaysExportEnabled}) {
return Settings._(
exportDirectoryPath: exportDirectoryPath ?? this.exportDirectoryPath,
alwaysExportEnabled: alwaysExportEnabled ?? this.alwaysExportEnabled,
);
}
}

View File

@@ -9,6 +9,7 @@ import '../service/notifying.dart';
import '../service/shared_link_provider.dart';
import '../service/storage.dart';
import '../service/url_launcher.dart';
import '../widgets/collection_page_widgets/list_item_actions_widget.dart';
import '../widgets/create_bookmark_dialog.dart';
class CollectionPage extends StatefulWidget {
@@ -22,6 +23,7 @@ class CollectionPage extends StatefulWidget {
class _CollectionPageState extends State<CollectionPage> {
MapsLinkMetadata? selectedMapsLink;
int selectedBookmarkId = -1;
@override
void initState() {
@@ -52,29 +54,46 @@ class _CollectionPageState extends State<CollectionPage> {
).whenComplete(() => setState(() {}));
},
),
);
).whenComplete(deselectBookmark);
void onBookmarkSaved(Bookmark bookmark) {
Storage.addOrUpdateBookmark(bookmark);
setState(() {});
context.read<SharedLinkProvider>().removeCurrentMapsLink();
Provider.of<SharedLinkProvider>(
context,
listen: false,
).removeCurrentMapsLink();
}
Widget bookmarksListItemBuilder(BuildContext context, Bookmark bookmark) {
final selected = selectedBookmarkId == bookmark.id;
return ListTile(
title: Text(bookmark.name),
onTap: () => launchUrlFromString(bookmark.link).then((errorCode) {
if (context.mounted) {
return Notifying.showUrlErrorSnackbar(context, errorCode);
selected: selected,
onTap: () {
if (selected) {
onCancelSelectionPressed();
setState(() {});
} else if (selectedBookmarkId != -1 && !selected) {
selectedBookmarkId = bookmark.id;
setState(() {});
} else {
launchUrlFromString(bookmark.link).then((errorCode) {
if (context.mounted) {
return Notifying.showUrlErrorSnackbar(context, errorCode);
}
});
}
},
onLongPress: () => setState(() {
selectedBookmarkId = bookmark.id;
}),
onLongPress: () => editBookmark(bookmark),
);
}
@override
Widget build(BuildContext context) {
SharedLinkProvider provider = context.watch<SharedLinkProvider>();
SharedLinkProvider provider = Provider.of<SharedLinkProvider>(context);
selectedMapsLink = provider.currentMapsLinkMetadata;
if (BookmarksProvider.selectedCollectionId == null) {
@@ -87,36 +106,69 @@ class _CollectionPageState extends State<CollectionPage> {
(c) => c.id == BookmarksProvider.selectedCollectionId,
);
return Scaffold(
appBar: AppBar(
title: selectedMapsLink != null
? Text(
AppLocalizations.of(context)!.addToCollection(collection.name),
return PopScope(
canPop: selectedBookmarkId == -1,
onPopInvokedWithResult: (didPop, result) {
if (didPop == false) deselectBookmark();
},
child: Scaffold(
appBar: AppBar(
title: selectedMapsLink != null
? Text(
AppLocalizations.of(
context,
)!.addToCollection(collection.name),
)
: Text(collection.name),
actions: [
if (selectedMapsLink != null)
TextButton(
onPressed: () => provider.removeCurrentMapsLink(),
child: Text(AppLocalizations.of(context)!.cancel),
),
],
),
bottomNavigationBar: selectedBookmarkId > 0
? ListItemActionsWidget(
onDeletePressed: onDeleteBookmarkPressed,
onCancelPressed: onCancelSelectionPressed,
onEditPressed: () => editBookmark(
bookmarks.firstWhere(
(element) => element.id == selectedBookmarkId,
),
),
)
: Text(collection.name),
actions: [
if (selectedMapsLink != null)
TextButton(
onPressed: () => provider.removeCurrentMapsLink(),
child: Text(AppLocalizations.of(context)!.cancel),
: null,
body: Center(
child: SizedBox(
width: MediaQuery.of(context).size.width * 0.9,
child: ListView.separated(
itemBuilder: (context, index) =>
bookmarksListItemBuilder(context, bookmarks.elementAt(index)),
itemCount: bookmarks.length,
separatorBuilder: (context, index) => SizedBox(height: 10),
),
],
),
body: Center(
child: SizedBox(
width: MediaQuery.of(context).size.width * 0.9,
child: ListView.separated(
itemBuilder: (context, index) =>
bookmarksListItemBuilder(context, bookmarks.elementAt(index)),
itemCount: bookmarks.length,
separatorBuilder: (context, index) => SizedBox(height: 10),
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: onAddButtonPressed,
child: Icon(selectedMapsLink != null ? Icons.save : Icons.add),
floatingActionButton: FloatingActionButton(
onPressed: onAddButtonPressed,
child: Icon(selectedMapsLink != null ? Icons.save : Icons.add),
),
),
);
}
void onCancelSelectionPressed() => deselectBookmark();
void onDeleteBookmarkPressed() {
Storage.deleteBookmarkById(
selectedBookmarkId,
).whenComplete(() => setState(() {}));
deselectBookmark();
}
void deselectBookmark() {
selectedBookmarkId = -1;
setState(() {});
}
}

View File

@@ -87,7 +87,8 @@ class _CollectionsListPageState extends State<CollectionsListPage> {
final collections = Storage.loadCollections();
bookmarkCountMap = Storage.loadPerCollectionBookmarkCount();
addingNewBookmark =
context.watch<SharedLinkProvider>().currentMapsLinkMetadata != null;
Provider.of<SharedLinkProvider>(context).currentMapsLinkMetadata !=
null;
return Scaffold(
appBar: AppBar(
title: addingNewBookmark
@@ -96,8 +97,10 @@ class _CollectionsListPageState extends State<CollectionsListPage> {
actions: [
if (addingNewBookmark)
TextButton(
onPressed: () =>
context.read<SharedLinkProvider>().removeCurrentMapsLink(),
onPressed: () => Provider.of<SharedLinkProvider>(
context,
listen: false,
).removeCurrentMapsLink(),
child: Text(AppLocalizations.of(context)!.cancel),
)
else

View File

@@ -1,15 +1,191 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart';
import '../l10n/app_localizations.dart';
import '../service/notifying.dart';
import '../service/permission_service.dart';
import '../service/settings_provider.dart';
import '../service/storage.dart';
class SettingsPage extends StatelessWidget {
class SettingsPage extends StatefulWidget {
static const routeName = '/settings';
const SettingsPage({super.key});
@override
State<SettingsPage> createState() => _SettingsPageState();
}
class _SettingsPageState extends State<SettingsPage> {
bool storagePermissionIsGranted = false;
final tileSpacing = 16.0;
@override
void initState() {
PermissionService.storagePermissionStatus.then((value) {
storagePermissionIsGranted = value.isGranted;
if (context.mounted) setState(() {});
});
super.initState();
}
// TODO: Localize
@override
Widget build(BuildContext context) {
final titlePadding = Theme.of(context).listTileTheme.contentPadding!;
checkStoragePermission();
final alwaysExportEnabled = context
.watch<SettingsProvider>()
.settings
.alwaysExportEnabled;
return Scaffold(
appBar: AppBar(title: Text(AppLocalizations.of(context)!.settings)),
body: Center(
child: SizedBox(
width: MediaQuery.of(context).size.width * 0.9,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: titlePadding,
child: Text(
AppLocalizations.of(context)!.appData,
style: Theme.of(context).textTheme.titleLarge,
),
),
SizedBox(height: tileSpacing),
ListTile(
title: Text('Grant storage permisson'),
subtitle: storagePermissionIsGranted
? Text('Storage permission granted')
: Text(
'For app-data settings to work, you need to grant the app permissions to manage internal storage.',
),
onTap: () => PermissionService.requestStoragePermission
.whenComplete(() => checkStoragePermission()),
trailing: Icon(Icons.arrow_forward_ios_rounded),
enabled: !storagePermissionIsGranted,
),
SizedBox(height: tileSpacing),
ListTile(
title: Text(AppLocalizations.of(context)!.import),
subtitle: Text('Import app-data from a json file.'),
onTap: () => onJsonImportPressed(),
trailing: Icon(Icons.arrow_forward_ios_rounded),
enabled: storagePermissionIsGranted,
),
SizedBox(height: tileSpacing),
ListTile(
title: Text(AppLocalizations.of(context)!.export),
subtitle: Text(
'Export app-data to a json file in the selected directory.',
),
onTap: () => onJsonExportPressed(),
trailing: Icon(Icons.arrow_forward_ios_rounded),
enabled: storagePermissionIsGranted,
),
SizedBox(height: tileSpacing),
ListTile(
title: Text('Always save to file'),
subtitle: Text(
'Export app data to a directory, every time you make a change',
),
onTap: () => onAlwaysSaveToJsonPressed(),
trailing: Checkbox(
value: alwaysExportEnabled,
onChanged: (value) {
onAlwaysSaveToJsonPressed();
},
),
enabled: storagePermissionIsGranted,
),
if (alwaysExportEnabled) SizedBox(height: tileSpacing),
if (alwaysExportEnabled)
ListTile(
title: Text('Change export directory'),
subtitle: Text(
context
.watch<SettingsProvider>()
.settings
.exportDirectoryPath,
),
onTap: () => onChangeExportDirectoryPressed(),
trailing: Icon(Icons.arrow_forward_ios_rounded),
enabled: storagePermissionIsGranted,
),
],
),
),
),
);
}
void onJsonExportPressed() async {
if (!await checkStoragePermission()) return;
Storage.exportToJsonFile().then(showExportInfo);
}
void onJsonImportPressed() async {
if (!await checkStoragePermission()) return;
Storage.importFromJsonFile().then(showImportInfo);
}
void onAlwaysSaveToJsonPressed() async {
if (context.read<SettingsProvider>().settings.alwaysExportEnabled) {
context.read<SettingsProvider>().setExportDirectoryPath('', silent: true);
context.read<SettingsProvider>().setAlwaysExportEnabled(false);
return;
}
if (!await PermissionService.storagePermissionStatus.isGranted) return;
final dir = await Storage.selectDirectoryPath();
if (dir.isEmpty || !context.mounted) return;
// ignore: use_build_context_synchronously
context.read<SettingsProvider>().setExportDirectoryPath(dir, silent: true);
// ignore: use_build_context_synchronously
Storage.saveDataToFile().whenComplete(
// ignore: use_build_context_synchronously
() => context.read<SettingsProvider>().setAlwaysExportEnabled(true),
);
}
void onChangeExportDirectoryPressed() async {
if (!await PermissionService.storagePermissionStatus.isGranted) return;
final dir = await Storage.selectDirectoryPath();
if (dir.isEmpty || !context.mounted) return;
// ignore: use_build_context_synchronously
context.read<SettingsProvider>().setExportDirectoryPath(dir);
}
Future<bool> checkStoragePermission() async {
PermissionService.storagePermissionStatus.then((value) {
if (context.mounted && value.isGranted != storagePermissionIsGranted) {
storagePermissionIsGranted = value.isGranted;
setState(() {});
}
});
return storagePermissionIsGranted;
}
void showExportInfo(bool success) => Notifying.showSnackbar(
context,
text: success
? AppLocalizations.of(context)!.exportSuccess
: AppLocalizations.of(context)!.exportFailed,
isError: !success,
);
void showImportInfo(bool success) => Notifying.showSnackbar(
context,
text: success
? AppLocalizations.of(context)!.importSuccess
: AppLocalizations.of(context)!.importFailed,
isError: !success,
);
}

View File

@@ -0,0 +1,90 @@
import 'dart:convert';
import 'dart:io';
import 'package:file_selector/file_selector.dart';
import 'package:flutter/services.dart';
import '../model/bookmark.dart';
import '../model/collection.dart';
import '../assets/constants.dart' as constants;
class JsonFileService {
static Future<bool> exportToJson({
required List<Collection> collections,
required List<Bookmark> bookmarks,
}) async {
try {
final dir = await selectDirectoryPath();
if (dir.isEmpty) return false;
saveDataToFile(collections, bookmarks, dir);
} catch (e) {
return false;
}
return true;
}
static Future<({List<Collection> collections, List<Bookmark> bookmarks})>
importFromJson() async {
try {
const typeGroup = XTypeGroup(label: 'json', extensions: <String>['json']);
final XFile? file = await openFile(
acceptedTypeGroups: <XTypeGroup>[typeGroup],
);
if (file == null) {
return (collections: <Collection>[], bookmarks: <Bookmark>[]);
}
final jsonString = await file.readAsString();
final data = jsonDecode(jsonString) as Map<String, dynamic>;
final collections = (data['collections'] as List<dynamic>? ?? [])
.map((json) => Collection.fromJson(json as Map<String, dynamic>))
.toList();
final bookmarks = (data['bookmarks'] as List<dynamic>? ?? [])
.map((json) => Bookmark.fromJson(json as Map<String, dynamic>))
.toList();
return (collections: collections, bookmarks: bookmarks);
} catch (e) {
return (collections: <Collection>[], bookmarks: <Bookmark>[]);
}
}
static Future<bool> saveDataToFile(
List<Collection> collections,
List<Bookmark> bookmarks,
String directory,
) async {
try {
final data = jsonEncode({
'collections': collections.map((c) => c.toJson()).toList(),
'bookmarks': bookmarks.map((b) => b.toJson()).toList(),
}).codeUnits;
final file = XFile.fromData(
Uint8List.fromList(data),
mimeType: 'application/json',
name: constants.jsonFileName,
);
file.saveTo('$directory/${constants.jsonFileName}');
} catch (e) {
return false;
}
return true;
}
static Future<String> selectDirectoryPath() async {
if (Platform.isAndroid) {
return await getDirectoryPath(
initialDirectory: constants.defaultAndroidExportDirectory,
) ??
'';
}
return await getDirectoryPath() ?? '';
}
}

View File

@@ -1,15 +1,9 @@
// service/maps_launcher_service.dart
import 'dart:io' show Platform;
import 'package:android_intent_plus/android_intent.dart';
class MapsLauncherService {
/// Opens a URL in Google Maps app
/// Falls back to browser if Maps app is not installed
static Future<bool> openInGoogleMaps(String url) async {
if (!Platform.isAndroid) {
// Handle iOS or other platforms if needed
return false;
}
if (!Platform.isAndroid) return false;
try {
// Try to open in Google Maps app
@@ -28,36 +22,16 @@ class MapsLauncherService {
await browserIntent.launch();
return true;
} catch (e) {
print('Failed to open maps link: $e');
return false;
}
}
}
/// Opens navigation to specific coordinates
static Future<bool> navigateToCoordinates(
String latitude,
String longitude,
) async {
final url = 'google.navigation:q=$latitude,$longitude';
return openInGoogleMaps(url);
}
/// Opens a search query in Google Maps
static Future<bool> searchInMaps(String query) async {
final encodedQuery = Uri.encodeComponent(query);
final url = 'geo:0,0?q=$encodedQuery';
return openInGoogleMaps(url);
}
/// Shares a Google Maps link or location via Android share sheet
static Future<bool> shareLocation({
required String text,
String? subject,
}) async {
if (!Platform.isAndroid) {
return false;
}
if (!Platform.isAndroid) return false;
try {
final intent = AndroidIntent(
@@ -72,7 +46,6 @@ class MapsLauncherService {
await intent.launch();
return true;
} catch (e) {
print('Failed to share location: $e');
return false;
}
}

View File

@@ -12,7 +12,7 @@ class Notifying {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
backgroundColor: Theme.of(context).colorScheme.error,
backgroundColor: isError ? Theme.of(context).colorScheme.error : null,
content: SizedBox(
height: 30,
child: Row(
@@ -29,7 +29,7 @@ class Notifying {
ScaffoldMessenger.of(context).hideCurrentSnackBar(),
icon: Icon(
Icons.close_rounded,
color: Theme.of(context).colorScheme.onError,
color: isError ? Theme.of(context).colorScheme.onError : null,
),
),
],
@@ -54,11 +54,11 @@ class Notifying {
showSnackbar(context, text: errorText, isError: true);
}
static void showStoragePermissionErrorSnackbar(BuildContext context) {
showSnackbar(
context,
text: AppLocalizations.of(context)!.errorStoragePermisson,
isError: true,
);
static void showErrorSnackbar(BuildContext context, String message) {
showSnackbar(context, text: message, isError: true);
}
static void showMessageSnackbar(BuildContext context, String message) {
showSnackbar(context, text: message, isError: false);
}
}

View File

@@ -0,0 +1,9 @@
import 'package:permission_handler/permission_handler.dart';
class PermissionService {
static Future<PermissionStatus> get storagePermissionStatus =>
Permission.manageExternalStorage.status;
static Future<PermissionStatus> get requestStoragePermission =>
Permission.manageExternalStorage.request();
}

View File

@@ -0,0 +1,24 @@
import 'package:flutter/material.dart';
import '../model/settings.dart';
import 'storage.dart';
class SettingsProvider extends ChangeNotifier {
SettingsProvider() : _settings = Storage.loadSettings();
Settings _settings;
Settings get settings => _settings;
void setExportDirectoryPath(String path, {bool silent = false}) {
_settings = _settings.copyWith(exportDirectoryPath: path);
Storage.saveSettings(_settings);
if (!silent) notifyListeners();
}
void setAlwaysExportEnabled(bool enabled, {bool silent = false}) {
_settings = _settings.copyWith(alwaysExportEnabled: enabled);
Storage.saveSettings(_settings);
if (!silent) notifyListeners();
}
}

View File

@@ -4,21 +4,49 @@ import 'package:shared_preferences/shared_preferences.dart';
import '../model/bookmark.dart';
import '../model/collection.dart';
import '../model/settings.dart';
import 'json_file_service.dart';
class Storage {
static const String _bookmarksKey = 'bookmarks';
static const String _collectionsKey = 'collections';
static SharedPreferencesWithCache? _prefsWithCache;
static const String _settingsKey = 'settings';
static const String _statsKey = 'stats';
static Settings _currentSettings = Settings.defaults();
static Future<void> initialize() async {
_prefsWithCache = await SharedPreferencesWithCache.create(
cacheOptions: const SharedPreferencesWithCacheOptions(
allowList: <String>{_collectionsKey, _bookmarksKey, _statsKey},
allowList: <String>{
_collectionsKey,
_bookmarksKey,
_statsKey,
_settingsKey,
},
),
);
}
static Settings loadSettings() {
final jsonString = _prefs.getString(_settingsKey);
if (jsonString != null) {
final json = jsonDecode(jsonString) as Map<String, dynamic>;
_currentSettings = Settings.fromJson(json);
return _currentSettings;
} else {
final settings = Settings.defaults();
saveSettings(settings);
return settings;
}
}
static Future<void> saveSettings(Settings settings) {
final json = jsonEncode(settings.toJson());
_currentSettings = settings;
return _prefs.setString(_settingsKey, json);
}
static List<Collection> loadCollections() {
final jsonString = _prefs.getString(_collectionsKey) ?? '[]';
final jsonList = jsonDecode(jsonString) as List;
@@ -38,11 +66,13 @@ class Storage {
static Future<void> saveCollections(List<Collection> collections) async {
final jsonList = collections.map((c) => c.toJson()).toList();
await _prefs.setString(_collectionsKey, jsonEncode(jsonList));
if (_currentSettings.alwaysExportEnabled) saveDataToFile();
}
static Future<void> saveBookmarks(List<Bookmark> bookmarks) async {
final jsonList = bookmarks.map((b) => b.toJson()).toList();
await _prefs.setString(_bookmarksKey, jsonEncode(jsonList));
if (_currentSettings.alwaysExportEnabled) saveDataToFile();
}
static List<Bookmark> loadBookmarksForCollection(int collectionId) {
@@ -155,6 +185,31 @@ class Storage {
await _prefs.setString(_statsKey, jsonEncode(stats));
}
static Future<bool> exportToJsonFile() => JsonFileService.exportToJson(
collections: loadCollections(),
bookmarks: loadBookmarks(),
);
static Future<bool> importFromJsonFile() async {
final import = await JsonFileService.importFromJson();
if (import.bookmarks.isNotEmpty || import.collections.isNotEmpty) {
saveBookmarks(import.bookmarks);
saveCollections(import.collections);
return true;
}
return false;
}
static Future<String> selectDirectoryPath() =>
JsonFileService.selectDirectoryPath();
static Future<bool> saveDataToFile() => JsonFileService.saveDataToFile(
loadCollections(),
loadBookmarks(),
_currentSettings.exportDirectoryPath,
);
static SharedPreferencesWithCache get _prefs {
if (_prefsWithCache == null) {
throw StateError(

View File

@@ -22,5 +22,9 @@ ThemeData _baseTheme(ColorScheme scheme) =>
shape: RoundedRectangleBorder(
borderRadius: BorderRadiusGeometry.circular(12),
),
textColor: scheme.onPrimaryContainer,
selectedTileColor: scheme.primaryContainer,
selectedColor: scheme.onPrimaryContainer,
contentPadding: EdgeInsetsDirectional.only(start: 16.0, end: 24.0),
),
);

View File

@@ -0,0 +1,53 @@
import 'package:flutter/material.dart';
class ListItemActionsWidget extends StatelessWidget {
final VoidCallback _onDeletePressed;
final VoidCallback _onCancelPressed;
final VoidCallback _onEditPressed;
const ListItemActionsWidget({
super.key,
required void Function() onDeletePressed,
required void Function() onCancelPressed,
required void Function() onEditPressed,
}) : _onEditPressed = onEditPressed,
_onCancelPressed = onCancelPressed,
_onDeletePressed = onDeletePressed;
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsetsGeometry.fromLTRB(
10,
10,
10,
MediaQuery.of(context).viewPadding.bottom,
),
color: Theme.of(context).colorScheme.surfaceContainer,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
IconButton(
onPressed: _onCancelPressed,
icon: const Icon(Icons.close_rounded),
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
onPressed: _onDeletePressed,
icon: const Icon(Icons.delete_forever_rounded),
),
IconButton(
onPressed: _onEditPressed,
icon: const Icon(Icons.edit_rounded),
),
],
),
],
),
);
}
}

View File

@@ -1,6 +1,8 @@
import 'package:flutter/material.dart' show TextButton, Theme;
import 'package:flutter/widgets.dart';
import '../../l10n/app_localizations.dart';
class EditDialogTitle extends StatelessWidget {
const EditDialogTitle({
super.key,
@@ -15,11 +17,10 @@ class EditDialogTitle extends StatelessWidget {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
// TODO: Localize
if (dialogType == DialogType.bookmark)
Text('Create Bookmark')
Text(AppLocalizations.of(context)!.createBookmark)
else
Text('Create Collection'),
Text(AppLocalizations.of(context)!.createCollection),
if (onDeletePressed != null)
TextButton(
@@ -28,7 +29,7 @@ class EditDialogTitle extends StatelessWidget {
Navigator.of(context).pop();
},
child: Text(
'Delete',
AppLocalizations.of(context)!.delete,
style: TextStyle(color: Theme.of(context).colorScheme.error),
),
),

View File

@@ -41,14 +41,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.2"
code_assets:
dependency: transitive
description:
name: code_assets
sha256: "83ccdaa064c980b5596c35dd64a8d3ecc68620174ab9b90b6343b753aa721687"
url: "https://pub.dev"
source: hosted
version: "1.0.0"
collection:
dependency: transitive
description:
@@ -57,14 +49,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.19.1"
crypto:
cross_file:
dependency: transitive
description:
name: crypto
sha256: c8ea0233063ba03258fbcf2ca4d6dadfefe14f02fab57702265467a19f27fadf
name: cross_file
sha256: "701dcfc06da0882883a2657c445103380e53e647060ad8d9dfb710c100996608"
url: "https://pub.dev"
source: hosted
version: "3.0.7"
version: "0.3.5+1"
csslib:
dependency: transitive
description:
@@ -105,6 +97,70 @@ packages:
url: "https://pub.dev"
source: hosted
version: "7.0.1"
file_selector:
dependency: "direct main"
description:
name: file_selector
sha256: bd15e43e9268db636b53eeaca9f56324d1622af30e5c34d6e267649758c84d9a
url: "https://pub.dev"
source: hosted
version: "1.1.0"
file_selector_android:
dependency: transitive
description:
name: file_selector_android
sha256: "51e8fd0446de75e4b62c065b76db2210c704562d072339d333bd89c57a7f8a7c"
url: "https://pub.dev"
source: hosted
version: "0.5.2+4"
file_selector_ios:
dependency: transitive
description:
name: file_selector_ios
sha256: e2ecf2885c121691ce13b60db3508f53c01f869fb6e8dc5c1cfa771e4c46aeca
url: "https://pub.dev"
source: hosted
version: "0.5.3+5"
file_selector_linux:
dependency: transitive
description:
name: file_selector_linux
sha256: "2567f398e06ac72dcf2e98a0c95df2a9edd03c2c2e0cacd4780f20cdf56263a0"
url: "https://pub.dev"
source: hosted
version: "0.9.4"
file_selector_macos:
dependency: transitive
description:
name: file_selector_macos
sha256: "5e0bbe9c312416f1787a68259ea1505b52f258c587f12920422671807c4d618a"
url: "https://pub.dev"
source: hosted
version: "0.9.5"
file_selector_platform_interface:
dependency: transitive
description:
name: file_selector_platform_interface
sha256: "35e0bd61ebcdb91a3505813b055b09b79dfdc7d0aee9c09a7ba59ae4bb13dc85"
url: "https://pub.dev"
source: hosted
version: "2.7.0"
file_selector_web:
dependency: transitive
description:
name: file_selector_web
sha256: c4c0ea4224d97a60a7067eca0c8fd419e708ff830e0c83b11a48faf566cec3e7
url: "https://pub.dev"
source: hosted
version: "0.9.4+2"
file_selector_windows:
dependency: transitive
description:
name: file_selector_windows
sha256: "62197474ae75893a62df75939c777763d39c2bc5f73ce5b88497208bc269abfd"
url: "https://pub.dev"
source: hosted
version: "0.9.3+5"
flutter:
dependency: "direct main"
description: flutter
@@ -133,22 +189,6 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
glob:
dependency: transitive
description:
name: glob
sha256: c3f1ee72c96f8f78935e18aa8cecced9ab132419e8625dc187e1c2408efc20de
url: "https://pub.dev"
source: hosted
version: "2.1.3"
hooks:
dependency: transitive
description:
name: hooks
sha256: "5d309c86e7ce34cd8e37aa71cb30cb652d3829b900ab145e4d9da564b31d59f7"
url: "https://pub.dev"
source: hosted
version: "1.0.0"
html:
dependency: transitive
description:
@@ -213,14 +253,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.0.0"
logging:
dependency: transitive
description:
name: logging
sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61
url: "https://pub.dev"
source: hosted
version: "1.3.0"
matcher:
dependency: transitive
description:
@@ -253,14 +285,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.4.2"
native_toolchain_c:
dependency: transitive
description:
name: native_toolchain_c
sha256: "89e83885ba09da5fdf2cdacc8002a712ca238c28b7f717910b34bcd27b0d03ac"
url: "https://pub.dev"
source: hosted
version: "0.17.4"
nested:
dependency: transitive
description:
@@ -269,14 +293,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.0"
objective_c:
dependency: transitive
description:
name: objective_c
sha256: "9922a1ad59ac5afb154cc948aa6ded01987a75003651d0a2866afc23f4da624e"
url: "https://pub.dev"
source: hosted
version: "9.2.3"
path:
dependency: transitive
description:
@@ -285,30 +301,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.9.1"
path_provider:
dependency: "direct main"
description:
name: path_provider
sha256: "50c5dd5b6e1aaf6fb3a78b33f6aa3afca52bf903a8a5298f53101fdaee55bbcd"
url: "https://pub.dev"
source: hosted
version: "2.1.5"
path_provider_android:
dependency: transitive
description:
name: path_provider_android
sha256: f2c65e21139ce2c3dad46922be8272bb5963516045659e71bb16e151c93b580e
url: "https://pub.dev"
source: hosted
version: "2.2.22"
path_provider_foundation:
dependency: transitive
description:
name: path_provider_foundation
sha256: "2a376b7d6392d80cd3705782d2caa734ca4727776db0b6ec36ef3f1855197699"
url: "https://pub.dev"
source: hosted
version: "2.6.0"
path_provider_linux:
dependency: transitive
description:
@@ -405,14 +397,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.1.5+1"
pub_semver:
dependency: transitive
description:
name: pub_semver
sha256: "5bfcf68ca79ef689f8990d1160781b4bad40a3bd5e5218ad4076ddb7f4081585"
url: "https://pub.dev"
source: hosted
version: "2.2.0"
shared_preferences:
dependency: "direct main"
description:
@@ -634,14 +618,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.0"
yaml:
dependency: transitive
description:
name: yaml
sha256: b9da305ac7c39faa3f030eccd175340f968459dae4af175130b3fc47e40d76ce
url: "https://pub.dev"
source: hosted
version: "3.1.3"
sdks:
dart: ">=3.10.3 <4.0.0"
flutter: ">=3.38.4"
dart: ">=3.10.0 <4.0.0"
flutter: ">=3.38.0"

View File

@@ -21,8 +21,8 @@ dependencies:
flutter_localizations:
sdk: flutter
intl: any
path_provider: ^2.1.5
permission_handler: ^12.0.1
file_selector: ^1.1.0
dev_dependencies:
flutter_test: