diff --git a/lib/app/library_model.dart b/lib/app/library_model.dart index 55fa3adc1..a6ff5c3d8 100644 --- a/lib/app/library_model.dart +++ b/lib/app/library_model.dart @@ -62,20 +62,45 @@ class LibraryModel extends SafeChangeNotifier { int get totalListAmount { const fix = 7; - return starredStationsLength + - podcastsLength + - playlistsLength + - pinnedAlbumsLength + - fix; + switch (_audioPageType) { + case AudioPageType.album: + return pinnedAlbumsLength + fix; + case AudioPageType.playlist: + return playlistsLength + fix; + case AudioPageType.podcast: + return podcastsLength + fix; + case AudioPageType.radio: + return starredStationsLength + fix; + default: + return starredStationsLength + + podcastsLength + + playlistsLength + + pinnedAlbumsLength + + fix; + } } AudioPageType? _audioPageType; AudioPageType? get audioPageType => _audioPageType; + int? _oldIndex; void setAudioPageType(AudioPageType? value) { if (value == _audioPageType) { _audioPageType = null; + _index = _oldIndex ?? 0; } else { _audioPageType = value; + _oldIndex = _index; + switch (value) { + case AudioPageType.radio: + _index = 1; + break; + case AudioPageType.podcast: + _index = 2; + break; + default: + _index = 0; + break; + } } notifyListeners(); } diff --git a/lib/app/local_audio/album_page.dart b/lib/app/local_audio/album_page.dart index a0a97ea05..6bcabf01b 100644 --- a/lib/app/local_audio/album_page.dart +++ b/lib/app/local_audio/album_page.dart @@ -22,7 +22,6 @@ class AlbumPage extends StatelessWidget { static Widget createIcon( BuildContext context, Uint8List? picture, - bool enabled, ) { Widget? albumArt; if (picture != null) { @@ -40,13 +39,10 @@ class AlbumPage extends StatelessWidget { ), ); } - return Opacity( - opacity: enabled ? 1 : 0.5, - child: albumArt ?? - const Icon( - YaruIcons.playlist_play, - ), - ); + return albumArt ?? + const Icon( + YaruIcons.playlist_play, + ); } final String? name; diff --git a/lib/app/master_detail_page.dart b/lib/app/master_detail_page.dart index 9503f473f..46e60913e 100644 --- a/lib/app/master_detail_page.dart +++ b/lib/app/master_detail_page.dart @@ -48,7 +48,7 @@ class MasterDetailPage extends StatelessWidget { layoutDelegate: const YaruMasterFixedPaneDelegate( paneWidth: 250, ), - breakpoint: 740, + breakpoint: 720, controller: YaruPageController( length: totalListAmount, initialIndex: index ?? 0, diff --git a/lib/app/master_items.dart b/lib/app/master_items.dart index 169e697ab..29d562293 100644 --- a/lib/app/master_items.dart +++ b/lib/app/master_items.dart @@ -115,102 +115,94 @@ List createMasterItems({ ), builder: (context) => const SizedBox.shrink(), ), - for (final podcast in subbedPodcasts.entries) - MasterItem( - tileBuilder: (context) => PodcastPage.createTitle( - context: context, - title: podcast.value.firstOrNull?.album ?? - podcast.value.firstOrNull?.title ?? - podcast.value.firstOrNull.toString(), - enabled: showSubbedPodcasts, - update: podcastUpdateAvailable(podcast.key), - ), - builder: (context) => isOnline - ? PodcastPage( - pageId: podcast.key, - title: podcast.value.firstOrNull?.album ?? - podcast.value.firstOrNull?.title ?? - podcast.value.firstOrNull.toString(), - audios: podcast.value, - onTextTap: onTextTap, - addPodcast: addPodcast, - removePodcast: removePodcast, - imageUrl: podcast.value.firstOrNull?.albumArtUrl ?? - podcast.value.firstOrNull?.imageUrl, - removePodcastUpdate: removePodcastUpdate, - ) - : const OfflinePage(), - iconBuilder: (context, selected) => PodcastPage.createIcon( - context: context, - imageUrl: podcast.value.firstOrNull?.albumArtUrl ?? - podcast.value.firstOrNull?.imageUrl, - isOnline: isOnline, - enabled: showSubbedPodcasts, - ), - ), - for (final playlist in playlists.entries) - MasterItem( - tileBuilder: (context) => Opacity( - opacity: showPlaylists ? 1 : 0.5, - child: Text(playlist.key), - ), - builder: (context) => PlaylistPage( - onTextTap: onTextTap, - playlist: playlist, - unPinPlaylist: removePlaylist, + if (showSubbedPodcasts) + for (final podcast in subbedPodcasts.entries) + MasterItem( + tileBuilder: (context) => PodcastPage.createTitle( + context: context, + title: podcast.value.firstOrNull?.album ?? + podcast.value.firstOrNull?.title ?? + podcast.value.firstOrNull.toString(), + update: podcastUpdateAvailable(podcast.key), + ), + builder: (context) => isOnline + ? PodcastPage( + pageId: podcast.key, + title: podcast.value.firstOrNull?.album ?? + podcast.value.firstOrNull?.title ?? + podcast.value.firstOrNull.toString(), + audios: podcast.value, + onTextTap: onTextTap, + addPodcast: addPodcast, + removePodcast: removePodcast, + imageUrl: podcast.value.firstOrNull?.albumArtUrl ?? + podcast.value.firstOrNull?.imageUrl, + removePodcastUpdate: removePodcastUpdate, + ) + : const OfflinePage(), + iconBuilder: (context, selected) => PodcastPage.createIcon( + context: context, + imageUrl: podcast.value.firstOrNull?.albumArtUrl ?? + podcast.value.firstOrNull?.imageUrl, + isOnline: isOnline, + ), ), - iconBuilder: (context, selected) => Opacity( - opacity: showPlaylists ? 1 : 0.5, - child: const Icon( + if (showPlaylists) + for (final playlist in playlists.entries) + MasterItem( + tileBuilder: (context) => Opacity( + opacity: showPlaylists ? 1 : 0.5, + child: Text(playlist.key), + ), + builder: (context) => PlaylistPage( + onTextTap: onTextTap, + playlist: playlist, + unPinPlaylist: removePlaylist, + ), + iconBuilder: (context, selected) => const Icon( YaruIcons.playlist, ), ), - ), - for (final album in pinnedAlbums.entries) - MasterItem( - tileBuilder: (context) => Opacity( - opacity: showPinnedAlbums ? 1 : 0.5, - child: Text(createPlaylistName(album.key, context)), - ), - builder: (context) => AlbumPage( - onTextTap: onTextTap, - album: album.value, - name: album.key, - addPinnedAlbum: addPinnedAlbum, - isPinnedAlbum: isPinnedAlbum, - removePinnedAlbum: removePinnedAlbum, - ), - iconBuilder: (context, selected) => AlbumPage.createIcon( - context, - album.value.firstOrNull?.pictureData, - showPinnedAlbums, - ), - ), - for (final station in starredStations.entries) - MasterItem( - tileBuilder: (context) => Opacity( - opacity: showStarredStations ? 1 : 0.5, - child: Text(station.key), - ), - builder: (context) => isOnline - ? StationPage( - isStarred: true, - starStation: (station) {}, - onTextTap: (text) => - onTextTap(text: text, audioType: AudioType.radio), - unStarStation: unStarStation, - name: station.key, - station: station.value.first, - play: play, - ) - : const OfflinePage(), - iconBuilder: (context, selected) => StationPage.createIcon( - context: context, - imageUrl: station.value.first.imageUrl, - selected: selected, - isOnline: isOnline, - enabled: showStarredStations, + if (showPinnedAlbums) + for (final album in pinnedAlbums.entries) + MasterItem( + tileBuilder: (context) => + Text(createPlaylistName(album.key, context)), + builder: (context) => AlbumPage( + onTextTap: onTextTap, + album: album.value, + name: album.key, + addPinnedAlbum: addPinnedAlbum, + isPinnedAlbum: isPinnedAlbum, + removePinnedAlbum: removePinnedAlbum, + ), + iconBuilder: (context, selected) => AlbumPage.createIcon( + context, + album.value.firstOrNull?.pictureData, + ), ), - ) + if (showStarredStations) + for (final station in starredStations.entries) + MasterItem( + tileBuilder: (context) => Text(station.key), + builder: (context) => isOnline + ? StationPage( + isStarred: true, + starStation: (station) {}, + onTextTap: (text) => + onTextTap(text: text, audioType: AudioType.radio), + unStarStation: unStarStation, + name: station.key, + station: station.value.first, + play: play, + ) + : const OfflinePage(), + iconBuilder: (context, selected) => StationPage.createIcon( + context: context, + imageUrl: station.value.first.imageUrl, + selected: selected, + isOnline: isOnline, + ), + ) ]; } diff --git a/lib/app/podcasts/podcast_page.dart b/lib/app/podcasts/podcast_page.dart index 5eb5d13d7..629e70874 100644 --- a/lib/app/podcasts/podcast_page.dart +++ b/lib/app/podcasts/podcast_page.dart @@ -27,56 +27,45 @@ class PodcastPage extends StatelessWidget { required BuildContext context, String? imageUrl, required bool isOnline, - required bool enabled, }) { - var clipRRect = isOnline - ? ClipRRect( - borderRadius: BorderRadius.circular(5), - child: SizedBox( - width: kSideBarIconSize, - height: kSideBarIconSize, - child: isOnline - ? SafeNetworkImage( - url: imageUrl, - fit: BoxFit.fitHeight, - filterQuality: FilterQuality.medium, - fallBackIcon: const Icon( - YaruIcons.rss, - size: kSideBarIconSize, - ), - errorIcon: const Icon( - YaruIcons.rss, - size: kSideBarIconSize, - ), - ) - : const Icon(YaruIcons.network_offline), - ), - ) - : const Icon( - YaruIcons.network_offline, - ); - return enabled - ? clipRRect - : Opacity( - opacity: 0.5, - child: clipRRect, - ); + final Widget icon; + if (isOnline) { + icon = SafeNetworkImage( + url: imageUrl, + fit: BoxFit.fitHeight, + filterQuality: FilterQuality.medium, + fallBackIcon: const Icon( + YaruIcons.rss, + size: kSideBarIconSize, + ), + errorIcon: const Icon( + YaruIcons.rss, + size: kSideBarIconSize, + ), + ); + } else { + icon = const Icon(YaruIcons.network_offline); + } + return ClipRRect( + borderRadius: BorderRadius.circular(5), + child: SizedBox( + width: kSideBarIconSize, + height: kSideBarIconSize, + child: icon, + ), + ); } static Widget createTitle({ required BuildContext context, - required bool enabled, required String title, required update, }) { - return Opacity( - opacity: enabled ? 1 : 0.5, - child: Badge( - alignment: Alignment.centerRight, - isLabelVisible: update, - label: Text(context.l10n.newEpisode), - child: Text(title), - ), + return Badge( + alignment: Alignment.centerRight, + isLabelVisible: update, + label: Text(context.l10n.newEpisode), + child: Text(title), ); } diff --git a/lib/app/radio/station_page.dart b/lib/app/radio/station_page.dart index 1dba477e1..43edb73ed 100644 --- a/lib/app/radio/station_page.dart +++ b/lib/app/radio/station_page.dart @@ -36,37 +36,33 @@ class StationPage extends StatelessWidget { required String? imageUrl, required bool selected, required bool isOnline, - required bool enabled, }) { - return Opacity( - opacity: enabled ? 1 : 0.5, - child: ClipRRect( - borderRadius: BorderRadius.circular(5), - child: SizedBox( - height: kSideBarIconSize, - width: kSideBarIconSize, - child: isOnline - ? SafeNetworkImage( - fallBackIcon: selected - ? const Icon( - YaruIcons.star_filled, - ) - : const Icon( - YaruIcons.star, - ), - errorIcon: selected - ? const Icon( - YaruIcons.star_filled, - ) - : const Icon( - YaruIcons.star, - ), - fit: BoxFit.fitHeight, - url: imageUrl, - filterQuality: FilterQuality.medium, - ) - : const Icon(YaruIcons.network_offline), - ), + return ClipRRect( + borderRadius: BorderRadius.circular(5), + child: SizedBox( + height: kSideBarIconSize, + width: kSideBarIconSize, + child: isOnline + ? SafeNetworkImage( + fallBackIcon: selected + ? const Icon( + YaruIcons.star_filled, + ) + : const Icon( + YaruIcons.star, + ), + errorIcon: selected + ? const Icon( + YaruIcons.star_filled, + ) + : const Icon( + YaruIcons.star, + ), + fit: BoxFit.fitHeight, + url: imageUrl, + filterQuality: FilterQuality.medium, + ) + : const Icon(YaruIcons.network_offline), ), ); }