Skip to content

Commit

Permalink
feat(yt): comment replies
Browse files Browse the repository at this point in the history
ref #227
  • Loading branch information
MSOB7YY committed Jul 9, 2024
1 parent d84bea7 commit 5fd9a90
Show file tree
Hide file tree
Showing 6 changed files with 346 additions and 32 deletions.
4 changes: 4 additions & 0 deletions lib/controller/navigator_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class NamidaNavigator {

bool isytLocalSearchInFullPage = false;
bool isInYTCommentsSubpage = false;
bool isInYTCommentRepliesSubpage = false;
bool isQueueSheetOpen = false;

final currentWidgetStack = <NamidaRoute>[].obs;
Expand Down Expand Up @@ -411,6 +412,9 @@ class NamidaNavigator {
if (isQueueSheetOpen) {
ytQueueSheetKey.currentState?.dismissSheet();
isQueueSheetOpen = false;
} else if (isInYTCommentRepliesSubpage) {
ytMiniplayerCommentsPageKey.currentState?.pop();
isInYTCommentRepliesSubpage = false;
} else if (isInYTCommentsSubpage) {
ytMiniplayerCommentsPageKey.currentState?.pop();
isInYTCommentsSubpage = false;
Expand Down
11 changes: 9 additions & 2 deletions lib/ui/widgets/settings/youtube_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,15 @@ class YoutubeSettings extends SettingSubpageProvider {

// -- pop comments subpage in case was inside.
if (settings.ytTopComments.value == false) {
NamidaNavigator.inst.ytMiniplayerCommentsPageKey.currentState?.pop();
NamidaNavigator.inst.isInYTCommentsSubpage = false;
if (NamidaNavigator.inst.isInYTCommentRepliesSubpage) {
NamidaNavigator.inst.ytMiniplayerCommentsPageKey.currentState?.pop();
NamidaNavigator.inst.isInYTCommentRepliesSubpage = false;
}
// we need to pop both if required
if (NamidaNavigator.inst.isInYTCommentsSubpage) {
NamidaNavigator.inst.ytMiniplayerCommentsPageKey.currentState?.pop();
NamidaNavigator.inst.isInYTCommentsSubpage = false;
}
}
},
),
Expand Down
66 changes: 41 additions & 25 deletions lib/youtube/widgets/yt_comment_card.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:youtipie/class/comments/comment_info_item.dart';
import 'package:youtipie/class/comments/comment_info_item_base.dart';
import 'package:youtipie/class/result_wrapper/comment_result.dart';
import 'package:youtipie/class/result_wrapper/list_wrapper_base.dart';
import 'package:youtipie/core/enum.dart';
import 'package:youtipie/youtipie.dart';

import 'package:namida/class/route.dart';
import 'package:namida/controller/navigator_controller.dart';
import 'package:namida/core/extensions.dart';
import 'package:namida/core/icon_fonts/broken_icons.dart';
import 'package:namida/core/translations/language.dart';
Expand All @@ -17,16 +20,21 @@ import 'package:namida/youtube/widgets/namida_read_more.dart';
import 'package:namida/youtube/widgets/yt_description_widget.dart';
import 'package:namida/youtube/widgets/yt_shimmer.dart';
import 'package:namida/youtube/widgets/yt_thumbnail.dart';
import 'package:namida/youtube/yt_minplayer_comment_replies_subpage.dart';

class YTCommentCard extends StatefulWidget {
class YTCommentCard<W extends YoutiPieListWrapper<CommentInfoItemBase>> extends StatefulWidget {
final EdgeInsetsGeometry? margin;
final int bgAlpha;
final bool showRepliesBox;
final String? videoId;
final CommentInfoItem? comment;
final YoutiPieCommentResult Function()? mainList;
final CommentInfoItemBase? comment;
final W Function()? mainList;

const YTCommentCard({
super.key,
required this.margin,
this.bgAlpha = 100,
this.showRepliesBox = true,
required this.videoId,
required this.comment,
required this.mainList,
Expand Down Expand Up @@ -65,6 +73,22 @@ class _YTCommentCardState extends State<YTCommentCard> {
}
}

void _onRepliesTap({required CommentInfoItem comment, required int? repliesCount}) {
final mainList = widget.mainList;
if (mainList == null) return;
if (mainList is! YoutiPieCommentResult Function()) return;
NamidaNavigator.inst.isInYTCommentRepliesSubpage = true;
NamidaNavigator.inst.ytMiniplayerCommentsPageKey.currentState?.pushPage(
YTMiniplayerCommentRepliesSubpage(
comment: comment,
mainList: mainList,
repliesCount: repliesCount,
videoId: widget.videoId,
),
maintainState: false,
);
}

@override
Widget build(BuildContext context) {
final comment = this.widget.comment;
Expand All @@ -74,11 +98,9 @@ class _YTCommentCardState extends State<YTCommentCard> {
final uploadedFrom = comment?.publishedTimeText;
final commentContent = comment?.content;
final likeCount = comment?.likesCount;
final repliesCount = comment?.repliesCount;
final isHearted = comment?.isHearted ?? false;
final isPinned = comment?.isPinned ?? false;

final containerColor = context.theme.cardColor.withAlpha(100);
final containerColor = context.theme.cardColor.withAlpha(widget.bgAlpha);
final readmoreColor = context.theme.colorScheme.primary.withAlpha(160);

final authorTextColor = context.theme.colorScheme.onSurface.withAlpha(180);
Expand Down Expand Up @@ -131,7 +153,7 @@ class _YTCommentCardState extends State<YTCommentCard> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 2.0),
if (isPinned) ...[
if (comment is CommentInfoItem && comment.isPinned) ...[
Row(
children: [
const Icon(
Expand Down Expand Up @@ -320,25 +342,19 @@ class _YTCommentCardState extends State<YTCommentCard> {
),
),
),
const SizedBox(width: 16.0),
SizedBox(
height: 28.0,
child: TextButton.icon(
style: TextButton.styleFrom(
visualDensity: VisualDensity.compact,
foregroundColor: context.theme.colorScheme.onSurface.withAlpha(200),
),
onPressed: () {},
icon: const Icon(Broken.document, size: 16.0),
label: NamidaButtonText(
[
lang.REPLIES,
if (repliesCount != null) repliesCount,
].join(' • '),
style: context.textTheme.displaySmall?.copyWith(fontWeight: FontWeight.w300),
),
if (widget.showRepliesBox && comment is CommentInfoItem) const SizedBox(width: 8.0),
if (widget.showRepliesBox && comment is CommentInfoItem)
NamidaInkWellButton(
sizeMultiplier: 0.8,
borderRadius: 6.0,
onTap: () => _onRepliesTap(comment: comment, repliesCount: comment.repliesCount),
bgColor: context.theme.colorScheme.secondaryContainer.withOpacity(0.2),
icon: Broken.document,
text: [
lang.REPLIES,
if (comment.repliesCount != null) comment.repliesCount!,
].join(' • '),
),
),
],
),
],
Expand Down
10 changes: 6 additions & 4 deletions lib/youtube/youtube_miniplayer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,13 @@ class YoutubeMiniPlayerState extends State<YoutubeMiniPlayer> {
child: Listener(
behavior: HitTestBehavior.translucent,
onPointerDown: (event) {
if (NamidaNavigator.inst.isInYTCommentsSubpage) return;
if (NamidaNavigator.inst.isInYTCommentsSubpage || NamidaNavigator.inst.isInYTCommentRepliesSubpage) return;
_mpState?.setDragExternally(true);
_mpState?.saveDragHeightStart();
_velocity.addPosition(event.timeStamp, event.position);
},
onPointerMove: (event) {
if (NamidaNavigator.inst.isInYTCommentsSubpage) return;
if (NamidaNavigator.inst.isInYTCommentsSubpage || NamidaNavigator.inst.isInYTCommentRepliesSubpage) return;
if (!_canScrollQueue) {
_mpState?.onVerticalDragUpdate(event.delta.dy);
_velocity.addPosition(event.timeStamp, event.position);
Expand All @@ -214,7 +214,7 @@ class YoutubeMiniPlayerState extends State<YoutubeMiniPlayer> {
});
},
onPointerUp: (event) {
if (!NamidaNavigator.inst.isInYTCommentsSubpage) {
if (!NamidaNavigator.inst.isInYTCommentsSubpage && !NamidaNavigator.inst.isInYTCommentRepliesSubpage) {
if (_scrollController.hasClients && _scrollController.position.pixels <= 0) {
_mpState?.onVerticalDragEnd(_velocity.getVelocity().pixelsPerSecond.dy);
}
Expand Down Expand Up @@ -1199,7 +1199,9 @@ class YoutubeMiniPlayerState extends State<YoutubeMiniPlayer> {

// ---- if was in comments subpage, and this gets hidden, the route is popped
// ---- same with [isQueueSheetOpen]
if (NamidaNavigator.inst.isInYTCommentsSubpage || NamidaNavigator.inst.isQueueSheetOpen ? true : percentage > 0)
if (NamidaNavigator.inst.isInYTCommentsSubpage || NamidaNavigator.inst.isInYTCommentRepliesSubpage || NamidaNavigator.inst.isQueueSheetOpen
? true
: percentage > 0)
Expanded(
child: Stack(
fit: StackFit.expand,
Expand Down
Loading

0 comments on commit 5fd9a90

Please sign in to comment.