Skip to content

Commit

Permalink
core: hot sauce
Browse files Browse the repository at this point in the history
- notification artist: fall back to channel name or 'unknown artist'
- remembered to load yt settings lmoa
- improved perf of translatePlaylistName()
- hide app bar stuff in acc & membership subpages
- app bar reorder icon for playlist not refreshing due to ghosts
- finally properly refresh yt download reactive maps when needed
- juust lil top padding for yt top comments card
- feed will no longer automatically refresh. and refresh icon is shown after n seconds passed without refreshing
- notification read status update properly on refresh
- comment likes count increase if liked
- channel subpage stuff not refreshing
- hide shorts from horizontal youtube (cuz they are not really ordered and they look ugly)
  • Loading branch information
MSOB7YY committed Jul 19, 2024
1 parent 71679c2 commit e486433
Show file tree
Hide file tree
Showing 15 changed files with 317 additions and 264 deletions.
2 changes: 1 addition & 1 deletion lib/base/audio_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1724,7 +1724,7 @@ extension YoutubeIDToMediaItem on YoutubeID {
return MediaItem(
id: id,
title: title,
artist: artistName,
artist: artistName ?? videoChannelTitle ?? UnknownTags.ARTIST,
album: '',
genre: '',
displayTitle: videoTitle,
Expand Down
11 changes: 7 additions & 4 deletions lib/core/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,13 @@ extension FavouriteYoutubeID on YoutubeID {
}

extension PLNAME on String {
String translatePlaylistName() => replaceFirst(k_PLAYLIST_NAME_AUTO_GENERATED, lang.AUTO_GENERATED)
.replaceFirst(k_PLAYLIST_NAME_FAV, lang.FAVOURITES)
.replaceFirst(k_PLAYLIST_NAME_HISTORY, lang.HISTORY)
.replaceFirst(k_PLAYLIST_NAME_MOST_PLAYED, lang.MOST_PLAYED);
String translatePlaylistName() {
final name = this;
if (name == k_PLAYLIST_NAME_FAV) return lang.FAVOURITES;
if (name == k_PLAYLIST_NAME_HISTORY) return lang.HISTORY;
if (name == k_PLAYLIST_NAME_MOST_PLAYED) return lang.MOST_PLAYED;
return name.replaceFirst(k_PLAYLIST_NAME_AUTO_GENERATED, lang.AUTO_GENERATED);
}
}

extension EnumUtils<E extends Enum> on E {
Expand Down
7 changes: 6 additions & 1 deletion lib/core/namida_converter_ext.dart
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,11 @@ extension RouteUtils on NamidaRoute {
);
}

final shouldShowInitialActions = route != RouteType.PAGE_stats && route != RouteType.SETTINGS_page && route != RouteType.SETTINGS_subpage;
final shouldShowInitialActions = route != RouteType.PAGE_stats &&
route != RouteType.SETTINGS_page &&
route != RouteType.SETTINGS_subpage &&
route != RouteType.YOUTUBE_USER_MANAGE_ACCOUNT_SUBPAGE &&
route != RouteType.YOUTUBE_USER_MANAGE_SUBSCRIPTION_SUBPAGE;
final shouldShowProgressPercentage = route != RouteType.SETTINGS_page && route != RouteType.SETTINGS_subpage;

final name = this.name;
Expand Down Expand Up @@ -939,6 +943,7 @@ extension RouteUtils on NamidaRoute {
// ---- Playlist Tracks ----
getAnimatedCrossFade(
child: ObxO(
key: UniqueKey(), // i have no f idea why this happens.. namida ghosts are here again
rx: PlaylistController.inst.canReorderTracks,
builder: (reorderable) => NamidaAppBarIcon(
tooltip: () => PlaylistController.inst.canReorderTracks.value ? lang.DISABLE_REORDERING : lang.ENABLE_REORDERING,
Expand Down
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ void mainInitialization() async {
await Future.wait([
settings.equalizer.prepareSettingsFile(),
settings.player.prepareSettingsFile(),
settings.youtube.prepareSettingsFile(),
settings.prepareSettingsFile(),
]);

Expand Down
42 changes: 31 additions & 11 deletions lib/youtube/controller/youtube_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,11 @@ class YoutubeController {
final filename = entry.key;
final title = titleCallback(videoId) ?? videoId;
final speedB = speedInBytes(filename, entry.value.progress);
currentSpeedsInByte.value[videoId] ??= <DownloadTaskFilename, int>{}.obs;
if (currentSpeedsInByte.value[videoId] == null) {
currentSpeedsInByte.value[videoId] = <DownloadTaskFilename, int>{}.obs;
currentSpeedsInByte.refresh();
}

currentSpeedsInByte.value[videoId]![filename] = speedB;
NotificationService.inst.downloadYoutubeNotification(
notificationID: entry.key,
Expand Down Expand Up @@ -322,14 +326,20 @@ class YoutubeController {
final aFile = File("$saveDirPath/.tempa_${ytitem.filename.filename}");
final vFile = File("$saveDirPath/.tempv_${ytitem.filename.filename}");
if (aFile.existsSync()) {
downloadsAudioProgressMap.value[ytitem.id] ??= <DownloadTaskFilename, DownloadProgress>{}.obs;
if (downloadsAudioProgressMap.value[ytitem.id] == null) {
downloadsAudioProgressMap.value[ytitem.id] = <DownloadTaskFilename, DownloadProgress>{}.obs;
downloadsAudioProgressMap.refresh();
}
downloadsAudioProgressMap.value[ytitem.id]![ytitem.filename] = DownloadProgress(
progress: aFile.fileSizeSync() ?? 0,
totalProgress: 0,
);
}
if (vFile.existsSync()) {
downloadsVideoProgressMap.value[ytitem.id] ??= <DownloadTaskFilename, DownloadProgress>{}.obs;
if (downloadsVideoProgressMap.value[ytitem.id] == null) {
downloadsVideoProgressMap.value[ytitem.id] = <DownloadTaskFilename, DownloadProgress>{}.obs;
downloadsVideoProgressMap.refresh();
}
downloadsVideoProgressMap.value[ytitem.id]![ytitem.filename] = DownloadProgress(
progress: vFile.fileSizeSync() ?? 0,
totalProgress: 0,
Expand Down Expand Up @@ -564,8 +574,10 @@ class YoutubeController {
} else {
YoutubeInfoController.video.fetchVideoStreams(videoID.videoId).then((value) => completer.completeIfWasnt(value));
}

isFetchingData.value[videoID] ??= <DownloadTaskFilename, bool>{}.obs;
if (isFetchingData.value[videoID] == null) {
isFetchingData.value[videoID] = <DownloadTaskFilename, bool>{}.obs;
isFetchingData.refresh();
}
isFetchingData.value[videoID]![config.filename] = true;

try {
Expand Down Expand Up @@ -604,11 +616,11 @@ class YoutubeController {
}
} catch (e) {
// -- force break
isFetchingData[videoID]?[config.filename] = false;
isFetchingData.value[videoID]?[config.filename] = false;
return;
}

isFetchingData[videoID]?[config.filename] = false;
isFetchingData.value[videoID]?[config.filename] = false;
_updateDownloadTask(groupName: groupName, itemsConfig: [config]); // to refresh with new data

final downloadedFile = await _downloadYoutubeVideoRaw(
Expand Down Expand Up @@ -782,7 +794,10 @@ class YoutubeController {
);
}

isDownloading.value[id] ??= <DownloadTaskFilename, bool>{}.obs;
if (isDownloading.value[id] == null) {
isDownloading.value[id] = <DownloadTaskFilename, bool>{}.obs;
isDownloading.refresh();
}
isDownloading.value[id]![finalFilenameWrapper] = true;

_startNotificationTimer();
Expand Down Expand Up @@ -832,8 +847,10 @@ class YoutubeController {
isVideoFileCached = true;
} else {
int bytesLength = 0;

downloadsVideoProgressMap.value[id] ??= <DownloadTaskFilename, DownloadProgress>{}.obs;
if (downloadsVideoProgressMap.value[id] == null) {
downloadsVideoProgressMap.value[id] = <DownloadTaskFilename, DownloadProgress>{}.obs;
downloadsVideoProgressMap.refresh();
}
final downloadedFile = await _checkFileAndDownload(
groupName: groupName,
url: videoStream.buildUrl() ?? '',
Expand Down Expand Up @@ -885,7 +902,10 @@ class YoutubeController {
} else {
int bytesLength = 0;

downloadsAudioProgressMap.value[id] ??= <DownloadTaskFilename, DownloadProgress>{}.obs;
if (downloadsAudioProgressMap.value[id] == null) {
downloadsAudioProgressMap.value[id] = <DownloadTaskFilename, DownloadProgress>{}.obs;
downloadsAudioProgressMap.refresh();
}
final downloadedFile = await _checkFileAndDownload(
groupName: groupName,
url: audioStream.buildUrl() ?? '',
Expand Down
1 change: 1 addition & 0 deletions lib/youtube/pages/youtube_feed_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class YoutubeHomeFeedPage extends StatelessWidget {
builder: (visibleMixes) {
final isMixesVisible = visibleMixes[YTVisibleMixesPlaces.homeFeed] ?? true;
return YoutubeMainPageFetcherAccBase<YoutiPieFeedResult, YoutubeFeed>(
showRefreshInsteadOfRefreshing: true,
transparentShimmer: false,
title: lang.HOME,
cacheReader: YoutiPie.cacheBuilder.forFeedItems(),
Expand Down
22 changes: 18 additions & 4 deletions lib/youtube/pages/youtube_main_page_fetcher_acc_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class YoutubeMainPageFetcherAccBase<W extends YoutiPieListWrapper<T>, T extends
final double itemExtent;
final YoutubeMainPageFetcherItemBuilder<T, W> itemBuilder;
final RenderObjectWidget? Function(W list, YoutubeMainPageFetcherItemBuilder<T, W> itemBuilder, Widget dummyCard)? sliverListBuilder;
final bool showRefreshInsteadOfRefreshing;

final Widget? pageHeader;
final void Function()? onHeaderTap;
Expand All @@ -54,6 +55,7 @@ class YoutubeMainPageFetcherAccBase<W extends YoutiPieListWrapper<T>, T extends
required this.itemExtent,
required this.itemBuilder,
this.sliverListBuilder,
this.showRefreshInsteadOfRefreshing = false,
this.pageHeader,
this.onHeaderTap,
this.isHorizontal = false,
Expand Down Expand Up @@ -91,6 +93,7 @@ class _YoutubePageState<W extends YoutiPieListWrapper<T>, T extends MapSerializa
final _isLoadingCurrentFeed = false.obs;
final _isLoadingNext = false.obs;
final _lastFetchWasCached = false.obs;
final _refreshButtonShown = false.obs;
final _currentFeed = Rxn<W>();

bool get _hasConnection => ConnectivityController.inst.hasConnection;
Expand All @@ -105,6 +108,7 @@ class _YoutubePageState<W extends YoutiPieListWrapper<T>, T extends MapSerializa

void _onInit({bool forceRequest = false}) async {
bool needNewRequest = false;
bool preferPromptRefreshing = false;

if (forceRequest) {
needNewRequest = true;
Expand All @@ -113,8 +117,11 @@ class _YoutubePageState<W extends YoutiPieListWrapper<T>, T extends MapSerializa
if (_hasConnection) {
if (lastFetchedTime == null) {
needNewRequest = true;
_refreshButtonShown.value = true;
} else if (lastFetchedTime.difference(DateTime.now()).abs() > const Duration(seconds: 180)) {
needNewRequest = true;
_refreshButtonShown.value = true;
if (widget.showRefreshInsteadOfRefreshing) preferPromptRefreshing = true;
}
}
}
Expand All @@ -124,10 +131,14 @@ class _YoutubePageState<W extends YoutiPieListWrapper<T>, T extends MapSerializa
_currentFeed.value = cachedFeed;
_lastFetchWasCached.value = true;
if (needNewRequest) {
if (widget.enablePullToRefresh) {
onRefresh(_fetchFeedSilent, forceProceed: true);
if (preferPromptRefreshing) {
_refreshButtonShown.value = true;
} else {
_fetchFeedSilent();
if (widget.enablePullToRefresh) {
onRefresh(_fetchFeedSilent, forceProceed: true);
} else {
_fetchFeedSilent();
}
}
}
} else {
Expand Down Expand Up @@ -163,6 +174,7 @@ class _YoutubePageState<W extends YoutiPieListWrapper<T>, T extends MapSerializa
if (!_hasConnection) return _showNetworkError();

_lastFetchWasCached.value = false;
_refreshButtonShown.value = false;
_isLoadingCurrentFeed.value = true;
final val = await widget.networkFetcher(ExecuteDetails.forceRequest());
_resultsFetchTime[W] = DateTime.now();
Expand All @@ -171,6 +183,7 @@ class _YoutubePageState<W extends YoutiPieListWrapper<T>, T extends MapSerializa
_currentFeed.value = val;
} else {
_lastFetchWasCached.value = true;
_refreshButtonShown.value = true;
}
}

Expand All @@ -182,6 +195,7 @@ class _YoutubePageState<W extends YoutiPieListWrapper<T>, T extends MapSerializa
if (val != null) {
_currentFeed.value = val;
_lastFetchWasCached.value = false;
_refreshButtonShown.value = false;
} else {
_lastFetchWasCached.value = true;
}
Expand Down Expand Up @@ -212,7 +226,7 @@ class _YoutubePageState<W extends YoutiPieListWrapper<T>, T extends MapSerializa
),
const SizedBox(width: 12.0),
ObxO(
rx: _lastFetchWasCached,
rx: _refreshButtonShown,
builder: (value) => value
? NamidaIconButton(
icon: Broken.refresh,
Expand Down
Loading

0 comments on commit e486433

Please sign in to comment.