Skip to content

Commit

Permalink
Merge pull request #21 from priyanshuverma-dev/dev
Browse files Browse the repository at this point in the history
Feat: Add songs in queue
  • Loading branch information
priyanshuverma-dev authored Jul 15, 2024
2 parents 64d4f4a + 4fac746 commit 4040a3b
Show file tree
Hide file tree
Showing 14 changed files with 412 additions and 193 deletions.
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

0 comments on commit 4040a3b

Please sign in to comment.