Skip to content

Commit

Permalink
chore(yt): fixes etc fixes etc
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed Jul 8, 2024
1 parent 02c9d8a commit 8bf29ac
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 147 deletions.
7 changes: 5 additions & 2 deletions lib/base/pull_to_refresh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,15 @@ mixin PullToRefreshMixin<T extends StatefulWidget> on State<T> implements Ticker
}

bool _isRefreshing = false;
Future<void> onRefresh(PullToRefreshCallback execute, {bool forceShow = false}) async {

/// Normally will not continue if not fully swiped, [forceProceed] forces bypassing that,
/// use if action not triggered by user but u want to show refresh indicator.
Future<void> onRefresh(PullToRefreshCallback execute, {bool forceProceed = false}) async {
if (!enablePullToRefresh) return;
onVerticalDragFinish();
if (_isRefreshing) return;
if (animation.value != 1) {
if (!forceShow) return;
if (!forceProceed) return;
animation.animateTo(1, duration: const Duration(milliseconds: 50));
}

Expand Down
4 changes: 2 additions & 2 deletions lib/controller/logs_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class _Log {
printer: PrettyPrinter(
colors: kDebugMode ? true : false,
printEmojis: true,
methodCount: 4,
errorMethodCount: 24,
methodCount: 48,
errorMethodCount: 48,
),
output: _FileOutput(file: File(AppPaths.LOGS), fileClean: File(AppPaths.LOGS_CLEAN)),
);
Expand Down
4 changes: 4 additions & 0 deletions lib/ui/widgets/video_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,10 @@ class NamidaVideoControlsState extends State<NamidaVideoControls> with TickerPro
qt = video == null ? null : '${video.resolution}p${video.framerateText()}';
} else {
qt = Player.inst.currentVideoStream.valueR?.qualityLabel;
if (qt == null) {
final cached = Player.inst.currentCachedVideo.valueR;
if (cached != null) qt = "${cached.resolution}p${cached.framerateText()}";
}
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/youtube/controller/youtube_current_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class _YoutubeCurrentInfoController {
details: ExecuteDetails.forceRequest(),
);
if (newRes != null && _canSafelyModifyMetadata(videoId)) {
fetchedSuccessfully = true;
_currentComments.value = newRes;
_isCurrentCommentsFromCache.value = false;
}
Expand Down
30 changes: 28 additions & 2 deletions lib/youtube/controller/youtube_info_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ library namidayoutubeinfo;

import 'dart:io';

import 'package:logger/logger.dart';
import 'package:namida/class/video.dart';
import 'package:namida/controller/connectivity.dart';
import 'package:namida/controller/logs_controller.dart' as namidalogs;
import 'package:namida/controller/navigator_controller.dart';
import 'package:namida/controller/player_controller.dart';
import 'package:namida/controller/settings_controller.dart';
Expand Down Expand Up @@ -54,7 +54,7 @@ class YoutubeInfoController {
sensitiveDataDirectory: AppDirs.YOUTIPIE_DATA,
checkJSPlayer: true, // wont await.. are we cooked? properly
);
YoutiPie.setLogs(namidalogs.logger.logger);
YoutiPie.setLogs(_YTReportingLog());
}

static Future<bool> ensureJSPlayerInitialized() async {
Expand All @@ -65,3 +65,29 @@ class YoutubeInfoController {
static final current = _YoutubeCurrentInfoController._();
static final utils = _YoutubeInfoUtils._();
}

class _YTReportingLog extends Logger {
static void _showError(String msg, {Object? exception}) {
String title = lang.ERROR;
if (exception != null) title += ': $exception';

snackyy(
message: msg,
title: title,
isError: true,
displaySeconds: 3,
top: false,
);
}

@override
void e(
dynamic message, {
DateTime? time,
Object? error,
StackTrace? stackTrace,
}) {
_showError(message.toString(), exception: error);
super.e(message, time: time, error: error, stackTrace: stackTrace);
}
}
247 changes: 128 additions & 119 deletions lib/youtube/functions/download_sheet.dart

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions lib/youtube/functions/video_download_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ class YTDownloadOptionFolderListTileState extends State<YTDownloadOptionFolderLi
visualDensity: widget.visualDensity,
title: lang.FOLDER,
subtitle: widget.subtitle?.call(groupName.value),
trailing: NamidaPopupWrapper(
trailingRaw: NamidaPopupWrapper(
childrenDefault: () => [
NamidaPopupItem(
icon: Broken.add,
Expand Down Expand Up @@ -376,7 +376,7 @@ class YTDownloadOptionFolderListTileState extends State<YTDownloadOptionFolderLi
final count = availableDirectoriesNames[groupName];
final countText = count == null || count == 0 ? '' : " ($count)";
return Row(
mainAxisAlignment: MainAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Expand All @@ -387,11 +387,15 @@ class YTDownloadOptionFolderListTileState extends State<YTDownloadOptionFolderLi
: Broken.folder,
size: 18.0),
const SizedBox(width: 6.0),
ConstrainedBox(
constraints: BoxConstraints(minWidth: 0, maxWidth: context.width * 0.34),
child: Text(
"$title$countText",
style: context.textTheme.displayMedium,
Flexible(
child: ConstrainedBox(
constraints: BoxConstraints(minWidth: 0, maxWidth: context.width * 0.34),
child: Text(
"$title$countText",
style: context.textTheme.displayMedium,
maxLines: 3,
overflow: TextOverflow.ellipsis,
),
),
),
SizedBox(width: widget.trailingPadding),
Expand Down
6 changes: 3 additions & 3 deletions lib/youtube/pages/user/youtube_manage_subscription_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class _YoutubeManageSubscriptionPageState extends State<YoutubeManageSubscriptio
}
}

void _onPatreonLoginTap(BuildContext context) {
void _onPatreonLoginTap(BuildContext context, {required SignInDecision signInDecision}) {
final header = Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
Expand All @@ -92,7 +92,7 @@ class _YoutubeManageSubscriptionPageState extends State<YoutubeManageSubscriptio
);
YoutubeAccountController.membership.claimPatreon(
pageConfig: pageConfig,
signIn: SignInDecision.enabled,
signIn: signInDecision,
);
}

Expand Down Expand Up @@ -135,7 +135,7 @@ class _YoutubeManageSubscriptionPageState extends State<YoutubeManageSubscriptio
CustomListTile(
icon: Broken.login_1,
title: lang.SIGN_IN,
onTap: () => _onPatreonLoginTap(context),
onTap: () => _onPatreonLoginTap(context, signInDecision: SignInDecision.forceSignIn),
),
],
),
Expand Down
4 changes: 3 additions & 1 deletion lib/youtube/pages/youtube_main_page_fetcher_acc_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ class _YoutubePageState<W extends YoutiPieListWrapper<T>, T extends MapSerializa
}

Future<void> _fetchFeedNext() async {
_isLoadingNext.value = true;
final feed = _currentFeed;
if (feed.value?.canFetchNext != true) return;

_isLoadingNext.value = true;
final fetched = await feed.value?.fetchNext();
if (fetched == true) feed.refresh();
_isLoadingNext.value = false;
Expand Down
7 changes: 4 additions & 3 deletions lib/youtube/pages/yt_channel_subpage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class _YTChannelSubpageState extends YoutubeChannelController<YTChannelSubpage>
(value) {
if (value != null) {
setState(() => _channelInfo = value);
onRefresh(() => fetchChannelStreams(value, forceRequest: true), forceShow: true);
onRefresh(() => fetchChannelStreams(value, forceRequest: true), forceProceed: true);
}
},
);
Expand Down Expand Up @@ -249,6 +249,7 @@ class _YTChannelSubpageState extends YoutubeChannelController<YTChannelSubpage>
videosCountVSTotalText += ' | ';
peakDatesText = "${streamsPeakDates!.oldest.millisecondsSinceEpoch.dateFormattedOriginal} (${Jiffy.parseFromDateTime(streamsPeakDates!.oldest).fromNow()})";
}
final hasMoreStreamsLeft = channelVideoTab?.canFetchNext == true;
return BackgroundWrapper(
child: Listener(
onPointerMove: (event) => onPointerMove(uploadsScrollController, event),
Expand Down Expand Up @@ -364,9 +365,9 @@ class _YTChannelSubpageState extends YoutubeChannelController<YTChannelSubpage>
borderRadius: 8.0,
icon: Broken.task_square,
text: lang.LOAD_ALL,
enabled: !isLoadingMoreUploads,
enabled: !isLoadingMoreUploads && hasMoreStreamsLeft,
disableWhenLoading: false,
showLoadingWhenDisabled: true,
showLoadingWhenDisabled: hasMoreStreamsLeft,
onTap: _onLoadAllTap,
),
),
Expand Down
4 changes: 2 additions & 2 deletions lib/youtube/pages/yt_channels_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class _YoutubeChannelsPageState extends YoutubeChannelController<YoutubeChannels
final subCh = YoutubeSubscriptionsController.inst.subscribedChannels.lastOrNull;
if (subCh != null) {
final sub = YoutubeSubscriptionsController.inst.availableChannels.value[subCh];
onRefresh(() => _updateChannel(sub, forceRequest: true), forceShow: true);
onRefresh(() => _updateChannel(sub, forceRequest: true), forceProceed: true);
}

final now = DateTime.now();
Expand Down Expand Up @@ -373,7 +373,7 @@ class _YoutubeChannelsPageState extends YoutubeChannelController<YoutubeChannels
children: [
Listener(
onPointerMove: (event) => onPointerMove(uploadsScrollController, event),
onPointerUp: (_) => channel == null ? null : onRefresh(() => _updateChannel(channel!, forceRequest: true), forceShow: true),
onPointerUp: (_) => channel == null ? null : onRefresh(() => _updateChannel(channel!, forceRequest: true)),
onPointerCancel: (_) => onVerticalDragFinish(),
child: isLoadingInitialStreams
? ShimmerWrapper(
Expand Down
16 changes: 11 additions & 5 deletions lib/youtube/pages/yt_playlist_subpage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -438,21 +438,27 @@ class _YTHostedPlaylistSubpageState extends State<YTHostedPlaylistSubpage> with
if (_isLoadingMoreItems.value) return;
_isLoadingMoreItems.value = true;

bool fetched = false;

try {
if (_playlist.items.isEmpty) {
final playlist = await YoutubeInfoController.playlist.fetchPlaylist(
playlistId: _playlist.basicInfo.id,
details: ExecuteDetails.forceRequest(),
);
if (playlist != null) _playlist = playlist;
if (playlist != null) {
_playlist = playlist;
fetched = true;
}
} else {
await _playlist.fetchNext();
if (_playlist.canFetchNext) {
fetched = await _playlist.fetchNext();
}
}
} catch (_) {}

trySortStreams();
_isLoadingMoreItems.value = false;
refreshState();
if (fetched) refreshState(trySortStreams);
}

@override
Expand Down Expand Up @@ -650,7 +656,7 @@ class _YTHostedPlaylistSubpageState extends State<YTHostedPlaylistSubpage> with
text: lang.LOAD_ALL,
enabled: !isLoadingMoreItems && hasMoreStreamsLeft, // this for lazylist
disableWhenLoading: false,
showLoadingWhenDisabled: true,
showLoadingWhenDisabled: hasMoreStreamsLeft,
onTap: () async {
if (_currentFetchAllRes != null) {
_currentFetchAllRes?.cancel();
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.0.6-beta+240707211
version: 3.0.7-beta+240708228

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

0 comments on commit 8bf29ac

Please sign in to comment.