1021 lines
35 KiB
Dart
1021 lines
35 KiB
Dart
import 'dart:async';
|
|
import 'dart:convert';
|
|
import 'dart:io';
|
|
import 'package:get/get.dart';
|
|
import 'package:onufitness/constants/api_enum_constant.dart';
|
|
import 'package:onufitness/controller/get_agora_token_controller.dart';
|
|
import 'package:onufitness/controller/notification_controller.dart';
|
|
import 'package:onufitness/routes/route_constant.dart';
|
|
import 'package:onufitness/screens/accounts/Controllers/coach_rating_controller.dart';
|
|
import 'package:onufitness/screens/chat/controllers/chat_controller.dart';
|
|
import 'package:onufitness/screens/chat/views/chat_inside_screen.dart';
|
|
import 'package:onufitness/screens/echoboard/controllers/connection_and_tribe_controller.dart';
|
|
import 'package:onufitness/screens/echoboard/controllers/echoboard_controller.dart';
|
|
import 'package:onufitness/screens/echoboard/views/single_post_screen.dart';
|
|
import 'package:onufitness/screens/echoboard/views/tribe_echoboard/tribe_echoboard_post_list_screen.dart';
|
|
import 'package:onufitness/screens/goals/controllers/goal_controller.dart';
|
|
import 'package:onufitness/screens/login/views/login_screen.dart';
|
|
import 'package:onufitness/screens/navbar/bottom_nav_bar.dart';
|
|
import 'package:onufitness/screens/rise/controllers/rise_controller.dart';
|
|
import 'package:onufitness/screens/streamming/controllers/get_api_live_streams_controller.dart';
|
|
import 'package:onufitness/services/agora/agora_chat_service.dart';
|
|
import 'package:onufitness/services/agora/call_services.dart';
|
|
import 'package:onufitness/services/local_storage_services/shared_services.dart';
|
|
import 'package:onufitness/utils/custom_sneakbar.dart';
|
|
|
|
class NotificationNavigationController extends GetxController {
|
|
RxString streamID = "".obs;
|
|
RxBool isCallingNotificationNavigation = false.obs;
|
|
RxBool isNotificationNavigation = false.obs;
|
|
|
|
void setFlagsFromPayload(Map<String, dynamic> data) {
|
|
try {
|
|
final notificationType = data['notificationType'];
|
|
|
|
int? typeAsInt;
|
|
if (notificationType is int) {
|
|
typeAsInt = notificationType;
|
|
} else if (notificationType is String) {
|
|
typeAsInt = int.tryParse(notificationType);
|
|
}
|
|
|
|
// Set flags based on notification type
|
|
if (typeAsInt != null && typeAsInt == ApiEnum.CallingNotification) {
|
|
isCallingNotificationNavigation.value = true;
|
|
isNotificationNavigation.value = false;
|
|
} else {
|
|
isNotificationNavigation.value = true;
|
|
isCallingNotificationNavigation.value = false;
|
|
}
|
|
} catch (e) {
|
|
// Fallback to normal notification
|
|
isNotificationNavigation.value = true;
|
|
isCallingNotificationNavigation.value = false;
|
|
}
|
|
}
|
|
|
|
Future<void> navigateBasedOnNotification(Map<String, dynamic> data) async {
|
|
await Future.delayed(const Duration(milliseconds: 100));
|
|
|
|
//................................................................................
|
|
try {
|
|
final notificationType = data['notificationType'];
|
|
|
|
// Convert string to integer for comparison
|
|
int? typeAsInt;
|
|
|
|
if (notificationType is int) {
|
|
typeAsInt = notificationType;
|
|
} else if (notificationType is String) {
|
|
typeAsInt = int.tryParse(notificationType);
|
|
}
|
|
|
|
if (typeAsInt == ApiEnum.LiveStream) {
|
|
try {
|
|
if (data['dataId'] != null) {
|
|
var dataId = data['dataId'];
|
|
|
|
// If dataId is a string (JSON), parse it
|
|
if (dataId is String) {
|
|
final parsedDataId = jsonDecode(dataId);
|
|
if (parsedDataId is Map && parsedDataId['StreamID'] != null) {
|
|
streamID.value = parsedDataId['StreamID'].toString();
|
|
}
|
|
}
|
|
// If dataId is already a Map
|
|
else if (dataId is Map && dataId['StreamID'] != null) {
|
|
streamID.value = dataId['StreamID'].toString();
|
|
}
|
|
}
|
|
} catch (e) {
|
|
// Error parsing dataId
|
|
}
|
|
}
|
|
|
|
// Use if-else instead of switch to avoid type issues
|
|
if (typeAsInt == ApiEnum.Goal) {
|
|
await navigateToGoalScreen();
|
|
} else if (typeAsInt == ApiEnum.Challenge) {
|
|
await navigateToChallengeScreen();
|
|
} else if (typeAsInt == ApiEnum.ConnectionRequest) {
|
|
await navigateToConnectionRequestScreen();
|
|
} else if (typeAsInt == ApiEnum.Post) {
|
|
await navigateToPostScreen(data);
|
|
} else if (typeAsInt == ApiEnum.RequestAccepted) {
|
|
await navigateToFriendsScreen();
|
|
} else if (typeAsInt == ApiEnum.CoachRequest) {
|
|
navigateToDefault();
|
|
} else if (typeAsInt == ApiEnum.ReportPost) {
|
|
navigateToDefault();
|
|
} else if (typeAsInt == ApiEnum.ChallengeCompleted) {
|
|
await navigateToJoinedChallengeTab();
|
|
} else if (typeAsInt == ApiEnum.GoalCompleted) {
|
|
await navigateToJoinedGoaltab();
|
|
} else if (typeAsInt == ApiEnum.LiveStream) {
|
|
await navigateToLiveStreamScreen();
|
|
} else if (typeAsInt == ApiEnum.CallingNotification) {
|
|
await navigateToCallScreen(data);
|
|
} else if (typeAsInt == ApiEnum.CommentPost) {
|
|
await navigateToPostScreen(data);
|
|
} else if (typeAsInt == ApiEnum.ReactPost) {
|
|
await navigateToPostScreen(data);
|
|
} else if (typeAsInt == ApiEnum.SubCommentPost) {
|
|
await navigateToPostScreen(data);
|
|
} else if (typeAsInt == ApiEnum.CoachApproval) {
|
|
navigateToDefault;
|
|
} else if (typeAsInt == ApiEnum.RemainGoal) {
|
|
await navigateToJoinedGoaltab();
|
|
} else if (typeAsInt == ApiEnum.RemainChallenge) {
|
|
await navigateToJoinedChallengeTab();
|
|
} else if (typeAsInt == ApiEnum.GoalProgressStatus) {
|
|
await navigateToJoinedGoaltab();
|
|
} else if (typeAsInt == ApiEnum.ChallengeProgressStatus) {
|
|
await navigateToJoinedChallengeTab();
|
|
} else if (typeAsInt == ApiEnum.AddTribeMember) {
|
|
await navigateToViewTribeScreen(data);
|
|
} else if (typeAsInt == ApiEnum.CallingNotificationCancel) {
|
|
await navigateToChatDetailScreen(data);
|
|
} else if (typeAsInt == ApiEnum.ChatNotification) {
|
|
await navigateToChatDetailScreen(data);
|
|
} else if (typeAsInt == ApiEnum.GroupChatNotification) {
|
|
await navigateToGroupChatDetailsScreen(data);
|
|
} else {
|
|
navigateToDefault();
|
|
}
|
|
} catch (e) {
|
|
navigateToDefault();
|
|
}
|
|
}
|
|
|
|
//....................................................................................................................................
|
|
|
|
//..........................................................................................................................
|
|
Future<void> navigateToCallScreen(Map<String, dynamic> data) async {
|
|
isCallingNotificationNavigation.value = true;
|
|
try {
|
|
if (!Get.isRegistered<AgoraCallService>()) {
|
|
Get.put(AgoraCallService());
|
|
}
|
|
|
|
await AgoraCallService.instance.init();
|
|
String? dataIdString = data['dataId'];
|
|
Map<String, dynamic>? notificationCallData;
|
|
|
|
if (dataIdString != null) {
|
|
try {
|
|
notificationCallData = jsonDecode(dataIdString);
|
|
} catch (e) {
|
|
// Error parsing dataId
|
|
}
|
|
}
|
|
|
|
if (notificationCallData != null) {
|
|
// Setup call data in Agora service
|
|
AgoraCallService.instance.channelName.value =
|
|
notificationCallData['ChannelName'] ?? '';
|
|
AgoraCallService.instance.remoteUserId.value =
|
|
notificationCallData['UserID'] ?? '';
|
|
AgoraCallService.instance.callerProfilePic.value =
|
|
notificationCallData['ProfilePicture'] ?? '';
|
|
AgoraCallService.instance.callerName.value =
|
|
notificationCallData['CallerName'] ?? '';
|
|
AgoraCallService.instance.currentCallType.value =
|
|
notificationCallData['CallType'] == 'VIDEO'
|
|
? CallType.video
|
|
: CallType.voice;
|
|
|
|
AgoraCallService.instance.callState.value = CallState.ringing;
|
|
AgoraCallService.instance.amICaller.value = false;
|
|
if (AgoraCallService.instance.currentCallType.value == CallType.video) {
|
|
await AgoraCallService.instance.startVideoPreview();
|
|
}
|
|
|
|
// Fetch RTC token here (important for terminated state)
|
|
if (!Get.isRegistered<AgoraTokenController>()) {
|
|
Get.put(AgoraTokenController());
|
|
}
|
|
final agoraTokenController = Get.find<AgoraTokenController>();
|
|
bool tokenOk = await agoraTokenController.getRTCtoken(
|
|
channelName: AgoraCallService.instance.channelName.value,
|
|
role: ApiEnum.SUBSCRIBER,
|
|
);
|
|
if (tokenOk) {
|
|
AgoraCallService.instance.rtcToken.value =
|
|
agoraTokenController.rTCtoken.value;
|
|
}
|
|
if (Platform.isIOS &&
|
|
(Get.currentRoute != RouteConstant.incomingCallScreen &&
|
|
Get.currentRoute != RouteConstant.splashScreen)) {
|
|
// Navigate to incoming call screen
|
|
Get.toNamed(RouteConstant.incomingCallScreen);
|
|
}
|
|
} else {
|
|
navigateToDefault();
|
|
}
|
|
} catch (e) {
|
|
navigateToDefault();
|
|
}
|
|
}
|
|
//==================================================================================================================
|
|
//....Below codes is Chat Related code...............................................................................
|
|
//==================================================================================================================
|
|
|
|
// Future<void> navigateToChatListScreen() async {
|
|
// isNotificationNavigation(true);
|
|
|
|
// try {
|
|
// if (Get.currentRoute == RouteConstant.splashScreen) {
|
|
// Get.offNamedUntil(
|
|
// RouteConstant.dashboardScreen,
|
|
// (route) => false,
|
|
// arguments: 0,
|
|
// );
|
|
// }
|
|
// //..................................................
|
|
// if (!Get.isRegistered<ChatController>()) {
|
|
// Get.put(ChatController());
|
|
// }
|
|
|
|
// if (!Get.isRegistered<RatingsReviewsController>()) {
|
|
// Get.put(RatingsReviewsController());
|
|
// }
|
|
|
|
// if (!Get.isRegistered<NotificationController>()) {
|
|
// Get.put(NotificationController());
|
|
|
|
// if (!Get.isRegistered<NavigationController>()) {
|
|
// Get.put(NavigationController());
|
|
// }
|
|
// if (!Get.isRegistered<EchoBoardController>()) {
|
|
// Get.put(EchoBoardController());
|
|
// }
|
|
// }
|
|
// //..................................................
|
|
// await agoraChatTokenAPIcall();
|
|
|
|
// Get.toNamed(RouteConstant.chatListScreen);
|
|
// log("Navigated directly to Chat List Screen successfully");
|
|
// } catch (e) {
|
|
// log("Error navigating to chat after dashboard load: $e");
|
|
// navigateToDefault();
|
|
// }
|
|
// }
|
|
//...........................................................................................................................
|
|
|
|
Future<void> navigateToChatDetailScreen(Map<String, dynamic> data) async {
|
|
isNotificationNavigation(true);
|
|
// Initialize required controllers if needed
|
|
if (Get.currentRoute == RouteConstant.splashScreen) {
|
|
Get.offNamedUntil(
|
|
RouteConstant.dashboardScreen,
|
|
(route) => false,
|
|
arguments: 0,
|
|
);
|
|
}
|
|
|
|
try {
|
|
// Parse dataId to get chat information
|
|
String? dataIdString = data['dataId'];
|
|
Map<String, dynamic>? chatData;
|
|
|
|
if (dataIdString != null) {
|
|
try {
|
|
// Clean the JSON string by removing control characters
|
|
String cleanedDataId =
|
|
dataIdString
|
|
.replaceAll(
|
|
RegExp(r'[\n\r\t]'),
|
|
' ',
|
|
) // Replace newlines, returns, tabs with space
|
|
.replaceAll(
|
|
RegExp(r'\s+'),
|
|
' ',
|
|
) // Replace multiple spaces with single space
|
|
.trim();
|
|
|
|
chatData = jsonDecode(cleanedDataId);
|
|
} catch (e) {
|
|
// Try alternative parsing if the above fails
|
|
try {
|
|
// Remove all control characters (ASCII 0-31 except space)
|
|
String sanitizedDataId = dataIdString.replaceAll(
|
|
RegExp(r'[\x00-\x09\x0B-\x0C\x0E-\x1F\x7F]'),
|
|
'',
|
|
);
|
|
chatData = jsonDecode(sanitizedDataId);
|
|
} catch (e2) {
|
|
// Failed to parse even after sanitization
|
|
}
|
|
}
|
|
}
|
|
|
|
if (chatData != null) {
|
|
// Extract chat details
|
|
final userId = chatData['UserID'] ?? '';
|
|
final callerName =
|
|
chatData['CallerName'] ??
|
|
'${chatData['CallerFirstName'] ?? ''} ${chatData['CallerLastName'] ?? ''}'
|
|
.trim();
|
|
final profilePicture = chatData['ProfilePicture'] ?? '';
|
|
|
|
if (!Get.isRegistered<ChatController>()) {
|
|
Get.put(ChatController());
|
|
}
|
|
|
|
if (!Get.isRegistered<RatingsReviewsController>()) {
|
|
Get.put(RatingsReviewsController());
|
|
}
|
|
|
|
if (!Get.isRegistered<NotificationController>()) {
|
|
Get.put(NotificationController());
|
|
}
|
|
|
|
if (!Get.isRegistered<NavigationController>()) {
|
|
Get.put(NavigationController());
|
|
}
|
|
|
|
if (!Get.isRegistered<EchoBoardController>()) {
|
|
Get.put(EchoBoardController());
|
|
}
|
|
|
|
if (!Get.isRegistered<AgoraChatService>()) {
|
|
Get.put(AgoraChatService());
|
|
}
|
|
await agoraChatTokenAPIcall();
|
|
|
|
// Get ChatController and ensure it's initialized
|
|
final chatController = Get.find<ChatController>();
|
|
|
|
// IMPORTANT: Set the selected user BEFORE navigating
|
|
chatController.selectedUserId.value = userId;
|
|
|
|
// Navigate directly to ChatDetailScreen
|
|
Get.to(
|
|
() => ChatDetailScreen(
|
|
targetUserId: userId,
|
|
targetUserName: callerName,
|
|
targetUserAvatar: profilePicture,
|
|
isGroupMessage: false,
|
|
),
|
|
);
|
|
} else {
|
|
navigateToDefault();
|
|
}
|
|
} catch (e) {
|
|
// Fallback to chat list screen on error
|
|
navigateToDefault();
|
|
}
|
|
}
|
|
|
|
//................................................................................................................
|
|
Future<void> navigateToGroupChatDetailsScreen(
|
|
Map<String, dynamic> data,
|
|
) async {
|
|
isNotificationNavigation(true);
|
|
|
|
try {
|
|
// Parse dataId to get tribe chat information
|
|
String? dataIdString = data['dataId'];
|
|
Map<String, dynamic>? chatData;
|
|
|
|
if (dataIdString != null) {
|
|
try {
|
|
// Clean the JSON string by removing control characters
|
|
String cleanedDataId =
|
|
dataIdString
|
|
.replaceAll(
|
|
RegExp(r'[\n\r\t]'),
|
|
' ',
|
|
) // Replace newlines, returns, tabs with space
|
|
.replaceAll(
|
|
RegExp(r'\s+'),
|
|
' ',
|
|
) // Replace multiple spaces with single space
|
|
.trim();
|
|
|
|
chatData = jsonDecode(cleanedDataId);
|
|
} catch (e) {
|
|
// Try alternative parsing if the above fails
|
|
try {
|
|
// Remove all control characters (ASCII 0-31 except space)
|
|
String sanitizedDataId = dataIdString.replaceAll(
|
|
RegExp(r'[\x00-\x09\x0B-\x0C\x0E-\x1F\x7F]'),
|
|
'',
|
|
);
|
|
chatData = jsonDecode(sanitizedDataId);
|
|
} catch (e2) {
|
|
// Failed to parse even after sanitization
|
|
}
|
|
}
|
|
}
|
|
|
|
if (chatData != null) {
|
|
// Extract tribe chat details
|
|
final tribeAgoraId = chatData['TribeAgoraId'] ?? '';
|
|
final tribrName = chatData['TribeName'] ?? '';
|
|
final tribeImage = chatData['TribeImage'] ?? '';
|
|
|
|
// Initialize required controllers if needed
|
|
if (Get.currentRoute == RouteConstant.splashScreen) {
|
|
Get.offNamedUntil(
|
|
RouteConstant.dashboardScreen,
|
|
(route) => false,
|
|
arguments: 0,
|
|
);
|
|
}
|
|
|
|
if (!Get.isRegistered<ChatController>()) {
|
|
Get.put(ChatController());
|
|
}
|
|
|
|
if (!Get.isRegistered<RatingsReviewsController>()) {
|
|
Get.put(RatingsReviewsController());
|
|
}
|
|
|
|
if (!Get.isRegistered<NotificationController>()) {
|
|
Get.put(NotificationController());
|
|
}
|
|
|
|
if (!Get.isRegistered<NavigationController>()) {
|
|
Get.put(NavigationController());
|
|
}
|
|
|
|
if (!Get.isRegistered<EchoBoardController>()) {
|
|
Get.put(EchoBoardController());
|
|
}
|
|
await agoraChatTokenAPIcall();
|
|
|
|
// Get ChatController
|
|
final chatController = Get.find<ChatController>();
|
|
// Set group chat flag and selected user
|
|
chatController.isGroupChattt.value = true;
|
|
|
|
Get.to(
|
|
() => ChatDetailScreen(
|
|
targetUserId: tribeAgoraId,
|
|
targetUserName: tribrName,
|
|
targetUserAvatar: tribeImage,
|
|
isGroupMessage: true,
|
|
),
|
|
);
|
|
} else {
|
|
navigateToDefault();
|
|
}
|
|
} catch (e) {
|
|
// Fallback to chat list screen on error
|
|
navigateToDefault();
|
|
}
|
|
}
|
|
|
|
//......................................................................................................
|
|
Future<void> agoraChatTokenAPIcall() async {
|
|
try {
|
|
if (!Get.isRegistered<AgoraTokenController>()) {
|
|
Get.put(AgoraTokenController());
|
|
}
|
|
final agoraTokenController = Get.find<AgoraTokenController>();
|
|
|
|
final success = await agoraTokenController.getAgoraUserAndRrmToken();
|
|
if (success) {
|
|
await agoraChatCallServicesLogin();
|
|
} else {
|
|
// Agora token fetch failed
|
|
}
|
|
} catch (e) {
|
|
// Error in agoraChatTokenAPIcall
|
|
}
|
|
}
|
|
|
|
Future<void> agoraChatCallServicesLogin() async {
|
|
// Agora Chat Service Initialization
|
|
await chatLoginToAgora();
|
|
//Small delay
|
|
await Future.delayed(Duration(milliseconds: 500));
|
|
// Agora Call Service Initialization
|
|
await Get.find<AgoraCallService>().agoraRTMlogin();
|
|
}
|
|
|
|
chatLoginToAgora() async {
|
|
if (!Get.isRegistered<AgoraChatService>()) {
|
|
Get.put(await AgoraChatService().init(), permanent: true);
|
|
} else {
|
|
final chatService = Get.find<AgoraChatService>();
|
|
await chatService.initChatSdk();
|
|
await chatService.loginToAgora();
|
|
}
|
|
}
|
|
|
|
//==================================================================================================================
|
|
//....Above one is Chat Related code...............................................................................
|
|
//==================================================================================================================
|
|
|
|
Future<void> navigateToGoalScreen() async {
|
|
isNotificationNavigation(true);
|
|
// Initialize required controllers if needed
|
|
if (Get.currentRoute == RouteConstant.splashScreen) {
|
|
Get.offNamedUntil(
|
|
RouteConstant.dashboardScreen,
|
|
(route) => false,
|
|
arguments: 0,
|
|
);
|
|
}
|
|
|
|
try {
|
|
// Ensure controllers are registered
|
|
if (!Get.isRegistered<NavigationController>()) {
|
|
Get.put(NavigationController());
|
|
}
|
|
if (!Get.isRegistered<GoalController>()) {
|
|
Get.put(GoalController());
|
|
}
|
|
|
|
final navController = Get.find<NavigationController>();
|
|
final goalController = Get.find<GoalController>();
|
|
|
|
if (Get.currentRoute == RouteConstant.dashboardScreen) {
|
|
await goalController.fetchAllExploreGoals(isRefresh: true);
|
|
navController.changeIndex(2);
|
|
} else {
|
|
await goalController.fetchAllExploreGoals(isRefresh: true);
|
|
Get.toNamed(RouteConstant.goalScreen, arguments: 2);
|
|
}
|
|
} catch (e) {
|
|
navigateToDefault();
|
|
}
|
|
}
|
|
|
|
//..........................................................................................................................
|
|
Future<void> navigateToJoinedGoaltab() async {
|
|
isNotificationNavigation(true);
|
|
// Initialize required controllers if needed
|
|
if (Get.currentRoute == RouteConstant.splashScreen) {
|
|
Get.offNamedUntil(
|
|
RouteConstant.dashboardScreen,
|
|
(route) => false,
|
|
arguments: 0,
|
|
);
|
|
}
|
|
|
|
try {
|
|
// Ensure controllers are registered
|
|
if (!Get.isRegistered<NavigationController>()) {
|
|
Get.put(NavigationController());
|
|
}
|
|
if (!Get.isRegistered<GoalController>()) {
|
|
Get.put(GoalController());
|
|
}
|
|
|
|
final navController = Get.find<NavigationController>();
|
|
final goalController = Get.find<GoalController>();
|
|
|
|
if (Get.currentRoute == RouteConstant.dashboardScreen) {
|
|
await goalController.fetchAllExploreGoals(isRefresh: true);
|
|
navController.changeIndex(2);
|
|
goalController.selectedTabIndex.value = 1;
|
|
goalController.switchTab(1);
|
|
} else {
|
|
await goalController.fetchAllExploreGoals(isRefresh: true);
|
|
Get.toNamed(RouteConstant.goalScreen, arguments: 2);
|
|
goalController.selectedTabIndex.value = 1;
|
|
goalController.switchTab(1);
|
|
}
|
|
} catch (e) {
|
|
navigateToDefault();
|
|
}
|
|
}
|
|
|
|
//..........................................................................................................................
|
|
Future<void> navigateToChallengeScreen() async {
|
|
isNotificationNavigation(true);
|
|
|
|
try {
|
|
if (Get.currentRoute == RouteConstant.splashScreen) {
|
|
Get.offNamedUntil(
|
|
RouteConstant.dashboardScreen,
|
|
(route) => false,
|
|
arguments: 0,
|
|
);
|
|
}
|
|
//..................................................
|
|
if (!Get.isRegistered<RatingsReviewsController>()) {
|
|
Get.put(RatingsReviewsController());
|
|
}
|
|
if (!Get.isRegistered<ChatController>()) {
|
|
Get.put(ChatController());
|
|
}
|
|
if (!Get.isRegistered<NotificationController>()) {
|
|
Get.put(NotificationController());
|
|
}
|
|
|
|
if (!Get.isRegistered<RiseController>()) {
|
|
Get.put(RiseController());
|
|
}
|
|
//....................................................
|
|
|
|
final challengeController = Get.find<RiseController>();
|
|
Get.toNamed(RouteConstant.challengeListScreen);
|
|
await challengeController.fetchOngoingChallenges(isRefresh: true);
|
|
await challengeController.fetchUpcomingChallenges(isRefresh: true);
|
|
await challengeController.fetchJoinedChallenges(isRefresh: true);
|
|
} catch (e) {
|
|
navigateToDefault();
|
|
}
|
|
}
|
|
|
|
//..........................................................................................................................
|
|
Future<void> navigateToJoinedChallengeTab() async {
|
|
isNotificationNavigation(true);
|
|
|
|
try {
|
|
if (Get.currentRoute == RouteConstant.splashScreen) {
|
|
Get.offNamedUntil(
|
|
RouteConstant.dashboardScreen,
|
|
(route) => false,
|
|
arguments: 0,
|
|
);
|
|
}
|
|
//..................................................
|
|
if (!Get.isRegistered<RatingsReviewsController>()) {
|
|
Get.put(RatingsReviewsController());
|
|
}
|
|
if (!Get.isRegistered<ChatController>()) {
|
|
Get.put(ChatController());
|
|
}
|
|
if (!Get.isRegistered<NotificationController>()) {
|
|
Get.put(NotificationController());
|
|
}
|
|
if (!Get.isRegistered<RiseController>()) {
|
|
Get.put(RiseController());
|
|
}
|
|
//...................................................
|
|
final challengeController = Get.find<RiseController>();
|
|
|
|
Get.toNamed(
|
|
RouteConstant.challengeListScreen,
|
|
arguments: {'tabIndex': 2},
|
|
);
|
|
await challengeController.fetchJoinedChallenges(isRefresh: true);
|
|
await challengeController.fetchOngoingChallenges(isRefresh: true);
|
|
await challengeController.fetchUpcomingChallenges(isRefresh: true);
|
|
} catch (e) {
|
|
navigateToDefault();
|
|
}
|
|
}
|
|
|
|
//..........................................................................................................................
|
|
Future<void> navigateToPostScreen(Map<String, dynamic> data) async {
|
|
isNotificationNavigation(true);
|
|
|
|
try {
|
|
Map<String, dynamic>? dataIdMap;
|
|
if (data['dataId'] != null && data['dataId'] is String) {
|
|
dataIdMap = jsonDecode(data['dataId']);
|
|
}
|
|
|
|
final tribeId = dataIdMap?['TribeID'];
|
|
// Check if TribeID exists and is not null/empty
|
|
if (tribeId != null && tribeId.toString().isNotEmpty) {
|
|
// Navigate to tribe echoboard
|
|
await navigateToTribeEchoboardScreen(data);
|
|
} else {
|
|
// Navigate to regular echoboard
|
|
await navigateToEchoboardScreen(data);
|
|
}
|
|
} catch (e) {
|
|
navigateToDefault();
|
|
}
|
|
}
|
|
|
|
//..........................................................................................
|
|
//..........................................................................................
|
|
Future<void> navigateToTribeEchoboardScreen(Map<String, dynamic> data) async {
|
|
if (Get.currentRoute == RouteConstant.splashScreen) {
|
|
Get.offNamedUntil(
|
|
RouteConstant.dashboardScreen,
|
|
(route) => false,
|
|
arguments: 0,
|
|
);
|
|
}
|
|
|
|
try {
|
|
Map<String, dynamic>? dataIdMap;
|
|
if (data['dataId'] != null && data['dataId'] is String) {
|
|
dataIdMap = jsonDecode(data['dataId']);
|
|
}
|
|
|
|
final postId = dataIdMap?['PostID'];
|
|
final tribeId = dataIdMap?['TribeID'];
|
|
|
|
if (postId == null || tribeId == null) {
|
|
navigateToDefault();
|
|
return;
|
|
}
|
|
|
|
// Initialize controllers
|
|
if (!Get.isRegistered<SocialConnectionController>()) {
|
|
Get.put(SocialConnectionController());
|
|
}
|
|
|
|
final socialConnectionController = Get.find<SocialConnectionController>();
|
|
|
|
// Load tribe details
|
|
final tribeDetailsLoaded = await socialConnectionController
|
|
.getSingleTribeDetails(tribeId: int.parse(tribeId.toString()));
|
|
if (tribeDetailsLoaded) {
|
|
controllerInitialization();
|
|
|
|
// Navigate to SinglePostPage with tribe context
|
|
Get.to(
|
|
() => SinglePostPage(
|
|
postId: postId.toString(),
|
|
tribeId: int.parse(tribeId.toString()),
|
|
),
|
|
);
|
|
} else {
|
|
customSnackbar(
|
|
title: "Error",
|
|
message: "Failed to load tribe details",
|
|
duration: 2,
|
|
);
|
|
navigateToDefault();
|
|
}
|
|
} catch (e) {
|
|
navigateToDefault();
|
|
}
|
|
}
|
|
|
|
//..........................................................................................................................
|
|
//..........................................................................................................................
|
|
Future<void> navigateToEchoboardScreen(Map<String, dynamic> data) async {
|
|
if (Get.currentRoute == RouteConstant.splashScreen) {
|
|
Get.offNamedUntil(
|
|
RouteConstant.dashboardScreen,
|
|
(route) => false,
|
|
arguments: 0,
|
|
);
|
|
}
|
|
|
|
try {
|
|
Map<String, dynamic>? dataIdMap;
|
|
if (data['dataId'] != null && data['dataId'] is String) {
|
|
dataIdMap = jsonDecode(data['dataId']);
|
|
}
|
|
|
|
final postId = dataIdMap?['PostID'];
|
|
|
|
if (postId == null) {
|
|
navigateToDefault();
|
|
return;
|
|
}
|
|
|
|
// Initialize required controllers
|
|
controllerInitialization();
|
|
|
|
// Navigate directly to SinglePostPage
|
|
Get.to(() => SinglePostPage(postId: postId.toString(), tribeId: 0));
|
|
} catch (e) {
|
|
navigateToDefault();
|
|
}
|
|
}
|
|
|
|
//..........................................................................................................................
|
|
//..........................................................................................................................
|
|
Future<void> navigateToConnectionRequestScreen() async {
|
|
isNotificationNavigation(true);
|
|
|
|
try {
|
|
if (Get.currentRoute == RouteConstant.splashScreen) {
|
|
Get.offNamedUntil(
|
|
RouteConstant.dashboardScreen,
|
|
(route) => false,
|
|
arguments: 0,
|
|
);
|
|
}
|
|
//..................................................
|
|
if (!Get.isRegistered<RatingsReviewsController>()) {
|
|
Get.put(RatingsReviewsController());
|
|
}
|
|
if (!Get.isRegistered<ChatController>()) {
|
|
Get.put(ChatController());
|
|
}
|
|
if (!Get.isRegistered<NotificationController>()) {
|
|
Get.put(NotificationController());
|
|
}
|
|
//...................................................
|
|
|
|
// Ensure controller is registered
|
|
if (!Get.isRegistered<SocialConnectionController>()) {
|
|
Get.put(SocialConnectionController());
|
|
}
|
|
|
|
final controller = Get.find<SocialConnectionController>();
|
|
controller.currentTab.value = "Invitations";
|
|
await controller.searchUsers();
|
|
|
|
Get.toNamed(RouteConstant.friendRequestScreen);
|
|
} catch (e) {
|
|
navigateToDefault();
|
|
}
|
|
}
|
|
|
|
//........................................................................................................
|
|
//........................................................................................................
|
|
Future<void> navigateToFriendsScreen() async {
|
|
isNotificationNavigation(true);
|
|
|
|
try {
|
|
if (Get.currentRoute == RouteConstant.splashScreen) {
|
|
Get.offNamedUntil(
|
|
RouteConstant.dashboardScreen,
|
|
(route) => false,
|
|
arguments: 0,
|
|
);
|
|
}
|
|
//..................................................
|
|
if (!Get.isRegistered<RatingsReviewsController>()) {
|
|
Get.put(RatingsReviewsController());
|
|
}
|
|
if (!Get.isRegistered<ChatController>()) {
|
|
Get.put(ChatController());
|
|
}
|
|
if (!Get.isRegistered<NotificationController>()) {
|
|
Get.put(NotificationController());
|
|
}
|
|
//...................................................
|
|
|
|
// Ensure controller is registered
|
|
if (!Get.isRegistered<SocialConnectionController>()) {
|
|
Get.put(SocialConnectionController());
|
|
}
|
|
|
|
final controller = Get.find<SocialConnectionController>();
|
|
controller.currentTab.value = "Friends";
|
|
await controller.searchUsers();
|
|
|
|
Get.toNamed(RouteConstant.friendRequestScreen);
|
|
} catch (e) {
|
|
navigateToDefault();
|
|
}
|
|
}
|
|
|
|
//..........................................................................................
|
|
//..........................................................................................
|
|
Future<void> navigateToLiveStreamScreen() async {
|
|
isNotificationNavigation(true);
|
|
|
|
if (Get.currentRoute == RouteConstant.splashScreen) {
|
|
Get.offNamedUntil(
|
|
RouteConstant.dashboardScreen,
|
|
(route) => false,
|
|
arguments: 0,
|
|
);
|
|
}
|
|
//..................................................
|
|
if (!Get.isRegistered<RatingsReviewsController>()) {
|
|
Get.put(RatingsReviewsController());
|
|
}
|
|
if (!Get.isRegistered<ChatController>()) {
|
|
Get.put(ChatController());
|
|
}
|
|
if (!Get.isRegistered<NotificationController>()) {
|
|
Get.put(NotificationController());
|
|
}
|
|
//...................................................
|
|
|
|
try {
|
|
if (!Get.isRegistered<GetLiveStreamsController>()) {
|
|
Get.put(GetLiveStreamsController());
|
|
}
|
|
|
|
final controller = Get.find<GetLiveStreamsController>();
|
|
await controller.getSpecificStream(streamID: streamID.value);
|
|
|
|
Get.toNamed(RouteConstant.singleLiveStreamScreen);
|
|
} catch (e) {
|
|
navigateToDefault();
|
|
}
|
|
}
|
|
|
|
//.............................................................................................
|
|
|
|
Future<void> navigateToViewTribeScreen(Map<String, dynamic> data) async {
|
|
isNotificationNavigation(true);
|
|
|
|
try {
|
|
if (Get.currentRoute == RouteConstant.splashScreen) {
|
|
Get.offNamedUntil(
|
|
RouteConstant.dashboardScreen,
|
|
(route) => false,
|
|
arguments: 0,
|
|
);
|
|
}
|
|
//..................................................
|
|
if (!Get.isRegistered<RatingsReviewsController>()) {
|
|
Get.put(RatingsReviewsController());
|
|
}
|
|
if (!Get.isRegistered<ChatController>()) {
|
|
Get.put(ChatController());
|
|
}
|
|
if (!Get.isRegistered<NotificationController>()) {
|
|
Get.put(NotificationController());
|
|
}
|
|
|
|
if (!Get.isRegistered<SocialConnectionController>()) {
|
|
Get.put(SocialConnectionController());
|
|
}
|
|
//..........................................................
|
|
//..........................................................
|
|
//..........................................................
|
|
Map<String, dynamic>? dataIdMap;
|
|
if (data['dataId'] != null && data['dataId'] is String) {
|
|
dataIdMap = jsonDecode(data['dataId']);
|
|
}
|
|
final tribeId = dataIdMap?['TribeID'];
|
|
// Check if TribeID exists and is not null/empty
|
|
if (tribeId != null && tribeId.toString().isNotEmpty) {
|
|
final socialConnectionController =
|
|
Get.find<SocialConnectionController>();
|
|
|
|
// Navigate to TribeEchoboardPostListScreen with tribe and post IDs
|
|
final tribeDetailsLoaded = await socialConnectionController
|
|
.getSingleTribeDetails(tribeId: int.parse(tribeId));
|
|
|
|
if (tribeDetailsLoaded) {
|
|
await Future.delayed(Duration(milliseconds: 100));
|
|
|
|
Get.to(
|
|
() => TribeEchoboardPostListScreen(
|
|
tribeId: int.parse(tribeId),
|
|
tribeImage:
|
|
socialConnectionController
|
|
.singleTribeDetails
|
|
.value!
|
|
.data!
|
|
.tribeImage!,
|
|
tribeName:
|
|
socialConnectionController
|
|
.singleTribeDetails
|
|
.value!
|
|
.data!
|
|
.tribeName!,
|
|
),
|
|
arguments: 1, // Keep parent bottom nav at Echoboard Index
|
|
);
|
|
|
|
scheduleMicrotask(() {
|
|
controllerInitialization();
|
|
});
|
|
} else {
|
|
// Failed to load tribe details
|
|
customSnackbar(
|
|
title: "Error",
|
|
message: "Failed to load tribe details",
|
|
duration: 2,
|
|
);
|
|
Get.offAll(() => const DashboardScreen());
|
|
controllerInitialization();
|
|
}
|
|
}
|
|
} catch (e) {
|
|
navigateToDefault();
|
|
}
|
|
}
|
|
|
|
//..........................................................................................
|
|
//..........................................................................................
|
|
|
|
void navigateToDefault() {
|
|
if (SharedServices.isLoggedIn()) {
|
|
controllerInitialization();
|
|
|
|
if (Get.currentRoute != RouteConstant.dashboardScreen) {
|
|
// Get.toNamed(RouteConstant.dashboardScreen, arguments: 0);
|
|
Get.offAll(() => const DashboardScreen());
|
|
}
|
|
controllerInitialization();
|
|
} else {
|
|
Get.offAll(() => LoginScreen());
|
|
}
|
|
}
|
|
|
|
controllerInitialization() {
|
|
if (!Get.isRegistered<NavigationController>()) {
|
|
Get.put(NavigationController());
|
|
}
|
|
if (!Get.isRegistered<RatingsReviewsController>()) {
|
|
Get.put(RatingsReviewsController());
|
|
}
|
|
|
|
if (!Get.isRegistered<EchoBoardController>()) {
|
|
Get.put(EchoBoardController());
|
|
}
|
|
if (!Get.isRegistered<ChatController>()) {
|
|
Get.put(ChatController());
|
|
}
|
|
|
|
if (!Get.isRegistered<NotificationController>()) {
|
|
Get.put(NotificationController());
|
|
}
|
|
}
|
|
}
|