Store URI within tracks

This commit is contained in:
Elias Projahn 2020-04-19 18:37:16 +02:00
parent da804bf699
commit 5216c7d359
3 changed files with 32 additions and 1 deletions

View file

@ -44,6 +44,11 @@ class MainActivity : FlutterActivity() {
val treeUri = Uri.parse(call.argument<String>("treeUri"))
val id = call.argument<String>("id")!!
result.success(readFile(treeUri, id))
} else if (call.method == "getUriByName") {
val treeUri = Uri.parse(call.argument<String>("treeUri"))
val parentId = call.argument<String>("parentId")!!
val fileName = call.argument<String>("fileName")!!
result.success(getUriByName(treeUri, parentId, fileName).toString())
} else if (call.method == "readFileByName") {
val treeUri = Uri.parse(call.argument<String>("treeUri"))
val parentId = call.argument<String>("parentId")!!

View file

@ -24,6 +24,8 @@ class Track {
/// Which work parts of the recorded work are contained in this track.
final List<int> partIds;
String uri;
Track({
this.fileName,
this.index,
@ -110,6 +112,10 @@ class MusicLibrary {
final content = await Platform.readFile(treeUri, child.id);
final musicusFile = MusicusFile.fromJson(jsonDecode(content));
for (final track in musicusFile.tracks) {
final uri =
await Platform.getUriByName(treeUri, parentId, track.fileName);
track.uri = uri;
if (tracks.containsKey(track.recordingId)) {
tracks[track.recordingId].add(track);
} else {
@ -140,6 +146,10 @@ class MusicLibrary {
}
for (final track in newTracks) {
final uri =
await Platform.getUriByName(treeUri, parentId, track.fileName);
track.uri = uri;
musicusFile.tracks.add(track);
if (tracks.containsKey(track.recordingId)) {

View file

@ -62,6 +62,22 @@ class Platform {
);
}
/// Get document URI by file name
///
/// [treeId] is the base URI from the SAF, [parentId] is the document ID of
/// the parent directory.
static Future<String> getUriByName(
String treeUri, String parentId, String fileName) async {
return await _platform.invokeMethod(
'getUriByName',
{
'treeUri': treeUri,
'parentId': parentId,
'fileName': fileName,
},
);
}
/// Read contents of file by name
///
/// [treeId] is the base URI from the SAF, [parentId] is the document ID of