8 Commits

Author SHA1 Message Date
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
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
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
8 changed files with 218 additions and 74 deletions

View File

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

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

@@ -17,55 +17,90 @@ class SettingsPage extends StatefulWidget {
}
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();
}
@override
Widget build(BuildContext context) {
final titlePadding = Theme.of(context).listTileTheme.contentPadding!;
checkStoragePermission();
return Scaffold(
appBar: AppBar(title: Text(AppLocalizations.of(context)!.settings)),
body: SizedBox(
width: MediaQuery.of(context).size.width * 0.9,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
AppLocalizations.of(context)!.appData,
style: Theme.of(context).textTheme.titleLarge,
),
ElevatedButton(
onPressed: () => onActivateJsonImportPressed(),
child: Text(AppLocalizations.of(context)!.import),
),
ElevatedButton(
onPressed: () => onActivateJsonExportPressed(),
child: Text(AppLocalizations.of(context)!.export),
),
],
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: 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: () => onActivateJsonImportPressed(),
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: () => onActivateJsonExportPressed(),
trailing: Icon(Icons.arrow_forward_ios_rounded),
enabled: storagePermissionIsGranted,
),
],
),
),
),
);
}
void onActivateJsonExportPressed() async {
if (!await checkStoragePermission) return;
if (!await PermissionService.storagePermissionStatus.isGranted) return;
Storage.exportToJsonFile().then(showExportInfo);
}
void onActivateJsonImportPressed() async {
if (!await checkStoragePermission) return;
if (!await PermissionService.storagePermissionStatus.isGranted) return;
Storage.importFromJsonFile().then(showImportInfo);
}
Future<bool> get checkStoragePermission async {
if (!(await PermissionService.requestStoragePermission).isGranted) {
if (mounted) {
Notifying.showErrorSnackbar(
context,
AppLocalizations.of(context)!.errorStoragePermisson,
);
return false;
Future<void> checkStoragePermission() async {
PermissionService.storagePermissionStatus.then((value) {
storagePermissionIsGranted = value.isGranted;
if (context.mounted && value.isGranted != storagePermissionIsGranted) {
setState(() {});
}
}
return true;
});
}
void showExportInfo(bool success) => Notifying.showSnackbar(
@@ -73,7 +108,7 @@ class _SettingsPageState extends State<SettingsPage> {
text: success
? AppLocalizations.of(context)!.exportSuccess
: AppLocalizations.of(context)!.exportFailed,
isError: success,
isError: !success,
);
void showImportInfo(bool success) => Notifying.showSnackbar(
@@ -81,6 +116,6 @@ class _SettingsPageState extends State<SettingsPage> {
text: success
? AppLocalizations.of(context)!.importSuccess
: AppLocalizations.of(context)!.importFailed,
isError: success,
isError: !success,
);
}

View File

@@ -32,7 +32,7 @@ class JsonFileService {
} catch (e) {
return false;
}
return false;
return true;
}
static Future<({List<Collection> collections, List<Bookmark> bookmarks})>

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,
),
),
],

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),
),
],
),
],
),
);
}
}