Skip to content

Commit

Permalink
Show badge in sidebar for updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Feichtmeier committed Aug 13, 2023
1 parent 1407ff4 commit bbc9a49
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 63 deletions.
3 changes: 3 additions & 0 deletions lib/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ class _AppState extends State<App> {
context.select((LibraryModel m) => m.pinnedAlbums.length);
context.select((LibraryModel m) => m.starredStations.length);
context.select((LibraryModel m) => m.playlists.length);
context.select<LibraryModel, int>((m) => m.podcastUpdates.length);

if (!ready) {
return SplashScreen(
Expand Down Expand Up @@ -244,6 +245,8 @@ class _AppState extends State<App> {
unStarStation: libraryModel.unStarStation,
play: play,
countryCode: _countryCode,
podcastUpdateAvailable: libraryModel.podcastUpdateAvailable,
removePodcastUpdate: libraryModel.removePodcastUpdate,
);

final yaruMasterDetailPage = MasterDetailPage(
Expand Down
3 changes: 3 additions & 0 deletions lib/app/common/audio_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class AudioPage extends StatelessWidget {
this.albumFlex = 4,
this.showAudioTileHeader = true,
this.countryCode,
this.removeUpdate,
});

final Set<Audio>? audios;
Expand All @@ -63,6 +64,7 @@ class AudioPage extends StatelessWidget {
final String? titleLabel, artistLabel, albumLabel;
final int titleFlex, artistFlex, albumFlex;
final String? countryCode;
final void Function(String id)? removeUpdate;

final void Function({
required String text,
Expand Down Expand Up @@ -102,6 +104,7 @@ class AudioPage extends StatelessWidget {
pageTitleWidget: pageTitleWidget,
showAudioPageHeader: showAudioPageHeader,
showAudioTileHeader: showAudioTileHeader,
removeUpdate: () => removeUpdate?.call(pageId),
);

return YaruDetailPage(
Expand Down
37 changes: 19 additions & 18 deletions lib/app/common/audio_page_body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class AudioPageBody extends StatefulWidget {
this.albumFlex = 4,
this.showAudioTileHeader = true,
this.countryCode,
this.removeUpdate,
});

final Set<Audio>? audios;
Expand All @@ -67,6 +68,7 @@ class AudioPageBody extends StatefulWidget {
final String? titleLabel, artistLabel, albumLabel;
final int titleFlex, artistFlex, albumFlex;
final String? countryCode;
final void Function()? removeUpdate;

final void Function({
required String text,
Expand Down Expand Up @@ -233,23 +235,9 @@ class _AudioPageBodyState extends State<AudioPageBody> {
final audio = sortedAudios.elementAt(index);
final audioSelected = currentAudio == audio;

final likeButton = LikeButton(
key: ObjectKey(audio),
pageId: widget.pageId,
audio: audio,
audioSelected: audioSelected,
audioPageType: widget.audioPageType,
isLiked: liked,
removeLikedAudio: removeLikedAudio,
addLikedAudio: addLikedAudio,
removeAudioFromPlaylist: removeAudioFromPlaylist,
getTopFivePlaylistNames: getTopFivePlaylistNames,
addAudioToPlaylist: addAudioToPlaylist,
addPlaylist: addPlaylist,
);

if (audio.audioType == AudioType.podcast) {
return PodcastAudioTile(
removeUpdate: () => widget.removeUpdate?.call(),
isExpanded: audioSelected,
audio: audio,
isPlayerPlaying: isPlaying,
Expand All @@ -265,16 +253,29 @@ class _AudioPageBodyState extends State<AudioPageBody> {
);
}

final likeButton = LikeButton(
key: ObjectKey(audio),
pageId: widget.pageId,
audio: audio,
audioSelected: audioSelected,
audioPageType: widget.audioPageType,
isLiked: liked,
removeLikedAudio: removeLikedAudio,
addLikedAudio: addLikedAudio,
removeAudioFromPlaylist: removeAudioFromPlaylist,
getTopFivePlaylistNames: getTopFivePlaylistNames,
addAudioToPlaylist: addAudioToPlaylist,
addPlaylist: addPlaylist,
);

return AudioTile(
titleFlex: widget.titleFlex,
artistFlex: widget.artistFlex,
albumFlex: widget.albumFlex,
onTextTap: widget.onTextTap,
isPlayerPlaying: isPlaying,
pause: pause,
play: () async {
await play(newAudio: audio);
},
play: play,
startPlaylist: widget.audios == null
? null
: () => startPlaylist(
Expand Down
20 changes: 10 additions & 10 deletions lib/app/common/audio_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AudioTile extends StatelessWidget {
final void Function()? onLike;
final Widget? likeIcon;
final bool isPlayerPlaying;
final Future<void> Function() play;
final Future<void> Function({bool bigPlay, Audio? newAudio}) play;
final Future<void> Function() resume;
final void Function()? startPlaylist;
final void Function() pause;
Expand All @@ -53,17 +53,17 @@ class AudioTile extends StatelessWidget {
borderRadius: BorderRadius.circular(kYaruButtonRadius),
),
onTap: () {
if (isPlayerPlaying && selected) {
pause();
} else {
if (selected) {
if (selected) {
if (isPlayerPlaying) {
pause();
} else {
resume();
}
} else {
if (startPlaylist != null) {
startPlaylist!();
} else {
if (startPlaylist != null) {
startPlaylist!();
} else {
play();
}
play(newAudio: audio);
}
}
},
Expand Down
25 changes: 18 additions & 7 deletions lib/app/library_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class LibraryModel extends SafeChangeNotifier {
StreamSubscription<bool>? _stationsSub;
StreamSubscription<int?>? _localAudioIndexSub;
StreamSubscription<bool>? _lastPositionsSub;
StreamSubscription<bool>? _updatesChangedSub;

bool ready = false;

Expand All @@ -37,6 +38,8 @@ class LibraryModel extends SafeChangeNotifier {
_service.starredStationsChanged.listen((event) => notifyListeners());
_lastPositionsSub =
_service.lastPositionsChanged.listen((_) => notifyListeners());
_updatesChangedSub =
_service.updatesChanged.listen((_) => notifyListeners());

ready = true;
notifyListeners();
Expand All @@ -51,6 +54,7 @@ class LibraryModel extends SafeChangeNotifier {
_podcastsSub?.cancel();
_stationsSub?.cancel();
_lastPositionsSub?.cancel();
_updatesChangedSub?.cancel();

super.dispose();
}
Expand Down Expand Up @@ -145,15 +149,15 @@ class LibraryModel extends SafeChangeNotifier {

Map<String, Set<Audio>> get podcasts => _service.podcasts;
int get podcastsLength => podcasts.length;
void addPodcast(String name, Set<Audio> audios) =>
_service.addPodcast(name, audios);
void updatePodcast(String name, Set<Audio> audios) =>
_service.updatePodcast(name, audios);
void addPodcast(String feedUrl, Set<Audio> audios) =>
_service.addPodcast(feedUrl, audios);
void updatePodcast(String feedUrl, Set<Audio> audios) =>
_service.updatePodcast(feedUrl, audios);

void removePodcast(String name) => _service.removePodcast(name);
void removePodcast(String feedUrl) => _service.removePodcast(feedUrl);

bool podcastSubscribed(String? name) =>
name == null ? false : podcasts.containsKey(name);
bool podcastSubscribed(String? feedUrl) =>
feedUrl == null ? false : podcasts.containsKey(feedUrl);

Map<String, String> get podcastsToFeedUrls => _service.podcastsToFeedUrls;
void addPlaylistFeed(String playlist, String feedUrl) =>
Expand All @@ -162,6 +166,13 @@ class LibraryModel extends SafeChangeNotifier {
bool get showSubbedPodcasts =>
audioPageType == null || audioPageType == AudioPageType.podcast;

bool podcastUpdateAvailable(String feedUrl) =>
_service.updateAvailable(feedUrl);

Set<String> get podcastUpdates => _service.podcastUpdates;

void removePodcastUpdate(String feedUrl) => _service.removeUpdate(feedUrl);

//
// Albums
//
Expand Down
4 changes: 1 addition & 3 deletions lib/app/local_audio/local_audio_search_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,7 @@ class _Titles extends StatelessWidget {
showTrack: false,
isPlayerPlaying: isPlaying,
pause: pause,
play: () async {
await play(newAudio: audio);
},
play: play,
resume: resume,
key: ValueKey(audio),
selected: audioSelected,
Expand Down
5 changes: 5 additions & 0 deletions lib/app/master_items.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ List<MasterItem> createMasterItems({
required void Function(String name) unStarStation,
required Future<void> Function({bool bigPlay, Audio? newAudio}) play,
String? countryCode,
required bool Function(String feedUrl) podcastUpdateAvailable,
required void Function(String feedUrl) removePodcastUpdate,
}) {
return [
MasterItem(
Expand Down Expand Up @@ -116,10 +118,12 @@ List<MasterItem> createMasterItems({
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(
Expand All @@ -133,6 +137,7 @@ List<MasterItem> createMasterItems({
removePodcast: removePodcast,
imageUrl: podcast.value.firstOrNull?.albumArtUrl ??
podcast.value.firstOrNull?.imageUrl,
removePodcastUpdate: removePodcastUpdate,
)
: const OfflinePage(),
iconBuilder: (context, selected) => PodcastPage.createIcon(
Expand Down
6 changes: 5 additions & 1 deletion lib/app/player/player_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ class PlayerModel extends SafeChangeNotifier {

Future<void> resume() async {
if (audio == null) return;
await _player.playOrPause();
if (_firstPlay) {
play(bigPlay: true);
} else {
await _player.playOrPause();
}
}

Future<void> init() async {
Expand Down
24 changes: 14 additions & 10 deletions lib/app/podcasts/podcast_audio_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class PodcastAudioTile extends StatelessWidget {
required this.lastPosition,
this.isExpanded = false,
this.countryCode,
this.removeUpdate,
});

final Audio audio;
Expand All @@ -33,7 +34,9 @@ class PodcastAudioTile extends StatelessWidget {
final void Function() pause;
final Future<void> Function() resume;
final void Function()? startPlaylist;
final Future<void> Function() play;
final Future<void> Function({bool bigPlay, Audio? newAudio}) play;
final void Function()? removeUpdate;

final Duration? lastPosition;
final bool isExpanded;
final String? countryCode;
Expand Down Expand Up @@ -78,18 +81,19 @@ class PodcastAudioTile extends StatelessWidget {
)
: const Icon(YaruIcons.media_play),
onPressed: () {
if (isPlayerPlaying && selected) {
pause();
} else {
if (selected) {
if (selected) {
if (isPlayerPlaying) {
pause();
} else {
resume();
}
} else {
if (startPlaylist != null) {
startPlaylist!();
} else {
if (startPlaylist != null) {
startPlaylist!();
} else {
play();
}
play(newAudio: audio);
}
removeUpdate?.call();
}
},
),
Expand Down
18 changes: 14 additions & 4 deletions lib/app/podcasts/podcast_page.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:musicpod/app/common/audio_page.dart';
import 'package:musicpod/constants.dart';
import 'package:musicpod/app/common/safe_network_image.dart';
import 'package:musicpod/constants.dart';
import 'package:musicpod/data/audio.dart';
import 'package:musicpod/l10n/l10n.dart';
import 'package:yaru_icons/yaru_icons.dart';
Expand All @@ -20,6 +20,7 @@ class PodcastPage extends StatelessWidget {
required this.addPodcast,
required this.title,
this.countryCode,
required this.removePodcastUpdate,
});

static Widget createIcon({
Expand Down Expand Up @@ -63,17 +64,25 @@ class PodcastPage extends StatelessWidget {
}

static Widget createTitle({
required BuildContext context,
required bool enabled,
required String title,
required update,
}) {
return Opacity(
opacity: enabled ? 1 : 0.5,
child: Text(title),
child: Badge(
alignment: Alignment.centerRight,
isLabelVisible: update,
label: Text(context.l10n.newEpisode),
child: Text(title),
),
);
}

final void Function(String name) removePodcast;
final void Function(String name, Set<Audio> audios) addPodcast;
final void Function(String feedUrl) removePodcast;
final void Function(String feedUrl, Set<Audio> audios) addPodcast;
final void Function(String feedUrl) removePodcastUpdate;
final void Function({
required String text,
required AudioType audioType,
Expand All @@ -90,6 +99,7 @@ class PodcastPage extends StatelessWidget {
final theme = Theme.of(context);
final genre = audios?.firstWhereOrNull((e) => e.genre != null)?.genre;
return AudioPage(
removeUpdate: removePodcastUpdate,
countryCode: countryCode,
showAudioTileHeader: false,
sort: false,
Expand Down
Loading

0 comments on commit bbc9a49

Please sign in to comment.