mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-09-10 02:32:20 +08:00
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:
@ -5,6 +5,10 @@
|
|||||||
<uses-permission android:name="com.android.vending.BILLING" />
|
<uses-permission android:name="com.android.vending.BILLING" />
|
||||||
<uses-feature android:name="android.hardware.camera" android:required="false" />
|
<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
|
<application
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:icon="@mipmap/launcher_icon">
|
android:icon="@mipmap/launcher_icon">
|
||||||
|
@ -134,6 +134,8 @@ settings:
|
|||||||
storage:
|
storage:
|
||||||
title: Storage
|
title: Storage
|
||||||
fileName: Filename
|
fileName: Filename
|
||||||
|
useLocal: Store Repo Internally
|
||||||
|
repoLocation: Repo Location
|
||||||
drawer:
|
drawer:
|
||||||
title: Sidebar Settings
|
title: Sidebar Settings
|
||||||
bottomMenuBar:
|
bottomMenuBar:
|
||||||
|
@ -3,6 +3,7 @@ import 'package:easy_localization/easy_localization.dart';
|
|||||||
class Features {
|
class Features {
|
||||||
static bool alwaysPro = false;
|
static bool alwaysPro = false;
|
||||||
static bool perFolderConfig = false;
|
static bool perFolderConfig = false;
|
||||||
|
static bool externalStorage = false;
|
||||||
|
|
||||||
static final all = <Feature>[
|
static final all = <Feature>[
|
||||||
Feature.basicSearch,
|
Feature.basicSearch,
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:dynamic_theme/dynamic_theme.dart';
|
import 'package:dynamic_theme/dynamic_theme.dart';
|
||||||
import 'package:easy_localization/easy_localization.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:provider/provider.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
@ -282,6 +288,61 @@ class SettingsListState extends State<SettingsList> {
|
|||||||
Navigator.of(context).push(route);
|
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(
|
ListTile(
|
||||||
title: Text(tr('settings.misc.title')),
|
title: Text(tr('settings.misc.title')),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
|
@ -61,6 +61,9 @@ class Settings extends ChangeNotifier {
|
|||||||
String remoteGitRepoFolderName = "";
|
String remoteGitRepoFolderName = "";
|
||||||
bool remoteGitRepoConfigured = false;
|
bool remoteGitRepoConfigured = false;
|
||||||
|
|
||||||
|
bool storeInternally = true;
|
||||||
|
String storageLocation = "";
|
||||||
|
|
||||||
void load(SharedPreferences pref) {
|
void load(SharedPreferences pref) {
|
||||||
gitAuthor = pref.getString("gitAuthor") ?? gitAuthor;
|
gitAuthor = pref.getString("gitAuthor") ?? gitAuthor;
|
||||||
gitAuthorEmail = pref.getString("gitAuthorEmail") ?? gitAuthorEmail;
|
gitAuthorEmail = pref.getString("gitAuthorEmail") ?? gitAuthorEmail;
|
||||||
@ -129,6 +132,8 @@ class Settings extends ChangeNotifier {
|
|||||||
remoteGitRepoFolderName = pref.getString("remoteGitRepoPath") ?? "";
|
remoteGitRepoFolderName = pref.getString("remoteGitRepoPath") ?? "";
|
||||||
|
|
||||||
bottomMenuBar = pref.getBool("bottomMenuBar") ?? bottomMenuBar;
|
bottomMenuBar = pref.getBool("bottomMenuBar") ?? bottomMenuBar;
|
||||||
|
storeInternally = pref.getBool("storeInternally") ?? storeInternally;
|
||||||
|
storageLocation = pref.getString("storageLocation") ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> save() async {
|
Future<void> save() async {
|
||||||
@ -199,6 +204,10 @@ class Settings extends ChangeNotifier {
|
|||||||
_setStringSet(pref, "inlineTagPrefixes", inlineTagPrefixes,
|
_setStringSet(pref, "inlineTagPrefixes", inlineTagPrefixes,
|
||||||
defaultSet.inlineTagPrefixes);
|
defaultSet.inlineTagPrefixes);
|
||||||
_setBool(pref, "bottomMenuBar", bottomMenuBar, defaultSet.bottomMenuBar);
|
_setBool(pref, "bottomMenuBar", bottomMenuBar, defaultSet.bottomMenuBar);
|
||||||
|
_setBool(
|
||||||
|
pref, "storeInternally", storeInternally, defaultSet.storeInternally);
|
||||||
|
_setString(
|
||||||
|
pref, "storageLocation", storageLocation, defaultSet.storageLocation);
|
||||||
|
|
||||||
pref.setInt("settingsVersion", version);
|
pref.setInt("settingsVersion", version);
|
||||||
|
|
||||||
@ -287,6 +296,8 @@ class Settings extends ChangeNotifier {
|
|||||||
'localGitRepoFolderName': localGitRepoFolderName.toString(),
|
'localGitRepoFolderName': localGitRepoFolderName.toString(),
|
||||||
'remoteGitRepoFolderName': remoteGitRepoFolderName.toString(),
|
'remoteGitRepoFolderName': remoteGitRepoFolderName.toString(),
|
||||||
'bottomMenuBar': bottomMenuBar.toString(),
|
'bottomMenuBar': bottomMenuBar.toString(),
|
||||||
|
'storeInternally': storeInternally.toString(),
|
||||||
|
'storageLocation': storageLocation,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
21
pubspec.lock
21
pubspec.lock
@ -248,6 +248,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.7"
|
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:
|
fimber:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -686,6 +693,20 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.10.0-nullsafety.1"
|
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:
|
petitparser:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -59,6 +59,8 @@ dependencies:
|
|||||||
multicast_dns: ^0.2.2
|
multicast_dns: ^0.2.2
|
||||||
bonsoir: ^0.1.2+2
|
bonsoir: ^0.1.2+2
|
||||||
file_picker: ^2.0.7
|
file_picker: ^2.0.7
|
||||||
|
filesystem_picker: ^1.0.3 # for directories
|
||||||
|
permission_handler: ^5.0.1+1
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_launcher_icons: "^0.7.2"
|
flutter_launcher_icons: "^0.7.2"
|
||||||
|
Reference in New Issue
Block a user