Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve page filtering #149

Merged
merged 1 commit into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions lib/app/library_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
12 changes: 4 additions & 8 deletions lib/app/local_audio/album_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class AlbumPage extends StatelessWidget {
static Widget createIcon(
BuildContext context,
Uint8List? picture,
bool enabled,
) {
Widget? albumArt;
if (picture != null) {
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/app/master_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class MasterDetailPage extends StatelessWidget {
layoutDelegate: const YaruMasterFixedPaneDelegate(
paneWidth: 250,
),
breakpoint: 740,
breakpoint: 720,
controller: YaruPageController(
length: totalListAmount,
initialIndex: index ?? 0,
Expand Down
176 changes: 84 additions & 92 deletions lib/app/master_items.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,102 +115,94 @@ List<MasterItem> 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,
),
)
];
}
73 changes: 31 additions & 42 deletions lib/app/podcasts/podcast_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
}

Expand Down
Loading