Add a setting to store the repo in the external storage

This is Android only, and for now it is disabled as I'm not sure why I
cannot access the "general" root directory.
This commit is contained in:
Vishesh Handa
2020-10-09 10:43:16 +02:00
parent 5ed1b5314b
commit cdfa7d690a
7 changed files with 102 additions and 0 deletions

View File

@ -5,6 +5,10 @@
<uses-permission android:name="com.android.vending.BILLING" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:label="@string/app_name"
android:icon="@mipmap/launcher_icon">

View File

@ -134,6 +134,8 @@ settings:
storage:
title: Storage
fileName: Filename
useLocal: Store Repo Internally
repoLocation: Repo Location
drawer:
title: Sidebar Settings
bottomMenuBar:

View File

@ -3,6 +3,7 @@ import 'package:easy_localization/easy_localization.dart';
class Features {
static bool alwaysPro = false;
static bool perFolderConfig = false;
static bool externalStorage = false;
static final all = <Feature>[
Feature.basicSearch,

View File

@ -1,7 +1,13 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:dynamic_theme/dynamic_theme.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:filesystem_picker/filesystem_picker.dart';
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';
@ -282,6 +288,61 @@ class SettingsListState extends State<SettingsList> {
Navigator.of(context).push(route);
},
),
if (Platform.isAndroid && Features.externalStorage)
SwitchListTile(
title: Text(tr('settings.storage.useLocal')),
value: settings.storeInternally,
onChanged: (bool newVal) async {
if (newVal == true) {
settings.storeInternally = true;
settings.storageLocation = "";
} else {
var req = await Permission.storage.request();
if (req.isDenied) {
settings.storeInternally = false;
settings.storageLocation = "";
settings.save();
setState(() {});
return;
}
settings.storeInternally = true;
var root = await getExternalStorageDirectory();
String path = await FilesystemPicker.open(
title: tr('settings.storage.repoLocation'),
context: context,
rootDirectory: root,
fsType: FilesystemType.folder,
folderIconColor: Colors.green[500],
);
if (path == null) {
settings.storeInternally = false;
settings.storageLocation = "";
settings.save();
setState(() {});
return;
}
settings.storageLocation = p.join(path, "GitJournal");
settings.storeInternally = false;
settings.save();
setState(() {});
return;
}
settings.save();
setState(() {});
// FIXME: Move the folder to be stored locally!
},
),
if (Platform.isAndroid && Features.externalStorage)
ListTile(
title: Text(tr('settings.storage.repoLocation')),
subtitle: Text(settings.storageLocation),
enabled: !settings.storeInternally,
),
ListTile(
title: Text(tr('settings.misc.title')),
onTap: () {

View File

@ -61,6 +61,9 @@ class Settings extends ChangeNotifier {
String remoteGitRepoFolderName = "";
bool remoteGitRepoConfigured = false;
bool storeInternally = true;
String storageLocation = "";
void load(SharedPreferences pref) {
gitAuthor = pref.getString("gitAuthor") ?? gitAuthor;
gitAuthorEmail = pref.getString("gitAuthorEmail") ?? gitAuthorEmail;
@ -129,6 +132,8 @@ class Settings extends ChangeNotifier {
remoteGitRepoFolderName = pref.getString("remoteGitRepoPath") ?? "";
bottomMenuBar = pref.getBool("bottomMenuBar") ?? bottomMenuBar;
storeInternally = pref.getBool("storeInternally") ?? storeInternally;
storageLocation = pref.getString("storageLocation") ?? "";
}
Future<void> save() async {
@ -199,6 +204,10 @@ class Settings extends ChangeNotifier {
_setStringSet(pref, "inlineTagPrefixes", inlineTagPrefixes,
defaultSet.inlineTagPrefixes);
_setBool(pref, "bottomMenuBar", bottomMenuBar, defaultSet.bottomMenuBar);
_setBool(
pref, "storeInternally", storeInternally, defaultSet.storeInternally);
_setString(
pref, "storageLocation", storageLocation, defaultSet.storageLocation);
pref.setInt("settingsVersion", version);
@ -287,6 +296,8 @@ class Settings extends ChangeNotifier {
'localGitRepoFolderName': localGitRepoFolderName.toString(),
'remoteGitRepoFolderName': remoteGitRepoFolderName.toString(),
'bottomMenuBar': bottomMenuBar.toString(),
'storeInternally': storeInternally.toString(),
'storageLocation': storageLocation,
};
}

View File

@ -248,6 +248,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.7"
filesystem_picker:
dependency: "direct main"
description:
name: filesystem_picker
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3"
fimber:
dependency: "direct main"
description:
@ -686,6 +693,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0-nullsafety.1"
permission_handler:
dependency: "direct main"
description:
name: permission_handler
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.1+1"
permission_handler_platform_interface:
dependency: transitive
description:
name: permission_handler_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
petitparser:
dependency: transitive
description:

View File

@ -59,6 +59,8 @@ dependencies:
multicast_dns: ^0.2.2
bonsoir: ^0.1.2+2
file_picker: ^2.0.7
filesystem_picker: ^1.0.3 # for directories
permission_handler: ^5.0.1+1
dev_dependencies:
flutter_launcher_icons: "^0.7.2"