mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 16:05:18 +00:00
refactor(tracktile): use popup menu instead of adaptive list tile
This commit is contained in:
parent
c85ae85002
commit
c1d67153ce
@ -7,7 +7,6 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|||||||
import 'package:spotify/spotify.dart' hide Image;
|
import 'package:spotify/spotify.dart' hide Image;
|
||||||
import 'package:spotube/collections/assets.gen.dart';
|
import 'package:spotube/collections/assets.gen.dart';
|
||||||
import 'package:spotube/collections/spotube_icons.dart';
|
import 'package:spotube/collections/spotube_icons.dart';
|
||||||
import 'package:spotube/components/shared/adaptive/adaptive_popup_menu_button.dart';
|
|
||||||
import 'package:spotube/components/shared/heart_button.dart';
|
import 'package:spotube/components/shared/heart_button.dart';
|
||||||
import 'package:spotube/components/shared/links/link_text.dart';
|
import 'package:spotube/components/shared/links/link_text.dart';
|
||||||
import 'package:spotube/components/shared/image/universal_image.dart';
|
import 'package:spotube/components/shared/image/universal_image.dart';
|
||||||
@ -62,6 +61,7 @@ class TrackTile extends HookConsumerWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, ref) {
|
Widget build(BuildContext context, ref) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
final breakpoint = useBreakpoints();
|
final breakpoint = useBreakpoints();
|
||||||
final isBlackListed = ref.watch(
|
final isBlackListed = ref.watch(
|
||||||
BlackListNotifier.provider.select(
|
BlackListNotifier.provider.select(
|
||||||
@ -177,7 +177,6 @@ class TrackTile extends HookConsumerWidget {
|
|||||||
);
|
);
|
||||||
|
|
||||||
final toggler = useTrackToggleLike(track.value, ref);
|
final toggler = useTrackToggleLike(track.value, ref);
|
||||||
final theme = Theme.of(context);
|
|
||||||
|
|
||||||
return AnimatedContainer(
|
return AnimatedContainer(
|
||||||
duration: const Duration(milliseconds: 500),
|
duration: const Duration(milliseconds: 500),
|
||||||
@ -301,14 +300,17 @@ class TrackTile extends HookConsumerWidget {
|
|||||||
Text(duration),
|
Text(duration),
|
||||||
],
|
],
|
||||||
const SizedBox(width: 10),
|
const SizedBox(width: 10),
|
||||||
if (!isLocal)
|
PopupMenuButton(
|
||||||
AdaptiveActions(
|
icon: const Icon(SpotubeIcons.moreHorizontal),
|
||||||
actions: [
|
elevation: 4,
|
||||||
|
position: PopupMenuPosition.under,
|
||||||
|
tooltip: "More options",
|
||||||
|
itemBuilder: (context) {
|
||||||
|
return [
|
||||||
if (!playlistQueueNotifier.isTrackOnQueue(track.value))
|
if (!playlistQueueNotifier.isTrackOnQueue(track.value))
|
||||||
Action(
|
PopupMenuItem(
|
||||||
icon: const Icon(SpotubeIcons.queueAdd),
|
padding: EdgeInsets.zero,
|
||||||
text: const Text("Add to queue"),
|
onTap: () {
|
||||||
onPressed: () {
|
|
||||||
playlistQueueNotifier.add([track.value]);
|
playlistQueueNotifier.add([track.value]);
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
@ -316,12 +318,15 @@ class TrackTile extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
child: const ListTile(
|
||||||
|
leading: Icon(SpotubeIcons.queueAdd),
|
||||||
|
title: Text("Add to queue"),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
Action(
|
PopupMenuItem(
|
||||||
icon: const Icon(SpotubeIcons.queueRemove),
|
padding: EdgeInsets.zero,
|
||||||
text: const Text("Remove from queue"),
|
onTap: () {
|
||||||
onPressed: () {
|
|
||||||
playlistQueueNotifier.remove([track.value]);
|
playlistQueueNotifier.remove([track.value]);
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
@ -330,60 +335,67 @@ class TrackTile extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
child: const ListTile(
|
||||||
|
leading: Icon(SpotubeIcons.queueRemove),
|
||||||
|
title: Text("Remove from queue"),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
if (toggler.item3.hasData)
|
if (toggler.item3.hasData)
|
||||||
Action(
|
PopupMenuItem(
|
||||||
icon: toggler.item1
|
padding: EdgeInsets.zero,
|
||||||
? const Icon(
|
onTap: () {
|
||||||
SpotubeIcons.heartFilled,
|
|
||||||
color: Colors.pink,
|
|
||||||
)
|
|
||||||
: const Icon(SpotubeIcons.heart),
|
|
||||||
text: const Text("Save as favorite"),
|
|
||||||
onPressed: () {
|
|
||||||
toggler.item2.mutate(toggler.item1);
|
toggler.item2.mutate(toggler.item1);
|
||||||
},
|
},
|
||||||
|
child: ListTile(
|
||||||
|
leading: toggler.item1
|
||||||
|
? const Icon(
|
||||||
|
SpotubeIcons.heartFilled,
|
||||||
|
color: Colors.pink,
|
||||||
|
)
|
||||||
|
: const Icon(SpotubeIcons.heart),
|
||||||
|
title: const Text("Save as favorite"),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
if (auth != null)
|
if (auth != null)
|
||||||
Action(
|
PopupMenuItem(
|
||||||
icon: const Icon(SpotubeIcons.playlistAdd),
|
padding: EdgeInsets.zero,
|
||||||
text: const Text("Add To playlist"),
|
onTap: actionAddToPlaylist,
|
||||||
onPressed: actionAddToPlaylist,
|
child: const ListTile(
|
||||||
|
leading: Icon(SpotubeIcons.playlistAdd),
|
||||||
|
title: Text("Add To playlist"),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
if (userPlaylist && auth != null)
|
if (userPlaylist && auth != null)
|
||||||
Action(
|
PopupMenuItem(
|
||||||
icon: (removeTrack.isMutating || !removeTrack.hasData) &&
|
padding: EdgeInsets.zero,
|
||||||
removingTrack.value == track.value.uri
|
onTap: () {
|
||||||
? const Center(
|
|
||||||
child: CircularProgressIndicator(),
|
|
||||||
)
|
|
||||||
: const Icon(SpotubeIcons.removeFilled),
|
|
||||||
text: const Text("Remove from playlist"),
|
|
||||||
onPressed: () {
|
|
||||||
removingTrack.value = track.value.uri;
|
removingTrack.value = track.value.uri;
|
||||||
removeTrack.mutate(track.value.uri!);
|
removeTrack.mutate(track.value.uri!);
|
||||||
},
|
},
|
||||||
),
|
child: ListTile(
|
||||||
Action(
|
leading:
|
||||||
icon: const Icon(SpotubeIcons.share),
|
(removeTrack.isMutating || !removeTrack.hasData) &&
|
||||||
text: const Text("Share"),
|
removingTrack.value == track.value.uri
|
||||||
onPressed: () {
|
? const Center(
|
||||||
actionShare(track.value);
|
child: CircularProgressIndicator(),
|
||||||
},
|
)
|
||||||
),
|
: const Icon(SpotubeIcons.removeFilled),
|
||||||
Action(
|
title: const Text("Remove from playlist"),
|
||||||
icon: Icon(
|
|
||||||
SpotubeIcons.playlistRemove,
|
|
||||||
color: isBlackListed ? Colors.white : Colors.red[400],
|
|
||||||
),
|
|
||||||
backgroundColor: isBlackListed ? Colors.red[400] : null,
|
|
||||||
text: Text(
|
|
||||||
"${isBlackListed ? "Remove from" : "Add to"} blacklist",
|
|
||||||
style: TextStyle(
|
|
||||||
color: isBlackListed ? Colors.white : Colors.red[400],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onPressed: () {
|
PopupMenuItem(
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
onTap: () {
|
||||||
|
actionShare(track.value);
|
||||||
|
},
|
||||||
|
child: const ListTile(
|
||||||
|
leading: Icon(SpotubeIcons.share),
|
||||||
|
title: Text("Share"),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
PopupMenuItem(
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
onTap: () {
|
||||||
if (isBlackListed) {
|
if (isBlackListed) {
|
||||||
ref.read(BlackListNotifier.provider.notifier).remove(
|
ref.read(BlackListNotifier.provider.notifier).remove(
|
||||||
BlacklistedElement.track(
|
BlacklistedElement.track(
|
||||||
@ -396,9 +408,24 @@ class TrackTile extends HookConsumerWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
child: ListTile(
|
||||||
|
leading: Icon(
|
||||||
|
SpotubeIcons.playlistRemove,
|
||||||
|
color: isBlackListed ? Colors.white : Colors.red[400],
|
||||||
|
),
|
||||||
|
iconColor: isBlackListed ? Colors.red[400] : null,
|
||||||
|
textColor: isBlackListed ? Colors.red[400] : null,
|
||||||
|
title: Text(
|
||||||
|
"${isBlackListed ? "Remove from" : "Add to"} blacklist",
|
||||||
|
style: TextStyle(
|
||||||
|
color: isBlackListed ? Colors.white : Colors.red[400],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
],
|
];
|
||||||
),
|
},
|
||||||
|
),
|
||||||
...?actions,
|
...?actions,
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user