From 6ac49c7d08049da690607324b58d32732ed1980b Mon Sep 17 00:00:00 2001 From: MSOB7YY Date: Sat, 13 Jul 2024 23:46:23 +0300 Subject: [PATCH] chore: various tweaks n fixes --- lib/base/audio_handler.dart | 11 ++-- lib/controller/navigator_controller.dart | 5 +- lib/controller/storage_cache_manager.dart | 7 +-- lib/ui/widgets/artwork.dart | 2 +- lib/youtube/class/youtube_id.dart | 4 +- .../controller/youtube_controller.dart | 3 +- lib/youtube/pages/yt_channels_page.dart | 29 ++++++++- lib/youtube/pages/yt_search_results_page.dart | 1 + .../widgets/yt_description_widget.dart | 6 +- lib/youtube/widgets/yt_thumbnail.dart | 2 +- lib/youtube/widgets/yt_video_card.dart | 62 +++++++++++++------ lib/youtube/youtube_miniplayer.dart | 18 ++++-- pubspec.yaml | 2 +- 13 files changed, 107 insertions(+), 45 deletions(-) diff --git a/lib/base/audio_handler.dart b/lib/base/audio_handler.dart index c8c35096..50832c50 100644 --- a/lib/base/audio_handler.dart +++ b/lib/base/audio_handler.dart @@ -679,7 +679,7 @@ class NamidaAudioVideoHandler extends BasicAudioHandler { if (newStreams != null) YoutubeInfoController.current.currentYTStreams.value = newStreams; VideoStream? sameStream = newStreams?.videoStreams.firstWhereEff((e) => e.itag == stream.itag); if (sameStream == null && newStreams != null) { - YoutubeController.inst.getPreferredStreamQuality(newStreams.videoStreams, preferIncludeWebm: false); + sameStream = YoutubeController.inst.getPreferredStreamQuality(newStreams.videoStreams, preferIncludeWebm: false); } final sameStreamUrl = sameStream?.buildUrl(); @@ -884,7 +884,7 @@ class NamidaAudioVideoHandler extends BasicAudioHandler { Duration? duration = streamsResult?.audioStreams.firstOrNull?.duration; _ytNotificationVideoInfo = streamsResult?.info; - _ytNotificationVideoThumbnail = item.getThumbnailSync(); + _ytNotificationVideoThumbnail = item.getThumbnailSync(temp: false); bool checkInterrupted({bool refreshNoti = true}) { final curr = currentItem.value; @@ -922,7 +922,10 @@ class NamidaAudioVideoHandler extends BasicAudioHandler { onInfoOrThumbObtained(info: _ytNotificationVideoInfo, thumbnail: _ytNotificationVideoThumbnail); if (_ytNotificationVideoThumbnail == null) { - ThumbnailManager.inst.getYoutubeThumbnailAndCache(id: item.id).then((thumbFile) => onInfoOrThumbObtained(thumbnail: thumbFile)); + ThumbnailManager.inst.getYoutubeThumbnailAndCache(id: item.id).then((thumbFile) { + thumbFile ??= item.getThumbnailSync(temp: true); + if (thumbFile != null) onInfoOrThumbObtained(thumbnail: thumbFile); + }); } Future plsplsplsPlay(bool wasPlayingFromCache, bool sourceChanged) async { @@ -1050,7 +1053,7 @@ class NamidaAudioVideoHandler extends BasicAudioHandler { final videoStreams = streamsResult?.videoStreams ?? []; if (audiostreams.isEmpty) { - snackyy(message: 'Error playing video, empty audio streams', top: false, isError: true); + if (!okaySetFromCache()) snackyy(message: 'Error playing video, empty audio streams', top: false, isError: true); return; } diff --git a/lib/controller/navigator_controller.dart b/lib/controller/navigator_controller.dart index 4ef24cb2..9cbfbad1 100644 --- a/lib/controller/navigator_controller.dart +++ b/lib/controller/navigator_controller.dart @@ -277,7 +277,7 @@ class NamidaNavigator { } /// Use [dialogBuilder] in case you want to acess the theme generated by [colorScheme]. - Future navigateDialog({ + Future navigateDialog({ final Widget? dialog, final Widget Function(ThemeData theme)? dialogBuilder, final int durationInMs = 300, @@ -306,7 +306,7 @@ class NamidaNavigator { final theme = AppThemes.inst.getAppTheme(colorScheme, null, lighterDialogColor); - await _rootNav.currentState?.pushPage( + final res = await _rootNav.currentState?.pushPage( WillPopScope( onWillPop: onWillPop, child: TapDetector( @@ -337,6 +337,7 @@ class NamidaNavigator { onDisposing.executeAfterDelay(durationMS: durationInMs * 2); } _printDialogs(); + return res; } Future closeDialog([int count = 1]) async { diff --git a/lib/controller/storage_cache_manager.dart b/lib/controller/storage_cache_manager.dart index d95eaa20..8942762b 100644 --- a/lib/controller/storage_cache_manager.dart +++ b/lib/controller/storage_cache_manager.dart @@ -603,14 +603,11 @@ class _ImageTrimmer { try { element.deleteSync(); i++; - imagesLength--; - continue; } catch (_) {} } - // if not continued safely, i-- indicating that we still need to delete more - i--; + // i--; // this made things non-safe imagesLength--; - if (imagesLength <= 0) break; // just to be safe that i-- doesnt mess things up + if (imagesLength <= 0) break; // to be safe that i++ wasnt called enough. } } } diff --git a/lib/ui/widgets/artwork.dart b/lib/ui/widgets/artwork.dart index b4eb05c0..83fb50ad 100644 --- a/lib/ui/widgets/artwork.dart +++ b/lib/ui/widgets/artwork.dart @@ -162,7 +162,7 @@ class _ArtworkWidgetState extends State with LoadingItemsDelayMix }) { final icon = Icon( widget.displayIcon ? widget.icon : null, - size: widget.iconSize ?? widget.thumbnailSize / 2, + size: widget.iconSize ?? widget.thumbnailSize * 0.5, ); return Container( key: key, diff --git a/lib/youtube/class/youtube_id.dart b/lib/youtube/class/youtube_id.dart index 2f7002ad..4ff6933b 100644 --- a/lib/youtube/class/youtube_id.dart +++ b/lib/youtube/class/youtube_id.dart @@ -61,8 +61,8 @@ class YoutubeID implements Playable, ItemWithDate { } extension YoutubeIDUtils on YoutubeID { - File? getThumbnailSync() { - return ThumbnailManager.inst.getYoutubeThumbnailFromCacheSync(id: id); + File? getThumbnailSync({required bool temp}) { + return ThumbnailManager.inst.getYoutubeThumbnailFromCacheSync(id: id, isTemp: temp); } } diff --git a/lib/youtube/controller/youtube_controller.dart b/lib/youtube/controller/youtube_controller.dart index e2fbc30b..50943ca3 100644 --- a/lib/youtube/controller/youtube_controller.dart +++ b/lib/youtube/controller/youtube_controller.dart @@ -157,7 +157,8 @@ class YoutubeController { await _writeTaskGroupToStorage(groupName: groupName); } - VideoStream getPreferredStreamQuality(List streams, {List qualities = const [], bool preferIncludeWebm = false}) { + VideoStream? getPreferredStreamQuality(List streams, {List qualities = const [], bool preferIncludeWebm = false}) { + if (streams.isEmpty) return null; final preferredQualities = (qualities.isNotEmpty ? qualities : settings.youtubeVideoQualities.value).map((element) => element.settingLabeltoVideoLabel()); VideoStream? plsLoop(bool webm) { for (int i = 0; i < streams.length; i++) { diff --git a/lib/youtube/pages/yt_channels_page.dart b/lib/youtube/pages/yt_channels_page.dart index c88c8d37..0ebede8a 100644 --- a/lib/youtube/pages/yt_channels_page.dart +++ b/lib/youtube/pages/yt_channels_page.dart @@ -8,6 +8,7 @@ import 'package:youtipie/youtipie.dart'; import 'package:namida/base/pull_to_refresh.dart'; import 'package:namida/base/youtube_channel_controller.dart'; import 'package:namida/class/route.dart'; +import 'package:namida/controller/connectivity.dart'; import 'package:namida/controller/file_browser.dart'; import 'package:namida/controller/navigator_controller.dart'; import 'package:namida/core/dimensions.dart'; @@ -96,8 +97,22 @@ class _YoutubeChannelsPageState extends YoutubeChannelController ConnectivityController.inst.hasConnection; + void _showNetworkError() { + snackyy( + title: lang.ERROR, + message: lang.NO_NETWORK_AVAILABLE_TO_FETCH_DATA, + isError: true, + top: false, + ); + } + /// TODO(youtipie): might be faster using rss feed, but limited to 15 vid. Future _fetchAllChannelsStreams({required bool forceRequest}) async { + if (!_hasConnection) { + _showNetworkError(); + return; + } setState(() { isLoadingInitialStreams = true; _allStreamsList = []; @@ -132,7 +147,16 @@ class _YoutubeChannelsPageState extends YoutubeChannelController> ${videosPage.length} videos'); if (channel != null) { - _allChannelsStreamsProgress.value = 0.0; - _allChannelsStreamsLoading.value = false; - return; + break; } YoutubeSubscriptionsController.inst.refreshLastFetchedTime(channelID, saveToStorage: false); streams.addAll(videosPage.items); } + YoutubeSubscriptionsController.inst.sortByLastFetched(); _allChannelsStreamsProgress.value = 0.0; _allChannelsStreamsLoading.value = false; diff --git a/lib/youtube/pages/yt_search_results_page.dart b/lib/youtube/pages/yt_search_results_page.dart index 39db6942..48ce128e 100644 --- a/lib/youtube/pages/yt_search_results_page.dart +++ b/lib/youtube/pages/yt_search_results_page.dart @@ -200,6 +200,7 @@ class YoutubeSearchResultsPageState extends State with thumbnailHeight: thumbnailHeightLocal, thumbnailWidth: thumbnailWidthLocal, showThirdLine: false, + dateInsteadOfChannel: true, isImageImportantInCache: false, video: item, playlistID: null, diff --git a/lib/youtube/widgets/yt_description_widget.dart b/lib/youtube/widgets/yt_description_widget.dart index ca3e8681..949e6fd6 100644 --- a/lib/youtube/widgets/yt_description_widget.dart +++ b/lib/youtube/widgets/yt_description_widget.dart @@ -140,11 +140,13 @@ class YoutubeDescriptionWidgetManager { if (surroundWithBG) { Widget child = Text(sw.text); + double hmargin = 0.0; double vpadding = 2.0; double hpadding = 4.0; double br = 4.0; if (_latestAttachment != null) { + hmargin += 4.0; vpadding += 2.0; hpadding += 2.0; br += 4.0; @@ -182,9 +184,9 @@ class YoutubeDescriptionWidgetManager { ); } - if (addVMargin) { + if (addVMargin || hmargin > 0) { child = Padding( - padding: const EdgeInsets.symmetric(vertical: 2.0), + padding: EdgeInsets.symmetric(vertical: addVMargin ? 2.0 : 0, horizontal: hmargin), child: child, ); } diff --git a/lib/youtube/widgets/yt_thumbnail.dart b/lib/youtube/widgets/yt_thumbnail.dart index 56537a30..59c072f4 100644 --- a/lib/youtube/widgets/yt_thumbnail.dart +++ b/lib/youtube/widgets/yt_thumbnail.dart @@ -207,7 +207,7 @@ class _YoutubeThumbnailState extends State with LoadingItemsDe thumbnailSize: widget.width, boxShadow: widget.boxShadow, icon: _typeToIcon[widget.type] ?? Broken.musicnote, - iconSize: widget.iconSize ?? (widget.customUrl != null ? null : widget.width * 0.3), + iconSize: widget.iconSize ?? widget.width * 0.3, forceSquared: widget.forceSquared, // cacheHeight: (widget.height?.round() ?? widget.width.round()) ~/ 1.2, onTopWidgets: [ diff --git a/lib/youtube/widgets/yt_video_card.dart b/lib/youtube/widgets/yt_video_card.dart index a5d22ea0..05d70671 100644 --- a/lib/youtube/widgets/yt_video_card.dart +++ b/lib/youtube/widgets/yt_video_card.dart @@ -264,25 +264,49 @@ class YoutubeShortVideoTallCard extends StatelessWidget { bottom: 0, left: 0, child: Padding( - padding: const EdgeInsets.all(2.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.end, - mainAxisSize: MainAxisSize.min, - children: [ - Text( - title, - style: context.textTheme.displayMedium?.copyWith(fontSize: 12.0), - maxLines: 1, - overflow: TextOverflow.ellipsis, - ), - Text( - viewsCountText, - style: context.textTheme.displaySmall?.copyWith(fontSize: 11.0), - maxLines: 1, - overflow: TextOverflow.ellipsis, - ), - ], + padding: const EdgeInsets.symmetric(horizontal: 4.0, vertical: 4.0), + child: SizedBox( + width: thumbnailWidth, + height: thumbnailHeight, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.end, + mainAxisSize: MainAxisSize.min, + children: [ + Text( + title, + style: context.textTheme.displayMedium?.copyWith( + fontSize: 12.0, + color: Colors.white70, + shadows: [ + const BoxShadow( + spreadRadius: 1.0, + blurRadius: 12.0, + color: Colors.black38, + ), + ], + ), + maxLines: 1, + overflow: TextOverflow.ellipsis, + ), + Text( + viewsCountText, + style: context.textTheme.displaySmall?.copyWith( + fontSize: 11.0, + color: Colors.white60, + shadows: [ + const BoxShadow( + spreadRadius: 1.0, + blurRadius: 12.0, + color: Colors.black38, + ), + ], + ), + maxLines: 1, + overflow: TextOverflow.ellipsis, + ), + ], + ), ), ), ), diff --git a/lib/youtube/youtube_miniplayer.dart b/lib/youtube/youtube_miniplayer.dart index 7a6b2d87..d7de8146 100644 --- a/lib/youtube/youtube_miniplayer.dart +++ b/lib/youtube/youtube_miniplayer.dart @@ -310,10 +310,14 @@ class YoutubeMiniPlayerState extends State { String? uploadDate; String? uploadDateAgo; - final parsedDate = videoInfoStream?.publishedAt.date ?? videoInfoStream?.publishDate.date; // videoInfo?.publishedAt.date aint no way near accurate - + DateTime? parsedDate = videoInfoStream?.publishedAt.date ?? videoInfoStream?.publishDate.date; // videoInfo?.publishedAt.date aint no way near accurate + bool accurateDate = true; + if (parsedDate == null) { + parsedDate = videoInfo?.publishedAt.date; + accurateDate = false; + } if (parsedDate != null) { - uploadDate = parsedDate.millisecondsSinceEpoch.dateFormattedOriginal; + if (accurateDate) uploadDate = parsedDate.millisecondsSinceEpoch.dateFormattedOriginal; uploadDateAgo = Jiffy.parseFromDateTime(parsedDate).fromNow(); } else { // uploadDateAgo = videoInfo?.publishedFromText; // warcrime @@ -832,7 +836,13 @@ class YoutubeMiniPlayerState extends State { ), ), const SizedBox(width: 12.0), - YTSubscribeButton(channelID: channelID), + YTSubscribeButton( + channelID: channelID, + listenable: YoutubeInfoController.current.currentVideoPage, + retrieveInfo: () => YoutubeInfoController.current.currentVideoPage.value?.channelInfo, + mainPage: () => YoutubeInfoController.current.currentVideoPage.value, + mainChannelInfo: null, + ), const SizedBox(width: 20.0), ], ), diff --git a/pubspec.yaml b/pubspec.yaml index cab504dc..77f2920c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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.2.2-beta+240713184 +version: 3.2.3-beta+240713186 environment: sdk: ">=3.4.0 <4.0.0"