Compare commits
5 Commits
600ff26016
...
v0.1.28
| Author | SHA1 | Date | |
|---|---|---|---|
| d51f3d4ba7 | |||
| 06a76afc42 | |||
| dca8c64555 | |||
| 1aaea5f6d9 | |||
| 3a54a077f3 |
@@ -4,6 +4,9 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import '../service/notifying.dart';
|
|||||||
import '../service/shared_link_provider.dart';
|
import '../service/shared_link_provider.dart';
|
||||||
import '../service/storage.dart';
|
import '../service/storage.dart';
|
||||||
import '../service/url_launcher.dart';
|
import '../service/url_launcher.dart';
|
||||||
import '../widgets/collection_page_widgets/list_item_actions_widget.dart';
|
|
||||||
import '../widgets/create_bookmark_dialog.dart';
|
import '../widgets/create_bookmark_dialog.dart';
|
||||||
|
|
||||||
class CollectionPage extends StatefulWidget {
|
class CollectionPage extends StatefulWidget {
|
||||||
@@ -23,7 +22,6 @@ class CollectionPage extends StatefulWidget {
|
|||||||
|
|
||||||
class _CollectionPageState extends State<CollectionPage> {
|
class _CollectionPageState extends State<CollectionPage> {
|
||||||
MapsLinkMetadata? selectedMapsLink;
|
MapsLinkMetadata? selectedMapsLink;
|
||||||
int selectedBookmarkId = -1;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -54,46 +52,29 @@ class _CollectionPageState extends State<CollectionPage> {
|
|||||||
).whenComplete(() => setState(() {}));
|
).whenComplete(() => setState(() {}));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
).whenComplete(deselectBookmark);
|
);
|
||||||
|
|
||||||
void onBookmarkSaved(Bookmark bookmark) {
|
void onBookmarkSaved(Bookmark bookmark) {
|
||||||
Storage.addOrUpdateBookmark(bookmark);
|
Storage.addOrUpdateBookmark(bookmark);
|
||||||
setState(() {});
|
setState(() {});
|
||||||
Provider.of<SharedLinkProvider>(
|
context.read<SharedLinkProvider>().removeCurrentMapsLink();
|
||||||
context,
|
|
||||||
listen: false,
|
|
||||||
).removeCurrentMapsLink();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget bookmarksListItemBuilder(BuildContext context, Bookmark bookmark) {
|
Widget bookmarksListItemBuilder(BuildContext context, Bookmark bookmark) {
|
||||||
final selected = selectedBookmarkId == bookmark.id;
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(bookmark.name),
|
title: Text(bookmark.name),
|
||||||
selected: selected,
|
onTap: () => launchUrlFromString(bookmark.link).then((errorCode) {
|
||||||
onTap: () {
|
|
||||||
if (selected) {
|
|
||||||
onCancelSelectionPressed();
|
|
||||||
setState(() {});
|
|
||||||
} else if (selectedBookmarkId != -1 && !selected) {
|
|
||||||
selectedBookmarkId = bookmark.id;
|
|
||||||
setState(() {});
|
|
||||||
} else {
|
|
||||||
launchUrlFromString(bookmark.link).then((errorCode) {
|
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
return Notifying.showUrlErrorSnackbar(context, errorCode);
|
return Notifying.showUrlErrorSnackbar(context, errorCode);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onLongPress: () => setState(() {
|
|
||||||
selectedBookmarkId = bookmark.id;
|
|
||||||
}),
|
}),
|
||||||
|
onLongPress: () => editBookmark(bookmark),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
SharedLinkProvider provider = Provider.of<SharedLinkProvider>(context);
|
SharedLinkProvider provider = context.watch<SharedLinkProvider>();
|
||||||
selectedMapsLink = provider.currentMapsLinkMetadata;
|
selectedMapsLink = provider.currentMapsLinkMetadata;
|
||||||
|
|
||||||
if (BookmarksProvider.selectedCollectionId == null) {
|
if (BookmarksProvider.selectedCollectionId == null) {
|
||||||
@@ -106,18 +87,11 @@ class _CollectionPageState extends State<CollectionPage> {
|
|||||||
(c) => c.id == BookmarksProvider.selectedCollectionId,
|
(c) => c.id == BookmarksProvider.selectedCollectionId,
|
||||||
);
|
);
|
||||||
|
|
||||||
return PopScope(
|
return Scaffold(
|
||||||
canPop: selectedBookmarkId == -1,
|
|
||||||
onPopInvokedWithResult: (didPop, result) {
|
|
||||||
if (didPop == false) deselectBookmark();
|
|
||||||
},
|
|
||||||
child: Scaffold(
|
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: selectedMapsLink != null
|
title: selectedMapsLink != null
|
||||||
? Text(
|
? Text(
|
||||||
AppLocalizations.of(
|
AppLocalizations.of(context)!.addToCollection(collection.name),
|
||||||
context,
|
|
||||||
)!.addToCollection(collection.name),
|
|
||||||
)
|
)
|
||||||
: Text(collection.name),
|
: Text(collection.name),
|
||||||
actions: [
|
actions: [
|
||||||
@@ -128,17 +102,6 @@ class _CollectionPageState extends State<CollectionPage> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
bottomNavigationBar: selectedBookmarkId > 0
|
|
||||||
? ListItemActionsWidget(
|
|
||||||
onDeletePressed: onDeleteBookmarkPressed,
|
|
||||||
onCancelPressed: onCancelSelectionPressed,
|
|
||||||
onEditPressed: () => editBookmark(
|
|
||||||
bookmarks.firstWhere(
|
|
||||||
(element) => element.id == selectedBookmarkId,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: null,
|
|
||||||
body: Center(
|
body: Center(
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: MediaQuery.of(context).size.width * 0.9,
|
width: MediaQuery.of(context).size.width * 0.9,
|
||||||
@@ -154,21 +117,6 @@ class _CollectionPageState extends State<CollectionPage> {
|
|||||||
onPressed: onAddButtonPressed,
|
onPressed: onAddButtonPressed,
|
||||||
child: Icon(selectedMapsLink != null ? Icons.save : Icons.add),
|
child: Icon(selectedMapsLink != null ? Icons.save : Icons.add),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onCancelSelectionPressed() => deselectBookmark();
|
|
||||||
|
|
||||||
void onDeleteBookmarkPressed() {
|
|
||||||
Storage.deleteBookmarkById(
|
|
||||||
selectedBookmarkId,
|
|
||||||
).whenComplete(() => setState(() {}));
|
|
||||||
deselectBookmark();
|
|
||||||
}
|
|
||||||
|
|
||||||
void deselectBookmark() {
|
|
||||||
selectedBookmarkId = -1;
|
|
||||||
setState(() {});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,8 +87,7 @@ class _CollectionsListPageState extends State<CollectionsListPage> {
|
|||||||
final collections = Storage.loadCollections();
|
final collections = Storage.loadCollections();
|
||||||
bookmarkCountMap = Storage.loadPerCollectionBookmarkCount();
|
bookmarkCountMap = Storage.loadPerCollectionBookmarkCount();
|
||||||
addingNewBookmark =
|
addingNewBookmark =
|
||||||
Provider.of<SharedLinkProvider>(context).currentMapsLinkMetadata !=
|
context.watch<SharedLinkProvider>().currentMapsLinkMetadata != null;
|
||||||
null;
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: addingNewBookmark
|
title: addingNewBookmark
|
||||||
@@ -97,10 +96,8 @@ class _CollectionsListPageState extends State<CollectionsListPage> {
|
|||||||
actions: [
|
actions: [
|
||||||
if (addingNewBookmark)
|
if (addingNewBookmark)
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Provider.of<SharedLinkProvider>(
|
onPressed: () =>
|
||||||
context,
|
context.read<SharedLinkProvider>().removeCurrentMapsLink(),
|
||||||
listen: false,
|
|
||||||
).removeCurrentMapsLink(),
|
|
||||||
child: Text(AppLocalizations.of(context)!.cancel),
|
child: Text(AppLocalizations.of(context)!.cancel),
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -17,90 +17,55 @@ class SettingsPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _SettingsPageState extends State<SettingsPage> {
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final titlePadding = Theme.of(context).listTileTheme.contentPadding!;
|
|
||||||
checkStoragePermission();
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(title: Text(AppLocalizations.of(context)!.settings)),
|
appBar: AppBar(title: Text(AppLocalizations.of(context)!.settings)),
|
||||||
body: Center(
|
body: SizedBox(
|
||||||
child: SizedBox(
|
|
||||||
width: MediaQuery.of(context).size.width * 0.9,
|
width: MediaQuery.of(context).size.width * 0.9,
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
Text(
|
||||||
padding: titlePadding,
|
|
||||||
child: Text(
|
|
||||||
AppLocalizations.of(context)!.appData,
|
AppLocalizations.of(context)!.appData,
|
||||||
style: Theme.of(context).textTheme.titleLarge,
|
style: Theme.of(context).textTheme.titleLarge,
|
||||||
),
|
),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () => onActivateJsonImportPressed(),
|
||||||
|
child: Text(AppLocalizations.of(context)!.import),
|
||||||
),
|
),
|
||||||
SizedBox(height: tileSpacing),
|
ElevatedButton(
|
||||||
ListTile(
|
onPressed: () => onActivateJsonExportPressed(),
|
||||||
title: Text('Grant storage permisson'),
|
child: Text(AppLocalizations.of(context)!.export),
|
||||||
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 {
|
void onActivateJsonExportPressed() async {
|
||||||
if (!await PermissionService.storagePermissionStatus.isGranted) return;
|
if (!await checkStoragePermission) return;
|
||||||
|
|
||||||
Storage.exportToJsonFile().then(showExportInfo);
|
Storage.exportToJsonFile().then(showExportInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onActivateJsonImportPressed() async {
|
void onActivateJsonImportPressed() async {
|
||||||
if (!await PermissionService.storagePermissionStatus.isGranted) return;
|
if (!await checkStoragePermission) return;
|
||||||
Storage.importFromJsonFile().then(showImportInfo);
|
Storage.importFromJsonFile().then(showImportInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> checkStoragePermission() async {
|
Future<bool> get checkStoragePermission async {
|
||||||
PermissionService.storagePermissionStatus.then((value) {
|
if (!(await PermissionService.requestStoragePermission).isGranted) {
|
||||||
storagePermissionIsGranted = value.isGranted;
|
if (mounted) {
|
||||||
if (context.mounted && value.isGranted != storagePermissionIsGranted) {
|
Notifying.showErrorSnackbar(
|
||||||
setState(() {});
|
context,
|
||||||
|
AppLocalizations.of(context)!.errorStoragePermisson,
|
||||||
|
);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void showExportInfo(bool success) => Notifying.showSnackbar(
|
void showExportInfo(bool success) => Notifying.showSnackbar(
|
||||||
@@ -108,7 +73,7 @@ class _SettingsPageState extends State<SettingsPage> {
|
|||||||
text: success
|
text: success
|
||||||
? AppLocalizations.of(context)!.exportSuccess
|
? AppLocalizations.of(context)!.exportSuccess
|
||||||
: AppLocalizations.of(context)!.exportFailed,
|
: AppLocalizations.of(context)!.exportFailed,
|
||||||
isError: !success,
|
isError: success,
|
||||||
);
|
);
|
||||||
|
|
||||||
void showImportInfo(bool success) => Notifying.showSnackbar(
|
void showImportInfo(bool success) => Notifying.showSnackbar(
|
||||||
@@ -116,6 +81,6 @@ class _SettingsPageState extends State<SettingsPage> {
|
|||||||
text: success
|
text: success
|
||||||
? AppLocalizations.of(context)!.importSuccess
|
? AppLocalizations.of(context)!.importSuccess
|
||||||
: AppLocalizations.of(context)!.importFailed,
|
: AppLocalizations.of(context)!.importFailed,
|
||||||
isError: !success,
|
isError: success,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class JsonFileService {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<({List<Collection> collections, List<Bookmark> bookmarks})>
|
static Future<({List<Collection> collections, List<Bookmark> bookmarks})>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class Notifying {
|
|||||||
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
backgroundColor: isError ? Theme.of(context).colorScheme.error : null,
|
backgroundColor: Theme.of(context).colorScheme.error,
|
||||||
content: SizedBox(
|
content: SizedBox(
|
||||||
height: 30,
|
height: 30,
|
||||||
child: Row(
|
child: Row(
|
||||||
@@ -29,7 +29,7 @@ class Notifying {
|
|||||||
ScaffoldMessenger.of(context).hideCurrentSnackBar(),
|
ScaffoldMessenger.of(context).hideCurrentSnackBar(),
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
Icons.close_rounded,
|
Icons.close_rounded,
|
||||||
color: isError ? Theme.of(context).colorScheme.onError : null,
|
color: Theme.of(context).colorScheme.onError,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -22,9 +22,5 @@ ThemeData _baseTheme(ColorScheme scheme) =>
|
|||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadiusGeometry.circular(12),
|
borderRadius: BorderRadiusGeometry.circular(12),
|
||||||
),
|
),
|
||||||
textColor: scheme.onPrimaryContainer,
|
|
||||||
selectedTileColor: scheme.primaryContainer,
|
|
||||||
selectedColor: scheme.onPrimaryContainer,
|
|
||||||
contentPadding: EdgeInsetsDirectional.only(start: 16.0, end: 24.0),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
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),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user