Compare commits
2 Commits
5fd690197a
...
600ff26016
| Author | SHA1 | Date | |
|---|---|---|---|
| 600ff26016 | |||
| 9c85d565a9 |
@@ -9,6 +9,7 @@ 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 {
|
||||||
@@ -22,6 +23,7 @@ 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() {
|
||||||
@@ -52,29 +54,46 @@ 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(() {});
|
||||||
context.read<SharedLinkProvider>().removeCurrentMapsLink();
|
Provider.of<SharedLinkProvider>(
|
||||||
|
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),
|
||||||
onTap: () => launchUrlFromString(bookmark.link).then((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) {
|
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 = context.watch<SharedLinkProvider>();
|
SharedLinkProvider provider = Provider.of<SharedLinkProvider>(context);
|
||||||
selectedMapsLink = provider.currentMapsLinkMetadata;
|
selectedMapsLink = provider.currentMapsLinkMetadata;
|
||||||
|
|
||||||
if (BookmarksProvider.selectedCollectionId == null) {
|
if (BookmarksProvider.selectedCollectionId == null) {
|
||||||
@@ -87,11 +106,18 @@ class _CollectionPageState extends State<CollectionPage> {
|
|||||||
(c) => c.id == BookmarksProvider.selectedCollectionId,
|
(c) => c.id == BookmarksProvider.selectedCollectionId,
|
||||||
);
|
);
|
||||||
|
|
||||||
return Scaffold(
|
return PopScope(
|
||||||
|
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(context)!.addToCollection(collection.name),
|
AppLocalizations.of(
|
||||||
|
context,
|
||||||
|
)!.addToCollection(collection.name),
|
||||||
)
|
)
|
||||||
: Text(collection.name),
|
: Text(collection.name),
|
||||||
actions: [
|
actions: [
|
||||||
@@ -102,6 +128,17 @@ 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,
|
||||||
@@ -117,6 +154,21 @@ 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,7 +87,8 @@ class _CollectionsListPageState extends State<CollectionsListPage> {
|
|||||||
final collections = Storage.loadCollections();
|
final collections = Storage.loadCollections();
|
||||||
bookmarkCountMap = Storage.loadPerCollectionBookmarkCount();
|
bookmarkCountMap = Storage.loadPerCollectionBookmarkCount();
|
||||||
addingNewBookmark =
|
addingNewBookmark =
|
||||||
context.watch<SharedLinkProvider>().currentMapsLinkMetadata != null;
|
Provider.of<SharedLinkProvider>(context).currentMapsLinkMetadata !=
|
||||||
|
null;
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: addingNewBookmark
|
title: addingNewBookmark
|
||||||
@@ -96,8 +97,10 @@ class _CollectionsListPageState extends State<CollectionsListPage> {
|
|||||||
actions: [
|
actions: [
|
||||||
if (addingNewBookmark)
|
if (addingNewBookmark)
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () =>
|
onPressed: () => Provider.of<SharedLinkProvider>(
|
||||||
context.read<SharedLinkProvider>().removeCurrentMapsLink(),
|
context,
|
||||||
|
listen: false,
|
||||||
|
).removeCurrentMapsLink(),
|
||||||
child: Text(AppLocalizations.of(context)!.cancel),
|
child: Text(AppLocalizations.of(context)!.cancel),
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ 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),
|
contentPadding: EdgeInsetsDirectional.only(start: 16.0, end: 24.0),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -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),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user