mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 10:47:25 +01:00
Store URI within tracks
This commit is contained in:
parent
da804bf699
commit
5216c7d359
3 changed files with 32 additions and 1 deletions
|
|
@ -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")!!
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
@ -124,7 +130,7 @@ class MusicLibrary {
|
|||
}
|
||||
|
||||
/// Add a list of new tracks to the music library.
|
||||
///
|
||||
///
|
||||
/// They are stored in this instance and on disk in the directory denoted by
|
||||
/// [parentId].
|
||||
Future<void> addTracks(String parentId, List<Track> newTracks) async {
|
||||
|
|
@ -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)) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue