Compare commits
5 Commits
cad43c7664
...
v0.1.29
| Author | SHA1 | Date | |
|---|---|---|---|
| d51f3d4ba7 | |||
| 06a76afc42 | |||
| dca8c64555 | |||
| 1aaea5f6d9 | |||
| 3a54a077f3 |
@@ -7,7 +7,6 @@ import 'pages/collections_list_page.dart';
|
|||||||
import 'pages/search_page.dart';
|
import 'pages/search_page.dart';
|
||||||
import 'pages/settings_page.dart';
|
import 'pages/settings_page.dart';
|
||||||
import 'service/search_provider.dart';
|
import 'service/search_provider.dart';
|
||||||
import 'service/settings_provider.dart';
|
|
||||||
import 'service/shared_link_provider.dart';
|
import 'service/shared_link_provider.dart';
|
||||||
import 'service/storage.dart';
|
import 'service/storage.dart';
|
||||||
import 'service/share_intent_service.dart';
|
import 'service/share_intent_service.dart';
|
||||||
@@ -21,7 +20,6 @@ void main() async {
|
|||||||
providers: [
|
providers: [
|
||||||
ChangeNotifierProvider(create: (_) => SharedLinkProvider()),
|
ChangeNotifierProvider(create: (_) => SharedLinkProvider()),
|
||||||
ChangeNotifierProvider(create: (_) => SearchProvider()),
|
ChangeNotifierProvider(create: (_) => SearchProvider()),
|
||||||
ChangeNotifierProvider(create: (_) => SettingsProvider()),
|
|
||||||
],
|
],
|
||||||
child: const MapsBookmarks(),
|
child: const MapsBookmarks(),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
import '../assets/constants.dart' as constants;
|
|
||||||
|
|
||||||
class Settings {
|
|
||||||
final String exportDirectoryPath;
|
|
||||||
|
|
||||||
Settings._({required this.exportDirectoryPath});
|
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
|
||||||
return {'exportDirectoryPath': exportDirectoryPath};
|
|
||||||
}
|
|
||||||
|
|
||||||
factory Settings.fromJson(Map<String, dynamic> json) {
|
|
||||||
return Settings._(
|
|
||||||
exportDirectoryPath: json['exportDirectoryPath'] as String,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
factory Settings.defaults() {
|
|
||||||
return Settings._(
|
|
||||||
exportDirectoryPath: constants.defaultAndroidExportDirectory,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Settings copyWith({String? exportDirectoryPath}) {
|
|
||||||
return Settings._(
|
|
||||||
exportDirectoryPath: exportDirectoryPath ?? this.exportDirectoryPath,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,89 +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.center,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
children: [
|
||||||
children: [
|
Text(
|
||||||
Padding(
|
AppLocalizations.of(context)!.appData,
|
||||||
padding: titlePadding,
|
style: Theme.of(context).textTheme.titleLarge,
|
||||||
child: Text(
|
),
|
||||||
AppLocalizations.of(context)!.appData,
|
ElevatedButton(
|
||||||
style: Theme.of(context).textTheme.titleLarge,
|
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,
|
|
||||||
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> get 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(
|
||||||
@@ -107,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(
|
||||||
@@ -115,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,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import '../model/settings.dart';
|
|
||||||
import 'storage.dart';
|
|
||||||
|
|
||||||
class SettingsProvider extends ChangeNotifier {
|
|
||||||
SettingsProvider() : _settings = Storage.loadSettings();
|
|
||||||
|
|
||||||
Settings _settings;
|
|
||||||
|
|
||||||
Settings get settings => _settings;
|
|
||||||
|
|
||||||
void setExportDirectoryPath(String path, {bool silent = false}) {
|
|
||||||
_settings = _settings.copyWith(exportDirectoryPath: path);
|
|
||||||
_saveSettings();
|
|
||||||
if (!silent) notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _saveSettings() => Storage.saveSettings(_settings);
|
|
||||||
}
|
|
||||||
@@ -4,46 +4,22 @@ import 'package:shared_preferences/shared_preferences.dart';
|
|||||||
|
|
||||||
import '../model/bookmark.dart';
|
import '../model/bookmark.dart';
|
||||||
import '../model/collection.dart';
|
import '../model/collection.dart';
|
||||||
import '../model/settings.dart';
|
|
||||||
import 'json_file_service.dart';
|
import 'json_file_service.dart';
|
||||||
|
|
||||||
class Storage {
|
class Storage {
|
||||||
static const String _bookmarksKey = 'bookmarks';
|
static const String _bookmarksKey = 'bookmarks';
|
||||||
static const String _collectionsKey = 'collections';
|
static const String _collectionsKey = 'collections';
|
||||||
static SharedPreferencesWithCache? _prefsWithCache;
|
static SharedPreferencesWithCache? _prefsWithCache;
|
||||||
static const String _settingsKey = 'settings';
|
|
||||||
static const String _statsKey = 'stats';
|
static const String _statsKey = 'stats';
|
||||||
|
|
||||||
static Future<void> initialize() async {
|
static Future<void> initialize() async {
|
||||||
_prefsWithCache = await SharedPreferencesWithCache.create(
|
_prefsWithCache = await SharedPreferencesWithCache.create(
|
||||||
cacheOptions: const SharedPreferencesWithCacheOptions(
|
cacheOptions: const SharedPreferencesWithCacheOptions(
|
||||||
allowList: <String>{
|
allowList: <String>{_collectionsKey, _bookmarksKey, _statsKey},
|
||||||
_collectionsKey,
|
|
||||||
_bookmarksKey,
|
|
||||||
_statsKey,
|
|
||||||
_settingsKey,
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Settings loadSettings() {
|
|
||||||
final jsonString = _prefs.getString(_settingsKey);
|
|
||||||
if (jsonString != null) {
|
|
||||||
final json = jsonDecode(jsonString) as Map<String, dynamic>;
|
|
||||||
return Settings.fromJson(json);
|
|
||||||
} else {
|
|
||||||
final settings = Settings.defaults();
|
|
||||||
saveSettings(settings);
|
|
||||||
return settings;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<void> saveSettings(Settings settings) {
|
|
||||||
final json = jsonEncode(settings.toJson());
|
|
||||||
return _prefs.setString(_settingsKey, json);
|
|
||||||
}
|
|
||||||
|
|
||||||
static List<Collection> loadCollections() {
|
static List<Collection> loadCollections() {
|
||||||
final jsonString = _prefs.getString(_collectionsKey) ?? '[]';
|
final jsonString = _prefs.getString(_collectionsKey) ?? '[]';
|
||||||
final jsonList = jsonDecode(jsonString) as List;
|
final jsonList = jsonDecode(jsonString) as List;
|
||||||
@@ -180,6 +156,15 @@ class Storage {
|
|||||||
await _prefs.setString(_statsKey, jsonEncode(stats));
|
await _prefs.setString(_statsKey, jsonEncode(stats));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SharedPreferencesWithCache get _prefs {
|
||||||
|
if (_prefsWithCache == null) {
|
||||||
|
throw StateError(
|
||||||
|
'BookmarkStorage not initialized. Call initialize() first.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return _prefsWithCache!;
|
||||||
|
}
|
||||||
|
|
||||||
static Future<bool> exportToJsonFile() => JsonFileService.exportToJson(
|
static Future<bool> exportToJsonFile() => JsonFileService.exportToJson(
|
||||||
collections: loadCollections(),
|
collections: loadCollections(),
|
||||||
bookmarks: loadBookmarks(),
|
bookmarks: loadBookmarks(),
|
||||||
@@ -195,13 +180,4 @@ class Storage {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SharedPreferencesWithCache get _prefs {
|
|
||||||
if (_prefsWithCache == null) {
|
|
||||||
throw StateError(
|
|
||||||
'BookmarkStorage not initialized. Call initialize() first.',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return _prefsWithCache!;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,5 @@ ThemeData _baseTheme(ColorScheme scheme) =>
|
|||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadiusGeometry.circular(12),
|
borderRadius: BorderRadiusGeometry.circular(12),
|
||||||
),
|
),
|
||||||
contentPadding: EdgeInsetsDirectional.only(start: 16.0, end: 24.0),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user