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 treeUri = Uri.parse(call.argument<String>("treeUri"))
|
||||||
val id = call.argument<String>("id")!!
|
val id = call.argument<String>("id")!!
|
||||||
result.success(readFile(treeUri, 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") {
|
} else if (call.method == "readFileByName") {
|
||||||
val treeUri = Uri.parse(call.argument<String>("treeUri"))
|
val treeUri = Uri.parse(call.argument<String>("treeUri"))
|
||||||
val parentId = call.argument<String>("parentId")!!
|
val parentId = call.argument<String>("parentId")!!
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@ class Track {
|
||||||
/// Which work parts of the recorded work are contained in this track.
|
/// Which work parts of the recorded work are contained in this track.
|
||||||
final List<int> partIds;
|
final List<int> partIds;
|
||||||
|
|
||||||
|
String uri;
|
||||||
|
|
||||||
Track({
|
Track({
|
||||||
this.fileName,
|
this.fileName,
|
||||||
this.index,
|
this.index,
|
||||||
|
|
@ -110,6 +112,10 @@ class MusicLibrary {
|
||||||
final content = await Platform.readFile(treeUri, child.id);
|
final content = await Platform.readFile(treeUri, child.id);
|
||||||
final musicusFile = MusicusFile.fromJson(jsonDecode(content));
|
final musicusFile = MusicusFile.fromJson(jsonDecode(content));
|
||||||
for (final track in musicusFile.tracks) {
|
for (final track in musicusFile.tracks) {
|
||||||
|
final uri =
|
||||||
|
await Platform.getUriByName(treeUri, parentId, track.fileName);
|
||||||
|
track.uri = uri;
|
||||||
|
|
||||||
if (tracks.containsKey(track.recordingId)) {
|
if (tracks.containsKey(track.recordingId)) {
|
||||||
tracks[track.recordingId].add(track);
|
tracks[track.recordingId].add(track);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -124,7 +130,7 @@ class MusicLibrary {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a list of new tracks to the music library.
|
/// Add a list of new tracks to the music library.
|
||||||
///
|
///
|
||||||
/// They are stored in this instance and on disk in the directory denoted by
|
/// They are stored in this instance and on disk in the directory denoted by
|
||||||
/// [parentId].
|
/// [parentId].
|
||||||
Future<void> addTracks(String parentId, List<Track> newTracks) async {
|
Future<void> addTracks(String parentId, List<Track> newTracks) async {
|
||||||
|
|
@ -140,6 +146,10 @@ class MusicLibrary {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final track in newTracks) {
|
for (final track in newTracks) {
|
||||||
|
final uri =
|
||||||
|
await Platform.getUriByName(treeUri, parentId, track.fileName);
|
||||||
|
track.uri = uri;
|
||||||
|
|
||||||
musicusFile.tracks.add(track);
|
musicusFile.tracks.add(track);
|
||||||
|
|
||||||
if (tracks.containsKey(track.recordingId)) {
|
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
|
/// Read contents of file by name
|
||||||
///
|
///
|
||||||
/// [treeId] is the base URI from the SAF, [parentId] is the document ID of
|
/// [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