23-02-1403 / Rhmn / changes: Mentions & Comments state Complete.

This commit is contained in:
OkaykOrhmn 2024-05-12 10:30:58 +03:30
parent 2d00d239be
commit 08d5564422
7 changed files with 144 additions and 60 deletions

View File

@ -6,7 +6,7 @@ class NotificationController {
@pragma("vm:entry-point") @pragma("vm:entry-point")
static Future <void> onNotificationCreatedMethod(ReceivedNotification receivedNotification) async { static Future <void> onNotificationCreatedMethod(ReceivedNotification receivedNotification) async {
// Your code goes here // Your code goes here
print("onNotificationCreatedMethod--------------------------------------------------------------"); // print("onNotificationCreatedMethod--------------------------------------------------------------");
} }
@ -14,7 +14,7 @@ class NotificationController {
@pragma("vm:entry-point") @pragma("vm:entry-point")
static Future <void> onNotificationDisplayedMethod(ReceivedNotification receivedNotification) async { static Future <void> onNotificationDisplayedMethod(ReceivedNotification receivedNotification) async {
// Your code goes here // Your code goes here
print("onNotificationDisplayedMethod--------------------------------------------------------------"); // print("onNotificationDisplayedMethod--------------------------------------------------------------");
} }
@ -22,7 +22,7 @@ class NotificationController {
@pragma("vm:entry-point") @pragma("vm:entry-point")
static Future <void> onDismissActionReceivedMethod(ReceivedAction receivedAction) async { static Future <void> onDismissActionReceivedMethod(ReceivedAction receivedAction) async {
// Your code goes here // Your code goes here
print("onDismissActionReceivedMethod--------------------------------------------------------------"); // print("onDismissActionReceivedMethod--------------------------------------------------------------");
} }
@ -36,6 +36,6 @@ class NotificationController {
// MyApp.navigatorKey.currentState?.pushNamedAndRemoveUntil('/notification-page', // MyApp.navigatorKey.currentState?.pushNamedAndRemoveUntil('/notification-page',
// (route) => (route.settings.name != '/notification-page') || route.isFirst, // (route) => (route.settings.name != '/notification-page') || route.isFirst,
// arguments: receivedAction); // arguments: receivedAction);
print("onActionReceivedMethod--------------------------------------------------------------"); // print("onActionReceivedMethod--------------------------------------------------------------");
} }
} }

View File

@ -1,9 +1,7 @@
import 'dart:ui';
import 'package:awesome_notifications/awesome_notifications.dart'; import 'package:awesome_notifications/awesome_notifications.dart';
import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import '../../../models/notification_message.dart'; import '../../../models/notification_message.dart';
import 'awsome_notification_controller.dart'; import 'awsome_notification_controller.dart';
@ -87,7 +85,6 @@ class AwsomeNotificationHandler {
break; break;
} }
try {} catch (ex) {}
} }
showNotificationTypeNews(NotificationMessage message) async { showNotificationTypeNews(NotificationMessage message) async {
@ -97,7 +94,7 @@ class AwsomeNotificationHandler {
channelKey: 'alerts', channelKey: 'alerts',
actionType: ActionType.Default, actionType: ActionType.Default,
title: "\u200f ${message.title} \u200f", title: "\u200f ${message.title} \u200f",
body: "${message.body.toString()}", body: message.body.toString(),
notificationLayout: NotificationLayout.BigText, notificationLayout: NotificationLayout.BigText,
largeIcon: message.image.toString(), largeIcon: message.image.toString(),
color: const Color(0xFF007EA7)), color: const Color(0xFF007EA7)),
@ -135,10 +132,8 @@ class AwsomeNotificationHandler {
content: NotificationContent( content: NotificationContent(
id: DateTime.now().millisecondsSinceEpoch ~/ 1000, id: DateTime.now().millisecondsSinceEpoch ~/ 1000,
channelKey: 'alerts', channelKey: 'alerts',
title: 'Emojis are awesome too! ' + title: 'Emojis are awes'
Emojis.animals_lady_beetle + 'ome too! ${Emojis.animals_lady_beetle}${Emojis.activites_balloon}${Emojis.emotion_red_heart}',
Emojis.activites_balloon +
Emojis.emotion_red_heart,
body: body:
'Simple body with a bunch of Emojis! ${Emojis.transport_police_car} ${Emojis.animals_dog} ${Emojis.flag_UnitedStates} ${Emojis.person_baby}', 'Simple body with a bunch of Emojis! ${Emojis.transport_police_car} ${Emojis.animals_dog} ${Emojis.flag_UnitedStates} ${Emojis.person_baby}',
largeIcon: largeIcon:

View File

@ -4,7 +4,6 @@ import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import '../lc/local_notification_service.dart';
import '../../app_initalizer.dart'; import '../../app_initalizer.dart';
class FirebaseNotificationHandler { class FirebaseNotificationHandler {

View File

@ -6,7 +6,6 @@ import 'package:didvan/constants/app_icons.dart';
import 'package:didvan/constants/assets.dart'; import 'package:didvan/constants/assets.dart';
import 'package:didvan/models/users_mention.dart'; import 'package:didvan/models/users_mention.dart';
import 'package:didvan/models/view/app_bar_data.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/comments_state.dart';
import 'package:didvan/views/comments/widgets/comment.dart'; import 'package:didvan/views/comments/widgets/comment.dart';
import 'package:didvan/views/widgets/animated_visibility.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/shimmer_placeholder.dart';
import 'package:didvan/views/widgets/state_handlers/empty_state.dart'; import 'package:didvan/views/widgets/state_handlers/empty_state.dart';
import 'package:didvan/views/widgets/state_handlers/sliver_state_handler.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/material.dart';
import 'package:flutter/widgets.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import '../widgets/skeleton_image.dart'; import '../widgets/didvan/didvan_title_divider.dart';
import '../widgets/user_mention.dart'; import '../widgets/user_mention.dart';
class Comments extends StatefulWidget { class Comments extends StatefulWidget {
@ -83,6 +80,7 @@ class _CommentsState extends State<Comments> {
) )
: null, : null,
padding: const EdgeInsets.only(left: 16, right: 16, bottom: 92), padding: const EdgeInsets.only(left: 16, right: 16, bottom: 92),
showSliversFirst: false,
slivers: [ slivers: [
Consumer<CommentsState>( Consumer<CommentsState>(
builder: (context, state, child) => builder: (context, state, child) =>
@ -93,7 +91,8 @@ class _CommentsState extends State<Comments> {
childCount: state.comments.length, childCount: state.comments.length,
placeholder: const _CommentPlaceholder(), placeholder: const _CommentPlaceholder(),
centerEmptyState: _isPage, centerEmptyState: _isPage,
enableEmptyState: state.comments.isEmpty, enableEmptyState:
state.comments.isEmpty && state.privateComments.isEmpty,
emptyState: EmptyState( emptyState: EmptyState(
asset: Assets.emptyChat, asset: Assets.emptyChat,
title: 'اولین نظر را بنویسید...', title: 'اولین نظر را بنویسید...',
@ -109,6 +108,35 @@ class _CommentsState extends State<Comments> {
), ),
), ),
], ],
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( AnimatedVisibility(
duration: DesignConfig.lowAnimationDuration, duration: DesignConfig.lowAnimationDuration,
@ -162,6 +190,23 @@ class _CommentsState extends State<Comments> {
), ),
); );
} }
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 { class _MessageBox extends StatefulWidget {
@ -178,7 +223,7 @@ class _MessageBoxState extends State<_MessageBox> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final state = context.watch<CommentsState>(); final state = context.watch<CommentsState>();
void _onCheckBoxChange(bool b) { void onCheckBoxChange(bool b) {
state.hideMentionedUser = b; state.hideMentionedUser = b;
state.update(); state.update();
} }
@ -263,16 +308,10 @@ class _MessageBoxState extends State<_MessageBox> {
decoration: BoxDecoration( decoration: BoxDecoration(
color: Theme.of(context).colorScheme.secondCTA, color: Theme.of(context).colorScheme.secondCTA,
borderRadius: !state.showReplyBox borderRadius: !state.showReplyBox
? BorderRadius.only( ? const BorderRadius.only(
topLeft: Radius.circular(16), topLeft: Radius.circular(16),
topRight: Radius.circular(16)) topRight: Radius.circular(16))
: null : null),
// border: Border(
// top: BorderSide(
// color: Theme.of(context).colorScheme.border,
// ),
// ),
),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
@ -285,7 +324,7 @@ class _MessageBoxState extends State<_MessageBox> {
width: 2, width: 2,
height: 40, height: 40,
), ),
SizedBox( const SizedBox(
width: 8, width: 8,
), ),
Column( Column(
@ -322,10 +361,10 @@ class _MessageBoxState extends State<_MessageBox> {
title: "پنهان کردن فراخوانی", title: "پنهان کردن فراخوانی",
value: state.hideMentionedUser, value: state.hideMentionedUser,
color: Theme.of(context).colorScheme.primary, color: Theme.of(context).colorScheme.primary,
onChanged: _onCheckBoxChange, onChanged: onCheckBoxChange,
size: 12, size: 12,
) )
: SizedBox(), : const SizedBox(),
], ],
) )
], ],
@ -353,11 +392,6 @@ class _MessageBoxState extends State<_MessageBox> {
color: state.showReplyBox && state.usersMentioned.name == null color: state.showReplyBox && state.usersMentioned.name == null
? Theme.of(context).colorScheme.secondCTA ? Theme.of(context).colorScheme.secondCTA
: Theme.of(context).colorScheme.surface, : Theme.of(context).colorScheme.surface,
// border: Border(
// top: BorderSide(
// color: Theme.of(context).colorScheme.border,
// ),
// ),
), ),
child: Row( child: Row(
children: [ children: [

View File

@ -11,7 +11,6 @@ import 'package:didvan/providers/user.dart';
import 'package:didvan/services/network/request.dart'; import 'package:didvan/services/network/request.dart';
import 'package:didvan/services/network/request_helper.dart'; import 'package:didvan/services/network/request_helper.dart';
import 'package:didvan/utils/action_sheet.dart'; import 'package:didvan/utils/action_sheet.dart';
import 'package:didvan/views/widgets/user_mention.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@ -23,12 +22,14 @@ class CommentsState extends CoreProvier {
UserOverview? replyingTo; UserOverview? replyingTo;
bool showReplyBox = false; bool showReplyBox = false;
bool showUsersForMentionsLayout = false; bool showUsersForMentionsLayout = false;
bool showPrivates = false;
bool hideMentionedUser = false; bool hideMentionedUser = false;
late void Function(int count) onCommentsChanged; late void Function(int count) onCommentsChanged;
int _count = 0; int _count = 0;
late String type; late String type;
final List<CommentData> comments = []; final List<CommentData> comments = [];
final List<CommentData> privateComments = [];
final List<UsersMention> usersMention = []; final List<UsersMention> usersMention = [];
final Map<int, MapEntry<bool, bool>> _feedbackQueue = {}; final Map<int, MapEntry<bool, bool>> _feedbackQueue = {};
@ -41,11 +42,20 @@ class CommentsState extends CoreProvier {
await service.httpGet(); await service.httpGet();
if (service.isSuccess) { if (service.isSuccess) {
comments.clear(); comments.clear();
final messages = service.result['comments']['public']; final messagesPublic = service.result['comments']['public'];
for (var i = 0; i < messages.length; i++) { for (var i = 0; i < messagesPublic.length; i++) {
comments.add(CommentData.fromJson(messages[i], false)); comments.add(CommentData.fromJson(messagesPublic[i], false));
_count++; _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++; _count++;
} }
} }
@ -112,6 +122,8 @@ class CommentsState extends CoreProvier {
} }
Future<void> addComment() async { Future<void> addComment() async {
late List<CommentData> cList =
hideMentionedUser ? privateComments : comments;
final user = DesignConfig.context!.read<UserProvider>().user; final user = DesignConfig.context!.read<UserProvider>().user;
if (replyingTo != null) { if (replyingTo != null) {
comments.firstWhere((comment) => comment.id == commentId).replies.add( comments.firstWhere((comment) => comment.id == commentId).replies.add(
@ -133,25 +145,25 @@ class CommentsState extends CoreProvier {
), ),
); );
} else { } else {
comments.insert( cList.insert(
0, 0,
CommentData( CommentData(
id: 0, id: 0,
text: commentTextFieldController.text, text: commentTextFieldController.text,
createdAt: DateTime.now().toString(), createdAt: DateTime.now().toString(),
liked: false, liked: false,
disliked: false, disliked: false,
feedback: FeedbackData(like: 0, dislike: 0), feedback: FeedbackData(like: 0, dislike: 0),
user: UserOverview( user: UserOverview(
id: user.id, id: user.id,
fullName: user.fullName, fullName: user.fullName,
photo: user.photo, photo: user.photo,
), ),
replies: [], replies: [],
status: 2, status: 2,
private: hideMentionedUser, private: hideMentionedUser,
mention: usersMentioned.name, mention: usersMentioned.name,
), ),
); );
} }
@ -180,13 +192,13 @@ class CommentsState extends CoreProvier {
await service.post(); await service.post();
if (service.isSuccess) { if (service.isSuccess) {
if (replyingTo != null) { if (replyingTo != null) {
comments cList
.firstWhere((comment) => comment.id == commentId) .firstWhere((comment) => comment.id == commentId)
.replies .replies
.firstWhere((reply) => reply.id == 0) .firstWhere((reply) => reply.id == 0)
.id = service.result['comment']['id']; .id = service.result['comment']['id'];
} else { } else {
comments.firstWhere((comment) => comment.id == 0).id = cList.firstWhere((comment) => comment.id == 0).id =
service.result['comment']['id']; service.result['comment']['id'];
} }
commentId = null; commentId = null;

View File

@ -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,
)),
],
),
);
}
}

View File

@ -101,7 +101,7 @@ class _DidvanScaffoldState extends State<DidvanScaffold> {
), ),
if (widget.children != null && !widget.showSliversFirst) if (widget.children != null && !widget.showSliversFirst)
SliverPadding( SliverPadding(
padding: widget.padding, padding: widget.padding.copyWith(bottom: 16),
sliver: SliverList( sliver: SliverList(
delegate: SliverChildBuilderDelegate( delegate: SliverChildBuilderDelegate(
(context, index) => widget.children![index], (context, index) => widget.children![index],