mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 18:57:25 +01:00
common: Adapt to database changes
This commit is contained in:
parent
9e485eac11
commit
84b700236b
9 changed files with 85 additions and 270 deletions
|
|
@ -4,7 +4,6 @@ import 'package:flutter/material.dart';
|
|||
import 'package:musicus_database/musicus_database.dart';
|
||||
|
||||
import '../backend.dart';
|
||||
import '../library.dart';
|
||||
import '../screens/program.dart';
|
||||
|
||||
import 'play_pause_button.dart';
|
||||
|
|
@ -16,7 +15,7 @@ class PlayerBar extends StatefulWidget {
|
|||
|
||||
class _PlayerBarState extends State<PlayerBar> {
|
||||
MusicusBackendState _backend;
|
||||
StreamSubscription<InternalTrack> _currentTrackSubscribtion;
|
||||
StreamSubscription<Track> _currentTrackSubscribtion;
|
||||
WorkInfo _workInfo;
|
||||
List<int> _partIds;
|
||||
|
||||
|
|
@ -29,16 +28,22 @@ class _PlayerBarState extends State<PlayerBar> {
|
|||
_currentTrackSubscribtion?.cancel();
|
||||
_currentTrackSubscribtion = _backend.playback.currentTrack.listen((track) {
|
||||
if (track != null) {
|
||||
_setTrack(track.track);
|
||||
_setTrack(track);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _setTrack(Track track) async {
|
||||
final recording =
|
||||
await _backend.db.recordingById(track.recordingId).getSingle();
|
||||
await _backend.db.recordingById(track.recording).getSingle();
|
||||
|
||||
final workInfo = await _backend.db.getWork(recording.work);
|
||||
final partIds = track.partIds;
|
||||
|
||||
final partIds = track.workParts
|
||||
.split(',')
|
||||
.where((p) => p.isNotEmpty)
|
||||
.map((p) => int.parse(p))
|
||||
.toList();
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
|
|
@ -54,27 +59,14 @@ class _PlayerBarState extends State<PlayerBar> {
|
|||
String subtitle;
|
||||
|
||||
if (_workInfo != null) {
|
||||
title = _workInfo.composers
|
||||
.map((p) => '${p.firstName} ${p.lastName}')
|
||||
.join(', ');
|
||||
title = '${_workInfo.composer.firstName} ${_workInfo.composer.lastName}';
|
||||
|
||||
final subtitleBuffer = StringBuffer(_workInfo.work.title);
|
||||
|
||||
if (_partIds.isNotEmpty) {
|
||||
subtitleBuffer.write(': ');
|
||||
|
||||
final section = _workInfo.sections.lastWhere(
|
||||
(s) => s.beforePartIndex <= _partIds[0],
|
||||
orElse: () => null,
|
||||
);
|
||||
|
||||
if (section != null) {
|
||||
subtitleBuffer.write(section.title);
|
||||
subtitleBuffer.write(': ');
|
||||
}
|
||||
|
||||
subtitleBuffer.write(
|
||||
_partIds.map((i) => _workInfo.parts[i].part.title).join(', '));
|
||||
subtitleBuffer
|
||||
.write(_partIds.map((i) => _workInfo.parts[i].title).join(', '));
|
||||
}
|
||||
|
||||
subtitle = subtitleBuffer.toString();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue