Skip to content

Commit

Permalink
chore: pull to refresh in yt playlists subpage
Browse files Browse the repository at this point in the history
& other tweaks
  • Loading branch information
MSOB7YY committed Jul 10, 2024
1 parent e869894 commit 49e9c55
Show file tree
Hide file tree
Showing 14 changed files with 241 additions and 218 deletions.
2 changes: 1 addition & 1 deletion lib/base/youtube_streams_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ mixin YoutubeStreamsManager<W extends YoutiPieListWrapper<StreamInfoItem>> {

late final _defaultSorting = YTVideosSorting.date;
late final _defaultSortingByTop = true;
late final sorting = _defaultSorting.obs;
late final sorting = Rxn<YTVideosSorting>(_defaultSorting);
late final sortingByTop = _defaultSortingByTop.obs;

Widget get sortWidget => SingleChildScrollView(
Expand Down
17 changes: 9 additions & 8 deletions lib/controller/thumbnail_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class ThumbnailManager {
String? symlinkId,
bool isTemp = false,
}) {
final dirPrefix = isTemp ? 'temp/' : '';

if (id != null && id.isNotEmpty) {
return File("${AppDirs.YT_THUMBNAILS}$dirPrefix${symlinkId ?? '$id.png'}");
}
String? finalUrl = url;
final imageUrl = finalUrl?.split('i.ytimg.com/vi/');
if (imageUrl != null && imageUrl.length > 1) {
Expand All @@ -46,15 +51,11 @@ class ThumbnailManager {
if (finalUrl != null) finalUrl = '${finalUrl.splitLast('/')}.png'; // we need the quality after the =
}

final dirPrefix = isTemp ? 'temp/' : '';

final file = id != null && id != ''
? File("${AppDirs.YT_THUMBNAILS}$dirPrefix${symlinkId ?? '$id.png'}")
: finalUrl == null
? null
: File("${AppDirs.YT_THUMBNAILS_CHANNELS}$dirPrefix${symlinkId ?? finalUrl}");
if (finalUrl != null) {
return File("${AppDirs.YT_THUMBNAILS_CHANNELS}$dirPrefix${symlinkId ?? finalUrl}");
}

return file;
return null;
}

Future<File?> extractVideoThumbnailAndSave({
Expand Down
1 change: 1 addition & 0 deletions lib/youtube/functions/download_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ Future<void> showDownloadVideoBottomSheet({
isImportantInCache: true,
borderRadius: 10.0,
videoId: videoId,
customUrl: videoInfo?.thumbnails.pick()?.url,
width: context.width * 0.2,
height: context.width * 0.2 * 9 / 16,
onImageReady: (imageFile) {
Expand Down
2 changes: 1 addition & 1 deletion lib/youtube/pages/yt_channel_subpage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class _YTChannelSubpageState extends YoutubeChannelController<YTChannelSubpage>
final subsCountText = channelInfo?.subscribersCountText;
final streamsCount = channelInfo?.videosCount;

String videosCountVSTotalText = "${streamsList?.length ?? '?'} / ${streamsCount ?? '?'}";
String videosCountVSTotalText = "${streamsList?.length ?? '?'} / ${streamsCount?.formatDecimalShort() ?? '?'}";
String? peakDatesText;
if (streamsPeakDates != null) {
videosCountVSTotalText += ' | ';
Expand Down
2 changes: 2 additions & 0 deletions lib/youtube/pages/yt_playlist_download_subpage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:io';

import 'package:flutter/material.dart';
import 'package:youtipie/class/stream_info_item/stream_info_item.dart';
import 'package:youtipie/youtipie.dart';

import 'package:namida/class/route.dart';
import 'package:namida/controller/current_color.dart';
Expand Down Expand Up @@ -393,6 +394,7 @@ class _YTPlaylistDownloadPageState extends State<YTPlaylistDownloadPage> {
height: thumHeight - 4.0,
isImportantInCache: false,
videoId: id,
customUrl: info?.liveThumbs.pick()?.url,
smallBoxText: duration,
),
),
Expand Down
413 changes: 211 additions & 202 deletions lib/youtube/pages/yt_playlist_subpage.dart

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/youtube/pages/yt_search_results_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ class YoutubeSearchResultsPageState extends State<YoutubeSearchResultsPage> with
thumbnailWidthPercentage: 0.6,
thumbnailHeight: thumbnailHeightLocal,
thumbnailWidth: thumbnailWidthLocal,
showThirdLine: false,
isImageImportantInCache: false,
video: item,
playlistID: null,
Expand Down
2 changes: 2 additions & 0 deletions lib/youtube/widgets/yt_download_task_item_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import 'package:namida/youtube/controller/youtube_playlist_controller.dart';
import 'package:namida/youtube/functions/download_sheet.dart';
import 'package:namida/youtube/widgets/yt_thumbnail.dart';
import 'package:namida/youtube/yt_utils.dart';
import 'package:youtipie/youtipie.dart';

class YTDownloadTaskItemCard extends StatelessWidget {
final List<YoutubeItemDownloadConfig> videos;
Expand Down Expand Up @@ -526,6 +527,7 @@ class YTDownloadTaskItemCard extends StatelessWidget {
width: thumbWidth,
height: thumbHeight,
videoId: videoId,
customUrl: info?.liveThumbs.pick()?.url,
smallBoxText: duration,
),
const SizedBox(width: 8.0),
Expand Down
2 changes: 2 additions & 0 deletions lib/youtube/widgets/yt_history_video_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:jiffy/jiffy.dart';
import 'package:namida/youtube/controller/youtube_info_controller.dart';
import 'package:playlist_manager/module/playlist_id.dart';
import 'package:youtipie/youtipie.dart';

import 'package:namida/class/track.dart';
import 'package:namida/controller/current_color.dart';
Expand Down Expand Up @@ -143,6 +144,7 @@ class YTHistoryVideoCard extends StatelessWidget {
width: thumbWidth - 3.0,
height: thumbHeight - 3.0,
videoId: video.id,
customUrl: info?.liveThumbs.pick()?.url,
smallBoxText: duration,
smallBoxIcon: willSleepAfterThis ? Broken.timer_1 : null,
),
Expand Down
8 changes: 5 additions & 3 deletions lib/youtube/widgets/yt_notification_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ class _YoutubeVideoCardNotificationState extends State<YoutubeVideoCardNotificat
}

Future<void> _onTapInternal() async {
if (widget.notification.isComment) return;

final mainList = widget.mainList();
Player.inst.playOrPause(
mainList.items.length - widget.index - 1,
mainList.items.reversed.map(
(e) => YoutubeID(id: e.id, playlistID: null),
),
mainList.items.reversed.where((element) => !element.isComment).map((e) => YoutubeID(id: e.id, playlistID: null)),
QueueSource.others,
);
YTUtils.expandMiniplayer();
Expand All @@ -88,6 +88,8 @@ class _YoutubeVideoCardNotificationState extends State<YoutubeVideoCardNotificat
List<NamidaPopupItem> getMenuItems() {
final mainList = widget.mainList();
final videoId = widget.notification.id;
if (videoId.isEmpty) return [];
if (widget.notification.isComment) return [];
return YTUtils.getVideoCardMenuItems(
videoId: videoId,
url: widget.notification.buildUrl(),
Expand Down
4 changes: 3 additions & 1 deletion lib/youtube/widgets/yt_video_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class YoutubeVideoCard extends StatelessWidget {
final double fontMultiplier;
final double thumbnailWidthPercentage;
final bool dateInsteadOfChannel;
final bool showThirdLine;

const YoutubeVideoCard({
super.key,
Expand All @@ -44,6 +45,7 @@ class YoutubeVideoCard extends StatelessWidget {
this.fontMultiplier = 1.0,
this.thumbnailWidthPercentage = 1.0,
this.dateInsteadOfChannel = false,
this.showThirdLine = true,
});

List<NamidaPopupItem> getMenuItems() {
Expand Down Expand Up @@ -90,7 +92,7 @@ class YoutubeVideoCard extends StatelessWidget {
if (viewsCountText != null && viewsCountText.isNotEmpty) viewsCountText,
if (uploadDateAgo != null) uploadDateAgo,
].join(' - '),
displaythirdLineText: true,
displaythirdLineText: showThirdLine,
thirdLineText: dateInsteadOfChannel ? video.badges?.join(' - ') ?? '' : video.channel.title,
displayChannelThumbnail: !dateInsteadOfChannel,
channelThumbnailUrl: video.channel.thumbnails.pick()?.url,
Expand Down
2 changes: 1 addition & 1 deletion lib/youtube/youtube_miniplayer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class YoutubeMiniPlayerState extends State<YoutubeMiniPlayer> {
String? uploadDate;
String? uploadDateAgo;

final parsedDate = videoInfo?.publishedAt.date ?? videoInfoStream?.publishedAt.date ?? videoInfoStream?.publishDate.date;
final parsedDate = videoInfoStream?.publishedAt.date ?? videoInfoStream?.publishDate.date; // videoInfo?.publishedAt.date aint no way near accurate

if (parsedDate != null) {
uploadDate = parsedDate.millisecondsSinceEpoch.dateFormattedOriginal;
Expand Down
1 change: 1 addition & 0 deletions lib/youtube/yt_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class YTUtils {
final playAfterVid = getPlayerAfterVideo();
final currentVideo = Player.inst.currentVideo;
final isCurrentlyPlaying = currentVideo != null && videoId == currentVideo.id;
if (channelID == null || channelID.isEmpty) channelID = YoutubeInfoController.utils.getVideoChannelID(videoId);
return [
NamidaPopupItem(
icon: Broken.music_library_2,
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: 3.1.5-beta+240710224
version: 3.1.6-beta+240710229

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

0 comments on commit 49e9c55

Please sign in to comment.