Compare commits
17 Commits
b4016e6e5b
...
v0.1.37
| Author | SHA1 | Date | |
|---|---|---|---|
| 446ef9a57a | |||
| 6103d0b679 | |||
| 5fd690197a | |||
| 31c0ade243 | |||
| 8ec264cebe | |||
| 83bfdf322b | |||
| cad43c7664 | |||
| 5c44574949 | |||
| 336be6cb72 | |||
| 214ae08bb9 | |||
| 100b86d3f9 | |||
| ff1b102047 | |||
| d51f3d4ba7 | |||
| 06a76afc42 | |||
| dca8c64555 | |||
| 1aaea5f6d9 | |||
| 3a54a077f3 |
@@ -4,9 +4,6 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ 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';
|
||||||
@@ -20,6 +21,7 @@ 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(),
|
||||||
),
|
),
|
||||||
|
|||||||
39
lib/model/settings.dart
Normal file
39
lib/model/settings.dart
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import '../assets/constants.dart' as constants;
|
||||||
|
|
||||||
|
class Settings {
|
||||||
|
final String exportDirectoryPath;
|
||||||
|
final bool alwaysExportEnabled;
|
||||||
|
|
||||||
|
Settings._({
|
||||||
|
required this.exportDirectoryPath,
|
||||||
|
required this.alwaysExportEnabled,
|
||||||
|
});
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return {
|
||||||
|
'exportDirectoryPath': exportDirectoryPath,
|
||||||
|
'alwaysExportEnabled': alwaysExportEnabled,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
factory Settings.fromJson(Map<String, dynamic> json) {
|
||||||
|
return Settings._(
|
||||||
|
exportDirectoryPath: json['exportDirectoryPath'] as String,
|
||||||
|
alwaysExportEnabled: json['alwaysExportEnabled'] as bool,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
factory Settings.defaults() {
|
||||||
|
return Settings._(
|
||||||
|
exportDirectoryPath: constants.defaultAndroidExportDirectory,
|
||||||
|
alwaysExportEnabled: false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Settings copyWith({String? exportDirectoryPath, bool? alwaysExportEnabled}) {
|
||||||
|
return Settings._(
|
||||||
|
exportDirectoryPath: exportDirectoryPath ?? this.exportDirectoryPath,
|
||||||
|
alwaysExportEnabled: alwaysExportEnabled ?? this.alwaysExportEnabled,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,10 +2,12 @@ import 'dart:async';
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import '../l10n/app_localizations.dart';
|
import '../l10n/app_localizations.dart';
|
||||||
import '../service/notifying.dart';
|
import '../service/notifying.dart';
|
||||||
import '../service/permission_service.dart';
|
import '../service/permission_service.dart';
|
||||||
|
import '../service/settings_provider.dart';
|
||||||
import '../service/storage.dart';
|
import '../service/storage.dart';
|
||||||
|
|
||||||
class SettingsPage extends StatefulWidget {
|
class SettingsPage extends StatefulWidget {
|
||||||
@@ -17,55 +19,158 @@ 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Localize
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final titlePadding = Theme.of(context).listTileTheme.contentPadding!;
|
||||||
|
checkStoragePermission();
|
||||||
|
final alwaysExportEnabled = context
|
||||||
|
.watch<SettingsProvider>()
|
||||||
|
.settings
|
||||||
|
.alwaysExportEnabled;
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(title: Text(AppLocalizations.of(context)!.settings)),
|
appBar: AppBar(title: Text(AppLocalizations.of(context)!.settings)),
|
||||||
body: SizedBox(
|
body: Center(
|
||||||
|
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(
|
||||||
|
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),
|
|
||||||
),
|
),
|
||||||
ElevatedButton(
|
SizedBox(height: tileSpacing),
|
||||||
onPressed: () => onActivateJsonExportPressed(),
|
ListTile(
|
||||||
child: Text(AppLocalizations.of(context)!.export),
|
title: Text('Grant storage permisson'),
|
||||||
|
subtitle: storagePermissionIsGranted
|
||||||
|
? Text('Storage permission granted')
|
||||||
|
: 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: () => onJsonImportPressed(),
|
||||||
|
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: () => onJsonExportPressed(),
|
||||||
|
trailing: Icon(Icons.arrow_forward_ios_rounded),
|
||||||
|
enabled: storagePermissionIsGranted,
|
||||||
|
),
|
||||||
|
SizedBox(height: tileSpacing),
|
||||||
|
ListTile(
|
||||||
|
title: Text('Always save to file'),
|
||||||
|
subtitle: Text(
|
||||||
|
'Export app data to a directory, every time you make a change',
|
||||||
|
),
|
||||||
|
onTap: () => onAlwaysSaveToJsonPressed(),
|
||||||
|
trailing: Checkbox(
|
||||||
|
value: alwaysExportEnabled,
|
||||||
|
onChanged: (value) {
|
||||||
|
onAlwaysSaveToJsonPressed();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
enabled: storagePermissionIsGranted,
|
||||||
|
),
|
||||||
|
if (alwaysExportEnabled) SizedBox(height: tileSpacing),
|
||||||
|
if (alwaysExportEnabled)
|
||||||
|
ListTile(
|
||||||
|
title: Text('Change export directory'),
|
||||||
|
subtitle: Text(
|
||||||
|
context
|
||||||
|
.watch<SettingsProvider>()
|
||||||
|
.settings
|
||||||
|
.exportDirectoryPath,
|
||||||
|
),
|
||||||
|
onTap: () => onChangeExportDirectoryPressed(),
|
||||||
|
trailing: Icon(Icons.arrow_forward_ios_rounded),
|
||||||
|
enabled: storagePermissionIsGranted,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onActivateJsonExportPressed() async {
|
void onJsonExportPressed() async {
|
||||||
if (!await checkStoragePermission) return;
|
if (!await checkStoragePermission()) return;
|
||||||
|
|
||||||
Storage.exportToJsonFile().then(showExportInfo);
|
Storage.exportToJsonFile().then(showExportInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onActivateJsonImportPressed() async {
|
void onJsonImportPressed() async {
|
||||||
if (!await checkStoragePermission) return;
|
if (!await checkStoragePermission()) return;
|
||||||
Storage.importFromJsonFile().then(showImportInfo);
|
Storage.importFromJsonFile().then(showImportInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> get checkStoragePermission async {
|
void onAlwaysSaveToJsonPressed() async {
|
||||||
if (!(await PermissionService.requestStoragePermission).isGranted) {
|
if (context.read<SettingsProvider>().settings.alwaysExportEnabled) {
|
||||||
if (mounted) {
|
context.read<SettingsProvider>().setExportDirectoryPath('', silent: true);
|
||||||
Notifying.showErrorSnackbar(
|
context.read<SettingsProvider>().setAlwaysExportEnabled(false);
|
||||||
context,
|
return;
|
||||||
AppLocalizations.of(context)!.errorStoragePermisson,
|
}
|
||||||
|
|
||||||
|
if (!await PermissionService.storagePermissionStatus.isGranted) return;
|
||||||
|
final dir = await Storage.selectDirectoryPath();
|
||||||
|
if (dir.isEmpty || !context.mounted) return;
|
||||||
|
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
context.read<SettingsProvider>().setExportDirectoryPath(dir, silent: true);
|
||||||
|
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
Storage.saveDataToFile().whenComplete(
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
() => context.read<SettingsProvider>().setAlwaysExportEnabled(true),
|
||||||
);
|
);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onChangeExportDirectoryPressed() async {
|
||||||
|
if (!await PermissionService.storagePermissionStatus.isGranted) return;
|
||||||
|
final dir = await Storage.selectDirectoryPath();
|
||||||
|
if (dir.isEmpty || !context.mounted) return;
|
||||||
|
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
context.read<SettingsProvider>().setExportDirectoryPath(dir);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
|
Future<bool> checkStoragePermission() async {
|
||||||
|
PermissionService.storagePermissionStatus.then((value) {
|
||||||
|
if (context.mounted && value.isGranted != storagePermissionIsGranted) {
|
||||||
|
storagePermissionIsGranted = value.isGranted;
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return storagePermissionIsGranted;
|
||||||
}
|
}
|
||||||
|
|
||||||
void showExportInfo(bool success) => Notifying.showSnackbar(
|
void showExportInfo(bool success) => Notifying.showSnackbar(
|
||||||
@@ -73,7 +178,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(
|
||||||
@@ -81,6 +186,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,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,25 +14,14 @@ class JsonFileService {
|
|||||||
required List<Bookmark> bookmarks,
|
required List<Bookmark> bookmarks,
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
try {
|
||||||
final dir = await _directoryPath;
|
final dir = await selectDirectoryPath();
|
||||||
if (dir.isEmpty) return false;
|
if (dir.isEmpty) return false;
|
||||||
|
|
||||||
final data = {
|
saveDataToFile(collections, bookmarks, dir);
|
||||||
'collections': collections.map((c) => c.toJson()).toList(),
|
|
||||||
'bookmarks': bookmarks.map((b) => b.toJson()).toList(),
|
|
||||||
};
|
|
||||||
final json = jsonEncode(data).codeUnits;
|
|
||||||
final file = XFile.fromData(
|
|
||||||
Uint8List.fromList(json),
|
|
||||||
mimeType: 'application/json',
|
|
||||||
name: constants.jsonFileName,
|
|
||||||
);
|
|
||||||
|
|
||||||
file.saveTo('$dir/${constants.jsonFileName}');
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<({List<Collection> collections, List<Bookmark> bookmarks})>
|
static Future<({List<Collection> collections, List<Bookmark> bookmarks})>
|
||||||
@@ -65,7 +54,31 @@ class JsonFileService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<String> get _directoryPath async {
|
static Future<bool> saveDataToFile(
|
||||||
|
List<Collection> collections,
|
||||||
|
List<Bookmark> bookmarks,
|
||||||
|
String directory,
|
||||||
|
) async {
|
||||||
|
try {
|
||||||
|
final data = jsonEncode({
|
||||||
|
'collections': collections.map((c) => c.toJson()).toList(),
|
||||||
|
'bookmarks': bookmarks.map((b) => b.toJson()).toList(),
|
||||||
|
}).codeUnits;
|
||||||
|
|
||||||
|
final file = XFile.fromData(
|
||||||
|
Uint8List.fromList(data),
|
||||||
|
mimeType: 'application/json',
|
||||||
|
name: constants.jsonFileName,
|
||||||
|
);
|
||||||
|
|
||||||
|
file.saveTo('$directory/${constants.jsonFileName}');
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<String> selectDirectoryPath() async {
|
||||||
if (Platform.isAndroid) {
|
if (Platform.isAndroid) {
|
||||||
return await getDirectoryPath(
|
return await getDirectoryPath(
|
||||||
initialDirectory: constants.defaultAndroidExportDirectory,
|
initialDirectory: constants.defaultAndroidExportDirectory,
|
||||||
|
|||||||
@@ -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: Theme.of(context).colorScheme.error,
|
backgroundColor: isError ? Theme.of(context).colorScheme.error : null,
|
||||||
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: Theme.of(context).colorScheme.onError,
|
color: isError ? Theme.of(context).colorScheme.onError : null,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
24
lib/service/settings_provider.dart
Normal file
24
lib/service/settings_provider.dart
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
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);
|
||||||
|
Storage.saveSettings(_settings);
|
||||||
|
if (!silent) notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setAlwaysExportEnabled(bool enabled, {bool silent = false}) {
|
||||||
|
_settings = _settings.copyWith(alwaysExportEnabled: enabled);
|
||||||
|
Storage.saveSettings(_settings);
|
||||||
|
if (!silent) notifyListeners();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,22 +4,49 @@ 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 Settings _currentSettings = Settings.defaults();
|
||||||
|
|
||||||
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>{_collectionsKey, _bookmarksKey, _statsKey},
|
allowList: <String>{
|
||||||
|
_collectionsKey,
|
||||||
|
_bookmarksKey,
|
||||||
|
_statsKey,
|
||||||
|
_settingsKey,
|
||||||
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Settings loadSettings() {
|
||||||
|
final jsonString = _prefs.getString(_settingsKey);
|
||||||
|
if (jsonString != null) {
|
||||||
|
final json = jsonDecode(jsonString) as Map<String, dynamic>;
|
||||||
|
_currentSettings = Settings.fromJson(json);
|
||||||
|
return _currentSettings;
|
||||||
|
} else {
|
||||||
|
final settings = Settings.defaults();
|
||||||
|
saveSettings(settings);
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> saveSettings(Settings settings) {
|
||||||
|
final json = jsonEncode(settings.toJson());
|
||||||
|
_currentSettings = settings;
|
||||||
|
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;
|
||||||
@@ -39,11 +66,13 @@ class Storage {
|
|||||||
static Future<void> saveCollections(List<Collection> collections) async {
|
static Future<void> saveCollections(List<Collection> collections) async {
|
||||||
final jsonList = collections.map((c) => c.toJson()).toList();
|
final jsonList = collections.map((c) => c.toJson()).toList();
|
||||||
await _prefs.setString(_collectionsKey, jsonEncode(jsonList));
|
await _prefs.setString(_collectionsKey, jsonEncode(jsonList));
|
||||||
|
if (_currentSettings.alwaysExportEnabled) saveDataToFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> saveBookmarks(List<Bookmark> bookmarks) async {
|
static Future<void> saveBookmarks(List<Bookmark> bookmarks) async {
|
||||||
final jsonList = bookmarks.map((b) => b.toJson()).toList();
|
final jsonList = bookmarks.map((b) => b.toJson()).toList();
|
||||||
await _prefs.setString(_bookmarksKey, jsonEncode(jsonList));
|
await _prefs.setString(_bookmarksKey, jsonEncode(jsonList));
|
||||||
|
if (_currentSettings.alwaysExportEnabled) saveDataToFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<Bookmark> loadBookmarksForCollection(int collectionId) {
|
static List<Bookmark> loadBookmarksForCollection(int collectionId) {
|
||||||
@@ -156,15 +185,6 @@ 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(),
|
||||||
@@ -180,4 +200,22 @@ class Storage {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<String> selectDirectoryPath() =>
|
||||||
|
JsonFileService.selectDirectoryPath();
|
||||||
|
|
||||||
|
static Future<bool> saveDataToFile() => JsonFileService.saveDataToFile(
|
||||||
|
loadCollections(),
|
||||||
|
loadBookmarks(),
|
||||||
|
_currentSettings.exportDirectoryPath,
|
||||||
|
);
|
||||||
|
|
||||||
|
static SharedPreferencesWithCache get _prefs {
|
||||||
|
if (_prefsWithCache == null) {
|
||||||
|
throw StateError(
|
||||||
|
'BookmarkStorage not initialized. Call initialize() first.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return _prefsWithCache!;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,5 +22,6 @@ 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