mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-25 19:27:24 +02:00
common, mobile: Adapt to new work part API
This commit is contained in:
parent
9bd0348f35
commit
813fa2e47a
5 changed files with 83 additions and 76 deletions
|
|
@ -156,8 +156,8 @@ class _TracksEditorState extends State<TracksEditor> {
|
|||
trackModels[i].workPartIndex = null;
|
||||
trackModels[i].workPartTitle = null;
|
||||
} else {
|
||||
trackModels[i].workPartIndex = workInfo.parts[i].work.partIndex;
|
||||
trackModels[i].workPartTitle = workInfo.parts[i].work.title;
|
||||
trackModels[i].workPartIndex = workInfo.parts[i].part.partIndex;
|
||||
trackModels[i].workPartTitle = workInfo.parts[i].part.title;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -190,7 +190,7 @@ class _WorkEditorState extends State<WorkEditor> {
|
|||
|
||||
for (final partInfo in widget.workInfo.parts) {
|
||||
parts.add(PartData(
|
||||
title: partInfo.work.title,
|
||||
title: partInfo.part.title,
|
||||
composer: partInfo.composer,
|
||||
instruments: List.from(partInfo.instruments),
|
||||
));
|
||||
|
|
@ -276,7 +276,7 @@ class _WorkEditorState extends State<WorkEditor> {
|
|||
for (var i = 0; i < parts.length; i++) {
|
||||
final part = parts[i];
|
||||
partInfos.add(PartInfo(
|
||||
work: Work(
|
||||
part: WorkPart(
|
||||
id: generateId(),
|
||||
title: part.titleController.text,
|
||||
composer: part.composer?.id,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:musicus_database/musicus_database.dart';
|
||||
|
||||
import '../backend.dart';
|
||||
|
||||
/// A widget showing information on a list of performances.
|
||||
class PerformancesText extends StatelessWidget {
|
||||
/// The information to show.
|
||||
|
|
@ -38,36 +36,3 @@ class PerformancesText extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
|
||||
class WorkText extends StatelessWidget {
|
||||
final int workId;
|
||||
|
||||
WorkText(this.workId);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final backend = MusicusBackend.of(context);
|
||||
|
||||
return StreamBuilder<Work>(
|
||||
stream: backend.db.workById(workId).watchSingle(),
|
||||
builder: (context, snapshot) => Text(snapshot.data?.title ?? '...'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ComposersText extends StatelessWidget {
|
||||
final int workId;
|
||||
|
||||
ComposersText(this.workId);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final backend = MusicusBackend.of(context);
|
||||
|
||||
return StreamBuilder<List<Person>>(
|
||||
stream: backend.db.composersByWork(workId).watch(),
|
||||
builder: (context, snapshot) => Text(snapshot.hasData
|
||||
? snapshot.data.map((p) => '${p.firstName} ${p.lastName}').join(', ')
|
||||
: '...'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ class _ProgramScreenState extends State<ProgramScreen> {
|
|||
left: 8.0,
|
||||
),
|
||||
child: Text(
|
||||
partInfo.work.title,
|
||||
partInfo.part.title,
|
||||
style: TextStyle(
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:musicus_common/musicus_common.dart';
|
||||
import 'package:musicus_database/musicus_database.dart';
|
||||
|
|
@ -6,10 +8,68 @@ import '../screens/program.dart';
|
|||
|
||||
import 'play_pause_button.dart';
|
||||
|
||||
class PlayerBar extends StatelessWidget {
|
||||
class PlayerBar extends StatefulWidget {
|
||||
@override
|
||||
_PlayerBarState createState() => _PlayerBarState();
|
||||
}
|
||||
|
||||
class _PlayerBarState extends State<PlayerBar> {
|
||||
MusicusBackendState _backend;
|
||||
StreamSubscription<InternalTrack> _currentTrackSubscribtion;
|
||||
WorkInfo _workInfo;
|
||||
List<int> _partIds;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
|
||||
_backend = MusicusBackend.of(context);
|
||||
|
||||
_currentTrackSubscribtion?.cancel();
|
||||
_currentTrackSubscribtion = _backend.playback.currentTrack.listen((track) {
|
||||
if (track != null) {
|
||||
_setTrack(track.track);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _setTrack(Track track) async {
|
||||
final recording =
|
||||
await _backend.db.recordingById(track.recordingId).getSingle();
|
||||
final workInfo = await _backend.db.getWork(recording.work);
|
||||
final partIds = track.partIds;
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_workInfo = workInfo;
|
||||
_partIds = partIds;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final backend = MusicusBackend.of(context);
|
||||
String title;
|
||||
String subtitle;
|
||||
|
||||
if (_workInfo != null) {
|
||||
title = _workInfo.composers
|
||||
.map((p) => '${p.firstName} ${p.lastName}')
|
||||
.join(', ');
|
||||
|
||||
final subtitleBuffer = StringBuffer(_workInfo.work.title);
|
||||
|
||||
if (_partIds.isNotEmpty) {
|
||||
subtitleBuffer.write(': ');
|
||||
subtitleBuffer.write(
|
||||
_partIds.map((i) => _workInfo.parts[i].part.title).join(', '));
|
||||
}
|
||||
|
||||
subtitle = subtitleBuffer.toString();
|
||||
} else {
|
||||
title = '...';
|
||||
subtitle = '...';
|
||||
}
|
||||
|
||||
return BottomAppBar(
|
||||
child: InkWell(
|
||||
|
|
@ -17,7 +77,7 @@ class PlayerBar extends StatelessWidget {
|
|||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
StreamBuilder(
|
||||
stream: backend.playback.normalizedPosition,
|
||||
stream: _backend.playback.normalizedPosition,
|
||||
builder: (context, snapshot) => LinearProgressIndicator(
|
||||
value: snapshot.data,
|
||||
),
|
||||
|
|
@ -29,39 +89,15 @@ class PlayerBar extends StatelessWidget {
|
|||
child: Icon(Icons.keyboard_arrow_up),
|
||||
),
|
||||
Expanded(
|
||||
child: StreamBuilder<InternalTrack>(
|
||||
stream: backend.playback.currentTrack,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.data != null) {
|
||||
final recordingId = snapshot.data.track.recordingId;
|
||||
|
||||
return FutureBuilder<Recording>(
|
||||
future:
|
||||
backend.db.recordingById(recordingId).getSingle(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
final workId = snapshot.data.work;
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
DefaultTextStyle.merge(
|
||||
style:
|
||||
TextStyle(fontWeight: FontWeight.bold),
|
||||
child: ComposersText(workId),
|
||||
),
|
||||
WorkText(workId),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return Container();
|
||||
}
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return Container();
|
||||
}
|
||||
},
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
DefaultTextStyle.merge(
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
child: Text(title),
|
||||
),
|
||||
Text(subtitle),
|
||||
],
|
||||
),
|
||||
),
|
||||
PlayPauseButton(),
|
||||
|
|
@ -78,4 +114,10 @@ class PlayerBar extends StatelessWidget {
|
|||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
_currentTrackSubscribtion?.cancel();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue