34 Commits

Author SHA1 Message Date
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
c80606b7d0 changed appearance of lists
All checks were successful
Flutter APK Build / Build Flutter APK (pull_request) Successful in 6m44s
2026-01-21 15:04:24 +01:00
be6020d6c5 added label text 2026-01-21 14:44:36 +01:00
5eb58d7cf2 Changed theme to globally enable rounded borders for textfields 2026-01-21 14:43:02 +01:00
306a38a36a revert workflow to a working state 2026-01-21 14:30:25 +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
99a8aaa409 added localizations
Some checks failed
Flutter APK Build / Calculate Version (pull_request) Successful in 15s
Flutter APK Build / Create Release (pull_request) Has been cancelled
Flutter APK Build / Build Flutter APK (pull_request) Has been cancelled
2026-01-21 14:11:50 +01:00
85d57c6e1c changed workflow to support pull requests 2026-01-21 14:06:06 +01:00
77a647d17d [fix] Added basic locatlization
All checks were successful
Flutter APK Build / Calculate Version (pull_request) Successful in 14s
Flutter APK Build / Build Flutter APK (pull_request) Successful in 6m35s
Flutter APK Build / Create Release (pull_request) Has been skipped
2026-01-21 13:50:24 +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
cf88a9a371 added bookmark count number in collections view
All checks were successful
Flutter APK Build / Calculate Version (pull_request) Successful in 12s
Flutter APK Build / Build Flutter APK (pull_request) Successful in 6m38s
Flutter APK Build / Create Release (pull_request) Has been skipped
2026-01-21 13:19:45 +01:00
5feb535cf3 changed app version 2026-01-21 13:19:13 +01:00
2d23207497 added automatic versioning in workflow 2026-01-21 12:40:52 +01:00
c7c5b3682d added functionality to clear search text
All checks were successful
Flutter APK Build / Build Flutter APK (push) Successful in 6m38s
2026-01-21 12:27:52 +01:00
321a310add added function to remove search text 2026-01-21 12:16:37 +01:00
3bc7d713dd changed version number
All checks were successful
Flutter APK Build / Build Flutter APK (push) Successful in 6m31s
2026-01-19 23:09:14 +01:00
1d9ace45a1 added automated release
Some checks failed
Flutter APK Build / Build Flutter APK (push) Failing after 17s
2026-01-19 23:05:51 +01:00
588843a989 changed android sdk version
All checks were successful
Flutter APK Build / Build Flutter APK (push) Successful in 6m32s
2026-01-19 22:47:35 +01:00
f780638269 setup android sdk
Some checks failed
Flutter APK Build / Build Flutter APK (push) Has been cancelled
2026-01-19 22:41:39 +01:00
37447b4a53 changed flutter setup
Some checks failed
Flutter APK Build / Build Flutter APK (push) Failing after 30s
2026-01-19 22:38:49 +01:00
c283de7a45 specified url
Some checks failed
Flutter APK Build / Build Flutter APK (push) Failing after 31s
2026-01-19 22:36:11 +01:00
483db8bfbd added 'uses' clause for flutter-action
Some checks failed
Flutter APK Build / Build Flutter APK (push) Failing after 18s
2026-01-19 22:34:06 +01:00
a4d471dc62 added permissons and commented out cache
Some checks failed
Flutter APK Build / Build Flutter APK (push) Failing after 19s
2026-01-19 22:29:55 +01:00
970d78943b added pub cache and changed java version
Some checks failed
Flutter APK Build / Build Flutter APK (push) Failing after 5m58s
2026-01-19 22:21:13 +01:00
a66c25c784 removed flutter version
Some checks failed
Flutter APK Build / Build Flutter APK (push) Failing after 3m4s
2026-01-19 22:15:44 +01:00
609a477b75 changed build runner script to a static flutter version
Some checks failed
Flutter APK Build / Build Flutter APK (push) Failing after 2m24s
2026-01-19 22:05:52 +01:00
6d847aa2bb gitea workflow for automated building
Some checks failed
Flutter APK Build / Build Flutter APK (push) Failing after 3m23s
2026-01-19 20:19:54 +01:00
f0b3c11e63 refactored search function using provider 2026-01-19 18:25:02 +01:00
143206cd72 added simple search feature 2026-01-14 22:49:32 +01:00
36e4eaee17 encapsulated snackbar call on error 2026-01-14 22:25:08 +01:00
11a43a39fa added search page 2026-01-14 21:58:39 +01:00
c0f92fac58 added error handling for invalid urls 2026-01-14 20:50:36 +01:00
be6a44e7f0 added abilty to edit and delete collections 2026-01-14 20:29:15 +01:00
36e035c09c changed delete button placement 2026-01-14 16:06:25 +01:00
25 changed files with 1061 additions and 181 deletions

View File

@@ -0,0 +1,71 @@
name: Flutter APK Build
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
permissions:
contents: write
actions: read
jobs:
build_apk:
name: Build Flutter APK
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Java (Temurin 17)
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: '17'
- name: Setup Android SDK
uses: android-actions/setup-android@v3
with:
packages: "platform-tools platforms;android-36 build-tools;36.0.0"
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
- run: flutter --version
- run: flutter doctor
- name: Get dependencies
run: flutter pub get
- name: Build APK
run: flutter build apk --release
- name: Upload APK artifact
uses: actions/upload-artifact@v3
with:
name: flutter-apk
path: build/app/outputs/flutter-apk/app-release.apk
retention-days: 30
- name: Create Gitea release
uses: akkuman/gitea-release-action@v1
env:
GITEA_TOKEN: ${{ secrets.RUNNER_CREATE_RELEASE }}
with:
tag_name: "v0.1.${{ github.run_number }}"
name: "Flutter Android v0.1.${{ github.run_number }}"
body: "Automated build from CI"
draft: false
prerelease: false
files: |
build/app/outputs/flutter-apk/app-release.apk
gitea_url: "https://git.skup.in"
owner: "marco"
repo: "maps_bookmarks"

3
l10n.yaml Normal file
View File

@@ -0,0 +1,3 @@
arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart

27
lib/l10n/app_de.arb Normal file
View File

@@ -0,0 +1,27 @@
{
"@@locale": "de",
"addToCollection": "Speichern in {collection_name}",
"@addToCollection": {
"placeholders": {
"collection_name" : {
"type": "String"
}
}
},
"cancel": "Abbrechen",
"chooseCollection": "Sammlung auswählen",
"collections": "Sammlungen",
"tipCreateCollections": "Erstelle deine erste Sammlung!",
"search": "Suche",
"createBookmark": "Lesezeichen erstellen",
"createCollection": "Sammlung erstellen",
"create": "Erstellen",
"delete": "Löschen",
"add": "Hinzufügen",
"startSearching": "Suche etwas",
"tipNoResults": "Keine Suchergebnisse gefunden",
"collectionName": "Name der Sammlung",
"bookmarkTitle": "Titel des Lesezeichens",
"url": "Url",
"description": "Beschreibung"
}

27
lib/l10n/app_en.arb Normal file
View File

@@ -0,0 +1,27 @@
{
"@@locale": "en",
"addToCollection": "Add to {collection_name}",
"@addToCollection": {
"placeholders": {
"collection_name" : {
"type": "String"
}
}
},
"cancel": "Cancel",
"chooseCollection": "Choose Collection",
"collections": "Collections",
"tipCreateCollections": "Create your first Collection to get started!",
"search": "Search",
"createBookmark": "Create Bookmark",
"createCollection": "Create Collection",
"create": "Create",
"delete": "Delete",
"add": "Add",
"startSearching": "Start searching",
"tipNoResults": "There are no results that match your search",
"collectionName": "Collection Name",
"bookmarkTitle": "Bookmark Title",
"url": "Url",
"description": "Description"
}

View File

@@ -0,0 +1,236 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:intl/intl.dart' as intl;
import 'app_localizations_de.dart';
import 'app_localizations_en.dart';
// ignore_for_file: type=lint
/// Callers can lookup localized strings with an instance of AppLocalizations
/// returned by `AppLocalizations.of(context)`.
///
/// Applications need to include `AppLocalizations.delegate()` in their app's
/// `localizationDelegates` list, and the locales they support in the app's
/// `supportedLocales` list. For example:
///
/// ```dart
/// import 'l10n/app_localizations.dart';
///
/// return MaterialApp(
/// localizationsDelegates: AppLocalizations.localizationsDelegates,
/// supportedLocales: AppLocalizations.supportedLocales,
/// home: MyApplicationHome(),
/// );
/// ```
///
/// ## Update pubspec.yaml
///
/// Please make sure to update your pubspec.yaml to include the following
/// packages:
///
/// ```yaml
/// dependencies:
/// # Internationalization support.
/// flutter_localizations:
/// sdk: flutter
/// intl: any # Use the pinned version from flutter_localizations
///
/// # Rest of dependencies
/// ```
///
/// ## iOS Applications
///
/// iOS applications define key application metadata, including supported
/// locales, in an Info.plist file that is built into the application bundle.
/// To configure the locales supported by your app, youll need to edit this
/// file.
///
/// First, open your projects ios/Runner.xcworkspace Xcode workspace file.
/// Then, in the Project Navigator, open the Info.plist file under the Runner
/// projects Runner folder.
///
/// Next, select the Information Property List item, select Add Item from the
/// Editor menu, then select Localizations from the pop-up menu.
///
/// Select and expand the newly-created Localizations item then, for each
/// locale your application supports, add a new item and select the locale
/// you wish to add from the pop-up menu in the Value field. This list should
/// be consistent with the languages listed in the AppLocalizations.supportedLocales
/// property.
abstract class AppLocalizations {
AppLocalizations(String locale)
: localeName = intl.Intl.canonicalizedLocale(locale.toString());
final String localeName;
static AppLocalizations? of(BuildContext context) {
return Localizations.of<AppLocalizations>(context, AppLocalizations);
}
static const LocalizationsDelegate<AppLocalizations> delegate =
_AppLocalizationsDelegate();
/// A list of this localizations delegate along with the default localizations
/// delegates.
///
/// Returns a list of localizations delegates containing this delegate along with
/// GlobalMaterialLocalizations.delegate, GlobalCupertinoLocalizations.delegate,
/// and GlobalWidgetsLocalizations.delegate.
///
/// Additional delegates can be added by appending to this list in
/// MaterialApp. This list does not have to be used at all if a custom list
/// of delegates is preferred or required.
static const List<LocalizationsDelegate<dynamic>> localizationsDelegates =
<LocalizationsDelegate<dynamic>>[
delegate,
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
];
/// A list of this localizations delegate's supported locales.
static const List<Locale> supportedLocales = <Locale>[
Locale('de'),
Locale('en'),
];
/// No description provided for @addToCollection.
///
/// In en, this message translates to:
/// **'Add to {collection_name}'**
String addToCollection(String collection_name);
/// No description provided for @cancel.
///
/// In en, this message translates to:
/// **'Cancel'**
String get cancel;
/// No description provided for @chooseCollection.
///
/// In en, this message translates to:
/// **'Choose Collection'**
String get chooseCollection;
/// No description provided for @collections.
///
/// In en, this message translates to:
/// **'Collections'**
String get collections;
/// No description provided for @tipCreateCollections.
///
/// In en, this message translates to:
/// **'Create your first Collection to get started!'**
String get tipCreateCollections;
/// No description provided for @search.
///
/// In en, this message translates to:
/// **'Search'**
String get search;
/// No description provided for @createBookmark.
///
/// In en, this message translates to:
/// **'Create Bookmark'**
String get createBookmark;
/// No description provided for @createCollection.
///
/// In en, this message translates to:
/// **'Create Collection'**
String get createCollection;
/// No description provided for @create.
///
/// In en, this message translates to:
/// **'Create'**
String get create;
/// No description provided for @delete.
///
/// In en, this message translates to:
/// **'Delete'**
String get delete;
/// No description provided for @add.
///
/// In en, this message translates to:
/// **'Add'**
String get add;
/// No description provided for @startSearching.
///
/// In en, this message translates to:
/// **'Start searching'**
String get startSearching;
/// No description provided for @tipNoResults.
///
/// In en, this message translates to:
/// **'There are no results that match your search'**
String get tipNoResults;
/// No description provided for @collectionName.
///
/// In en, this message translates to:
/// **'Collection Name'**
String get collectionName;
/// No description provided for @bookmarkTitle.
///
/// In en, this message translates to:
/// **'Bookmark Title'**
String get bookmarkTitle;
/// No description provided for @url.
///
/// In en, this message translates to:
/// **'Url'**
String get url;
/// No description provided for @description.
///
/// In en, this message translates to:
/// **'Description'**
String get description;
}
class _AppLocalizationsDelegate
extends LocalizationsDelegate<AppLocalizations> {
const _AppLocalizationsDelegate();
@override
Future<AppLocalizations> load(Locale locale) {
return SynchronousFuture<AppLocalizations>(lookupAppLocalizations(locale));
}
@override
bool isSupported(Locale locale) =>
<String>['de', 'en'].contains(locale.languageCode);
@override
bool shouldReload(_AppLocalizationsDelegate old) => false;
}
AppLocalizations lookupAppLocalizations(Locale locale) {
// Lookup logic when only language code is specified.
switch (locale.languageCode) {
case 'de':
return AppLocalizationsDe();
case 'en':
return AppLocalizationsEn();
}
throw FlutterError(
'AppLocalizations.delegate failed to load unsupported locale "$locale". This is likely '
'an issue with the localizations generation tool. Please file an issue '
'on GitHub with a reproducible sample app and the gen-l10n configuration '
'that was used.',
);
}

View File

@@ -0,0 +1,63 @@
// ignore: unused_import
import 'package:intl/intl.dart' as intl;
import 'app_localizations.dart';
// ignore_for_file: type=lint
/// The translations for German (`de`).
class AppLocalizationsDe extends AppLocalizations {
AppLocalizationsDe([String locale = 'de']) : super(locale);
@override
String addToCollection(String collection_name) {
return 'Speichern in $collection_name';
}
@override
String get cancel => 'Abbrechen';
@override
String get chooseCollection => 'Sammlung auswählen';
@override
String get collections => 'Sammlungen';
@override
String get tipCreateCollections => 'Erstelle deine erste Sammlung!';
@override
String get search => 'Suche';
@override
String get createBookmark => 'Lesezeichen erstellen';
@override
String get createCollection => 'Sammlung erstellen';
@override
String get create => 'Erstellen';
@override
String get delete => 'Löschen';
@override
String get add => 'Hinzufügen';
@override
String get startSearching => 'Suche etwas';
@override
String get tipNoResults => 'Keine Suchergebnisse gefunden';
@override
String get collectionName => 'Name der Sammlung';
@override
String get bookmarkTitle => 'Titel des Lesezeichens';
@override
String get url => 'Url';
@override
String get description => 'Beschreibung';
}

View File

@@ -0,0 +1,64 @@
// ignore: unused_import
import 'package:intl/intl.dart' as intl;
import 'app_localizations.dart';
// ignore_for_file: type=lint
/// The translations for English (`en`).
class AppLocalizationsEn extends AppLocalizations {
AppLocalizationsEn([String locale = 'en']) : super(locale);
@override
String addToCollection(String collection_name) {
return 'Add to $collection_name';
}
@override
String get cancel => 'Cancel';
@override
String get chooseCollection => 'Choose Collection';
@override
String get collections => 'Collections';
@override
String get tipCreateCollections =>
'Create your first Collection to get started!';
@override
String get search => 'Search';
@override
String get createBookmark => 'Create Bookmark';
@override
String get createCollection => 'Create Collection';
@override
String get create => 'Create';
@override
String get delete => 'Delete';
@override
String get add => 'Add';
@override
String get startSearching => 'Start searching';
@override
String get tipNoResults => 'There are no results that match your search';
@override
String get collectionName => 'Collection Name';
@override
String get bookmarkTitle => 'Bookmark Title';
@override
String get url => 'Url';
@override
String get description => 'Description';
}

View File

@@ -1,7 +1,11 @@
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:provider/provider.dart';
import 'l10n/app_localizations.dart';
import 'pages/collection_page.dart';
import 'pages/collections_list_page.dart';
import 'pages/search_page.dart';
import 'service/search_provider.dart';
import 'service/shared_link_provider.dart';
import 'service/storage.dart';
import 'service/share_intent_service.dart';
@@ -11,8 +15,11 @@ void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Storage.initialize();
runApp(
ChangeNotifierProvider(
create: (_) => SharedLinkProvider(),
MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => SharedLinkProvider()),
ChangeNotifierProvider(create: (_) => SearchProvider()),
],
child: const MapsBookmarks(),
),
);
@@ -61,6 +68,13 @@ class _MapsBookmarksState extends State<MapsBookmarks>
@override
Widget build(BuildContext context) {
return MaterialApp(
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [Locale('en'), Locale('de')],
navigatorKey: _navigatorKey,
theme: lightTheme,
darkTheme: darkTheme,
@@ -68,6 +82,7 @@ class _MapsBookmarksState extends State<MapsBookmarks>
routes: {
CollectionsListPage.routeName: (context) => const CollectionsListPage(),
CollectionPage.routeName: (context) => const CollectionPage(),
SearchPage.routeName: (context) => const SearchPage(),
},
);
}

View File

@@ -7,12 +7,28 @@ class Collection {
createdAt: json['createdAt'] as int,
);
String name;
int createdAt; // used as Id with millisecondsSinceEpoch
String name;
@override
bool operator ==(Object other) {
if (other is Collection) {
return hashCode == other.hashCode;
} else {
return false;
}
}
@override
int get hashCode => id.hashCode;
int get id => createdAt;
DateTime get createdDate => DateTime.fromMillisecondsSinceEpoch(createdAt);
Map<String, dynamic> toJson() => {'name': name, 'createdAt': createdAt};
Collection copyWith({String? name}) {
return Collection(name: name ?? this.name, createdAt: createdAt);
}
}

View File

@@ -1,9 +1,11 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../l10n/app_localizations.dart';
import '../model/bookmark.dart';
import '../model/maps_link_metadata.dart';
import '../service/bookmarks_provider.dart';
import '../service/notifying.dart';
import '../service/shared_link_provider.dart';
import '../service/storage.dart';
import '../service/url_launcher.dart';
@@ -21,6 +23,14 @@ class CollectionPage extends StatefulWidget {
class _CollectionPageState extends State<CollectionPage> {
MapsLinkMetadata? selectedMapsLink;
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
if (selectedMapsLink != null) onAddButtonPressed();
});
}
void onAddButtonPressed() => showDialog(
context: context,
builder: (context) => CreateBookmarkDialog(
@@ -37,30 +47,27 @@ class _CollectionPageState extends State<CollectionPage> {
selectedBookmark: selectedBookmark,
onSavePressed: onBookmarkSaved,
onDeletePressed: () {
Storage.deleteBookmarkById(selectedBookmark.id);
setState(() {});
Storage.deleteBookmarkById(
selectedBookmark.id,
).whenComplete(() => setState(() {}));
},
),
);
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
if (selectedMapsLink != null) onAddButtonPressed();
});
}
void onBookmarkSaved(Bookmark bookmark) {
Storage.addOrUpdateBookmark(bookmark);
setState(() {});
context.read<SharedLinkProvider>().removeCurrentMapsLink();
}
Widget bookmarkListBuilder(BuildContext context, Bookmark bookmark) {
Widget bookmarksListItemBuilder(BuildContext context, Bookmark bookmark) {
return ListTile(
title: Text(bookmark.name),
onTap: () => launchUrlFromString(bookmark.link),
onTap: () => launchUrlFromString(bookmark.link).then((errorCode) {
if (context.mounted) {
return Notifying.showUrlErrorSnackbar(context, errorCode);
}
}),
onLongPress: () => editBookmark(bookmark),
);
}
@@ -83,20 +90,28 @@ class _CollectionPageState extends State<CollectionPage> {
return Scaffold(
appBar: AppBar(
title: selectedMapsLink != null
? Text('Add to ${collection.name}')
? Text(
AppLocalizations.of(context)!.addToCollection(collection.name),
)
: Text(collection.name),
actions: [
if (selectedMapsLink != null)
TextButton(
onPressed: () => provider.removeCurrentMapsLink(),
child: Text('Cancel'),
child: Text(AppLocalizations.of(context)!.cancel),
),
],
),
body: ListView.builder(
itemBuilder: (context, index) =>
bookmarkListBuilder(context, bookmarks.elementAt(index)),
itemCount: bookmarks.length,
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,

View File

@@ -1,15 +1,18 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../l10n/app_localizations.dart';
import '../model/collection.dart';
import '../service/bookmarks_provider.dart';
import '../service/shared_link_provider.dart';
import '../service/storage.dart';
import '../widgets/create_bookmark_collection_dialog.dart';
import 'collection_page.dart';
import 'search_page.dart' show SearchPage;
class CollectionsListPage extends StatefulWidget {
const CollectionsListPage({super.key});
static const String routeName = '/collections';
@override
@@ -17,37 +20,8 @@ class CollectionsListPage extends StatefulWidget {
}
class _CollectionsListPageState extends State<CollectionsListPage> {
final collections = Storage.loadCollections();
bool addingNewBookmark = false;
@override
Widget build(BuildContext context) {
final provider = context.watch<SharedLinkProvider>();
addingNewBookmark = provider.currentMapsLinkMetadata != null;
return Scaffold(
appBar: AppBar(
title: addingNewBookmark ? Text('Choose Collection') : null,
actions: [
if (addingNewBookmark)
TextButton(
onPressed: () => provider.removeCurrentMapsLink(),
child: Text('Cancel'),
),
],
),
floatingActionButton: FloatingActionButton(
onPressed: onAddButtonPressed,
child: Icon(Icons.add),
),
body: ListView.builder(
itemBuilder: itemBuilder,
itemCount: collections.length,
),
// bottomSheet: provider.currentMapsLinkMetadata == null
// ? null
// : BottomSheet(onClosing: () {}, builder: bottomSheetBuilder),
);
}
final bookmarkCountMap = Storage.loadPerCollectionBookmarkCount();
Widget bottomSheetBuilder(BuildContext context) {
final titleTextFieldController = TextEditingController(
@@ -62,26 +36,30 @@ class _CollectionsListPageState extends State<CollectionsListPage> {
);
}
void onAddButtonPressed() =>
showDialog(
context: context,
builder: (context) =>
CreateBookmarkCollectionDialog(onSavePressed: onCollectionSaved),
).whenComplete(() {
if (addingNewBookmark) navigateToCollection(collections.last.id);
});
void onAddButtonPressed() => showDialog(
context: context,
builder: (context) =>
CreateBookmarkCollectionDialog(onSavePressed: onCollectionSaved),
);
void onCollectionSaved(String name) {
collections.add(Collection(name: name));
Storage.saveCollections(collections);
void onCollectionSaved(Collection collection) {
Storage.addOrUpdateCollection(collection);
setState(() {});
}
Widget itemBuilder(BuildContext context, int index) {
final collection = collections.elementAt(index);
Widget collectionsListItemBuilder(
BuildContext context,
Collection collection,
) {
return ListTile(
title: Text(collection.name),
onTap: () => navigateToCollection(collection.id),
onLongPress: () => onEditCollection(collection),
leading: const Icon(Icons.list_rounded),
trailing: Text(
bookmarkCountMap[collection.id]?.toString() ?? '0',
style: Theme.of(context).textTheme.bodyMedium,
),
);
}
@@ -90,8 +68,64 @@ class _CollectionsListPageState extends State<CollectionsListPage> {
Navigator.pushNamed(context, CollectionPage.routeName);
}
void onEditCollection(Collection selectedCollection) => showDialog(
context: context,
builder: (context) => CreateBookmarkCollectionDialog(
selectedCollection: selectedCollection,
onSavePressed: onCollectionSaved,
onDeletePressed: () {
Storage.deleteCollection(
selectedCollection,
).whenComplete(() => setState(() {}));
},
),
);
@override
void didChangeDependencies() {
super.didChangeDependencies();
Widget build(BuildContext context) {
final collections = Storage.loadCollections();
final provider = context.watch<SharedLinkProvider>();
addingNewBookmark = provider.currentMapsLinkMetadata != null;
return Scaffold(
appBar: AppBar(
title: addingNewBookmark
? Text(AppLocalizations.of(context)!.chooseCollection)
: Text(AppLocalizations.of(context)!.collections),
actions: [
if (addingNewBookmark)
TextButton(
onPressed: () => provider.removeCurrentMapsLink(),
child: Text(AppLocalizations.of(context)!.cancel),
)
else
IconButton(
onPressed: () =>
Navigator.of(context).pushNamed(SearchPage.routeName),
icon: Icon(Icons.search),
),
],
),
floatingActionButton: FloatingActionButton(
onPressed: onAddButtonPressed,
child: Icon(Icons.add),
),
body: collections.isNotEmpty
? Center(
child: SizedBox(
width: MediaQuery.of(context).size.width * 0.9,
child: ListView.separated(
itemBuilder: (context, index) => collectionsListItemBuilder(
context,
collections.elementAt(index),
),
itemCount: collections.length,
separatorBuilder: (context, index) => SizedBox(height: 10),
),
),
)
: Center(
child: Text(AppLocalizations.of(context)!.tipCreateCollections),
),
);
}
}

View File

@@ -0,0 +1,35 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../l10n/app_localizations.dart';
import '../service/search_provider.dart';
import '../widgets/search_widgets/search_bar_widget.dart';
import '../widgets/search_widgets/search_results_widget.dart';
class SearchPage extends StatelessWidget {
const SearchPage({super.key});
static const String routeName = '/search';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(AppLocalizations.of(context)!.search)),
body: Center(
child: SizedBox(
width: MediaQuery.of(context).size.width * 0.9,
child: Column(
children: [
Padding(padding: EdgeInsetsGeometry.only(top: 10)),
SearchBarWidget(
onEditingComplete: context.read<SearchProvider>().setSearchText,
onResetSearch: context.read<SearchProvider>().removeSearchText,
),
Padding(padding: EdgeInsetsGeometry.only(top: 10)),
Expanded(child: SearchResultsWidget()),
],
),
),
),
);
}
}

View File

@@ -0,0 +1,37 @@
import 'package:flutter/material.dart';
import 'url_launcher.dart' show UrlLaunchErrorCode;
class Notifying {
static void showSnackbar(
BuildContext context, {
required String text,
bool isError = false,
}) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
text,
style: isError
? TextStyle(color: Theme.of(context).colorScheme.error)
: null,
),
),
);
}
static void showUrlErrorSnackbar(
BuildContext context,
UrlLaunchErrorCode errorCode,
) {
String errorText = '';
if (errorCode == UrlLaunchErrorCode.none) {
return;
} else if (errorCode == UrlLaunchErrorCode.couldNotLaunch) {
errorText = 'Could not launch Url';
} else {
errorText = 'Invalid Url';
}
showSnackbar(context, text: errorText, isError: true);
}
}

View File

@@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
class SearchProvider extends ChangeNotifier {
String _searchText = '';
void setSearchText(String searchText, {bool silent = false}) {
_searchText = searchText;
if (!silent) notifyListeners();
}
void removeSearchText({bool silent = false}) {
_searchText = '';
if (!silent) notifyListeners();
}
String get searchText => _searchText;
}

View File

@@ -6,10 +6,10 @@ import '../model/bookmark.dart';
import '../model/collection.dart';
class Storage {
static const String _collectionsKey = 'collections';
static const String _bookmarksKey = 'bookmarks';
static const String _statsKey = 'stats';
static const String _collectionsKey = 'collections';
static SharedPreferencesWithCache? _prefsWithCache;
static const String _statsKey = 'stats';
static Future<void> initialize() async {
_prefsWithCache = await SharedPreferencesWithCache.create(
@@ -19,15 +19,6 @@ class Storage {
);
}
static SharedPreferencesWithCache get _prefs {
if (_prefsWithCache == null) {
throw StateError(
'BookmarkStorage not initialized. Call initialize() first.',
);
}
return _prefsWithCache!;
}
static List<Collection> loadCollections() {
final jsonString = _prefs.getString(_collectionsKey) ?? '[]';
final jsonList = jsonDecode(jsonString) as List;
@@ -36,12 +27,7 @@ class Storage {
.toList();
}
static Future<void> saveCollections(List<Collection> collections) async {
final jsonList = collections.map((c) => c.toJson()).toList();
await _prefs.setString(_collectionsKey, jsonEncode(jsonList));
}
static List<Bookmark> loadAllBookmarks() {
static List<Bookmark> loadBookmarks() {
final jsonString = _prefs.getString(_bookmarksKey) ?? '[]';
final jsonList = jsonDecode(jsonString) as List;
return jsonList
@@ -49,42 +35,37 @@ class Storage {
.toList();
}
static Future<void> saveAllBookmarks(List<Bookmark> bookmarks) async {
static Future<void> saveCollections(List<Collection> collections) async {
final jsonList = collections.map((c) => c.toJson()).toList();
await _prefs.setString(_collectionsKey, jsonEncode(jsonList));
}
static Future<void> saveBookmarks(List<Bookmark> bookmarks) async {
final jsonList = bookmarks.map((b) => b.toJson()).toList();
await _prefs.setString(_bookmarksKey, jsonEncode(jsonList));
}
static List<Bookmark> loadBookmarksForCollection(int collectionId) {
final allBookmarks = loadAllBookmarks();
final allBookmarks = loadBookmarks();
return allBookmarks.where((b) => b.collectionId == collectionId).toList();
}
static Map<int, int> loadPerCollectionBookmarkCount() {
return loadBookmarks().fold(<int, int>{}, (map, bookmark) {
map[bookmark.collectionId] ??= 0;
map[bookmark.collectionId] = map[bookmark.collectionId]! + 1;
return map;
});
}
static Future<void> addBookmark(Bookmark bookmark) async {
final bookmarks = loadAllBookmarks();
final bookmarks = loadBookmarks();
bookmarks.add(bookmark);
await saveAllBookmarks(bookmarks);
}
static Future<void> deleteBookmark(Bookmark bookmark) async {
final bookmarks = loadAllBookmarks();
bookmarks.remove(bookmark);
await saveAllBookmarks(bookmarks);
}
static Future<void> deleteBookmarkById(int bookmarkId) async {
final bookmarks = loadAllBookmarks();
bookmarks.removeWhere((b) => b.id == bookmarkId);
await saveAllBookmarks(bookmarks);
}
static Future<void> deleteBookmarksForCollection(int collectionId) async {
final bookmarks = loadAllBookmarks();
bookmarks.removeWhere((b) => b.collectionId == collectionId);
await saveAllBookmarks(bookmarks);
await saveBookmarks(bookmarks);
}
static Future<void> addOrUpdateBookmark(Bookmark bookmark) async {
final bookmarks = loadAllBookmarks();
final bookmarks = loadBookmarks();
final index = bookmarks.indexWhere((b) => b.id == bookmark.id);
if (index == -1) {
@@ -92,7 +73,19 @@ class Storage {
} else if (index >= 0) {
bookmarks[index] = bookmark;
}
await saveAllBookmarks(bookmarks);
await saveBookmarks(bookmarks);
}
static Future<void> addOrUpdateCollection(Collection collection) async {
final collections = loadCollections();
final index = collections.indexWhere((b) => b.id == collection.id);
if (index == -1) {
collections.add(collection);
} else if (index >= 0) {
collections[index] = collection;
}
await saveCollections(collections);
}
static Future<void> updateBookmarkById(
@@ -101,7 +94,7 @@ class Storage {
String? description,
String? link,
}) async {
final bookmarks = loadAllBookmarks();
final bookmarks = loadBookmarks();
final index = bookmarks.indexWhere((b) => b.id == bookmarkId);
if (index == -1) return;
@@ -110,7 +103,34 @@ class Storage {
if (description != null) bookmarks[index].description = description;
if (link != null) bookmarks[index].link = link;
await saveAllBookmarks(bookmarks);
await saveBookmarks(bookmarks);
}
static Future<void> deleteBookmark(Bookmark bookmark) async {
final bookmarks = loadBookmarks();
bookmarks.remove(bookmark);
await saveBookmarks(bookmarks);
}
static Future<void> deleteBookmarkById(int bookmarkId) async {
final bookmarks = loadBookmarks();
bookmarks.removeWhere((b) => b.id == bookmarkId);
await saveBookmarks(bookmarks);
}
static Future<void> deleteBookmarksForCollection(int collectionId) async {
final bookmarks = loadBookmarks();
bookmarks.removeWhere((b) => b.collectionId == collectionId);
await saveBookmarks(bookmarks);
}
static Future<void> deleteCollection(Collection collection) async {
final collections = loadCollections();
final bookmarks = loadBookmarks();
bookmarks.removeWhere((bookmark) => bookmark.collectionId == collection.id);
collections.remove(collection);
await saveBookmarks(bookmarks);
await saveCollections(collections);
}
static Map<String, int> getStats() {
@@ -124,7 +144,7 @@ class Storage {
static Future<void> updateStats() async {
final collections = loadCollections();
final bookmarks = loadAllBookmarks();
final bookmarks = loadBookmarks();
final stats = {
'totalCollections': collections.length,
@@ -134,4 +154,13 @@ class Storage {
await _prefs.setString(_statsKey, jsonEncode(stats));
}
static SharedPreferencesWithCache get _prefs {
if (_prefsWithCache == null) {
throw StateError(
'BookmarkStorage not initialized. Call initialize() first.',
);
}
return _prefsWithCache!;
}
}

View File

@@ -1,8 +1,14 @@
import 'package:url_launcher/url_launcher.dart';
Future<void> launchUrlFromString(String url) async {
final Uri uri = Uri.parse(url);
Future<UrlLaunchErrorCode> launchUrlFromString(String url) async {
final Uri? uri = Uri.tryParse(url);
final isValid =
uri != null && uri.hasAbsolutePath && uri.scheme.startsWith('http');
if (!isValid) return UrlLaunchErrorCode.invalidUrl;
if (!await launchUrl(uri, mode: LaunchMode.externalApplication)) {
throw Exception('Could not launch $url');
return UrlLaunchErrorCode.couldNotLaunch;
}
return UrlLaunchErrorCode.none;
}
enum UrlLaunchErrorCode { none, couldNotLaunch, invalidUrl }

View File

@@ -1,15 +1,26 @@
import 'package:flutter/material.dart';
ThemeData get lightTheme => ThemeData.from(colorScheme: _lightColorScheme);
const _seed = Colors.deepPurple;
ThemeData get darkTheme => ThemeData.from(colorScheme: _darkColorScheme);
ColorScheme get _lightColorScheme =>
ColorScheme.fromSeed(seedColor: _seed, brightness: Brightness.light);
ColorScheme get _darkColorScheme => ColorScheme.fromSeed(
seedColor: Colors.deepPurple,
brightness: Brightness.dark,
);
ColorScheme get _darkColorScheme =>
ColorScheme.fromSeed(seedColor: _seed, brightness: Brightness.dark);
ColorScheme get _lightColorScheme => ColorScheme.fromSeed(
seedColor: Colors.deepPurple,
brightness: Brightness.light,
);
ThemeData get lightTheme => _baseTheme(_lightColorScheme);
ThemeData get darkTheme => _baseTheme(_darkColorScheme);
ThemeData _baseTheme(ColorScheme scheme) =>
ThemeData.from(colorScheme: scheme, useMaterial3: true).copyWith(
inputDecorationTheme: InputDecorationTheme(
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)),
),
listTileTheme: ListTileThemeData(
tileColor: scheme.surfaceContainer,
shape: RoundedRectangleBorder(
borderRadius: BorderRadiusGeometry.circular(12),
),
),
);

View File

@@ -1,18 +1,36 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../l10n/app_localizations.dart';
import '../model/collection.dart';
import 'edit_dialog_widgets/edit_dialog_actions.dart' show EditDialogActions;
import 'edit_dialog_widgets/edit_dialog_title.dart';
class CreateBookmarkCollectionDialog extends StatelessWidget {
const CreateBookmarkCollectionDialog({
super.key,
required this.onSavePressed,
this.onDeletePressed,
this.selectedCollection,
});
final void Function(String name) onSavePressed;
final void Function()? onDeletePressed;
final void Function(Collection collection) onSavePressed;
final Collection? selectedCollection;
@override
Widget build(BuildContext context) {
final nameController = TextEditingController();
if (selectedCollection != null) {
nameController.text = selectedCollection!.name;
}
return AlertDialog(
title: Text('Create Collection'),
title: EditDialogTitle(
dialogType: DialogType.collection,
onDeletePressed: onDeletePressed,
),
content: TextField(
controller: nameController,
autofocus: true,
@@ -23,17 +41,18 @@ class CreateBookmarkCollectionDialog extends StatelessWidget {
FilteringTextInputFormatter.deny(RegExp(r'\s\s+')),
],
decoration: InputDecoration(
labelText: 'Collection Name',
border: OutlineInputBorder(borderRadius: BorderRadius.circular(10)),
labelText: AppLocalizations.of(context)!.collectionName,
),
),
actions: [
FloatingActionButton(
onPressed: () {
onSavePressed(nameController.text);
EditDialogActions(
onSavePressed: () {
final bookmark =
selectedCollection?.copyWith(name: nameController.text) ??
Collection(name: nameController.text);
onSavePressed(bookmark);
Navigator.of(context).pop();
},
child: Icon(Icons.save),
),
],
);

View File

@@ -1,8 +1,11 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../l10n/app_localizations.dart';
import '../model/bookmark.dart';
import '../model/maps_link_metadata.dart';
import 'edit_dialog_widgets/edit_dialog_actions.dart';
import 'edit_dialog_widgets/edit_dialog_title.dart';
class CreateBookmarkDialog extends StatelessWidget {
const CreateBookmarkDialog({
@@ -13,6 +16,7 @@ class CreateBookmarkDialog extends StatelessWidget {
this.selectedBookmark,
this.selectedMapsLink,
});
final void Function(Bookmark bookmark)? onSavePressed;
final void Function()? onDeletePressed;
final int collectionId;
@@ -36,7 +40,10 @@ class CreateBookmarkDialog extends StatelessWidget {
}
return AlertDialog(
title: Text('Create Bookmark'),
title: EditDialogTitle(
dialogType: DialogType.bookmark,
onDeletePressed: onDeletePressed,
),
content: SingleChildScrollView(
child: Column(
children: [
@@ -53,10 +60,7 @@ class CreateBookmarkDialog extends StatelessWidget {
FilteringTextInputFormatter.deny(RegExp(r'\s\s+')),
],
decoration: InputDecoration(
labelText: 'Bookmark Title',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
labelText: AppLocalizations.of(context)!.bookmarkTitle,
),
),
TextField(
@@ -70,10 +74,7 @@ class CreateBookmarkDialog extends StatelessWidget {
FilteringTextInputFormatter.deny(RegExp(r'\s\s+')),
],
decoration: InputDecoration(
labelText: 'Url',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
labelText: AppLocalizations.of(context)!.url,
),
),
TextField(
@@ -87,51 +88,30 @@ class CreateBookmarkDialog extends StatelessWidget {
FilteringTextInputFormatter.deny(RegExp(r'\s\s+')),
],
decoration: InputDecoration(
labelText: 'Description',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
labelText: AppLocalizations.of(context)!.description,
),
),
],
),
),
actions: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text('Cancel'),
),
FloatingActionButton(
onPressed: () {
final bookmark =
selectedBookmark?.copyWith(
name: nameController.text,
link: linkController.text,
description: descriptionController.text,
) ??
Bookmark(
collectionId: collectionId,
name: nameController.text,
link: linkController.text,
description: descriptionController.text,
);
onSavePressed?.call(bookmark);
Navigator.of(context).pop();
},
child: Icon(Icons.save),
),
if (selectedBookmark != null)
TextButton(
onPressed: () {
onDeletePressed?.call();
Navigator.of(context).pop();
},
child: Text('Delete'),
),
],
EditDialogActions(
onSavePressed: () {
final bookmark =
selectedBookmark?.copyWith(
name: nameController.text,
link: linkController.text,
description: descriptionController.text,
) ??
Bookmark(
collectionId: collectionId,
name: nameController.text,
link: linkController.text,
description: descriptionController.text,
);
onSavePressed?.call(bookmark);
Navigator.of(context).pop();
},
),
],
);

View File

@@ -0,0 +1,24 @@
import 'package:flutter/material.dart'
show TextButton, FloatingActionButton, Icons;
import 'package:flutter/widgets.dart';
import '../../l10n/app_localizations.dart';
class EditDialogActions extends StatelessWidget {
const EditDialogActions({super.key, required this.onSavePressed});
final VoidCallback onSavePressed;
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(AppLocalizations.of(context)!.cancel),
),
FloatingActionButton(onPressed: onSavePressed, child: Icon(Icons.save)),
],
);
}
}

View File

@@ -0,0 +1,40 @@
import 'package:flutter/material.dart' show TextButton, Theme;
import 'package:flutter/widgets.dart';
class EditDialogTitle extends StatelessWidget {
const EditDialogTitle({
super.key,
this.onDeletePressed,
required this.dialogType,
});
final VoidCallback? onDeletePressed;
final DialogType dialogType;
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
// TODO: Localize
if (dialogType == DialogType.bookmark)
Text('Create Bookmark')
else
Text('Create Collection'),
if (onDeletePressed != null)
TextButton(
onPressed: () {
onDeletePressed!.call();
Navigator.of(context).pop();
},
child: Text(
'Delete',
style: TextStyle(color: Theme.of(context).colorScheme.error),
),
),
],
);
}
}
enum DialogType { bookmark, collection }

View File

@@ -0,0 +1,37 @@
import 'package:flutter/material.dart';
import '../../l10n/app_localizations.dart';
class SearchBarWidget extends StatelessWidget {
const SearchBarWidget({
super.key,
required this.onEditingComplete,
required this.onResetSearch,
});
final Function(String searchString) onEditingComplete;
final Function() onResetSearch;
void onChanged(String text, BuildContext context) {
if (context.mounted) onEditingComplete(text);
}
@override
Widget build(BuildContext context) {
final searchTextController = TextEditingController();
return TextField(
controller: searchTextController,
onChanged: (text) => onChanged(text, context),
decoration: InputDecoration(
suffixIcon: IconButton(
onPressed: () {
searchTextController.clear();
onResetSearch();
},
icon: Icon(Icons.delete_outline_outlined),
),
labelText: AppLocalizations.of(context)!.search,
),
);
}
}

View File

@@ -0,0 +1,58 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../l10n/app_localizations.dart';
import '../../model/bookmark.dart';
import '../../service/notifying.dart';
import '../../service/search_provider.dart';
import '../../service/storage.dart' show Storage;
import '../../service/url_launcher.dart';
class SearchResultsWidget extends StatefulWidget {
const SearchResultsWidget({super.key});
@override
State<SearchResultsWidget> createState() => _SearchResultsWidgetState();
}
class _SearchResultsWidgetState extends State<SearchResultsWidget> {
final List<Bookmark> allBookmarks = Storage.loadBookmarks();
@override
void deactivate() {
context.read<SearchProvider>().removeSearchText(silent: true);
super.deactivate();
}
Widget bookmarkListItemBuilder(BuildContext context, int index) {
final bookmark = filteredBookmarks.elementAt(index);
return ListTile(
title: Text(bookmark.name),
onTap: () => launchUrlFromString(bookmark.link).then((errorCode) {
if (context.mounted && errorCode != UrlLaunchErrorCode.none) {
Notifying.showUrlErrorSnackbar(context, errorCode);
} else if (context.mounted) {
Navigator.of(context).pop();
}
}),
);
}
Iterable<Bookmark> get filteredBookmarks => allBookmarks.where(
(bookmark) => bookmark.name.toLowerCase().contains(
context.watch<SearchProvider>().searchText.toLowerCase(),
),
);
@override
Widget build(BuildContext context) {
if (filteredBookmarks.isNotEmpty) {
return ListView.separated(
itemBuilder: bookmarkListItemBuilder,
itemCount: filteredBookmarks.length,
separatorBuilder: (context, index) => SizedBox(height: 10),
);
}
return Center(child: Text(AppLocalizations.of(context)!.tipNoResults));
}
}

View File

@@ -102,6 +102,11 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.0.0"
flutter_localizations:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_test:
dependency: "direct dev"
description: flutter
@@ -136,6 +141,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.1.2"
intl:
dependency: "direct main"
description:
name: intl
sha256: "3df61194eb431efc39c4ceba583b95633a403f46c9fd341e550ce0bfa50e9aa5"
url: "https://pub.dev"
source: hosted
version: "0.20.2"
leak_tracker:
dependency: transitive
description:

View File

@@ -3,7 +3,7 @@ description: "A new way to save google maps bookmarks"
publish_to: 'none'
version: 1.0.0+1
version: 0.0.18
environment:
sdk: ^3.9.2
@@ -18,6 +18,9 @@ dependencies:
provider: ^6.1.5+1
metadata_fetch: ^0.4.2
url_launcher: ^6.3.2
flutter_localizations:
sdk: flutter
intl: any
dev_dependencies:
flutter_test:
@@ -26,5 +29,5 @@ dev_dependencies:
flutter_lints: ^6.0.0
flutter:
generate: true
uses-material-design: true