Skip to content

Commit

Permalink
Extenstion of PR #288 and fr: #265
Browse files Browse the repository at this point in the history
  • Loading branch information
anandnet committed Oct 5, 2024
1 parent 14f82f4 commit be4db10
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 22 deletions.
50 changes: 46 additions & 4 deletions lib/ui/widgets/list_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import 'package:flutter_slidable/flutter_slidable.dart';
import '../../models/playlist.dart';
import '../navigator.dart';
import '../player/player_controller.dart';
import 'add_to_playlist.dart';
import 'image_widget.dart';
import 'songinfo_bottom_sheet.dart';

class ListWidget extends StatelessWidget {
class ListWidget extends StatelessWidget with RemoveSongFromPlaylistMixin{
const ListWidget(this.items, this.title, this.isCompleteList,
{super.key,
this.isPlaylist = false,
Expand Down Expand Up @@ -85,18 +86,59 @@ class ListWidget extends StatelessWidget {
? const BouncingScrollPhysics()
: const NeverScrollableScrollPhysics(),
itemBuilder: (context, index) => Slidable(
startActionPane: ActionPane(motion: const DrawerMotion(), children: [
SlidableAction(
onPressed: (context) {
showDialog(
context: context,
builder: (context) =>
AddToPlaylist([items[index] as MediaItem]),
).whenComplete(() => Get.delete<AddToPlaylistController>());
},
backgroundColor: Theme.of(context).colorScheme.secondary,
foregroundColor: Theme.of(context).textTheme.titleMedium!.color,
icon: Icons.playlist_add,
//label: 'Add to playlist',
),
if (playlist != null && !playlist.isCloudPlaylist)
SlidableAction(
onPressed: (context) {
removeSongFromPlaylist(items[index] as MediaItem, playlist);
},
backgroundColor: Theme.of(context).colorScheme.secondary,
foregroundColor: Theme.of(context).textTheme.titleMedium!.color,
icon: Icons.delete,
//label: 'delete',
),
]),
endActionPane: ActionPane(motion: const DrawerMotion(), children: [
SlidableAction(
onPressed: (context) {
playerController
.enqueueSong(items[index] as MediaItem)
.whenComplete(() {
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(snackbar(
context, "songEnqueueAlert".tr,
size: SanckBarSize.MEDIUM));
});
},
backgroundColor: Theme.of(context).colorScheme.secondary,
foregroundColor: Theme.of(context).textTheme.titleMedium!.color,
icon: Icons.merge,
//label: 'Enqueue',
),
SlidableAction(
onPressed: (context) {
playerController.playNext(items[index] as MediaItem);
ScaffoldMessenger.of(context).showSnackBar(snackbar(
context, "Upcoming ${(items[index] as MediaItem).title}".tr,
size: SanckBarSize.MEDIUM));
},
backgroundColor: Color(Colors.transparent.value),
foregroundColor: Colors.white,
backgroundColor: Theme.of(context).colorScheme.secondary,
foregroundColor: Theme.of(context).textTheme.titleMedium!.color,
icon: Icons.next_plan_outlined,
label: 'Play Next',
//label: 'Play Next',
),
]),
child: ListTile(
Expand Down
40 changes: 22 additions & 18 deletions lib/ui/widgets/songinfo_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ class SongInfoBottomSheet extends StatelessWidget {
}
}

class SongInfoController extends GetxController {
class SongInfoController extends GetxController with RemoveSongFromPlaylistMixin {
final isCurrentSongFav = false.obs;
final MediaItem song;
final bool calledFromPlayer;
Expand Down Expand Up @@ -370,6 +370,26 @@ class SongInfoController extends GetxController {
}
}


Future<void> toggleFav() async {
if (calledFromPlayer) {
final cntrl = Get.find<PlayerController>();
if (cntrl.currentSong.value == song) {
cntrl.toggleFavourite();
isCurrentSongFav.value = !isCurrentSongFav.value;
return;
}
}
final box = await Hive.openBox("LIBFAV");
isCurrentSongFav.isFalse
? box.put(song.id, MediaItemBuilder.toJson(song))
: box.delete(song.id);
isCurrentSongFav.value = !isCurrentSongFav.value;
}
}


mixin RemoveSongFromPlaylistMixin {
Future<void> removeSongFromPlaylist(MediaItem item, Playlist playlist) async {
final box = await Hive.openBox(playlist.playlistId);
//Library songs case
Expand Down Expand Up @@ -416,20 +436,4 @@ class SongInfoController extends GetxController {
playlist.playlistId == "SongsCache") return;
box.close();
}

Future<void> toggleFav() async {
if (calledFromPlayer) {
final cntrl = Get.find<PlayerController>();
if (cntrl.currentSong.value == song) {
cntrl.toggleFavourite();
isCurrentSongFav.value = !isCurrentSongFav.value;
return;
}
}
final box = await Hive.openBox("LIBFAV");
isCurrentSongFav.isFalse
? box.put(song.id, MediaItemBuilder.toJson(song))
: box.delete(song.id);
isCurrentSongFav.value = !isCurrentSongFav.value;
}
}
}

0 comments on commit be4db10

Please sign in to comment.