mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 10:47:25 +01: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].workPartIndex = null;
|
||||||
trackModels[i].workPartTitle = null;
|
trackModels[i].workPartTitle = null;
|
||||||
} else {
|
} else {
|
||||||
trackModels[i].workPartIndex = workInfo.parts[i].work.partIndex;
|
trackModels[i].workPartIndex = workInfo.parts[i].part.partIndex;
|
||||||
trackModels[i].workPartTitle = workInfo.parts[i].work.title;
|
trackModels[i].workPartTitle = workInfo.parts[i].part.title;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -190,7 +190,7 @@ class _WorkEditorState extends State<WorkEditor> {
|
||||||
|
|
||||||
for (final partInfo in widget.workInfo.parts) {
|
for (final partInfo in widget.workInfo.parts) {
|
||||||
parts.add(PartData(
|
parts.add(PartData(
|
||||||
title: partInfo.work.title,
|
title: partInfo.part.title,
|
||||||
composer: partInfo.composer,
|
composer: partInfo.composer,
|
||||||
instruments: List.from(partInfo.instruments),
|
instruments: List.from(partInfo.instruments),
|
||||||
));
|
));
|
||||||
|
|
@ -276,7 +276,7 @@ class _WorkEditorState extends State<WorkEditor> {
|
||||||
for (var i = 0; i < parts.length; i++) {
|
for (var i = 0; i < parts.length; i++) {
|
||||||
final part = parts[i];
|
final part = parts[i];
|
||||||
partInfos.add(PartInfo(
|
partInfos.add(PartInfo(
|
||||||
work: Work(
|
part: WorkPart(
|
||||||
id: generateId(),
|
id: generateId(),
|
||||||
title: part.titleController.text,
|
title: part.titleController.text,
|
||||||
composer: part.composer?.id,
|
composer: part.composer?.id,
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:musicus_database/musicus_database.dart';
|
import 'package:musicus_database/musicus_database.dart';
|
||||||
|
|
||||||
import '../backend.dart';
|
|
||||||
|
|
||||||
/// A widget showing information on a list of performances.
|
/// A widget showing information on a list of performances.
|
||||||
class PerformancesText extends StatelessWidget {
|
class PerformancesText extends StatelessWidget {
|
||||||
/// The information to show.
|
/// 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,
|
left: 8.0,
|
||||||
),
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
partInfo.work.title,
|
partInfo.part.title,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontStyle: FontStyle.italic,
|
fontStyle: FontStyle.italic,
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:musicus_common/musicus_common.dart';
|
import 'package:musicus_common/musicus_common.dart';
|
||||||
import 'package:musicus_database/musicus_database.dart';
|
import 'package:musicus_database/musicus_database.dart';
|
||||||
|
|
@ -6,10 +8,68 @@ import '../screens/program.dart';
|
||||||
|
|
||||||
import 'play_pause_button.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
|
@override
|
||||||
Widget build(BuildContext context) {
|
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(
|
return BottomAppBar(
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
|
|
@ -17,7 +77,7 @@ class PlayerBar extends StatelessWidget {
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
StreamBuilder(
|
StreamBuilder(
|
||||||
stream: backend.playback.normalizedPosition,
|
stream: _backend.playback.normalizedPosition,
|
||||||
builder: (context, snapshot) => LinearProgressIndicator(
|
builder: (context, snapshot) => LinearProgressIndicator(
|
||||||
value: snapshot.data,
|
value: snapshot.data,
|
||||||
),
|
),
|
||||||
|
|
@ -29,39 +89,15 @@ class PlayerBar extends StatelessWidget {
|
||||||
child: Icon(Icons.keyboard_arrow_up),
|
child: Icon(Icons.keyboard_arrow_up),
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: StreamBuilder<InternalTrack>(
|
child: Column(
|
||||||
stream: backend.playback.currentTrack,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
builder: (context, snapshot) {
|
children: <Widget>[
|
||||||
if (snapshot.data != null) {
|
DefaultTextStyle.merge(
|
||||||
final recordingId = snapshot.data.track.recordingId;
|
style: TextStyle(fontWeight: FontWeight.bold),
|
||||||
|
child: Text(title),
|
||||||
return FutureBuilder<Recording>(
|
),
|
||||||
future:
|
Text(subtitle),
|
||||||
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();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
PlayPauseButton(),
|
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