Allow load/remove commands to take multiple entries at once

This commit is contained in:
Oystein Kristoffer Tveit 2024-12-23 13:08:17 +01:00
parent 48f03354d3
commit 8fa9c0b762
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
2 changed files with 8 additions and 10 deletions

View File

@ -52,11 +52,11 @@ class Command extends PlayerConnectionEvent {
// ); // );
// } // }
factory Command.load(String url) { factory Command.load(List<String> urls) {
return Command( return Command(
type: 'load', type: 'load',
value: { value: {
'url': url, 'urls': urls,
}, },
); );
} }
@ -116,11 +116,11 @@ class Command extends PlayerConnectionEvent {
); );
} }
factory Command.playlistRemove(int position) { factory Command.playlistRemove(List<int> positions) {
return Command( return Command(
type: 'playlist_remove', type: 'playlist_remove',
value: { value: {
'position': position, 'positions': positions,
}, },
); );
} }

View File

@ -107,7 +107,7 @@ class PlayerUIBody extends StatelessWidget {
color: Colors.redAccent, color: Colors.redAccent,
onPressed: () { onPressed: () {
BlocProvider.of<ConnectionStateBloc>(context) BlocProvider.of<ConnectionStateBloc>(context)
.add(Command.playlistRemove(i)); .add(Command.playlistRemove([i]));
}, },
), ),
], ],
@ -133,7 +133,7 @@ class PlayerUIBody extends StatelessWidget {
), ),
onSubmitted: (value) { onSubmitted: (value) {
BlocProvider.of<ConnectionStateBloc>(context) BlocProvider.of<ConnectionStateBloc>(context)
.add(Command.load(value)); .add(Command.load([value]));
_textController.clear(); _textController.clear();
}, },
), ),
@ -144,7 +144,7 @@ class PlayerUIBody extends StatelessWidget {
tooltip: 'Add link to playlist', tooltip: 'Add link to playlist',
onPressed: () { onPressed: () {
BlocProvider.of<ConnectionStateBloc>(context) BlocProvider.of<ConnectionStateBloc>(context)
.add(Command.load(_textController.text)); .add(Command.load([_textController.text]));
_textController.clear(); _textController.clear();
}, },
), ),
@ -159,9 +159,7 @@ class PlayerUIBody extends StatelessWidget {
return; return;
} }
for (final link in links.split('\n')) { blocProvider.add(Command.load(links.split('\n')));
blocProvider.add(Command.load(link));
}
}, },
), ),
], ],