From 96021e1a49d22bd25fd052c122f49f439c2bea43 Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Mon, 27 Nov 2023 20:38:50 +0600 Subject: [PATCH] fix: "Add () to Playlist" option not showing in favorited playlists #904 --- .../dialogs/playlist_add_track_dialog.dart | 8 +++++-- .../shared/track_tile/track_options.dart | 6 ++++- .../sections/body/track_view_body.dart | 3 +-- .../body/track_view_body_headers.dart | 24 ++++++++----------- .../sections/body/track_view_options.dart | 22 +++++++---------- lib/main.dart | 2 +- .../playlist_generate_result.dart | 1 + lib/themes/theme.dart | 3 +++ 8 files changed, 35 insertions(+), 34 deletions(-) diff --git a/lib/components/shared/dialogs/playlist_add_track_dialog.dart b/lib/components/shared/dialogs/playlist_add_track_dialog.dart index aadcd9d67..1c8e5aaa0 100644 --- a/lib/components/shared/dialogs/playlist_add_track_dialog.dart +++ b/lib/components/shared/dialogs/playlist_add_track_dialog.dart @@ -11,9 +11,12 @@ import 'package:spotube/services/queries/queries.dart'; import 'package:spotube/utils/type_conversion_utils.dart'; class PlaylistAddTrackDialog extends HookConsumerWidget { + /// The id of the playlist this dialog was opened from + final String? openFromPlaylist; final List tracks; const PlaylistAddTrackDialog({ required this.tracks, + required this.openFromPlaylist, Key? key, }) : super(key: key); @@ -30,11 +33,12 @@ class PlaylistAddTrackDialog extends HookConsumerWidget { ?.where( (playlist) => playlist.owner?.id != null && - playlist.owner!.id == me.data?.id, + playlist.owner!.id == me.data?.id && + playlist.id != openFromPlaylist, ) .toList() ?? [], - [userPlaylists.data, me.data?.id], + [userPlaylists.data, me.data?.id, openFromPlaylist], ); final playlistsCheck = useState({}); diff --git a/lib/components/shared/track_tile/track_options.dart b/lib/components/shared/track_tile/track_options.dart index b0633d34a..9a587be68 100644 --- a/lib/components/shared/track_tile/track_options.dart +++ b/lib/components/shared/track_tile/track_options.dart @@ -64,11 +64,15 @@ class TrackOptions extends HookConsumerWidget { }); } - void actionAddToPlaylist(BuildContext context, Track track) { + void actionAddToPlaylist( + BuildContext context, + Track track, + ) { showDialog( context: context, builder: (context) => PlaylistAddTrackDialog( tracks: [track], + openFromPlaylist: playlistId, ), ); } diff --git a/lib/components/shared/tracks_view/sections/body/track_view_body.dart b/lib/components/shared/tracks_view/sections/body/track_view_body.dart index 1c3ba3fb5..d77a3e6ff 100644 --- a/lib/components/shared/tracks_view/sections/body/track_view_body.dart +++ b/lib/components/shared/tracks_view/sections/body/track_view_body.dart @@ -24,6 +24,7 @@ class TrackViewBodySection extends HookConsumerWidget { final playlist = ref.watch(ProxyPlaylistNotifier.provider); final playlistNotifier = ref.watch(ProxyPlaylistNotifier.notifier); final props = InheritedTrackView.of(context); + final trackViewState = ref.watch(trackViewProvider(props.tracks)); final searchController = useTextEditingController(); final searchFocus = useFocusNode(); @@ -38,8 +39,6 @@ class TrackViewBodySection extends HookConsumerWidget { return props.tracks.where((e) => trackIds.remove(e.id)).toList(); }, [props.tracks]); - final trackViewState = ref.watch(trackViewProvider(uniqTracks)); - final tracks = useMemoized(() { List filteredTracks; if (searchQuery.isEmpty) { diff --git a/lib/components/shared/tracks_view/sections/body/track_view_body_headers.dart b/lib/components/shared/tracks_view/sections/body/track_view_body_headers.dart index 57d8b296b..7e4522a00 100644 --- a/lib/components/shared/tracks_view/sections/body/track_view_body_headers.dart +++ b/lib/components/shared/tracks_view/sections/body/track_view_body_headers.dart @@ -38,20 +38,16 @@ class TrackViewBodyHeaders extends HookConsumerWidget { ), ); }, - child: trackViewState.isSelecting - ? Checkbox( - value: trackViewState.hasSelectedAll, - onChanged: (checked) { - if (checked == true) { - trackViewState.selectAll(); - } else { - trackViewState.deselectAll(); - } - }, - ) - : constrains.mdAndUp - ? const SizedBox(width: 32) - : const SizedBox(width: 16), + child: Checkbox( + value: trackViewState.hasSelectedAll, + onChanged: (checked) { + if (checked == true) { + trackViewState.selectAll(); + } else { + trackViewState.deselectAll(); + } + }, + ), ), Expanded( flex: 7, diff --git a/lib/components/shared/tracks_view/sections/body/track_view_options.dart b/lib/components/shared/tracks_view/sections/body/track_view_options.dart index 4fcd0a59a..583c91076 100644 --- a/lib/components/shared/tracks_view/sections/body/track_view_options.dart +++ b/lib/components/shared/tracks_view/sections/body/track_view_options.dart @@ -11,7 +11,6 @@ import 'package:spotube/provider/download_manager_provider.dart'; import 'package:spotube/provider/proxy_playlist/proxy_playlist_provider.dart'; import 'package:spotube/provider/user_preferences/user_preferences_provider.dart'; import 'package:spotube/provider/user_preferences/user_preferences_state.dart'; -import 'package:spotube/services/queries/queries.dart'; class TrackViewBodyOptions extends HookConsumerWidget { const TrackViewBodyOptions({Key? key}) : super(key: key); @@ -30,11 +29,6 @@ class TrackViewBodyOptions extends HookConsumerWidget { final trackViewState = ref.watch(trackViewProvider(props.tracks)); final selectedTracks = trackViewState.selectedTracks; - final userPlaylists = useQueries.playlist.ofMineAll(ref); - - final isUserPlaylist = - userPlaylists.data?.any((e) => e.id == props.collectionId) ?? false; - return AdaptivePopSheetList( tooltip: context.l10n.more_actions, headings: [ @@ -66,6 +60,7 @@ class TrackViewBodyOptions extends HookConsumerWidget { context: context, builder: (context) { return PlaylistAddTrackDialog( + openFromPlaylist: props.collectionId, tracks: selectedTracks.toList(), ); }, @@ -100,15 +95,14 @@ class TrackViewBodyOptions extends HookConsumerWidget { context.l10n.download_count(selectedTracks.length), ), ), - if (!isUserPlaylist) - PopSheetEntry( - value: "add-to-playlist", - leading: const Icon(SpotubeIcons.playlistAdd), - enabled: selectedTracks.isNotEmpty, - title: Text( - context.l10n.add_count_to_playlist(selectedTracks.length), - ), + PopSheetEntry( + value: "add-to-playlist", + leading: const Icon(SpotubeIcons.playlistAdd), + enabled: selectedTracks.isNotEmpty, + title: Text( + context.l10n.add_count_to_playlist(selectedTracks.length), ), + ), PopSheetEntry( enabled: selectedTracks.isNotEmpty, value: "add-to-queue", diff --git a/lib/main.dart b/lib/main.dart index 7bb965434..c68b6bc66 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -201,7 +201,7 @@ class SpotubeState extends ConsumerState { Brightness.dark, isAmoledTheme, ), - [paletteColor, accentMaterialColor, isAmoledTheme], + ); return MaterialApp.router( diff --git a/lib/pages/library/playlist_generate/playlist_generate_result.dart b/lib/pages/library/playlist_generate/playlist_generate_result.dart index 015685f1f..f751b65b8 100644 --- a/lib/pages/library/playlist_generate/playlist_generate_result.dart +++ b/lib/pages/library/playlist_generate/playlist_generate_result.dart @@ -163,6 +163,7 @@ class PlaylistGenerateResultPage extends HookConsumerWidget { context: context, builder: (context) => PlaylistAddTrackDialog( + openFromPlaylist: null, tracks: selectedTracks.value .map( (e) => generatedPlaylist.data! diff --git a/lib/themes/theme.dart b/lib/themes/theme.dart index 8c968e1b3..9a5e473f7 100644 --- a/lib/themes/theme.dart +++ b/lib/themes/theme.dart @@ -71,5 +71,8 @@ ThemeData theme(Color seed, Brightness brightness, bool isAmoled) { scrollbarTheme: const ScrollbarThemeData( thickness: MaterialStatePropertyAll(14), ), + checkboxTheme: CheckboxThemeData( + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)), + ), ); }