feat: also sync beat annotations to api, store beat annotations in Documents
This commit is contained in:
@@ -167,12 +167,13 @@ class LockstepViewModel(
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes one JSON file under app files dir ([BeatAnnotationStorage]) for the track described
|
||||
* by [event]. Skips when [beatTimesMs] is empty.
|
||||
* Writes one JSON file under public Documents/Lockstep/{sessionFolder}/ for the track described
|
||||
* by [event], records file metadata, and uploads when signed in. Skips when [beatTimesMs] is empty.
|
||||
*/
|
||||
fun persistBeatAnnotation(
|
||||
playlistId: String,
|
||||
playlistDisplayName: String,
|
||||
sessionFolder: String,
|
||||
event: TrackBoundaryEvent,
|
||||
beatTimesMs: List<Long>,
|
||||
) {
|
||||
@@ -183,15 +184,26 @@ class LockstepViewModel(
|
||||
val pairing = pairingDao.findForTrack(playlistId, event.trackId)
|
||||
val docId = BeatAnnotationStorage.mp3DocumentContentId(pairing?.localUri)
|
||||
val contentId = docId.ifBlank { event.trackId }
|
||||
BeatAnnotationStorage.writeAnnotationsFile(
|
||||
context = getApplication(),
|
||||
playlistDisplayName = playlistDisplayName,
|
||||
trackQueueIndex0Based = event.queueIndex,
|
||||
contentId = contentId,
|
||||
title = event.title,
|
||||
artist = event.artist,
|
||||
beatTimesMs = beatTimesMs,
|
||||
)
|
||||
val uri =
|
||||
BeatAnnotationStorage.writeAnnotationsFile(
|
||||
context = getApplication(),
|
||||
sessionFolder = sessionFolder,
|
||||
playlistDisplayName = playlistDisplayName,
|
||||
trackQueueIndex0Based = event.queueIndex,
|
||||
contentId = contentId,
|
||||
title = event.title,
|
||||
artist = event.artist,
|
||||
beatTimesMs = beatTimesMs,
|
||||
) ?: return@launch
|
||||
val entry =
|
||||
FileMetadataEntity(
|
||||
fileUri = uri.toString(),
|
||||
trackId = event.trackId,
|
||||
type = FileMetadataEntity.TYPE_ANNOTATION,
|
||||
version = BuildConfig.VERSION_CODE,
|
||||
)
|
||||
val id = fileMetadataDao.insert(entry)
|
||||
syncMetadataEntry(entry.copy(id = id))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,7 +311,7 @@ class LockstepViewModel(
|
||||
}
|
||||
val failures = pending.count { entry -> !syncMetadataEntry(entry) }
|
||||
if (failures > 0) {
|
||||
"Failed to sync $failures collection(s)"
|
||||
"Failed to sync $failures file(s)"
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user