From 18bc8eb9827e7aff8a3223c0d445872c3c3fb1e2 Mon Sep 17 00:00:00 2001 From: Elias Projahn Date: Fri, 24 Apr 2020 21:18:24 +0200 Subject: [PATCH] Remove support for nested work parts We will add a way to create sections as a much simpler replacement in the future. --- musicus/lib/database.moor | 3 +- musicus/lib/editors/work.dart | 132 +++++++------------------------ musicus/lib/screens/program.dart | 38 +-------- 3 files changed, 30 insertions(+), 143 deletions(-) diff --git a/musicus/lib/database.moor b/musicus/lib/database.moor index c53833a..2f1b81b 100644 --- a/musicus/lib/database.moor +++ b/musicus/lib/database.moor @@ -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 ( diff --git a/musicus/lib/editors/work.dart b/musicus/lib/editors/work.dart index f9ce830..6f77b48 100644 --- a/musicus/lib/editors/work.dart +++ b/musicus/lib/editors/work.dart @@ -8,13 +8,11 @@ import '../selectors/person.dart'; class PartData { final titleController = TextEditingController(); - int level; Person composer; List 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,72 +120,34 @@ class PartTile extends StatefulWidget { } class _PartTileState extends State { - 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( - children: [ - Padding( - padding: const EdgeInsets.only(left: 16.0, right: 8.0), - child: Icon( - Icons.drag_handle, - size: iconSize, - ), - ), - Expanded( - child: TextField( - controller: widget.part.titleController, - decoration: InputDecoration( - border: InputBorder.none, - hintText: 'Part title', - ), - ), - ), - 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, - ), - ], + return Row( + children: [ + Padding( + padding: const EdgeInsets.only(left: 16.0, right: 8.0), + child: Icon( + Icons.drag_handle, + ), ), - ), - 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; - }); - }, + Expanded( + child: TextField( + controller: widget.part.titleController, + decoration: InputDecoration( + border: InputBorder.none, + hintText: 'Part title', + ), + ), + ), + IconButton( + icon: const Icon(Icons.more_horiz), + onPressed: widget.onMore, + ), + IconButton( + icon: const Icon(Icons.delete), + onPressed: widget.onDelete, + ), + ], ); } } @@ -276,7 +232,6 @@ class _WorkEditorState extends State { parts.add(PartData( title: dbPart.title, composer: partComposer, - level: dbPart.partLevel, instruments: partInstruments, )); }); @@ -285,17 +240,6 @@ class _WorkEditorState extends State { } } - 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 partTiles = []; @@ -334,30 +278,11 @@ class _WorkEditorState extends State { ), ); }, - 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 { 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 { 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 { final newIndex = i2 > i1 ? i2 - 1 : i2; parts.insert(newIndex, part); - - cleanLevels(); }); }, ), @@ -447,7 +369,7 @@ class _WorkEditorState extends State { label: Text('Add part'), onPressed: () { setState(() { - parts.add(PartData(level: 0)); + parts.add(PartData()); }); }, ), diff --git a/musicus/lib/screens/program.dart b/musicus/lib/screens/program.dart index bbf4d90..6339c5d 100644 --- a/musicus/lib/screens/program.dart +++ b/musicus/lib/screens/program.dart @@ -71,8 +71,8 @@ class ProgramTile extends StatelessWidget { children: [ 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 { // 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 workParts = []; @@ -193,40 +189,10 @@ class _ProgramScreenState extends State { } 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 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(