Skip to content

Commit

Permalink
Queue fixes (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
Feichtmeier authored Dec 20, 2023
1 parent 49ea1ba commit 203dbdd
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 25 deletions.
37 changes: 29 additions & 8 deletions lib/src/app/master_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import 'package:provider/provider.dart';
import 'package:yaru_widgets/yaru_widgets.dart';

import '../../build_context_x.dart';
import '../../common.dart';
import '../../data.dart';
import '../../library.dart';
import '../../player.dart';
import '../../radio.dart';
import '../../settings.dart';
import '../../theme.dart';
import '../common/common_widgets.dart';
import '../globals.dart';
import '../l10n/l10n.dart';
import 'master_item.dart';
Expand All @@ -32,7 +32,9 @@ class MasterDetailPage extends StatelessWidget {

@override
Widget build(BuildContext context) {
final startPlaylist = context.read<PlayerModel>().startPlaylist;
final playerModel = context.read<PlayerModel>();
final startPlaylist = playerModel.startPlaylist;
final pause = playerModel.pause;

return YaruMasterDetailTheme(
data: YaruMasterDetailTheme.of(context).copyWith(
Expand Down Expand Up @@ -64,19 +66,38 @@ class MasterDetailPage extends StatelessWidget {
if (index == 3 || index == 5) {
return item.titleBuilder(context);
}

final isEnQueued = context.select(
(PlayerModel m) =>
m.queueName != null && m.queueName == item.content?.$1,
);
final isPlaying = context.select(
(PlayerModel m) => m.isPlaying,
);

final onPlay = item.content?.$1 == null || item.content?.$2 == null
? null
: () {
if (isEnQueued) {
isPlaying ? pause() : playerModel.resume();
} else {
startPlaylist(
item.content!.$2,
item.content!.$1,
);
}
};

return Padding(
padding:
index == 0 ? const EdgeInsets.only(top: 5) : EdgeInsets.zero,
child: MasterTile(
iconData:
isPlaying && isEnQueued ? Iconz().pause : Iconz().playFilled,
selected: index == 4 ? false : selected,
title: item.titleBuilder(context),
subtitle: item.subtitleBuilder?.call(context),
onPlay: item.content?.$1 == null || item.content?.$2 == null
? null
: () => startPlaylist(
item.content!.$2,
item.content!.$1,
),
onPlay: onPlay,
leading: item.iconBuilder == null
? null
: Padding(
Expand Down
10 changes: 8 additions & 2 deletions lib/src/app/master_items.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:collection/collection.dart';
import 'package:flutter/material.dart';

import '../../common.dart';
import '../../constants.dart';
import '../../data.dart';
import '../../library.dart';
import '../../local_audio.dart';
Expand Down Expand Up @@ -88,6 +89,7 @@ List<MasterItem> createMasterItems({
),
MasterItem(
titleBuilder: (context) => Text(context.l10n.likedSongs),
content: (kLikedAudios, likedLocalAudios),
pageBuilder: (context) => LikedAudioPage(
onTextTap: onTextTap,
likedLocalAudios: likedLocalAudios,
Expand Down Expand Up @@ -168,8 +170,12 @@ List<MasterItem> createMasterItems({
for (final station in starredStations.entries)
MasterItem(
titleBuilder: (context) => Text(station.key),
subtitleBuilder: (context) =>
Text(station.value.firstOrNull?.artist ?? context.l10n.station),
subtitleBuilder: (context) {
final text = station.value.firstOrNull?.artist?.isNotEmpty == true
? station.value.firstOrNull!.artist!
: context.l10n.station;
return Text(text);
},
content: (station.key, station.value),
pageBuilder: (context) => isOnline
? StationPage(
Expand Down
9 changes: 1 addition & 8 deletions lib/src/common/audio_page_body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ class _AudioPageBodyState extends State<AudioPageBody> {
final playerModel = context.read<PlayerModel>();
final startPlaylist = playerModel.startPlaylist;

final queueName = context.select((PlayerModel m) => m.queueName);
final currentAudio = context.select((PlayerModel m) => m.audio);
final play = playerModel.play;
final pause = playerModel.pause;
Expand Down Expand Up @@ -231,9 +230,6 @@ class _AudioPageBodyState extends State<AudioPageBody> {
selected: audioSelected,
pause: pause,
resume: resume,
startPlaylist: widget.audios == null
? null
: () => play(newAudio: audio),
play: play,
lastPosition: libraryModel.getLastPosition.call(audio.url),
safeLastPosition: playerModel.safeLastPosition,
Expand Down Expand Up @@ -274,10 +270,7 @@ class _AudioPageBodyState extends State<AudioPageBody> {
? null
: () => startPlaylist(
widget.audios!.skip(index).toSet(),
queueName ??
audio.artist ??
audio.album ??
widget.audios.toString(),
widget.pageId,
),
resume: resume,
key: ValueKey(audio),
Expand Down
5 changes: 3 additions & 2 deletions lib/src/common/master_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:yaru_widgets/yaru_widgets.dart';

import '../../build_context_x.dart';
import '../../common.dart';
import '../../constants.dart';

class MasterTile extends StatefulWidget {
Expand All @@ -15,6 +14,7 @@ class MasterTile extends StatefulWidget {
this.subtitle,
this.trailing,
this.onPlay,
required this.iconData,
});

final bool? selected;
Expand All @@ -24,6 +24,7 @@ class MasterTile extends StatefulWidget {
final Widget? trailing;
final void Function()? onTap;
final void Function()? onPlay;
final IconData iconData;

@override
State<MasterTile> createState() => _MasterTileState();
Expand Down Expand Up @@ -62,7 +63,7 @@ class _MasterTileState extends State<MasterTile> {
child: IconButton(
onPressed: widget.onPlay,
icon: Icon(
Iconz().playFilled,
widget.iconData,
size: kTinyButtonIconSize,
color: context.t.colorScheme.primary,
),
Expand Down
7 changes: 4 additions & 3 deletions lib/src/player/player_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,10 @@ class PlayerService {
}

Future<void> insertIntoQueue(Audio audio) async {
if (_queue.$2.isNotEmpty && !_queue.$2.contains(audio)) {
_queue.$2.insert(1, audio);
nextAudio = queue.$2[1];
if (_queue.$2.isNotEmpty && !_queue.$2.contains(audio) && _audio != null) {
final currentIndex = queue.$2.indexOf(_audio!);
_queue.$2.insert(currentIndex + 1, audio);
nextAudio = queue.$2[currentIndex + 1];
}
}

Expand Down
2 changes: 0 additions & 2 deletions lib/src/podcasts/podcast_audio_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class PodcastAudioTile extends StatelessWidget {
required this.selected,
required this.pause,
required this.resume,
required this.startPlaylist,
required this.play,
required this.lastPosition,
this.isExpanded = false,
Expand All @@ -41,7 +40,6 @@ class PodcastAudioTile extends StatelessWidget {
final bool selected;
final void Function() pause;
final Future<void> Function() resume;
final void Function()? startPlaylist;
final Future<void> Function({Duration? newPosition, Audio? newAudio}) play;
final void Function()? removeUpdate;
final void Function() safeLastPosition;
Expand Down

0 comments on commit 203dbdd

Please sign in to comment.