diff --git a/lib/services/notification/awsome/awsome_notification_controller.dart b/lib/services/notification/awsome/awsome_notification_controller.dart index 4781752..4917700 100644 --- a/lib/services/notification/awsome/awsome_notification_controller.dart +++ b/lib/services/notification/awsome/awsome_notification_controller.dart @@ -6,7 +6,7 @@ class NotificationController { @pragma("vm:entry-point") static Future onNotificationCreatedMethod(ReceivedNotification receivedNotification) async { // Your code goes here - print("onNotificationCreatedMethod--------------------------------------------------------------"); + // print("onNotificationCreatedMethod--------------------------------------------------------------"); } @@ -14,7 +14,7 @@ class NotificationController { @pragma("vm:entry-point") static Future onNotificationDisplayedMethod(ReceivedNotification receivedNotification) async { // Your code goes here - print("onNotificationDisplayedMethod--------------------------------------------------------------"); + // print("onNotificationDisplayedMethod--------------------------------------------------------------"); } @@ -22,7 +22,7 @@ class NotificationController { @pragma("vm:entry-point") static Future onDismissActionReceivedMethod(ReceivedAction receivedAction) async { // Your code goes here - print("onDismissActionReceivedMethod--------------------------------------------------------------"); + // print("onDismissActionReceivedMethod--------------------------------------------------------------"); } @@ -36,6 +36,6 @@ class NotificationController { // MyApp.navigatorKey.currentState?.pushNamedAndRemoveUntil('/notification-page', // (route) => (route.settings.name != '/notification-page') || route.isFirst, // arguments: receivedAction); - print("onActionReceivedMethod--------------------------------------------------------------"); + // print("onActionReceivedMethod--------------------------------------------------------------"); } } \ No newline at end of file diff --git a/lib/services/notification/awsome/awsome_notification_handler.dart b/lib/services/notification/awsome/awsome_notification_handler.dart index e7091e4..e1ed2a7 100644 --- a/lib/services/notification/awsome/awsome_notification_handler.dart +++ b/lib/services/notification/awsome/awsome_notification_handler.dart @@ -1,9 +1,7 @@ -import 'dart:ui'; import 'package:awesome_notifications/awesome_notifications.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/material.dart'; -import 'package:intl/intl.dart'; import '../../../models/notification_message.dart'; import 'awsome_notification_controller.dart'; @@ -87,7 +85,6 @@ class AwsomeNotificationHandler { break; } - try {} catch (ex) {} } showNotificationTypeNews(NotificationMessage message) async { @@ -97,7 +94,7 @@ class AwsomeNotificationHandler { channelKey: 'alerts', actionType: ActionType.Default, title: "\u200f ${message.title} \u200f", - body: "${message.body.toString()}", + body: message.body.toString(), notificationLayout: NotificationLayout.BigText, largeIcon: message.image.toString(), color: const Color(0xFF007EA7)), @@ -135,10 +132,8 @@ class AwsomeNotificationHandler { content: NotificationContent( id: DateTime.now().millisecondsSinceEpoch ~/ 1000, channelKey: 'alerts', - title: 'Emojis are awesome too! ' + - Emojis.animals_lady_beetle + - Emojis.activites_balloon + - Emojis.emotion_red_heart, + title: 'Emojis are awes' + 'ome too! ${Emojis.animals_lady_beetle}${Emojis.activites_balloon}${Emojis.emotion_red_heart}', body: 'Simple body with a bunch of Emojis! ${Emojis.transport_police_car} ${Emojis.animals_dog} ${Emojis.flag_UnitedStates} ${Emojis.person_baby}', largeIcon: diff --git a/lib/services/notification/fcm/firebase_notification_handler.dart b/lib/services/notification/fcm/firebase_notification_handler.dart index c1f905e..8462dc9 100644 --- a/lib/services/notification/fcm/firebase_notification_handler.dart +++ b/lib/services/notification/fcm/firebase_notification_handler.dart @@ -4,7 +4,6 @@ import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; -import '../lc/local_notification_service.dart'; import '../../app_initalizer.dart'; class FirebaseNotificationHandler { diff --git a/lib/views/comments/comments.dart b/lib/views/comments/comments.dart index e70175e..6527465 100644 --- a/lib/views/comments/comments.dart +++ b/lib/views/comments/comments.dart @@ -6,7 +6,6 @@ import 'package:didvan/constants/app_icons.dart'; import 'package:didvan/constants/assets.dart'; import 'package:didvan/models/users_mention.dart'; import 'package:didvan/models/view/app_bar_data.dart'; -import 'package:didvan/services/network/request_helper.dart'; import 'package:didvan/views/comments/comments_state.dart'; import 'package:didvan/views/comments/widgets/comment.dart'; import 'package:didvan/views/widgets/animated_visibility.dart'; @@ -17,12 +16,10 @@ import 'package:didvan/views/widgets/didvan/text.dart'; import 'package:didvan/views/widgets/shimmer_placeholder.dart'; import 'package:didvan/views/widgets/state_handlers/empty_state.dart'; import 'package:didvan/views/widgets/state_handlers/sliver_state_handler.dart'; -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; import 'package:provider/provider.dart'; -import '../widgets/skeleton_image.dart'; +import '../widgets/didvan/didvan_title_divider.dart'; import '../widgets/user_mention.dart'; class Comments extends StatefulWidget { @@ -83,6 +80,7 @@ class _CommentsState extends State { ) : null, padding: const EdgeInsets.only(left: 16, right: 16, bottom: 92), + showSliversFirst: false, slivers: [ Consumer( builder: (context, state, child) => @@ -93,7 +91,8 @@ class _CommentsState extends State { childCount: state.comments.length, placeholder: const _CommentPlaceholder(), centerEmptyState: _isPage, - enableEmptyState: state.comments.isEmpty, + enableEmptyState: + state.comments.isEmpty && state.privateComments.isEmpty, emptyState: EmptyState( asset: Assets.emptyChat, title: 'اولین نظر را بنویسید...', @@ -109,6 +108,35 @@ class _CommentsState extends State { ), ), ], + children: commentsState.privateComments.isNotEmpty + ? [ + const SizedBox( + height: 6, + ), + DidvanTitleDivider( + title: "نظرات پنهان شده", + onClick: () { + commentsState.showPrivates = + !commentsState.showPrivates; + commentsState.update(); + }, + ), + const SizedBox( + height: 16, + ), + AnimatedVisibility( + duration: DesignConfig.lowAnimationDuration, + isVisible: commentsState.showPrivates, + child: _buildPrivateComments(commentsState), + ), + const SizedBox( + height: 16, + ), + const DidvanTitleDivider( + title: "سایر نظرات", + ), + ] + : null, ), AnimatedVisibility( duration: DesignConfig.lowAnimationDuration, @@ -162,6 +190,23 @@ class _CommentsState extends State { ), ); } + + ListView _buildPrivateComments(CommentsState commentsState) { + return ListView.builder( + physics: const BouncingScrollPhysics(), + itemCount: commentsState.privateComments.length, + shrinkWrap: true, + itemBuilder: (context, index) { + return Comment( + key: ValueKey( + commentsState.privateComments[index].id.toString() + + commentsState.privateComments[index].text, + ), + focusNode: _focusNode, + comment: commentsState.privateComments[index], + ); + }); + } } class _MessageBox extends StatefulWidget { @@ -178,7 +223,7 @@ class _MessageBoxState extends State<_MessageBox> { Widget build(BuildContext context) { final state = context.watch(); - void _onCheckBoxChange(bool b) { + void onCheckBoxChange(bool b) { state.hideMentionedUser = b; state.update(); } @@ -263,16 +308,10 @@ class _MessageBoxState extends State<_MessageBox> { decoration: BoxDecoration( color: Theme.of(context).colorScheme.secondCTA, borderRadius: !state.showReplyBox - ? BorderRadius.only( + ? const BorderRadius.only( topLeft: Radius.circular(16), topRight: Radius.circular(16)) - : null - // border: Border( - // top: BorderSide( - // color: Theme.of(context).colorScheme.border, - // ), - // ), - ), + : null), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, @@ -285,7 +324,7 @@ class _MessageBoxState extends State<_MessageBox> { width: 2, height: 40, ), - SizedBox( + const SizedBox( width: 8, ), Column( @@ -322,10 +361,10 @@ class _MessageBoxState extends State<_MessageBox> { title: "پنهان کردن فراخوانی", value: state.hideMentionedUser, color: Theme.of(context).colorScheme.primary, - onChanged: _onCheckBoxChange, + onChanged: onCheckBoxChange, size: 12, ) - : SizedBox(), + : const SizedBox(), ], ) ], @@ -353,11 +392,6 @@ class _MessageBoxState extends State<_MessageBox> { color: state.showReplyBox && state.usersMentioned.name == null ? Theme.of(context).colorScheme.secondCTA : Theme.of(context).colorScheme.surface, - // border: Border( - // top: BorderSide( - // color: Theme.of(context).colorScheme.border, - // ), - // ), ), child: Row( children: [ diff --git a/lib/views/comments/comments_state.dart b/lib/views/comments/comments_state.dart index 1344860..d47c2a3 100644 --- a/lib/views/comments/comments_state.dart +++ b/lib/views/comments/comments_state.dart @@ -11,7 +11,6 @@ import 'package:didvan/providers/user.dart'; import 'package:didvan/services/network/request.dart'; import 'package:didvan/services/network/request_helper.dart'; import 'package:didvan/utils/action_sheet.dart'; -import 'package:didvan/views/widgets/user_mention.dart'; import 'package:flutter/cupertino.dart'; import 'package:provider/provider.dart'; @@ -23,12 +22,14 @@ class CommentsState extends CoreProvier { UserOverview? replyingTo; bool showReplyBox = false; bool showUsersForMentionsLayout = false; + bool showPrivates = false; bool hideMentionedUser = false; late void Function(int count) onCommentsChanged; int _count = 0; late String type; final List comments = []; + final List privateComments = []; final List usersMention = []; final Map> _feedbackQueue = {}; @@ -41,11 +42,20 @@ class CommentsState extends CoreProvier { await service.httpGet(); if (service.isSuccess) { comments.clear(); - final messages = service.result['comments']['public']; - for (var i = 0; i < messages.length; i++) { - comments.add(CommentData.fromJson(messages[i], false)); + final messagesPublic = service.result['comments']['public']; + for (var i = 0; i < messagesPublic.length; i++) { + comments.add(CommentData.fromJson(messagesPublic[i], false)); _count++; - for (var j = 0; j < messages[i]['replies'].length; j++) { + for (var j = 0; j < messagesPublic[i]['replies'].length; j++) { + _count++; + } + } + + final messagesPrivate = service.result['comments']['private']; + for (var i = 0; i < messagesPrivate.length; i++) { + privateComments.add(CommentData.fromJson(messagesPrivate[i], true)); + _count++; + for (var j = 0; j < messagesPrivate[i]['replies'].length; j++) { _count++; } } @@ -112,6 +122,8 @@ class CommentsState extends CoreProvier { } Future addComment() async { + late List cList = + hideMentionedUser ? privateComments : comments; final user = DesignConfig.context!.read().user; if (replyingTo != null) { comments.firstWhere((comment) => comment.id == commentId).replies.add( @@ -133,25 +145,25 @@ class CommentsState extends CoreProvier { ), ); } else { - comments.insert( + cList.insert( 0, CommentData( - id: 0, - text: commentTextFieldController.text, - createdAt: DateTime.now().toString(), - liked: false, - disliked: false, - feedback: FeedbackData(like: 0, dislike: 0), - user: UserOverview( - id: user.id, - fullName: user.fullName, - photo: user.photo, - ), - replies: [], - status: 2, - private: hideMentionedUser, - mention: usersMentioned.name, - ), + id: 0, + text: commentTextFieldController.text, + createdAt: DateTime.now().toString(), + liked: false, + disliked: false, + feedback: FeedbackData(like: 0, dislike: 0), + user: UserOverview( + id: user.id, + fullName: user.fullName, + photo: user.photo, + ), + replies: [], + status: 2, + private: hideMentionedUser, + mention: usersMentioned.name, + ), ); } @@ -180,13 +192,13 @@ class CommentsState extends CoreProvier { await service.post(); if (service.isSuccess) { if (replyingTo != null) { - comments + cList .firstWhere((comment) => comment.id == commentId) .replies .firstWhere((reply) => reply.id == 0) .id = service.result['comment']['id']; } else { - comments.firstWhere((comment) => comment.id == 0).id = + cList.firstWhere((comment) => comment.id == 0).id = service.result['comment']['id']; } commentId = null; diff --git a/lib/views/widgets/didvan/didvan_title_divider.dart b/lib/views/widgets/didvan/didvan_title_divider.dart new file mode 100644 index 0000000..53b92d3 --- /dev/null +++ b/lib/views/widgets/didvan/didvan_title_divider.dart @@ -0,0 +1,44 @@ +import 'package:didvan/config/theme_data.dart'; +import 'package:flutter/material.dart'; + +import 'text.dart'; +import '../ink_wrapper.dart'; + +class DidvanTitleDivider extends StatelessWidget{ + + final String title; + final Function()? onClick; + + const DidvanTitleDivider({super.key, required this.title, this.onClick}); + + @override + Widget build(BuildContext context) { + return InkWrapper( + onPressed: onClick, + child: Row( + children: [ + Expanded( + child: Divider( + height: 1, + color: Theme.of(context).colorScheme.border, + )), + Padding( + padding: const EdgeInsets.only(left: 8, right: 8), + child: DidvanText( + title, + style: Theme.of(context).textTheme.bodySmall, + color: Theme.of(context).colorScheme.inputText, + ), + ), + Expanded( + child: Divider( + height: 1, + color: Theme.of(context).colorScheme.border, + )), + ], + ), + ); + } + + +} \ No newline at end of file diff --git a/lib/views/widgets/didvan/scaffold.dart b/lib/views/widgets/didvan/scaffold.dart index 7d77a3b..38733e1 100644 --- a/lib/views/widgets/didvan/scaffold.dart +++ b/lib/views/widgets/didvan/scaffold.dart @@ -101,7 +101,7 @@ class _DidvanScaffoldState extends State { ), if (widget.children != null && !widget.showSliversFirst) SliverPadding( - padding: widget.padding, + padding: widget.padding.copyWith(bottom: 16), sliver: SliverList( delegate: SliverChildBuilderDelegate( (context, index) => widget.children![index],