Skip to content

Commit

Permalink
feat: long press favourites button to add to playlist
Browse files Browse the repository at this point in the history
in miniplayer
ref: #223
  • Loading branch information
MSOB7YY committed Jul 4, 2024
1 parent 7c750b3 commit 0647e83
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
12 changes: 8 additions & 4 deletions lib/packages/miniplayer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import 'package:namida/core/themes.dart';
import 'package:namida/core/translations/language.dart';
import 'package:namida/packages/lyrics_lrc_parsed_view.dart';
import 'package:namida/packages/miniplayer_base.dart';
import 'package:namida/ui/dialogs/add_to_playlist_dialog.dart';
import 'package:namida/ui/dialogs/common_dialogs.dart';
import 'package:namida/ui/widgets/artwork.dart';
import 'package:namida/ui/widgets/custom_widgets.dart';
Expand All @@ -35,6 +36,7 @@ import 'package:namida/youtube/class/youtube_id.dart';
import 'package:namida/youtube/controller/youtube_info_controller.dart';
import 'package:namida/youtube/controller/youtube_playlist_controller.dart';
import 'package:namida/youtube/controller/yt_miniplayer_ui_controller.dart';
import 'package:namida/youtube/functions/add_to_playlist_sheet.dart';
import 'package:namida/youtube/pages/yt_channel_subpage.dart';
import 'package:namida/youtube/widgets/yt_history_video_card.dart';
import 'package:namida/youtube/widgets/yt_thumbnail.dart';
Expand Down Expand Up @@ -113,7 +115,7 @@ class NamidaMiniPlayerTrack extends StatelessWidget {

void _openMenu(Track track) => NamidaDialogs.inst.showTrackDialog(track, source: QueueSource.playerQueue);

MiniplayerTextData<TrackWithDate, Track> _textBuilder(Selectable selectable) {
MiniplayerInfoData<TrackWithDate, Track> _textBuilder(Selectable selectable) {
String firstLine = '';
String secondLine = '';

Expand All @@ -133,12 +135,13 @@ class NamidaMiniPlayerTrack extends StatelessWidget {
firstLine = secondLine;
secondLine = '';
}
return MiniplayerTextData(
return MiniplayerInfoData(
firstLine: firstLine,
secondLine: secondLine,
favouritePlaylist: PlaylistController.inst.favouritesPlaylist,
itemToLike: track,
onLikeTap: (isLiked) async => PlaylistController.inst.favouriteButtonOnPressed(track),
onShowAddToPlaylistDialog: () => showAddToPlaylistDialog([track]),
onMenuOpen: (_) => _openMenu(track),
likedIcon: Broken.heart_tick,
normalIcon: Broken.heart,
Expand Down Expand Up @@ -317,7 +320,7 @@ class NamidaMiniPlayerYoutubeID extends StatelessWidget {
);
}

MiniplayerTextData<YoutubeID, String> _textBuilder(BuildContext context, YoutubeID video) {
MiniplayerInfoData<YoutubeID, String> _textBuilder(BuildContext context, YoutubeID video) {
String firstLine = '';
String secondLine = '';

Expand All @@ -328,12 +331,13 @@ class NamidaMiniPlayerYoutubeID extends StatelessWidget {
secondLine = '';
}

return MiniplayerTextData(
return MiniplayerInfoData(
firstLine: firstLine,
secondLine: secondLine,
favouritePlaylist: YoutubePlaylistController.inst.favouritesPlaylist,
itemToLike: video.id,
onLikeTap: (isLiked) async => YoutubePlaylistController.inst.favouriteButtonOnPressed(video.id),
onShowAddToPlaylistDialog: () => showAddToPlaylistSheet(ctx: context, ids: [video.id], idsNamesLookup: {}),
onMenuOpen: (d) => _openMenu(context, video, d),
likedIcon: Broken.like_filled,
normalIcon: Broken.like_1,
Expand Down
29 changes: 17 additions & 12 deletions lib/packages/miniplayer_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,27 @@ class FocusedMenuOptions<E> {
});
}

class MiniplayerTextData<T, E> {
class MiniplayerInfoData<T, E> {
final String firstLine;
final String secondLine;
final FavouritePlaylist<T, E> favouritePlaylist;
final E itemToLike;
final Future<bool> Function(bool isLiked) onLikeTap;
final void Function() onShowAddToPlaylistDialog;
final void Function(TapUpDetails details) onMenuOpen;
final IconData likedIcon;
final IconData normalIcon;

late final bool firstLineGood;
late final bool secondLineGood;

MiniplayerTextData({
MiniplayerInfoData({
required this.firstLine,
required this.secondLine,
required this.favouritePlaylist,
required this.itemToLike,
required this.onLikeTap,
required this.onShowAddToPlaylistDialog,
required this.onMenuOpen,
required this.likedIcon,
required this.normalIcon,
Expand All @@ -101,7 +103,7 @@ class NamidaMiniPlayerBase<E> extends StatefulWidget {
final FocusedMenuOptions<E> focusedMenuOptions;
final Widget Function(E item, double cp) imageBuilder;
final Widget Function(E item, double bcp) currentImageBuilder;
final MiniplayerTextData Function(E item) textBuilder;
final MiniplayerInfoData Function(E item) textBuilder;
final bool canShowBuffering;

const NamidaMiniPlayerBase({
Expand Down Expand Up @@ -1233,7 +1235,7 @@ class _RawImageContainer extends StatelessWidget {
}

class _TrackInfo<T, E> extends StatelessWidget {
final MiniplayerTextData<T, E> textData;
final MiniplayerInfoData<T, E> textData;
final double cp;
final double qp;
final double p;
Expand Down Expand Up @@ -1315,14 +1317,17 @@ class _TrackInfo<T, E> extends StatelessWidget {
opacity: opacity,
child: Transform.translate(
offset: Offset(-100 * (1.0 - cp), 0.0),
child: ObxOClass(
rx: textData.favouritePlaylist,
builder: (favouritePlaylist) => NamidaRawLikeButton(
size: 32.0,
likedIcon: textData.likedIcon,
normalIcon: textData.normalIcon,
isLiked: favouritePlaylist.isSubItemFavourite(textData.itemToLike),
onTap: textData.onLikeTap,
child: LongPressDetector(
onLongPress: textData.onShowAddToPlaylistDialog,
child: ObxOClass(
rx: textData.favouritePlaylist,
builder: (favouritePlaylist) => NamidaRawLikeButton(
size: 32.0,
likedIcon: textData.likedIcon,
normalIcon: textData.normalIcon,
isLiked: favouritePlaylist.isSubItemFavourite(textData.itemToLike),
onTap: textData.onLikeTap,
),
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: namida
description: A Beautiful and Feature-rich Music Player, With YouTube & Video Support Built in Flutter
publish_to: "none"
version: 2.9.5-beta+240704206
version: 2.9.6-beta+240704207

environment:
sdk: ">=3.4.0 <4.0.0"
Expand Down

0 comments on commit 0647e83

Please sign in to comment.