Skip to content

Commit

Permalink
chore: apply on swipe actions for yt cards as well
Browse files Browse the repository at this point in the history
- this took shitload of refactor, but improved perf so yey
- ref #333
  • Loading branch information
MSOB7YY committed Feb 1, 2025
1 parent b0c1d0e commit 7249a94
Show file tree
Hide file tree
Showing 37 changed files with 2,737 additions and 2,351 deletions.
4 changes: 2 additions & 2 deletions lib/class/queue.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:namida/core/enums.dart';
import 'package:namida/core/extensions.dart';

class Queue {
final QueueSource source;
final QueueSourceBase source;
final HomePageItems? homePageItem;
final int date;
final bool isFav;
Expand All @@ -29,7 +29,7 @@ class Queue {
}).toList() ??
[];
return Queue(
source: QueueSource.values.getEnum(json['source'] ?? '') ?? QueueSource.others,
source: QueueSource.values.getEnum(json['source'] ?? '') ?? QueueSourceYoutubeID.values.getEnum(json['source'] ?? '') ?? QueueSource.others,
homePageItem: HomePageItems.values.getEnum(json['homePageItem'] ?? ''),
date: json['date'] ?? DateTime(1970),
isFav: json['isFav'] ?? false,
Expand Down
2 changes: 1 addition & 1 deletion lib/controller/player_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ class Player {
Future<void> playOrPause<Q extends Playable>(
int index,
Iterable<Q> queue,
QueueSource source, {
QueueSourceBase source, {
HomePageItems? homePageItem,
bool shuffle = false,
bool startPlaying = true,
Expand Down
2 changes: 1 addition & 1 deletion lib/controller/queue_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class QueueController {

/// doesnt save queues with more than 2000 tracks.
Future<void> addNewQueue({
required QueueSource source,
required QueueSourceBase source,
required HomePageItems? homePageItem,
int? date,
List<Track> tracks = const <Track>[],
Expand Down
71 changes: 52 additions & 19 deletions lib/core/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,25 +135,58 @@ enum TrackSource {
lastfm,
}

enum QueueSource {
allTracks,
album,
artist,
genre,
playlist,
folder,
folderVideos,
search,
queuePage,
playerQueue,
mostPlayed,
history,
favourites,
selectedTracks,
externalFile,
homePageItem,
recentlyAdded,
others,
sealed class QueueSourceBase implements Enum {}

enum QueueSource implements QueueSourceBase {
allTracks(false),
album(false),
artist(false),
genre(false),
playlist(true),
folder(false),
folderVideos(false),
search(false),
queuePage(true),
playerQueue(true),
mostPlayed(false),
history(true),
favourites(false),
selectedTracks(false),
externalFile(false),
homePageItem(false),
recentlyAdded(false),

others(true);

final bool canHaveDuplicates;
const QueueSource(this.canHaveDuplicates);
}

enum QueueSourceYoutubeID implements QueueSourceBase {
channel(true),
playlist(true),
search(false),
playerQueue(true),
mostPlayed(false),
history(true),
historyFiltered(false),
favourites(false),
externalLink(true),
homeFeed(false),
notificationsHosted(false),
relatedVideos(false),
historyFilteredHosted(false),
searchHosted(false),
channelHosted(false),
historyHosted(true),
playlistHosted(true),

downloadTask(false),
videoEndCard(false),
videoDescription(false);

final bool canHaveDuplicates;
const QueueSourceYoutubeID(this.canHaveDuplicates);
}

enum TagField {
Expand Down
2 changes: 1 addition & 1 deletion lib/core/functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ class NamidaOnTaps {
final values = List<QueueSource>.from(QueueSource.values);
values.remove(QueueSource.homePageItem);

final lookup = <QueueSource, List<int>>{};
final lookup = <QueueSourceBase, List<int>>{};
final lookupHomepageItem = <HomePageItems, List<int>>{};
final lookupNonFavourites = <int, bool>{};
final map = QueueController.inst.queuesMap.value;
Expand Down
26 changes: 25 additions & 1 deletion lib/core/namida_converter_ext.dart
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ extension QueueNameGetter on Queue {
String toText() => homePageItem?.toText() ?? source.toText();
}

extension QUEUESOURCEExtensions on QueueSourceBase {
String toText() => _NamidaConverters.inst.getTitle(this);
}

extension QUEUESOURCEtoTRACKS on QueueSource {
String toText() => _NamidaConverters.inst.getTitle(this);

Expand Down Expand Up @@ -459,7 +463,7 @@ extension OnYoutubeLinkOpenActionUtils on OnYoutubeLinkOpenAction {
showAddToPlaylistSheet(ids: ids, idsNamesLookup: {});
return true;
case OnYoutubeLinkOpenAction.play:
await Player.inst.playOrPause(0, getPlayables(), QueueSource.others);
await Player.inst.playOrPause(0, getPlayables(), QueueSourceYoutubeID.externalLink);
return true;
case OnYoutubeLinkOpenAction.playNext:
return Player.inst.addToQueue(getPlayables(), insertNext: true);
Expand Down Expand Up @@ -1219,6 +1223,26 @@ class _NamidaConverters {
QueueSource.recentlyAdded: lang.RECENTLY_ADDED,
QueueSource.homePageItem: '',
QueueSource.others: lang.OTHERS,
// ==========
QueueSourceYoutubeID.channel: lang.CHANNEL,
QueueSourceYoutubeID.playlist: lang.PLAYLIST,
QueueSourceYoutubeID.search: lang.SEARCH,
QueueSourceYoutubeID.playerQueue: lang.QUEUE,
QueueSourceYoutubeID.mostPlayed: lang.MOST_PLAYED,
QueueSourceYoutubeID.history: lang.HISTORY,
QueueSourceYoutubeID.historyFiltered: lang.HISTORY,
QueueSourceYoutubeID.favourites: lang.FAVOURITES,
QueueSourceYoutubeID.externalLink: lang.EXTERNAL_FILES,
QueueSourceYoutubeID.homeFeed: lang.HOME,
QueueSourceYoutubeID.relatedVideos: lang.RELATED_VIDEOS,
QueueSourceYoutubeID.historyFilteredHosted: lang.HISTORY,
QueueSourceYoutubeID.searchHosted: lang.SEARCH,
QueueSourceYoutubeID.channelHosted: lang.CHANNEL,
QueueSourceYoutubeID.historyHosted: lang.HISTORY,
QueueSourceYoutubeID.playlistHosted: lang.PLAYLIST,
QueueSourceYoutubeID.downloadTask: lang.DOWNLOADS,
QueueSourceYoutubeID.videoEndCard: lang.VIDEO,
QueueSourceYoutubeID.videoDescription: lang.DESCRIPTION,
},
TagField: {
TagField.title: lang.TITLE,
Expand Down
31 changes: 17 additions & 14 deletions lib/packages/miniplayer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,16 @@ class NamidaMiniPlayerMixed extends StatelessWidget {

return NamidaMiniPlayerBase(
trackTileConfigs: trackConfig.trackTileConfigs,
videoTileConfigs: trackConfig.videoTileConfigs,
queueItemExtent: null,
queueItemExtentBuilder: (item) {
return item is Selectable ? trackConfig.queueItemExtent : ytConfig.queueItemExtent;
},
itemBuilder: (context, index, currentIndex, queue, properties) {
itemBuilder: (context, index, currentIndex, queue, trackTileProperties, videoTileProperties) {
final item = queue[index];
return item is Selectable
? trackConfig.itemBuilder(context, index, currentIndex, queue, properties)
: ytConfig.itemBuilder(context, index, currentIndex, queue, properties);
? trackConfig.itemBuilder(context, index, currentIndex, queue, trackTileProperties, videoTileProperties)
: ytConfig.itemBuilder(context, index, currentIndex, queue, trackTileProperties, videoTileProperties);
},
getDurationMS: (currentItem) {
return (currentItem is Selectable ? trackConfig.getDurationMS?.call(currentItem) : ytConfig.getDurationMS?.call(currentItem)) ?? 0;
Expand Down Expand Up @@ -224,7 +225,7 @@ class NamidaMiniPlayerTrack extends StatelessWidget {
horizontalGestures: false,
queueSource: QueueSource.playerQueue,
),
itemBuilder: (context, i, currentIndex, queue, properties) {
itemBuilder: (context, i, currentIndex, queue, properties, _) {
final track = queue[i] as Selectable;
final key = Key("${i}_${track.track.path}");
return (
Expand Down Expand Up @@ -416,6 +417,7 @@ class _NamidaMiniPlayerYoutubeIDState extends State<NamidaMiniPlayerYoutubeID> {
final videoChannelId = vidpage?.channelInfo?.id ?? vidstreams?.info?.channelId;
final popUpItems = NamidaPopupWrapper(
childrenDefault: () => YTUtils.getVideoCardMenuItemsForCurrentlyPlaying(
queueSource: QueueSourceYoutubeID.playerQueue,
context: context,
numberOfRepeats: _numberOfRepeats,
videoId: video.id,
Expand Down Expand Up @@ -461,27 +463,28 @@ class _NamidaMiniPlayerYoutubeIDState extends State<NamidaMiniPlayerYoutubeID> {
NamidaMiniPlayerBase getMiniPlayerBase(BuildContext context) {
return NamidaMiniPlayerBase<String, YTSortType>(
queueItemExtent: Dimensions.youtubeCardItemExtent,
itemBuilder: (context, i, currentIndex, queue, _) {
videoTileConfigs: const VideoTilePropertiesConfigs(
openMenuOnLongPress: false,
displayTimeAgo: false,
draggingEnabled: true,
draggableThumbnail: true,
horizontalGestures: false,
queueSource: QueueSourceYoutubeID.playerQueue,
showMoreIcon: true,
),
itemBuilder: (context, i, currentIndex, queue, _, properties) {
final video = queue[i] as YoutubeID;
final key = Key("${i}_${video.id}");
return (
YTHistoryVideoCard(
properties: properties!,
key: key,
videos: queue,
index: i,
day: null,
playlistID: null,
playlistName: '',
openMenuOnLongPress: false,
displayTimeAgo: false,
thumbnailHeight: Dimensions.youtubeThumbnailHeight,
fromPlayerQueue: true,
draggingEnabled: true,
draggableThumbnail: true,
showMoreIcon: true,
cardColorOpacity: 0.5,
fadeOpacity: i < currentIndex ? 0.3 : 0.0,
canHaveDuplicates: true,
),
key,
);
Expand Down
22 changes: 18 additions & 4 deletions lib/packages/miniplayer_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import 'package:namida/ui/widgets/custom_widgets.dart';
import 'package:namida/ui/widgets/library/track_tile.dart';
import 'package:namida/ui/widgets/settings/extra_settings.dart';
import 'package:namida/ui/widgets/waveform.dart';
import 'package:namida/youtube/widgets/yt_history_video_card.dart';

class FocusedMenuOptions {
final bool Function(Playable currentItem) onOpen;
Expand Down Expand Up @@ -103,7 +104,8 @@ class MiniplayerInfoData<E, S> {
class NamidaMiniPlayerBase<E, S> extends StatefulWidget {
final double? queueItemExtent;
final double? Function(Playable item)? queueItemExtentBuilder;
final (Widget, Key) Function(BuildContext context, int index, int currentIndex, List<Playable> queue, TrackTileProperties? properties) itemBuilder;
final (Widget, Key) Function(BuildContext context, int index, int currentIndex, List<Playable> queue, TrackTileProperties? properties, VideoTileProperties? videoTileProperties)
itemBuilder;
final int Function(Playable currentItem)? getDurationMS;
final String Function(int number, Playable item) itemsKeyword;
final void Function(Playable currentItem) onAddItemsTap;
Expand All @@ -116,6 +118,7 @@ class NamidaMiniPlayerBase<E, S> extends StatefulWidget {
final MiniplayerInfoData<E, S> Function(Playable item) textBuilder;
final bool Function(Playable item) canShowBuffering;
final TrackTilePropertiesConfigs? trackTileConfigs;
final VideoTilePropertiesConfigs? videoTileConfigs;

const NamidaMiniPlayerBase({
super.key,
Expand All @@ -134,6 +137,7 @@ class NamidaMiniPlayerBase<E, S> extends StatefulWidget {
required this.textBuilder,
required this.canShowBuffering,
this.trackTileConfigs,
this.videoTileConfigs,
});

@override
Expand Down Expand Up @@ -164,8 +168,9 @@ class _NamidaMiniPlayerBaseState extends State<NamidaMiniPlayerBase> {
}
}

Widget _queueItemBuilder(BuildContext context, int i, int currentIndex, List<Playable> queue, {TrackTileProperties? trackTileProperties}) {
final childWK = widget.itemBuilder(context, i, currentIndex, queue, trackTileProperties);
Widget _queueItemBuilder(BuildContext context, int i, int currentIndex, List<Playable> queue,
{TrackTileProperties? trackTileProperties, VideoTileProperties? videoTileProperties}) {
final childWK = widget.itemBuilder(context, i, currentIndex, queue, trackTileProperties, videoTileProperties);
return FadeDismissible(
key: Key("Diss_${i}_${childWK.$2}_${queue.length}"), // queue length only for when removing current item and next is the same.
onDismissed: (direction) async {
Expand Down Expand Up @@ -354,7 +359,16 @@ class _NamidaMiniPlayerBaseState extends State<NamidaMiniPlayerBase> {
builder: (properties) => _QueueListChildWrapper(
queueItemExtent: widget.queueItemExtent,
queueItemExtentBuilder: widget.queueItemExtentBuilder,
itemBuilder: (context, index, currentIndex, queue) => _queueItemBuilder(context, index, currentIndex, queue, trackTileProperties: properties),
itemBuilder: (context, index, currentIndex, queue) => _queueItemBuilder(context, index, currentIndex, queue, trackTileProperties: properties, videoTileProperties: null),
),
);
} else if (widget.videoTileConfigs != null) {
queueListChild = VideoTilePropertiesProvider(
configs: widget.videoTileConfigs!,
builder: (properties) => _QueueListChildWrapper(
queueItemExtent: widget.queueItemExtent,
queueItemExtentBuilder: widget.queueItemExtentBuilder,
itemBuilder: (context, index, currentIndex, queue) => _queueItemBuilder(context, index, currentIndex, queue, trackTileProperties: null, videoTileProperties: properties),
),
);
} else {
Expand Down
3 changes: 1 addition & 2 deletions lib/ui/pages/subpages/playlist_tracks_subpage.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';

import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
import 'package:history_manager/history_manager.dart';
import 'package:sticky_headers/sticky_headers.dart';
Expand Down Expand Up @@ -67,7 +68,6 @@ class _HistoryTracksPageState extends State<HistoryTracksPage> with HistoryDaysR
configs: const TrackTilePropertiesConfigs(
queueSource: QueueSource.history,
playlistName: k_PLAYLIST_NAME_HISTORY,
draggableThumbnail: false,
),
builder: (properties) => CustomScrollView(
controller: HistoryController.inst.scrollController,
Expand Down Expand Up @@ -190,7 +190,6 @@ class MostPlayedTracksPage extends StatelessWidget with NamidaRouteWidget {
configs: const TrackTilePropertiesConfigs(
queueSource: QueueSource.mostPlayed,
playlistName: k_PLAYLIST_NAME_MOST_PLAYED,
draggableThumbnail: false,
),
builder: (properties) {
return ObxO(
Expand Down
1 change: 0 additions & 1 deletion lib/ui/pages/tracks_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ class _TracksPageState extends State<TracksPage> with TickerProviderStateMixin,
child: AnimationLimiter(
child: TrackTilePropertiesProvider(
configs: const TrackTilePropertiesConfigs(
draggableThumbnail: false,
queueSource: QueueSource.allTracks,
),
builder: (properties) => ObxO(
Expand Down
Loading

0 comments on commit 7249a94

Please sign in to comment.