mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 18:57:25 +01:00
Use the storage access framework
Everything related to file system access has been rewritten to make use of the storage access framework. This means that the WRITE_EXTERNAL_STORAGE is no longer needed. Because of that, the dependency on permission_handler could be dropped and all code related to permission handling has been removed. To be able to open a whole document tree, the minSdkVersion was bumped to 21. Finally the file selector was rewritten using custom platform dependent code.
This commit is contained in:
parent
febcf29cf1
commit
e9f0bd03e7
9 changed files with 204 additions and 281 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
|
|
@ -7,7 +7,6 @@ import 'database.dart';
|
|||
|
||||
enum BackendStatus {
|
||||
loading,
|
||||
needsPermissions,
|
||||
setup,
|
||||
ready,
|
||||
}
|
||||
|
|
@ -27,15 +26,15 @@ class Backend extends StatefulWidget {
|
|||
}
|
||||
|
||||
class BackendState extends State<Backend> {
|
||||
final _permissionHandler = PermissionHandler();
|
||||
static const _platform = MethodChannel('de.johrpan.musicus/platform');
|
||||
|
||||
final playerActive = BehaviorSubject.seeded(false);
|
||||
final playing = BehaviorSubject.seeded(false);
|
||||
final position = BehaviorSubject.seeded(0.0);
|
||||
|
||||
Database db;
|
||||
BackendStatus status = BackendStatus.loading;
|
||||
String musicLibraryPath;
|
||||
Database db;
|
||||
String musicLibraryUri;
|
||||
|
||||
SharedPreferences _shPref;
|
||||
|
||||
|
|
@ -54,25 +53,15 @@ class BackendState extends State<Backend> {
|
|||
}
|
||||
|
||||
Future<void> _load() async {
|
||||
_shPref = await SharedPreferences.getInstance();
|
||||
musicLibraryPath = _shPref.getString('musicLibraryPath');
|
||||
|
||||
db = Database('musicus.sqlite');
|
||||
|
||||
final permissionStatus =
|
||||
await _permissionHandler.checkPermissionStatus(PermissionGroup.storage);
|
||||
|
||||
if (permissionStatus != PermissionStatus.granted) {
|
||||
setState(() {
|
||||
status = BackendStatus.needsPermissions;
|
||||
});
|
||||
} else {
|
||||
await _loadMusicLibrary();
|
||||
}
|
||||
_shPref = await SharedPreferences.getInstance();
|
||||
musicLibraryUri = _shPref.getString('musicLibraryUri');
|
||||
|
||||
_loadMusicLibrary();
|
||||
}
|
||||
|
||||
Future<void> _loadMusicLibrary() async {
|
||||
if (musicLibraryPath == null) {
|
||||
if (musicLibraryUri == null) {
|
||||
setState(() {
|
||||
status = BackendStatus.setup;
|
||||
});
|
||||
|
|
@ -83,26 +72,19 @@ class BackendState extends State<Backend> {
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> requestPermissions() async {
|
||||
final result =
|
||||
await _permissionHandler.requestPermissions([PermissionGroup.storage]);
|
||||
Future<void> chooseMusicLibraryUri() async {
|
||||
final uri = await _platform.invokeMethod<String>('openTree');
|
||||
|
||||
if (result[PermissionGroup.storage] == PermissionStatus.granted) {
|
||||
_loadMusicLibrary();
|
||||
if (uri != null) {
|
||||
musicLibraryUri = uri;
|
||||
await _shPref.setString('musicLibraryUri', uri);
|
||||
setState(() {
|
||||
status = BackendStatus.loading;
|
||||
});
|
||||
await _loadMusicLibrary();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> openAppSettings() => _permissionHandler.openAppSettings();
|
||||
|
||||
Future<void> setMusicLibraryPath(String path) async {
|
||||
musicLibraryPath = path;
|
||||
await _shPref.setString('musicLibraryPath', path);
|
||||
setState(() {
|
||||
status = BackendStatus.loading;
|
||||
});
|
||||
await _loadMusicLibrary();
|
||||
}
|
||||
|
||||
void startPlayer() {
|
||||
playerActive.add(true);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue