Compare commits
6 Commits
v0.1.28
...
5fd690197a
| Author | SHA1 | Date | |
|---|---|---|---|
| 5fd690197a | |||
| 31c0ade243 | |||
| 336be6cb72 | |||
| 214ae08bb9 | |||
| 100b86d3f9 | |||
| ff1b102047 |
@@ -4,9 +4,6 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,55 +17,90 @@ 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: SizedBox(
|
body: Center(
|
||||||
width: MediaQuery.of(context).size.width * 0.9,
|
child: SizedBox(
|
||||||
child: Column(
|
width: MediaQuery.of(context).size.width * 0.9,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
child: Column(
|
||||||
children: [
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
Text(
|
children: [
|
||||||
AppLocalizations.of(context)!.appData,
|
Padding(
|
||||||
style: Theme.of(context).textTheme.titleLarge,
|
padding: titlePadding,
|
||||||
),
|
child: Text(
|
||||||
ElevatedButton(
|
AppLocalizations.of(context)!.appData,
|
||||||
onPressed: () => onActivateJsonImportPressed(),
|
style: Theme.of(context).textTheme.titleLarge,
|
||||||
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: 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: () => 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 checkStoragePermission) return;
|
if (!await PermissionService.storagePermissionStatus.isGranted) return;
|
||||||
|
|
||||||
Storage.exportToJsonFile().then(showExportInfo);
|
Storage.exportToJsonFile().then(showExportInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onActivateJsonImportPressed() async {
|
void onActivateJsonImportPressed() async {
|
||||||
if (!await checkStoragePermission) return;
|
if (!await PermissionService.storagePermissionStatus.isGranted) return;
|
||||||
Storage.importFromJsonFile().then(showImportInfo);
|
Storage.importFromJsonFile().then(showImportInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> get checkStoragePermission async {
|
Future<void> checkStoragePermission() async {
|
||||||
if (!(await PermissionService.requestStoragePermission).isGranted) {
|
PermissionService.storagePermissionStatus.then((value) {
|
||||||
if (mounted) {
|
storagePermissionIsGranted = value.isGranted;
|
||||||
Notifying.showErrorSnackbar(
|
if (context.mounted && value.isGranted != storagePermissionIsGranted) {
|
||||||
context,
|
setState(() {});
|
||||||
AppLocalizations.of(context)!.errorStoragePermisson,
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void showExportInfo(bool success) => Notifying.showSnackbar(
|
void showExportInfo(bool success) => Notifying.showSnackbar(
|
||||||
@@ -73,7 +108,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 +116,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 false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
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: 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,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -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