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

Feat: Add songs in queue #21

Merged
merged 4 commits into from
Jul 15, 2024
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
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ on:
branches:
- main
- master
- dev
push:
branches:
- main
- master
- dev


name: "Integration Tests"
Expand Down
137 changes: 74 additions & 63 deletions lib/core/widgets/media_card.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:context_menus/context_menus.dart';
import 'package:flutter/material.dart';

import 'cache_image.dart';

class MediaCard extends StatelessWidget {
Expand All @@ -13,6 +13,7 @@ class MediaCard extends StatelessWidget {
final bool showMenu;
final bool explicitContent;
final Color? accentColor;
final List<ContextMenuButtonConfig?> contextMenu;
const MediaCard({
super.key,
required this.onTap,
Expand All @@ -23,6 +24,7 @@ class MediaCard extends StatelessWidget {
this.badgeIcon,
required this.explicitContent,
this.onDoubleTap,
this.contextMenu = const [],
this.onMenuTap,
this.showMenu = true,
});
Expand All @@ -31,77 +33,86 @@ class MediaCard extends StatelessWidget {
Widget build(BuildContext context) {
return Card(
surfaceTintColor: accentColor,
child: InkWell(
onTap: onTap,
onDoubleTap: onDoubleTap,
borderRadius: BorderRadius.circular(12),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Badge(
isLabelVisible: badgeIcon != null,
backgroundColor:
explicitContent ? Colors.redAccent : Colors.teal,
label: Icon(
badgeIcon,
size: 10,
),
child: ClipRRect(
borderRadius: const BorderRadius.only(
bottomLeft: Radius.circular(8),
topLeft: Radius.circular(8),
child: ContextMenuRegion(
contextMenu: GenericContextMenu(
buttonStyle: ContextMenuButtonStyle(
hoverBgColor: Colors.teal.shade100,
hoverFgColor: Colors.black,
),
buttonConfigs: contextMenu,
),
child: InkWell(
onTap: onTap,
onDoubleTap: onDoubleTap,
borderRadius: BorderRadius.circular(12),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Badge(
isLabelVisible: badgeIcon != null,
backgroundColor:
explicitContent ? Colors.redAccent : Colors.teal,
label: Icon(
badgeIcon,
size: 10,
),
child: CacheImage(
url: image,
width: 60,
height: 60,
child: ClipRRect(
borderRadius: const BorderRadius.only(
bottomLeft: Radius.circular(8),
topLeft: Radius.circular(8),
),
child: CacheImage(
url: image,
width: 60,
height: 60,
),
),
),
),
Flexible(
child: Container(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
title,
style: const TextStyle(
fontWeight: FontWeight.bold,
Flexible(
child: Container(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
title,
style: const TextStyle(
fontWeight: FontWeight.bold,
),
maxLines: 1,
softWrap: true,
),
maxLines: 1,
softWrap: true,
),
Text(
subtitle,
style: const TextStyle(
overflow: TextOverflow.fade,
Text(
subtitle,
style: const TextStyle(
overflow: TextOverflow.fade,
),
maxLines: 1,
softWrap: true,
),
maxLines: 1,
softWrap: true,
),
],
],
),
),
),
),
],
],
),
),
),
Visibility(
visible: showMenu,
child: IconButton(
tooltip: "Options",
onPressed: onMenuTap ?? () {},
icon: const Icon(Icons.more_vert_rounded),
Visibility(
visible: showMenu,
child: IconButton(
tooltip: "Options",
onPressed: onMenuTap ?? () {},
icon: const Icon(Icons.more_vert_rounded),
),
),
),
],
],
),
),
),
);
Expand Down
66 changes: 66 additions & 0 deletions lib/core/widgets/related_songs_list.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import 'package:context_menus/context_menus.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:sangeet/core/core.dart';
import 'package:sangeet/core/skeletions/media_loading_skeletion.dart';
import 'package:sangeet/functions/explore/controllers/explore_controller.dart';
import 'package:sangeet/functions/player/controllers/player_controller.dart';
import 'package:sangeet/functions/song/view/song_view.dart';

import 'media_card.dart';

class RelatedSongsList extends ConsumerWidget {
final String songId;
const RelatedSongsList({required this.songId, super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
final controller = ref.watch(playerControllerProvider.notifier);
return Container(
padding: const EdgeInsets.symmetric(vertical: 10),
child: ref.watch(getRelatedSongsProvider(songId)).when(
data: (songlist) {
return ListView.builder(
shrinkWrap: true,
physics: const BouncingScrollPhysics(),
scrollDirection: Axis.vertical,
itemCount: songlist.songs.length,
itemBuilder: (context, index) {
final song = songlist.songs[index];
return MediaCard(
onDoubleTap: () => controller.runRadio(
radioId: song.id,
type: MediaType.song,
prevSongs: songlist.songs,
playCurrent: true,
),
onTap: () => Navigator.of(context).push(
SongView.route(song.id),
),
contextMenu: [
ContextMenuButtonConfig(
icon: const Icon(Icons.queue_music_rounded),
"Add in Queue",
onPressed: () => controller.addSongToQueue(song: song),
),
ContextMenuButtonConfig(
icon: const Icon(Icons.play_circle_filled_rounded),
"Play Next",
onPressed: () => controller.addSongToNext(song: song),
)
],
image: song.images[1].url,
title: song.title,
subtitle:
"${formatNumber(song.playCount)} listens, ${song.label}",
explicitContent: song.explicitContent,
);
},
);
},
error: (er, st) => ErrorPage(error: er.toString()),
loading: () => const MediaLoader(),
),
);
}
}
44 changes: 28 additions & 16 deletions lib/functions/album/view/album_view.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:context_menus/context_menus.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:sangeet/core/core.dart';
Expand All @@ -24,7 +25,7 @@ class AlbumView extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final name = ModalRoute.of(context)?.settings.name ?? albumId;

final controller = ref.watch(playerControllerProvider.notifier);
return ref.watch(albumByIdProvider(name)).when(
data: (album) {
return BlurImageContainer(
Expand Down Expand Up @@ -82,12 +83,10 @@ class AlbumView extends ConsumerWidget {
),
),
PlayButton(
onPressed: () => ref
.watch(playerControllerProvider.notifier)
.runRadio(
radioId: album.id,
type: MediaType.album,
),
onPressed: () => controller.runRadio(
radioId: album.id,
type: MediaType.album,
),
)
],
),
Expand All @@ -101,15 +100,28 @@ class AlbumView extends ConsumerWidget {
itemBuilder: (context, index) {
final song = album.songs[index];
return MediaCard(
onTap: () => ref
.watch(playerControllerProvider.notifier)
.runRadio(
radioId: song.id,
type: MediaType.song,
prevSongs: album.songs,
playCurrent: true,
),
onDoubleTap: () => Navigator.of(context).push(
onDoubleTap: () => controller.runRadio(
radioId: song.id,
type: MediaType.song,
prevSongs: album.songs,
playCurrent: true,
),
contextMenu: [
ContextMenuButtonConfig(
icon: const Icon(Icons.queue_music_rounded),
"Add in Queue",
onPressed: () =>
controller.addSongToQueue(song: song),
),
ContextMenuButtonConfig(
icon: const Icon(
Icons.play_circle_filled_rounded),
"Play Next",
onPressed: () =>
controller.addSongToNext(song: song),
)
],
onTap: () => Navigator.of(context).push(
SongView.route(song.id),
),
image: song.images[1].url,
Expand Down
Loading
Loading