Skip to content

Commit

Permalink
chore: fixes and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed Sep 9, 2024
1 parent 035a9e0 commit 14f1bc1
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 106 deletions.
2 changes: 1 addition & 1 deletion lib/base/audio_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class NamidaAudioVideoHandler<Q extends Playable> extends BasicAudioHandler<Q> {
AudioLoadConfiguration? get defaultAndroidLoadConfig {
return AudioLoadConfiguration(
androidLoadControl: AndroidLoadControl(
minBufferDuration: const Duration(seconds: 50),
minBufferDuration: const Duration(seconds: 5),
maxBufferDuration: const Duration(minutes: 3),
),
);
Expand Down
6 changes: 6 additions & 0 deletions lib/controller/folders_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ class Folders<T extends Folder> {

final _latestScrollOffset = <T?, double>{};

void refreshLists() {
currentFolderslist.refresh(); // refreshes folders
currentFolder.refresh(); // refreshes tracks
}

/// Indicates wether the navigator can go back at this point.
/// Returns true only if at home, otherwise will call [stepOut] and return false.
bool onBackButton() {
Expand Down Expand Up @@ -161,6 +166,7 @@ class Folders<T extends Folder> {
);

map.assignAllEntries(sorted); // we clear after building new sorted one
refreshLists();
}

Map<String, _ParsedResult?> _buildParsedMap(Iterable<String> names) {
Expand Down
7 changes: 4 additions & 3 deletions lib/controller/indexer_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,12 @@ class Indexer<T extends Track> {
case MediaType.folder:
sortPls(mainMapFolders.values, MediaType.folder);
mainMapFolders.refresh();
Folders.tracks.refreshLists();
break;
case MediaType.folderVideo:
sortPls(mainMapFoldersVideos.values, MediaType.folderVideo);
mainMapFoldersVideos.refresh();
Folders.videos.refreshLists();
break;
default:
null;
Expand Down Expand Up @@ -374,7 +376,7 @@ class Indexer<T extends Track> {
final List<String> addedComposers = [];
final List<String> addedGenres = [];
final List<Folder> addedFolders = [];
final List<Folder> addedFoldersVideos = [];
final List<VideoFolder> addedFoldersVideos = [];

tracks.loop((tr) {
final trExt = tr.toTrackExt();
Expand Down Expand Up @@ -412,10 +414,9 @@ class Indexer<T extends Track> {
final folderSorters = SearchSortController.inst.getMediaTracksSortingComparables(MediaType.folder);
final folderVideosSorters = SearchSortController.inst.getMediaTracksSortingComparables(MediaType.folderVideo);

void cleanyLoopy<T, E>(MediaType type, List<E> added, Map<E, List<T>> map, List<Comparable<dynamic> Function(T tr)> sorters) {
void cleanyLoopy<A, E>(MediaType type, List<E> added, Map<E, List<A>> map, List<Comparable<dynamic> Function(A tr)> sorters) {
if (added.isEmpty) return;
added.removeDuplicates();
if (added.isEmpty) return;

final reverse = settings.mediaItemsTrackSortingReverse.value[type] ?? false;
if (reverse) {
Expand Down
4 changes: 3 additions & 1 deletion lib/controller/video_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,10 @@ class VideoController {
}

Future<NamidaVideo?> updateCurrentVideo(Track? track, {bool returnEarly = false, bool handleVideoPlayback = true}) async {
currentVideo.value = null;
currentPossibleLocalVideos.value.clear();
isNoVideosAvailable.value = false;
currentDownloadedBytes.value = null;
currentVideo.value = null;
currentYTStreams.value = null;
if (track == null || track == kDummyTrack) return null;
if (!settings.enableVideoPlayback.value) return null;
Expand All @@ -288,6 +289,7 @@ class VideoController {
durationMS: 0,
bitrate: 0);
currentVideo.value = nv;
currentPossibleLocalVideos.value = [nv];
if (handleVideoPlayback) await Player.inst.setAudioOnlyPlayback(false);
return nv;
}
Expand Down
46 changes: 13 additions & 33 deletions lib/packages/miniplayer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ class NamidaMiniPlayerYoutubeID extends StatefulWidget {

class _NamidaMiniPlayerYoutubeIDState extends State<NamidaMiniPlayerYoutubeID> {
final _videoLikeManager = YtVideoLikeManager();
final _numberOfRepeats = 1.obs;

@override
void initState() {
Expand All @@ -321,46 +322,25 @@ class _NamidaMiniPlayerYoutubeIDState extends State<NamidaMiniPlayerYoutubeID> {
@override
void dispose() {
_videoLikeManager.dispose();
_numberOfRepeats.close();
super.dispose();
}

void _openMenu(BuildContext context, YoutubeID video, TapUpDetails details) {
final vidpage = YoutubeInfoController.video.fetchVideoPageSync(video.id);
final vidstreams = YoutubeInfoController.video.fetchVideoStreamsSync(video.id, infoOnly: true);
final videoTitle = vidpage?.videoInfo?.title ?? vidstreams?.info?.title;
final videoChannelId = vidpage?.channelInfo?.id ?? vidstreams?.info?.channelId;
final popUpItems = NamidaPopupWrapper(
childrenDefault: () {
final defaultItems = YTUtils.getVideoCardMenuItems(
downloadIndex: null,
totalLength: null,
streamInfoItem: null,
videoId: video.id,
url: vidpage?.videoInfo?.buildUrl() ?? vidstreams?.info?.buildUrl(),
channelID: vidpage?.channelInfo?.id,
playlistID: null,
idsNamesLookup: {video.id: vidpage?.videoInfo?.title ?? vidstreams?.info?.title},
playlistName: '',
videoYTID: video,
copyUrl: true,
);
final clearItem = NamidaPopupItem(
icon: Broken.trash,
title: lang.CLEAR,
onTap: () {
const YTUtils().showVideoClearDialog(context, video.id, CurrentColor.inst.miniplayerColor);
},
);
final isFavourite = video.isFavourite;
final favouriteItem = NamidaPopupItem(
icon: isFavourite ? Broken.heart_tick : Broken.heart,
title: lang.FAVOURITES,
onTap: () => YoutubePlaylistController.inst.favouriteButtonOnPressed(video.id),
);
final items = <NamidaPopupItem>[];
items.add(favouriteItem);
items.addAll(defaultItems);
items.add(clearItem);
return items;
},
childrenDefault: () => YTUtils.getVideoCardMenuItemsForCurrentlyPlaying(
context: context,
numberOfRepeats: _numberOfRepeats,
videoId: video.id,
videoTitle: videoTitle,
channelID: videoChannelId,
displayGoToChannel: true,
displayCopyUrl: true,
),
).convertItems(context);
NamidaNavigator.inst.showMenu(
context: context,
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/pages/folders_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class _SmolIconFolderScroll extends StatefulWidget {
}

class __SmolIconFolderScrollState extends State<_SmolIconFolderScroll> {
double get _getScrollToPosition => Dimensions.inst.trackTileItemExtent * (widget.indexToScrollTo + widget.foldersController.currentFolderslist.length - 2);
double get _getScrollToPosition => Dimensions.inst.trackTileItemExtent * (widget.indexToScrollTo + widget.foldersController.currentFolderslist.value.length - 2);

IconData _arrowIcon = Broken.cd;
void _updateIcon(IconData icon) {
Expand Down
75 changes: 9 additions & 66 deletions lib/youtube/youtube_miniplayer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import 'package:namida/youtube/class/youtube_id.dart';
import 'package:namida/youtube/controller/youtube_controller.dart';
import 'package:namida/youtube/controller/youtube_history_controller.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/functions/download_sheet.dart';
Expand Down Expand Up @@ -401,71 +400,15 @@ class YoutubeMiniPlayerState extends State<YoutubeMiniPlayer> {
onPop: () {
_numberOfRepeats.value = 1;
},
childrenDefault: () {
final videoId = currentId;
NamidaPopupItem? repeatForWidget;
final defaultItems = YTUtils.getVideoCardMenuItems(
downloadIndex: null,
totalLength: null,
streamInfoItem: null,
videoId: videoId,
url: videoInfo?.buildUrl(),
channelID: null,
displayGoToChannel: false,
playlistID: null,
idsNamesLookup: {videoId: videoTitle},
);
if (Player.inst.currentVideo != null && videoId == Player.inst.currentVideo?.id) {
repeatForWidget = NamidaPopupItem(
icon: Broken.cd,
title: '',
titleBuilder: (style) => Obx(
(context) => Text(
lang.REPEAT_FOR_N_TIMES.replaceFirst('_NUM_', _numberOfRepeats.valueR.toString()),
style: style,
),
),
onTap: () {
settings.player.save(repeatMode: RepeatMode.forNtimes);
Player.inst.updateNumberOfRepeats(_numberOfRepeats.value);
},
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
NamidaIconButton(
icon: Broken.minus_cirlce,
onPressed: () => _numberOfRepeats.value = (_numberOfRepeats.value - 1).clamp(1, 20),
iconSize: 20.0,
),
NamidaIconButton(
icon: Broken.add_circle,
onPressed: () => _numberOfRepeats.value = (_numberOfRepeats.value + 1).clamp(1, 20),
iconSize: 20.0,
),
],
),
);
}
final clearItem = NamidaPopupItem(
icon: Broken.trash,
title: lang.CLEAR,
onTap: () {
const YTUtils().showVideoClearDialog(context, videoId, CurrentColor.inst.miniplayerColor);
},
);
final isFavourite = currentItem.isFavourite;
final favouriteItem = NamidaPopupItem(
icon: isFavourite ? Broken.heart_tick : Broken.heart,
title: lang.FAVOURITES,
onTap: () => YoutubePlaylistController.inst.favouriteButtonOnPressed(currentId),
);
final items = <NamidaPopupItem>[];
items.add(favouriteItem);
items.addAll(defaultItems);
if (repeatForWidget != null) items.add(repeatForWidget);
items.add(clearItem);
return items;
},
childrenDefault: () => YTUtils.getVideoCardMenuItemsForCurrentlyPlaying(
context: context,
numberOfRepeats: _numberOfRepeats,
videoId: currentId,
videoTitle: videoTitle,
channelID: null,
displayGoToChannel: false,
displayCopyUrl: false,
),
child: const Icon(
Broken.arrow_down_2,
size: 20.0,
Expand Down
83 changes: 83 additions & 0 deletions lib/youtube/yt_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import 'package:youtipie/class/streams/video_stream.dart';
import 'package:youtipie/class/streams/video_streams_result.dart';
import 'package:youtipie/class/videos/video_result.dart';
import 'package:youtipie/class/youtipie_feed/playlist_basic_info.dart';
import 'package:youtipie/core/url_utils.dart';
import 'package:youtipie/youtipie.dart';

import 'package:namida/class/route.dart';
import 'package:namida/class/track.dart';
import 'package:namida/class/video.dart';
import 'package:namida/controller/current_color.dart';
import 'package:namida/controller/ffmpeg_controller.dart';
Expand Down Expand Up @@ -188,6 +190,87 @@ class YTUtils {
];
}

static List<NamidaPopupItem> getVideoCardMenuItemsForCurrentlyPlaying({
required BuildContext context,
required Rx<int> numberOfRepeats,
required String videoId,
required String? videoTitle,
required String? channelID,
required bool displayGoToChannel,
required bool displayCopyUrl,
}) {
final currentItem = Player.inst.currentItem.value;
NamidaPopupItem? repeatForWidget;
final defaultItems = YTUtils.getVideoCardMenuItems(
downloadIndex: null,
totalLength: null,
streamInfoItem: null,
videoId: videoId,
url: YTUrlUtils.buildVideoUrl(videoId),
channelID: channelID,
displayGoToChannel: displayGoToChannel,
playlistID: null,
idsNamesLookup: {videoId: videoTitle},
copyUrl: displayCopyUrl,
);
if (currentItem is YoutubeID && videoId == currentItem.id) {
repeatForWidget = NamidaPopupItem(
icon: Broken.cd,
title: '',
titleBuilder: (style) => Obx(
(context) => Text(
lang.REPEAT_FOR_N_TIMES.replaceFirst('_NUM_', numberOfRepeats.valueR.toString()),
style: style,
),
),
onTap: () {
settings.player.save(repeatMode: RepeatMode.forNtimes);
Player.inst.updateNumberOfRepeats(numberOfRepeats.value);
},
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
NamidaIconButton(
icon: Broken.minus_cirlce,
onPressed: () => numberOfRepeats.value = (numberOfRepeats.value - 1).clamp(1, 20),
iconSize: 20.0,
),
NamidaIconButton(
icon: Broken.add_circle,
onPressed: () => numberOfRepeats.value = (numberOfRepeats.value + 1).clamp(1, 20),
iconSize: 20.0,
),
],
),
);
}
final clearItem = NamidaPopupItem(
icon: Broken.trash,
title: lang.CLEAR,
onTap: () {
const YTUtils().showVideoClearDialog(context, videoId, CurrentColor.inst.miniplayerColor);
},
);
final isFavourite = currentItem is YoutubeID
? currentItem.isFavourite
: currentItem is Track
? currentItem.isFavourite
: null;
final favouriteItem = isFavourite == null
? null
: NamidaPopupItem(
icon: isFavourite ? Broken.heart_tick : Broken.heart,
title: lang.FAVOURITES,
onTap: () => YoutubePlaylistController.inst.favouriteButtonOnPressed(videoId),
);
final items = <NamidaPopupItem>[];
if (favouriteItem != null) items.add(favouriteItem);
items.addAll(defaultItems);
if (repeatForWidget != null) items.add(repeatForWidget);
items.add(clearItem);
return items;
}

static List<NamidaPopupItem> getVideoCardMenuItems({
required int? downloadIndex,
required int? totalLength,
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: 4.2.3-beta+240909211
version: 4.2.4-beta+240909212

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

0 comments on commit 14f1bc1

Please sign in to comment.