From f90d11c55d89e7e0128acaee923376cdfb0ed9d3 Mon Sep 17 00:00:00 2001 From: Frederik Feichtmeier Date: Sun, 15 Dec 2024 01:23:33 +0100 Subject: [PATCH] fix: mobile home and queue (#1096) --- lib/common/view/no_search_result_page.dart | 23 ++++++++-- lib/home/home_page.dart | 1 + lib/local_audio/view/album_view.dart | 2 +- lib/local_audio/view/artists_view.dart | 4 +- lib/local_audio/view/genres_view.dart | 2 +- lib/local_audio/view/local_audio_page.dart | 2 +- lib/local_audio/view/titles_view.dart | 2 +- lib/player/player_service.dart | 7 ++-- lib/player/view/queue/queue_button.dart | 42 +++++++++++++++---- .../view/sliver_local_search_results.dart | 2 +- .../view/sliver_podcast_search_results.dart | 21 +++++++++- .../view/sliver_radio_search_results.dart | 4 +- 12 files changed, 85 insertions(+), 27 deletions(-) diff --git a/lib/common/view/no_search_result_page.dart b/lib/common/view/no_search_result_page.dart index eda14dceb..b559ce9ef 100644 --- a/lib/common/view/no_search_result_page.dart +++ b/lib/common/view/no_search_result_page.dart @@ -57,16 +57,31 @@ class NoSearchResultPage extends StatelessWidget { } } -class SliverFillNoSearchResultPage extends StatelessWidget { - const SliverFillNoSearchResultPage({super.key, this.message, this.icon}); +class SliverNoSearchResultPage extends StatelessWidget { + const SliverNoSearchResultPage({ + super.key, + this.message, + this.icon, + this.expand = true, + }); final Widget? message; final Widget? icon; + final bool expand; @override Widget build(BuildContext context) { - return SliverFillRemaining( - hasScrollBody: false, + if (expand) { + return SliverFillRemaining( + hasScrollBody: false, + child: NoSearchResultPage( + icon: icon, + message: message, + ), + ); + } + + return SliverToBoxAdapter( child: NoSearchResultPage( icon: icon, message: message, diff --git a/lib/home/home_page.dart b/lib/home/home_page.dart index 5dece9d0b..9145de4b3 100644 --- a/lib/home/home_page.dart +++ b/lib/home/home_page.dart @@ -84,6 +84,7 @@ class HomePage extends StatelessWidget with WatchItMixin { SliverPadding( padding: padding, sliver: const SliverPodcastSearchResults( + expand: false, take: 3, ), ), diff --git a/lib/local_audio/view/album_view.dart b/lib/local_audio/view/album_view.dart index 9cabf814b..04aaeabb0 100644 --- a/lib/local_audio/view/album_view.dart +++ b/lib/local_audio/view/album_view.dart @@ -36,7 +36,7 @@ class AlbumsView extends StatelessWidget with WatchItMixin { } if (albums!.isEmpty) { - return SliverFillNoSearchResultPage( + return SliverNoSearchResultPage( icon: noResultIcon, message: noResultMessage, ); diff --git a/lib/local_audio/view/artists_view.dart b/lib/local_audio/view/artists_view.dart index 112700bcb..a7cbb082e 100644 --- a/lib/local_audio/view/artists_view.dart +++ b/lib/local_audio/view/artists_view.dart @@ -32,7 +32,7 @@ class ArtistsView extends StatelessWidget { } if (artists!.isEmpty) { - return SliverFillNoSearchResultPage( + return SliverNoSearchResultPage( icon: noResultIcon, message: noResultMessage, ); @@ -104,7 +104,7 @@ class AlbumArtistsView extends StatelessWidget { } if (albumArtists!.isEmpty) { - return SliverFillNoSearchResultPage( + return SliverNoSearchResultPage( icon: noResultIcon, message: noResultMessage, ); diff --git a/lib/local_audio/view/genres_view.dart b/lib/local_audio/view/genres_view.dart index 9dbd67e47..4c6e26809 100644 --- a/lib/local_audio/view/genres_view.dart +++ b/lib/local_audio/view/genres_view.dart @@ -27,7 +27,7 @@ class GenresView extends StatelessWidget { } if (genres!.isEmpty) { - return SliverFillNoSearchResultPage( + return SliverNoSearchResultPage( icon: noResultIcon, message: noResultMessage, ); diff --git a/lib/local_audio/view/local_audio_page.dart b/lib/local_audio/view/local_audio_page.dart index 4b1593f96..e49addc1c 100644 --- a/lib/local_audio/view/local_audio_page.dart +++ b/lib/local_audio/view/local_audio_page.dart @@ -100,7 +100,7 @@ class _LocalAudioPageState extends State { bottom: bottomPlayerPageGap, ), sliver: audios != null && audios.isEmpty - ? SliverFillNoSearchResultPage( + ? SliverNoSearchResultPage( icon: const AnimatedEmoji(AnimatedEmojis.bird), message: Column( mainAxisSize: MainAxisSize.min, diff --git a/lib/local_audio/view/titles_view.dart b/lib/local_audio/view/titles_view.dart index e52d1a906..d19a78e31 100644 --- a/lib/local_audio/view/titles_view.dart +++ b/lib/local_audio/view/titles_view.dart @@ -32,7 +32,7 @@ class TitlesView extends StatelessWidget { } if (audios!.isEmpty) { - return SliverFillNoSearchResultPage( + return SliverNoSearchResultPage( icon: noResultIcon, message: noResultMessage, ); diff --git a/lib/player/player_service.dart b/lib/player/player_service.dart index d51576dfb..d184adcca 100644 --- a/lib/player/player_service.dart +++ b/lib/player/player_service.dart @@ -818,9 +818,10 @@ class PlayerService { audio: _audio, duration: _duration?.toString(), position: _position?.toString(), - queue: - _queue.audios.length <= 100 ? _queue.audios.take(100).toList() : null, - queueName: _queue.audios.length <= 100 ? _queue.name : null, + queue: _queue.audios.length > 100 + ? _queue.audios.take(100).toList() + : _queue.audios, + queueName: _queue.name, volume: _volume.toString(), rate: _rate.toString(), ); diff --git a/lib/player/view/queue/queue_button.dart b/lib/player/view/queue/queue_button.dart index 573d4aacb..223af756e 100644 --- a/lib/player/view/queue/queue_button.dart +++ b/lib/player/view/queue/queue_button.dart @@ -9,6 +9,7 @@ import '../../../common/view/modals.dart'; import '../../../common/view/ui_constants.dart'; import '../../../extensions/build_context_x.dart'; import '../../../l10n/l10n.dart'; +import '../../../radio/view/radio_history_list.dart'; import '../../player_model.dart'; import 'queue_body.dart'; import 'queue_dialog.dart'; @@ -34,6 +35,18 @@ class QueueButton extends StatelessWidget with WatchItMixin { (PlayerModel m) => m.audio?.audioType == AudioType.radio, ); + final queueOrHistory = radio + ? const SizedBox( + width: 400, + height: 500, + child: RadioHistoryList( + simpleList: true, + ), + ) + : QueueBody( + selectedColor: theme.colorScheme.onSurface, + ); + return switch (_mode) { _QueueButtonMode.icon => IconButton( isSelected: isSelected ?? @@ -45,12 +58,22 @@ class QueueButton extends StatelessWidget with WatchItMixin { Iconz.playlist, color: color ?? theme.colorScheme.onSurface, ), - onPressed: () => onPressed(playerToTheRight, isFullScreen, context), + onPressed: () => onPressed( + playerToTheRight: playerToTheRight, + isFullScreen: isFullScreen, + context: context, + bottomSheetContent: queueOrHistory, + ), ), _QueueButtonMode.text => TextButton( - onPressed: () => onPressed(playerToTheRight, isFullScreen, context), + onPressed: () => onPressed( + playerToTheRight: playerToTheRight, + isFullScreen: isFullScreen, + context: context, + bottomSheetContent: queueOrHistory, + ), child: Text( - context.l10n.queue, + radio ? context.l10n.hearingHistory : context.l10n.queue, style: context.textTheme.bodyLarge?.copyWith( color: context.colorScheme.onSurface, ), @@ -59,11 +82,12 @@ class QueueButton extends StatelessWidget with WatchItMixin { }; } - void onPressed( - bool playerToTheRight, - bool? isFullScreen, - BuildContext context, - ) { + void onPressed({ + required bool playerToTheRight, + required bool? isFullScreen, + required BuildContext context, + required Widget bottomSheetContent, + }) { if ((playerToTheRight || isFullScreen == true) && !isMobilePlatform) { di().setOrToggleQueueOverlay(); } else { @@ -72,7 +96,7 @@ class QueueButton extends StatelessWidget with WatchItMixin { isScrollControlled: true, showDragHandle: true, content: ModalMode.platformModalMode == ModalMode.bottomSheet - ? const QueueBody() + ? bottomSheetContent : const QueueDialog(), mode: ModalMode.platformModalMode, ); diff --git a/lib/search/view/sliver_local_search_results.dart b/lib/search/view/sliver_local_search_results.dart index 39a629997..d6bab43d7 100644 --- a/lib/search/view/sliver_local_search_results.dart +++ b/lib/search/view/sliver_local_search_results.dart @@ -66,7 +66,7 @@ class _SliverLocalSearchResultState extends State { final searchQuery = watchPropertyValue((SearchModel m) => m.searchQuery); if (searchQuery == null || searchQuery.isEmpty == true) { - return SliverFillNoSearchResultPage( + return SliverNoSearchResultPage( icon: const AnimatedEmoji(AnimatedEmojis.drum), message: Text( context.l10n.search, diff --git a/lib/search/view/sliver_podcast_search_results.dart b/lib/search/view/sliver_podcast_search_results.dart index e6104590f..b313d7412 100644 --- a/lib/search/view/sliver_podcast_search_results.dart +++ b/lib/search/view/sliver_podcast_search_results.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import 'package:watch_it/watch_it.dart'; import '../../app/connectivity_model.dart'; +import '../../common/view/loading_grid.dart'; import '../../common/view/no_search_result_page.dart'; import '../../common/view/offline_page.dart'; import '../../common/view/progress.dart'; @@ -14,9 +15,14 @@ import 'podcast_card.dart'; class SliverPodcastSearchResults extends StatefulWidget with WatchItStatefulWidgetMixin { - const SliverPodcastSearchResults({super.key, this.take}); + const SliverPodcastSearchResults({ + super.key, + this.take, + this.expand = true, + }); final int? take; + final bool expand; @override State createState() => @@ -54,8 +60,19 @@ class _SliverPodcastSearchResultsState final searchResultItems = widget.take != null ? results?.take(widget.take!) : results; + if (!widget.expand) { + if (searchResultItems == null) { + return SliverLoadingGrid(limit: widget.take ?? 100); + } else if (searchResultItems.isEmpty) { + return const SliverNoSearchResultPage( + expand: false, + ); + } + } + if (searchResultItems == null || searchResultItems.isEmpty) { - return SliverFillNoSearchResultPage( + return SliverNoSearchResultPage( + expand: widget.expand, icon: loading ? const SizedBox.shrink() : searchResultItems == null diff --git a/lib/search/view/sliver_radio_search_results.dart b/lib/search/view/sliver_radio_search_results.dart index b21ff4d15..b9765131f 100644 --- a/lib/search/view/sliver_radio_search_results.dart +++ b/lib/search/view/sliver_radio_search_results.dart @@ -46,14 +46,14 @@ class SliverRadioSearchResults extends StatelessWidget with WatchItMixin { if (radioSearchResult == null || (searchQuery?.isEmpty == true && radioSearchResult.isEmpty == true)) { - return SliverFillNoSearchResultPage( + return SliverNoSearchResultPage( icon: const AnimatedEmoji(AnimatedEmojis.drum), message: Text('${context.l10n.search} ${searchType.localize(context.l10n)}'), ); } if (radioSearchResult.isEmpty && !loading) { - return SliverFillNoSearchResultPage( + return SliverNoSearchResultPage( icon: const AnimatedEmoji(AnimatedEmojis.rabbit), message: Text(context.l10n.noStationFound), );