Skip to content

Commit

Permalink
Let users find the podcast on player artist tap
Browse files Browse the repository at this point in the history
  • Loading branch information
Feichtmeier committed Feb 7, 2024
1 parent be2348f commit 8376a69
Show file tree
Hide file tree
Showing 12 changed files with 195 additions and 177 deletions.
1 change: 1 addition & 0 deletions lib/podcasts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export 'src/podcasts/podcast_audio_tile.dart';
export 'src/podcasts/podcast_model.dart';
export 'src/podcasts/podcast_page.dart';
export 'src/podcasts/podcast_service.dart';
export 'src/podcasts/podcast_utils.dart';
export 'src/podcasts/podcasts_page.dart';
2 changes: 0 additions & 2 deletions lib/src/app/master_items.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ List<MasterItem> createMasterItems({
podcast.value.firstOrNull?.title ??
podcast.value.firstOrNull.toString(),
audios: podcast.value,
addPodcast: libraryModel.addPodcast,
removePodcast: libraryModel.removePodcast,
imageUrl: podcast.value.firstOrNull?.albumArtUrl ??
podcast.value.firstOrNull?.imageUrl,
),
Expand Down
29 changes: 9 additions & 20 deletions lib/src/common/audio_page_control_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,15 @@ class AudioPageControlPanel extends StatelessWidget {
backgroundColor: theme.colorScheme.inverseSurface,
child: IconButton(
onPressed: () {
if (audios.length > kAudioQueueThreshHold) {
showDialog<bool>(
context: context,
builder: (context) {
return ConfirmationDialog(
message: Text(
context.l10n.queueConfirmMessage(
audios.length.toString(),
),
),
);
},
).then((value) {
if (value == true) {
onTap!();
}
});
} else {
onTap!();
}
runOrConfirm(
context: context,
noConfirm: audios.length < kAudioQueueThreshHold,
message: context.l10n.queueConfirmMessage(
audios.length.toString(),
),
run: () => onTap!(),
onCancel: () {},
);
},
icon: Padding(
padding: appleStyled
Expand Down
10 changes: 6 additions & 4 deletions lib/src/common/confirmation_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import 'package:yaru_widgets/constants.dart';
import '../../build_context_x.dart';
import '../l10n/l10n.dart';

class ConfirmationDialog extends StatelessWidget {
const ConfirmationDialog({
super.key,
class _ConfirmationDialog extends StatelessWidget {
const _ConfirmationDialog({
required this.message,
});

Expand Down Expand Up @@ -64,14 +63,15 @@ void runOrConfirm({
required bool noConfirm,
required String message,
required Function run,
required Function onCancel,
}) {
if (noConfirm) {
run();
} else {
showDialog<bool>(
context: context,
builder: (context) {
return ConfirmationDialog(
return _ConfirmationDialog(
message: Text(
context.l10n.queueConfirmMessage(
message,
Expand All @@ -82,6 +82,8 @@ void runOrConfirm({
).then((value) {
if (value == true) {
run();
} else {
onCancel();
}
});
}
Expand Down
25 changes: 15 additions & 10 deletions lib/src/player/bottom_player_title_artist.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ class BottomPlayerTitleArtist extends StatelessWidget {
final icyName = mpvMetaData?.icyName;
final icyTitle = mpvMetaData?.icyTitle;

final subTitle = icyName?.isNotEmpty == true
? icyName!
: (audio?.audioType == AudioType.podcast
? audio?.album
: audio?.artist ?? ' ') ??
'';

final title = icyTitle?.isNotEmpty == true
? icyTitle!
: (audio?.title?.isNotEmpty == true ? audio!.title! : ' ');

return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
Expand All @@ -30,13 +41,9 @@ class BottomPlayerTitleArtist extends StatelessWidget {
context: context,
),
child: Tooltip(
message: icyTitle?.isNotEmpty == true
? icyTitle!
: (audio?.title?.isNotEmpty == true ? audio!.title! : ' '),
message: title,
child: Text(
icyTitle?.isNotEmpty == true
? icyTitle!
: (audio?.title?.isNotEmpty == true ? audio!.title! : ' '),
title,
style: const TextStyle(
fontWeight: FontWeight.w400,
fontSize: 14,
Expand All @@ -56,11 +63,9 @@ class BottomPlayerTitleArtist extends StatelessWidget {
context: context,
),
child: Tooltip(
message: icyName?.isNotEmpty == true
? icyName!
: (audio?.artist ?? ' '),
message: subTitle,
child: Text(
icyName?.isNotEmpty == true ? icyName! : (audio?.artist ?? ' '),
subTitle,
style: TextStyle(
fontWeight: smallTextFontWeight,
fontSize: 12,
Expand Down
43 changes: 27 additions & 16 deletions lib/src/player/full_height_title_and_artist.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,20 @@ class FullHeightTitleAndArtist extends StatelessWidget {
Widget build(BuildContext context) {
final theme = context.t;
final mpvMetaData = context.select((PlayerModel m) => m.mpvMetaData);
final icyName = mpvMetaData?.icyName;
final icyTitle = mpvMetaData?.icyTitle;

final subTitle = icyName?.isNotEmpty == true
? icyName!
: (audio?.audioType == AudioType.podcast
? audio?.album
: audio?.artist ?? ' ') ??
'';

final title = icyTitle?.isNotEmpty == true
? icyTitle!
: (audio?.title?.isNotEmpty == true ? audio!.title! : ' ');

final label = mpvMetaData?.icyTitle.isNotEmpty == true
? mpvMetaData!.icyTitle
: (audio?.title?.isNotEmpty == true ? audio!.title! : '');
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Expand All @@ -33,9 +43,9 @@ class FullHeightTitleAndArtist extends StatelessWidget {
context: context,
),
child: Tooltip(
message: label,
message: title,
child: Text(
label,
title,
style: TextStyle(
fontWeight: largeTextWeight,
fontSize: 30,
Expand All @@ -54,18 +64,19 @@ class FullHeightTitleAndArtist extends StatelessWidget {
artist: mpvMetaData?.icyName,
context: context,
),
child: Text(
mpvMetaData?.icyName.isNotEmpty == true
? mpvMetaData!.icyName
: (audio?.artist ?? ''),
style: TextStyle(
fontWeight: smallTextFontWeight,
fontSize: 20,
color: theme.colorScheme.onSurface,
child: Tooltip(
message: subTitle,
child: Text(
subTitle,
style: TextStyle(
fontWeight: smallTextFontWeight,
fontSize: 20,
color: theme.colorScheme.onSurface,
),
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
),
],
Expand Down
21 changes: 19 additions & 2 deletions lib/src/player/player_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import '../../data.dart';
import '../../globals.dart';
import '../../library.dart';
import '../../local_audio.dart';
import '../../podcasts.dart';
import '../../utils.dart';
import '../app/app_model.dart';

void onLocalAudioTitleTap({
required Audio audio,
Expand Down Expand Up @@ -68,6 +70,9 @@ void onTitleTap({
if (audio?.audioType == null || audio?.title == null) {
return;
}
if (audio?.audioType == AudioType.local) {
context.read<AppModel>().setFullScreen(false);
}

if (text?.isNotEmpty == true) {
Clipboard.setData(ClipboardData(text: text!));
Expand Down Expand Up @@ -106,14 +111,17 @@ void onTitleTap({
}
}

void onArtistTap({
Future<void> onArtistTap({
required Audio? audio,
required String? artist,
required BuildContext context,
}) {
}) async {
if (audio?.audioType == null || audio?.artist == null) {
return;
}
if (audio?.audioType != AudioType.radio) {
context.read<AppModel>().setFullScreen(false);
}
if (audio!.audioType == AudioType.radio && audio.url?.isNotEmpty == true) {
Clipboard.setData(ClipboardData(text: audio.url!));
ScaffoldMessenger.of(context).clearSnackBars();
Expand All @@ -131,6 +139,15 @@ void onArtistTap({
),
),
);
} else if (audio.audioType == AudioType.podcast &&
audio.website?.isNotEmpty == true) {
await searchAndPushPodcastPage(
context: context,
feedUrl: audio.website,
itemImageUrl: audio.albumArtUrl,
genre: audio.genre,
play: false,
);
} else {
onLocalAudioArtistTap(audio: audio, context: context);
}
Expand Down
1 change: 0 additions & 1 deletion lib/src/podcasts/podcast_audio_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ class _Description extends StatelessWidget {
),
children: [
SizedBox(
height: 400,
width: 400,
child: _createHtml(
color: theme.colorScheme.onSurface,
Expand Down
14 changes: 5 additions & 9 deletions lib/src/podcasts/podcast_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ class PodcastPage extends StatelessWidget {
this.imageUrl,
required this.pageId,
this.audios,
this.subscribed = true,
required this.removePodcast,
required this.addPodcast,
required this.title,
});

Expand Down Expand Up @@ -47,19 +44,18 @@ class PodcastPage extends StatelessWidget {
);
}

final void Function(String feedUrl) removePodcast;
final void Function(String feedUrl, Set<Audio> audios) addPodcast;

final String? imageUrl;
final String pageId;
final String title;
final Set<Audio>? audios;
final bool subscribed;

@override
Widget build(BuildContext context) {
final theme = context.t;
final genre = audios?.firstWhereOrNull((e) => e.genre != null)?.genre;
final libraryModel = context.read<LibraryModel>();

final subscribed = libraryModel.podcastSubscribed(pageId);

context.select((LibraryModel m) => m.lastPositions?.length);
context.select((LibraryModel m) => m.downloadsLength);
Expand Down Expand Up @@ -115,9 +111,9 @@ class PodcastPage extends StatelessWidget {
? null
: () {
if (subscribed) {
removePodcast(pageId);
libraryModel.removePodcast(pageId);
} else if (audios?.isNotEmpty == true) {
addPodcast(pageId, audios!);
libraryModel.addPodcast(pageId, audios!);
}
},
),
Expand Down
Loading

0 comments on commit 8376a69

Please sign in to comment.