Remove support for nested work parts

We will add a way to create sections as a much simpler replacement in
the future.
This commit is contained in:
Elias Projahn 2020-04-24 21:18:24 +02:00
parent f7f109179f
commit 18bc8eb982
3 changed files with 30 additions and 143 deletions

View file

@ -16,8 +16,7 @@ CREATE TABLE works (
composer INTEGER REFERENCES persons(id),
title TEXT NOT NULL,
part_of INTEGER REFERENCES works(id) ON DELETE CASCADE,
part_index INTEGER,
part_level INTEGER
part_index INTEGER
);
CREATE TABLE instrumentations (

View file

@ -8,13 +8,11 @@ import '../selectors/person.dart';
class PartData {
final titleController = TextEditingController();
int level;
Person composer;
List<Instrument> instruments;
PartData({
String title,
this.level = 0,
this.composer,
this.instruments = const [],
}) {
@ -108,17 +106,13 @@ class WorkProperties extends StatelessWidget {
class PartTile extends StatefulWidget {
final PartData part;
final void Function() onMore;
final void Function() onAdd;
final void Function() onDelete;
final void Function(int levels) onMove;
PartTile({
Key key,
@required this.part,
@required this.onMore,
@required this.onAdd,
@required this.onDelete,
@required this.onMove,
}) : super(key: key);
@override
@ -126,27 +120,14 @@ class PartTile extends StatefulWidget {
}
class _PartTileState extends State<PartTile> {
static const unit = 16.0;
static const iconShrink = 4.0;
double dragStart;
double dragDelta = 0.0;
@override
Widget build(BuildContext context) {
final padding = widget.part.level * unit + dragDelta;
final iconSize = 24 - widget.part.level * iconShrink;
return GestureDetector(
child: Padding(
padding: EdgeInsets.only(left: padding > 0.0 ? padding : 0.0),
child: Row(
return Row(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 16.0, right: 8.0),
child: Icon(
Icons.drag_handle,
size: iconSize,
),
),
Expanded(
@ -160,38 +141,13 @@ class _PartTileState extends State<PartTile> {
),
IconButton(
icon: const Icon(Icons.more_horiz),
iconSize: iconSize,
onPressed: widget.onMore,
),
IconButton(
icon: const Icon(Icons.add),
iconSize: iconSize,
onPressed: widget.onAdd,
),
IconButton(
icon: const Icon(Icons.delete),
iconSize: iconSize,
onPressed: widget.onDelete,
),
],
),
),
onHorizontalDragStart: (details) {
dragStart = details.localPosition.dx;
},
onHorizontalDragUpdate: (details) {
setState(() {
dragDelta = details.localPosition.dx - dragStart;
});
},
onHorizontalDragEnd: (details) {
if (dragDelta.abs() >= unit) {
widget.onMove((dragDelta / unit).round());
}
setState(() {
dragDelta = 0.0;
});
},
);
}
}
@ -276,7 +232,6 @@ class _WorkEditorState extends State<WorkEditor> {
parts.add(PartData(
title: dbPart.title,
composer: partComposer,
level: dbPart.partLevel,
instruments: partInstruments,
));
});
@ -285,17 +240,6 @@ class _WorkEditorState extends State<WorkEditor> {
}
}
void cleanLevels() {
var previousLevel = -1;
for (var i = 0; i < parts.length; i++) {
final part = parts[i];
if (part.level > previousLevel + 1) {
part.level = previousLevel + 1;
}
previousLevel = part.level;
}
}
@override
Widget build(BuildContext context) {
final List<Widget> partTiles = [];
@ -334,30 +278,11 @@ class _WorkEditorState extends State<WorkEditor> {
),
);
},
onAdd: () {
setState(() {
parts.insert(i + 1, PartData(level: part.level + 1));
});
},
onDelete: () {
setState(() {
parts.removeAt(i);
cleanLevels();
});
},
onMove: (levels) {
if (levels > 0 && i > 0 && parts[i - 1].level >= part.level) {
setState(() {
part.level++;
});
} else if (levels < 0) {
final newLevel = part.level + levels;
setState(() {
part.level = newLevel > 0 ? newLevel : 0;
cleanLevels();
});
}
},
));
}
@ -389,7 +314,6 @@ class _WorkEditorState extends State<WorkEditor> {
composer: part.composer?.id,
partOf: workId,
partIndex: i,
partLevel: part.level,
),
instrumentIds: part.instruments.map((i) => i.id).toList(),
));
@ -425,7 +349,7 @@ class _WorkEditorState extends State<WorkEditor> {
padding: const EdgeInsets.only(left: 16.0, top: 16.0),
child: Text(
'Parts',
style: Theme.of(context).textTheme.subhead,
style: Theme.of(context).textTheme.subtitle1,
),
),
],
@ -437,8 +361,6 @@ class _WorkEditorState extends State<WorkEditor> {
final newIndex = i2 > i1 ? i2 - 1 : i2;
parts.insert(newIndex, part);
cleanLevels();
});
},
),
@ -447,7 +369,7 @@ class _WorkEditorState extends State<WorkEditor> {
label: Text('Add part'),
onPressed: () {
setState(() {
parts.add(PartData(level: 0));
parts.add(PartData());
});
},
),

View file

@ -71,8 +71,8 @@ class ProgramTile extends StatelessWidget {
children: <Widget>[
for (final part in item.workParts)
Padding(
padding: EdgeInsets.only(
left: 8.0 + part.partLevel * 8.0,
padding: const EdgeInsets.only(
left: 8.0,
),
child: Text(
part.title,
@ -162,10 +162,6 @@ class _ProgramScreenState extends State<ProgramScreen> {
// from the database again.
int lastWorkId;
// We need to keep track of the last work part to be able to check for the
// parent work parts that were left out between the two last tracks.
int lastPartId;
// This will always contain the parts of the current work.
List<Work> workParts = [];
@ -193,40 +189,10 @@ class _ProgramScreenState extends State<ProgramScreen> {
}
lastWorkId = recording.work;
lastPartId = null;
}
/// Search for all parent work parts of [partId] starting from the part
/// with the ID [startId] and add them to the part list.
void addParentParts(int startId, int partId) {
final level = workParts[partId].partLevel;
final List<Work> parents = List.filled(level - 1, null);
for (var i = startId; i < partId; i++) {
final part = workParts[i];
if (part.partLevel < parents.length) {
parents[part.partLevel] = part;
}
}
newWorkParts.addAll(parents);
}
for (final partId in partIds) {
// We will need to include all parent work parts first, if there were
// work parts left out between the last two tracks or if the current
// work part comes before the previous one.
if (lastPartId != null) {
if (partIds.first > lastPartId + 1) {
addParentParts(lastPartId + 1, partId);
}
} else if (partIds.first > 0) {
addParentParts(0, partId);
}
newWorkParts.add(workParts[partId]);
lastPartId = partId;
}
newItems.add(ProgramItem(