Skip to content

Commit

Permalink
Merge branch 'develop' into um/ASC-19973/Update-the-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
umareko authored Feb 7, 2024
2 parents ed7ffdc + 2b80109 commit 4176dcc
Show file tree
Hide file tree
Showing 17 changed files with 527 additions and 102 deletions.
9 changes: 9 additions & 0 deletions lib/core/preferences/preference_interface.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
abstract class PreferenceInterface{
Future<bool?> isLoggedIn();
Future<String?> loggedInUserId();
Future<String?> loggedInUserDisplayName();
Future<bool?> setLoggedIn( bool isLoggedIn );
Future<bool?> setLoggedInUserId(String userId);
Future<bool?> setLoggedInUserDisplayName(String userDisplayName);
void removeAllPreference();
}
53 changes: 53 additions & 0 deletions lib/core/preferences/preference_interface_impl.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

import 'package:flutter_social_sample_app/core/preferences/preference_interface.dart';
import 'package:flutter_social_sample_app/core/preferences/shared_preferences_manager.dart';

class PreferenceInterfaceImpl extends PreferenceInterface{

SharedPreferencesManager? sharedPreferencesManager;


PreferenceInterfaceImpl(){
sharedPreferencesManager = SharedPreferencesManager();
}



@override
Future<bool> isLoggedIn() async {
return await sharedPreferencesManager?.getBool("isLoggedIn") ?? false ;
}

@override
Future<String?> loggedInUserId() async {
return await sharedPreferencesManager?.getString("loggedInUserId") ;
}

@override
Future<bool?> setLoggedIn(bool isLoggedIn) async {
return await sharedPreferencesManager?.setBool("isLoggedIn", isLoggedIn) ?? false ;
}

@override
Future<bool?> setLoggedInUserId(String userId) async {
return await sharedPreferencesManager?.setString("loggedInUserId", userId);
}

@override
Future<String?> loggedInUserDisplayName() async {
return await sharedPreferencesManager?.getString("displayName") ;
}

@override
Future<bool?> setLoggedInUserDisplayName(String userDisplayName) async {
return await sharedPreferencesManager?.setString("displayName", userDisplayName);
}

@override
void removeAllPreference() async {
sharedPreferencesManager?.remove("displayName");
sharedPreferencesManager?.remove("loggedInUserId");
sharedPreferencesManager?.remove("isLoggedIn");
}

}
61 changes: 61 additions & 0 deletions lib/core/preferences/shared_preferences_manager.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import 'package:shared_preferences/shared_preferences.dart';

class SharedPreferencesManager {
static final SharedPreferencesManager _instance = SharedPreferencesManager._internal();

final Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
SharedPreferences? prefs;

factory SharedPreferencesManager() {
return _instance;
}


SharedPreferencesManager._internal(){
setup ();
}

Future<void> setup () async {
prefs = await _prefs;
print("prefs: $prefs");
}

Future<bool> setString(String key, String value) async {
if(prefs == null) setup();
return await prefs!.setString(key, value);
}

Future<bool?> setBool(String key, bool value) async {
if(prefs == null) setup();
return prefs?.setBool(key, value);
}

Future<bool?> setInt(String key, int value) async {
if(prefs == null) setup();
return prefs?.setInt(key, value);
}

Future<bool> getBool(String key) async {
if(prefs == null) await setup();
return prefs?.getBool(key) ?? false;
}

Future<String> getString(String key) async {
if(prefs == null) setup();
return prefs?.getString(key) ?? "";
}

Future<int> getInt(String key) async {
if(prefs == null) setup();
return prefs?.getInt(key) ?? 0;
}

void remove(String key) async {
if(prefs == null) setup();
await prefs?.remove(key);
}




}
3 changes: 3 additions & 0 deletions lib/core/route/app_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,7 @@ class AppRoute {
static const getCategory = 'getCategory';
static const getCategoryRoute = 'getCategory/:categoryId';

static const getReachUser = 'getReachUser';
static const getReachUserRoute = '/getReachUser';

}
87 changes: 61 additions & 26 deletions lib/core/route/app_router.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:developer';

import 'package:amity_sdk/amity_sdk.dart';
import 'package:flutter_social_sample_app/core/preferences/preference_interface_impl.dart';
import 'package:flutter_social_sample_app/core/route/app_route.dart';
import 'package:flutter_social_sample_app/presentation/screen/channel_create/channel_create_screen.dart';
import 'package:flutter_social_sample_app/presentation/screen/channel_list/channel_list_screen.dart';
Expand All @@ -22,7 +23,7 @@ import 'package:flutter_social_sample_app/presentation/screen/community_profile/
import 'package:flutter_social_sample_app/presentation/screen/community_update/community_update_screen.dart';
import 'package:flutter_social_sample_app/presentation/screen/create_poll_post/create_poll_post_screen.dart';
import 'package:flutter_social_sample_app/presentation/screen/create_post/create_post_screen.dart';
import 'package:flutter_social_sample_app/presentation/screen/dashboard/dashboar_screen.dart';
import 'package:flutter_social_sample_app/presentation/screen/dashboard/dashboard_screen.dart';
import 'package:flutter_social_sample_app/presentation/screen/follower_list/follower_list_screen.dart';
import 'package:flutter_social_sample_app/presentation/screen/following_list/following_list_screend.dart';
import 'package:flutter_social_sample_app/presentation/screen/global_feed/global_feed_screen.dart';
Expand All @@ -36,6 +37,7 @@ import 'package:flutter_social_sample_app/presentation/screen/my_follower_list/m
import 'package:flutter_social_sample_app/presentation/screen/my_following_list/my_following_list_screen.dart';
import 'package:flutter_social_sample_app/presentation/screen/my_pending_follower_list/my_pending_follower_screen.dart';
import 'package:flutter_social_sample_app/presentation/screen/post_detail/post_detail_screen.dart';
import 'package:flutter_social_sample_app/presentation/screen/post_reached_users/post_reached_users_screen.dart';
import 'package:flutter_social_sample_app/presentation/screen/reaction_list_comment/reaction_list_comment_screen.dart';
import 'package:flutter_social_sample_app/presentation/screen/reaction_list_message/reaction_list_message_screen.dart';
import 'package:flutter_social_sample_app/presentation/screen/reaction_list_post/reaction_list_post_screen.dart';
Expand All @@ -52,7 +54,7 @@ import 'package:go_router/go_router.dart';

class AppRouter {
static GoRouter router = GoRouter(
initialLocation: AppRoute.homeRoute,
initialLocation: AppRoute.loginRoute,
routes: [
GoRoute(
name: AppRoute.home,
Expand All @@ -64,17 +66,20 @@ class AppRouter {
GoRoute(
name: AppRoute.profile,
path: AppRoute.profileRoute,
builder: (context, state) => UserProfileScreen(userId: state.params['userId']!),
builder: (context, state) =>
UserProfileScreen(userId: state.params['userId']!),
routes: [
GoRoute(
name: AppRoute.followersUser,
path: AppRoute.followersUserRoute,
builder: (context, state) => FollowerListScreen(userId: state.params['userId']!),
builder: (context, state) =>
FollowerListScreen(userId: state.params['userId']!),
),
GoRoute(
name: AppRoute.followingsUser,
path: AppRoute.followingsUserRoute,
builder: (context, state) => FollowingListScreen(userId: state.params['userId']!),
builder: (context, state) =>
FollowingListScreen(userId: state.params['userId']!),
),
GoRoute(
name: AppRoute.followersMy,
Expand Down Expand Up @@ -120,7 +125,7 @@ class AppRouter {
builder: (context, state) {
AmityStream amityStream = state.extra as AmityStream;
return ViewStream(stream: amityStream);
},
},
),
GoRoute(
name: AppRoute.communityFeed,
Expand All @@ -133,13 +138,14 @@ class AppRouter {
GoRoute(
name: AppRoute.communityMember,
path: AppRoute.communityMemmberRoute,
builder: (context, state) => CommunityMemberScreen(communityId: state.params['communityId']!),
builder: (context, state) => CommunityMemberScreen(
communityId: state.params['communityId']!),
),

GoRoute(
name: AppRoute.userFeed,
path: AppRoute.userFeedRoute,
builder: (context, state) => UserFeedScreen(userId: state.params['userId']!),
builder: (context, state) =>
UserFeedScreen(userId: state.params['userId']!),
),
GoRoute(
name: AppRoute.communityList,
Expand All @@ -163,16 +169,20 @@ class AppRouter {
GoRoute(
name: AppRoute.communityInReviewPost,
path: AppRoute.communityInReviewPostRoute,
builder: (context, state) => CommunityInReviewPostListScreen(
communityId: state.queryParams['communityId']!,
isPublic: state.queryParams['isPublic'] == 'true'),
builder: (context, state) =>
CommunityInReviewPostListScreen(
communityId: state.queryParams['communityId']!,
isPublic:
state.queryParams['isPublic'] == 'true'),
),
GoRoute(
name: AppRoute.communityPendingPost,
path: AppRoute.communityPendingPostRoute,
builder: (context, state) => CommunityPendingPostListScreen(
communityId: state.queryParams['communityId']!,
isPublic: state.queryParams['isPublic'] == 'true'),
builder: (context, state) =>
CommunityPendingPostListScreen(
communityId: state.queryParams['communityId']!,
isPublic:
state.queryParams['isPublic'] == 'true'),
),
]),
GoRoute(
Expand Down Expand Up @@ -203,27 +213,32 @@ class AppRouter {
GoRoute(
name: AppRoute.postReaction,
path: AppRoute.postReactionRoute,
builder: (context, state) => ReactionListPostScreen(postId: state.params['postId']!),
builder: (context, state) =>
ReactionListPostScreen(postId: state.params['postId']!),
),
GoRoute(
name: AppRoute.commentReaction,
path: AppRoute.commentReactionRoute,
builder: (context, state) => ReactionListCommentScreen(commentId: state.params['commentId']!),
builder: (context, state) => ReactionListCommentScreen(
commentId: state.params['commentId']!),
),
GoRoute(
name: AppRoute.messageReaction,
path: AppRoute.messageReactionRoute,
builder: (context, state) => ReactionListMessageScreen(messageId: state.params['messageId']!),
builder: (context, state) => ReactionListMessageScreen(
messageId: state.params['messageId']!),
),
GoRoute(
name: AppRoute.postDetail,
path: AppRoute.postDetailRoute,
builder: (context, state) => PostDetailScreen(postId: state.params['postId']!),
builder: (context, state) =>
PostDetailScreen(postId: state.params['postId']!),
),
GoRoute(
name: AppRoute.getCategory,
path: AppRoute.getCategoryRoute,
builder: (context, state) => CommunityCategoryScreen(categoryId: state.params['categoryId']!),
builder: (context, state) => CommunityCategoryScreen(
categoryId: state.params['categoryId']!),
),
GoRoute(
name: AppRoute.createPollPost,
Expand All @@ -233,7 +248,8 @@ class AppRouter {
GoRoute(
name: AppRoute.chat,
path: AppRoute.chatRoute,
builder: (context, state) => ChatScreen(channelId: state.params['channelId']!),
builder: (context, state) =>
ChatScreen(channelId: state.params['channelId']!),
),
],
),
Expand Down Expand Up @@ -267,12 +283,14 @@ class AppRouter {
GoRoute(
name: AppRoute.updateChannel,
path: AppRoute.updateChannelRoute,
builder: (context, state) => ChannelUpdateScreen(channelId: state.queryParams['channelId']!),
builder: (context, state) =>
ChannelUpdateScreen(channelId: state.queryParams['channelId']!),
),
GoRoute(
name: AppRoute.updateMessage,
path: AppRoute.updateMessageRoute,
builder: (context, state) => MessageUpdateScreen(messageId: state.queryParams['messageId']!),
builder: (context, state) =>
MessageUpdateScreen(messageId: state.queryParams['messageId']!),
),
GoRoute(
name: AppRoute.globalUserSearch,
Expand Down Expand Up @@ -322,6 +340,15 @@ class AppRouter {
);
},
),
GoRoute(
name: AppRoute.getReachUser,
path: AppRoute.getReachUserRoute,
builder: (context, state) {
return PostReachedUsersScreen(
postId: state.queryParams['postId']!,
);
},
),
GoRoute(
name: AppRoute.commentRTE,
path: AppRoute.commentRTERoute,
Expand Down Expand Up @@ -355,11 +382,19 @@ class AppRouter {
},
),
],
redirect: (context, state) {
if (state.location != AppRoute.loginRoute) {
if (!AmityCoreClient.isUserLoggedIn()) {
redirect: (context, state) async {
if (state.location == AppRoute.loginRoute) {
if (!await PreferenceInterfaceImpl().isLoggedIn()) {
log('redirecting to /login');
return AppRoute.loginRoute;
} else {
// var user = await AmityCoreClient.getLoggedInUser();
var userId = await PreferenceInterfaceImpl().loggedInUserId();
var userName = await PreferenceInterfaceImpl().loggedInUserDisplayName();
await AmityCoreClient.login(userId!)
.displayName(userName!)
.submit();
return AppRoute.homeRoute;
}
}
return null;
Expand Down
Loading

0 comments on commit 4176dcc

Please sign in to comment.