Skip to content

Commit

Permalink
feat(yt): channel subscribe & notifications
Browse files Browse the repository at this point in the history
this comes with across-pages safety, hitting the button in a place temoprarely disables other active buttons
so damn cool
oh ye and a sneaky lil fix
ref: #227
  • Loading branch information
MSOB7YY committed Jul 14, 2024
1 parent 6ac49c7 commit 34a10fe
Show file tree
Hide file tree
Showing 11 changed files with 355 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/class/track.dart
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ extension TrackUtils on Track {
set duration(int value) {
final trx = Indexer.inst.allTracksMappedByPath.value[this];
if (trx != null) {
Indexer.inst.allTracksMappedByPath.value[this] = trx.copyWith(duration: value);
Indexer.inst.allTracksMappedByPath[this] = trx.copyWith(duration: value);
Indexer.inst.allTracksMappedByPath.refresh();
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/controller/waveform_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class WaveformController {
Future.delayed(const Duration(milliseconds: 800)),
]);

if (stillPlaying(path)) {
if (waveformData.isNotEmpty && stillPlaying(path)) {
// ----- Updating [_currentWaveform]
const maxWaveformCount = 2000;
final numberOfScales = duration.inMilliseconds ~/ 50;
Expand Down
9 changes: 9 additions & 0 deletions lib/core/namida_converter_ext.dart
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,10 @@ extension CommentsSortTypeUtils on CommentsSortType {
String toText() => _NamidaConverters.inst.getTitle(this);
}

extension ChannelNotificationsUtils on ChannelNotifications {
String toText() => _NamidaConverters.inst.getTitle(this);
}

extension RouteUtils on NamidaRoute {
List<Selectable> tracksListInside() {
final iter = tracksInside();
Expand Down Expand Up @@ -1305,6 +1309,11 @@ class _NamidaConverters {
CommentsSortType.top: lang.TOP,
CommentsSortType.newest: lang.NEWEST,
},
ChannelNotifications: {
ChannelNotifications.all: lang.ALL,
ChannelNotifications.personalized: lang.PERSONALIZED,
ChannelNotifications.none: lang.NONE,
},
};

// ====================================================
Expand Down
1 change: 1 addition & 0 deletions lib/core/translations/keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ abstract class LanguageKeys {
String get PERCENTAGE => _getKey('PERCENTAGE');
String get PERFORMANCE_MODE => _getKey('PERFORMANCE_MODE');
String get PERFORMANCE_NOTE => _getKey('PERFORMANCE_NOTE');
String get PERSONALIZED => _getKey('PERSONALIZED');
String get PICK_COLORS_FROM_DEVICE_WALLPAPER => _getKey('PICK_COLORS_FROM_DEVICE_WALLPAPER');
String get PICK_FROM_STORAGE => _getKey('PICK_FROM_STORAGE');
String get PINNED => _getKey('PINNED');
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/dialogs/general_popup_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ Future<void> showGeneralPopupDialog(
},
),

isSingle && tracks.first == Player.inst.currentItem.value
isSingle && tracks.first == Player.inst.currentTrack?.track
? NamidaOpacity(
opacity: Player.inst.sleepTimerConfig.value.sleepAfterItems == 1 ? 0.6 : 1.0,
child: IgnorePointer(
Expand Down
27 changes: 26 additions & 1 deletion lib/youtube/controller/youtube_current_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class _YoutubeCurrentInfoController {
bool get _canShowComments => settings.youtubeStyleMiniplayer.value;

RxBaseCore<YoutiPieVideoPageResult?> get currentVideoPage => _currentVideoPage;
RxBaseCore<YoutiPieChannelPageResult?> get currentChannelPage => _currentChannelPage;
RxBaseCore<YoutiPieCommentResult?> get currentComments => _currentComments;
RxBaseCore<bool> get isLoadingVideoPage => _isLoadingVideoPage;
RxBaseCore<bool> get isLoadingInitialComments => _isLoadingInitialComments;
Expand All @@ -20,6 +21,7 @@ class _YoutubeCurrentInfoController {
final currentCachedQualities = <NamidaVideo>[].obs;

final _currentVideoPage = Rxn<YoutiPieVideoPageResult>();
final _currentChannelPage = Rxn<YoutiPieChannelPageResult>();
final _currentRelatedVideos = Rxn<YoutiPieRelatedVideosResult>();
final _currentComments = Rxn<YoutiPieCommentResult>();
final currentYTStreams = Rxn<VideoStreamsResult>();
Expand All @@ -39,6 +41,7 @@ class _YoutubeCurrentInfoController {
void resetAll() {
currentCachedQualities.clear();
_currentVideoPage.value = null;
_currentChannelPage.value = null;
_currentRelatedVideos.value = null;
_currentComments.value = null;
currentYTStreams.value = null;
Expand All @@ -52,6 +55,11 @@ class _YoutubeCurrentInfoController {
final vidcache = YoutiPie.cacheBuilder.forVideoPage(videoId: videoId);
final vidPageCached = vidcache.read();
_currentVideoPage.value = vidPageCached;

final chId = vidPageCached?.channelInfo?.id ?? YoutubeInfoController.utils.getVideoChannelID(videoId);
final chPage = chId == null ? null : YoutiPie.cacheBuilder.forChannel(channelId: chId).read();
_currentChannelPage.value = chPage;

final relatedcache = YoutiPie.cacheBuilder.forRelatedVideos(videoId: videoId);
_currentRelatedVideos.value = relatedcache.read() ?? vidPageCached?.relatedVideosResult;
return vidPageCached != null;
Expand Down Expand Up @@ -80,6 +88,7 @@ class _YoutubeCurrentInfoController {
if (requestPage) {
if (onVideoPageReset != null) onVideoPageReset!(); // jumps miniplayer to top
_currentVideoPage.value = null;
_currentChannelPage.value = null;
}
if (requestComments) {
_currentComments.value = null;
Expand All @@ -92,8 +101,23 @@ class _YoutubeCurrentInfoController {
final page = await YoutubeInfoController.video.fetchVideoPage(videoId, details: ExecuteDetails.forceRequest());
_isLoadingVideoPage.value = false;

if (page != null) {
final chId = page.channelInfo?.id ?? YoutubeInfoController.utils.getVideoChannelID(videoId);
if (chId != null) {
YoutubeInfoController.channel.fetchChannelInfo(channelId: page.channelInfo?.id, details: ExecuteDetails.forceRequest()).then(
(chPage) {
if (_canSafelyModifyMetadata(videoId)) {
_currentChannelPage.value = chPage;
}
},
);
}
}

if (_canSafelyModifyMetadata(videoId)) {
if (requestPage) _currentVideoPage.value = page; // page is still requested cuz comments need it
if (requestPage) {
_currentVideoPage.value = page; // page is still requested cuz comments need it
}
if (requestComments) {
final commentsContinuation = page?.commentResult.continuation;
if (commentsContinuation != null && _canShowComments) {
Expand All @@ -106,6 +130,7 @@ class _YoutubeCurrentInfoController {
if (_canSafelyModifyMetadata(videoId)) {
_isLoadingInitialComments.value = false;
_currentVideoPage.refresh();
_currentChannelPage.refresh();
_currentComments.value = comm;
_isCurrentCommentsFromCache.value = false;
_initialCommentsContinuation = comm?.continuation;
Expand Down
13 changes: 8 additions & 5 deletions lib/youtube/pages/yt_channel_subpage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class _YTChannelSubpageState extends YoutubeChannelController<YTChannelSubpage>
subscribed: false,
);

YoutiPieChannelPageResult? _channelInfo;
final _channelInfo = Rxn<YoutiPieChannelPageResult?>(); // rx is accessed only in subscribe button. keep using setState().
YoutiPieFetchAllRes? _currentFetchAllRes;

@override
Expand All @@ -68,15 +68,15 @@ class _YTChannelSubpageState extends YoutubeChannelController<YTChannelSubpage>

final channelInfoCache = YoutubeInfoController.channel.fetchChannelInfoSync(ch.channelID);
if (channelInfoCache != null) {
_channelInfo = channelInfoCache;
_channelInfo.value = channelInfoCache;
fetchChannelStreams(channelInfoCache);
}

// -- always get new info.
YoutubeInfoController.channel.fetchChannelInfo(channelId: ch.channelID, details: ExecuteDetails.forceRequest()).then(
(value) {
if (value != null) {
setState(() => _channelInfo = value);
setState(() => _channelInfo.value = value);
onRefresh(() => fetchChannelStreams(value, forceRequest: true), forceProceed: true);
}
},
Expand Down Expand Up @@ -213,7 +213,7 @@ class _YTChannelSubpageState extends YoutubeChannelController<YTChannelSubpage>

@override
Widget build(BuildContext context) {
final channelInfo = _channelInfo;
final channelInfo = _channelInfo.value;
const thumbnailHeight = Dimensions.youtubeThumbnailHeight;
const thumbnailWidth = Dimensions.youtubeThumbnailWidth;
const thumbnailItemExtent = thumbnailHeight + 8.0 * 2;
Expand Down Expand Up @@ -344,7 +344,10 @@ class _YTChannelSubpageState extends YoutubeChannelController<YTChannelSubpage>
),
),
const SizedBox(width: 4.0),
YTSubscribeButton(channelID: channelID),
YTSubscribeButton(
channelID: channelID,
mainChannelInfo: _channelInfo,
),
const SizedBox(width: 12.0),
],
),
Expand Down
6 changes: 3 additions & 3 deletions lib/youtube/widgets/yt_comment_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ class _YTCommentCardState extends State<YTCommentCard> {
onEnd();
if (res == true) {
_currentLikeStatus.value = _currentLikeStatus.value = action.toExpectedStatus();
return true;
} else {
return false;
return !isLiked;
}

return isLiked;
}

void _onRepliesTap({required CommentInfoItem comment, required int? repliesCount}) {
Expand Down
Loading

0 comments on commit 34a10fe

Please sign in to comment.