Use SAF for Android
This commit is contained in:
@@ -11,27 +11,34 @@ class Sheet {
|
||||
Sheet(this.author, this.name, this.path);
|
||||
}
|
||||
|
||||
Future<List<Sheet>> loadSheetsSorted(String path) async {
|
||||
var sheets = await _loadSheets(path);
|
||||
Future<List<Sheet>> loadSheetsSorted(List<String> sheetsDirectoryFiles) async {
|
||||
var sheets = await _loadSheets(sheetsDirectoryFiles);
|
||||
sheets.sort((left, right) => left.name.compareTo(right.name));
|
||||
return sheets;
|
||||
}
|
||||
|
||||
Future<List<Sheet>> _loadSheets(String path) async {
|
||||
var dir = Directory(path);
|
||||
if (!dir.existsSync()) {
|
||||
throw Exception("Specified path '$path' does not exist");
|
||||
}
|
||||
Future<List<Sheet>> _loadSheets(List<String> sheetsDirectoryFiles) async {
|
||||
final List<Sheet> sheets = List.empty(growable: true);
|
||||
await for (final FileSystemEntity x in dir.list()) {
|
||||
if (x is Directory) {
|
||||
var authorName = p.basename(x.path);
|
||||
await for (final FileSystemEntity a in x.list()) {
|
||||
if (a is File) {
|
||||
var sheetName = p.basenameWithoutExtension(a.path);
|
||||
sheetName = sheetName.capitalize();
|
||||
sheets.add(Sheet(authorName, sheetName, a.path));
|
||||
var authorDirectories = sheetsDirectoryFiles
|
||||
.map((e) => Directory(e))
|
||||
.where((element) => element.existsSync());
|
||||
|
||||
for (Directory authorDirectory in authorDirectories) {
|
||||
var authorName = p.basename(authorDirectory.path);
|
||||
// Ignore hidden directories
|
||||
if (authorName.startsWith(".")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
await for (final FileSystemEntity sheetFile in authorDirectory.list()) {
|
||||
if (sheetFile is File) {
|
||||
var sheetName = p.basenameWithoutExtension(sheetFile.path);
|
||||
// Ignore hidden files
|
||||
if (sheetName.startsWith(".")) {
|
||||
continue;
|
||||
}
|
||||
sheetName = sheetName.capitalize();
|
||||
sheets.add(Sheet(authorName, sheetName, sheetFile.path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user