Compare commits
18 Commits
c0f92fac58
...
v0.1.18
| Author | SHA1 | Date | |
|---|---|---|---|
| c7c5b3682d | |||
| 321a310add | |||
| 3bc7d713dd | |||
| 1d9ace45a1 | |||
| 588843a989 | |||
| f780638269 | |||
| 37447b4a53 | |||
| c283de7a45 | |||
| 483db8bfbd | |||
| a4d471dc62 | |||
| 970d78943b | |||
| a66c25c784 | |||
| 609a477b75 | |||
| 6d847aa2bb | |||
| f0b3c11e63 | |||
| 143206cd72 | |||
| 36e4eaee17 | |||
| 11a43a39fa |
79
.gitea/workflows/android_build.yml
Normal file
79
.gitea/workflows/android_build.yml
Normal file
@@ -0,0 +1,79 @@
|
||||
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: Cache pub deps
|
||||
# uses: actions/cache@v3
|
||||
# with:
|
||||
# path: ~/.pub-cache
|
||||
# key: ${{ runner.os }}-pub-${{ hashFiles('**/pubspec.yaml') }}
|
||||
# restore-keys: ${{ runner.os }}-pub-
|
||||
|
||||
- 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: adjust to your versioning
|
||||
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"
|
||||
@@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.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 +13,11 @@ void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await Storage.initialize();
|
||||
runApp(
|
||||
ChangeNotifierProvider(
|
||||
create: (_) => SharedLinkProvider(),
|
||||
MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider(create: (_) => SharedLinkProvider()),
|
||||
ChangeNotifierProvider(create: (_) => SearchProvider()),
|
||||
],
|
||||
child: const MapsBookmarks(),
|
||||
),
|
||||
);
|
||||
@@ -68,6 +73,7 @@ class _MapsBookmarksState extends State<MapsBookmarks>
|
||||
routes: {
|
||||
CollectionsListPage.routeName: (context) => const CollectionsListPage(),
|
||||
CollectionPage.routeName: (context) => const CollectionPage(),
|
||||
SearchPage.routeName: (context) => const SearchPage(),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:provider/provider.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';
|
||||
@@ -62,8 +63,8 @@ class _CollectionPageState extends State<CollectionPage> {
|
||||
return ListTile(
|
||||
title: Text(bookmark.name),
|
||||
onTap: () => launchUrlFromString(bookmark.link).then((errorCode) {
|
||||
if (context.mounted && errorCode != UrlLaunchErrorCode.none) {
|
||||
return showUrlError(context, errorCode);
|
||||
if (context.mounted) {
|
||||
return Notifying.showUrlErrorSnackbar(context, errorCode);
|
||||
}
|
||||
}),
|
||||
onLongPress: () => editBookmark(bookmark),
|
||||
@@ -109,16 +110,4 @@ class _CollectionPageState extends State<CollectionPage> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void showUrlError(BuildContext context, UrlLaunchErrorCode errorCode) {
|
||||
String errorText = '';
|
||||
if (errorCode == UrlLaunchErrorCode.couldNotLaunch) {
|
||||
errorText = 'Could not launch Url';
|
||||
} else {
|
||||
errorText = 'Invalid Url';
|
||||
}
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(errorText)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ 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});
|
||||
@@ -88,6 +89,12 @@ class _CollectionsListPageState extends State<CollectionsListPage> {
|
||||
TextButton(
|
||||
onPressed: () => provider.removeCurrentMapsLink(),
|
||||
child: Text('Cancel'),
|
||||
)
|
||||
else
|
||||
IconButton(
|
||||
onPressed: () =>
|
||||
Navigator.of(context).pushNamed(SearchPage.routeName),
|
||||
icon: Icon(Icons.search),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
27
lib/pages/search_page.dart
Normal file
27
lib/pages/search_page.dart
Normal file
@@ -0,0 +1,27 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.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('Search')),
|
||||
body: Column(
|
||||
children: [
|
||||
SearchBarWidget(
|
||||
onEditingComplete: context.read<SearchProvider>().setSearchText,
|
||||
onResetSearch: context.read<SearchProvider>().removeSearchText,
|
||||
),
|
||||
Expanded(child: SearchResultsWidget()),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
37
lib/service/notifying.dart
Normal file
37
lib/service/notifying.dart
Normal 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);
|
||||
}
|
||||
}
|
||||
17
lib/service/search_provider.dart
Normal file
17
lib/service/search_provider.dart
Normal 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;
|
||||
}
|
||||
34
lib/widgets/search_widgets/search_bar_widget.dart
Normal file
34
lib/widgets/search_widgets/search_bar_widget.dart
Normal file
@@ -0,0 +1,34 @@
|
||||
import 'package:flutter/material.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),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
56
lib/widgets/search_widgets/search_results_widget.dart
Normal file
56
lib/widgets/search_widgets/search_results_widget.dart
Normal file
@@ -0,0 +1,56 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.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.builder(
|
||||
itemBuilder: bookmarkListItemBuilder,
|
||||
itemCount: filteredBookmarks.length,
|
||||
);
|
||||
}
|
||||
return Center(child: Text('Start searching'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user