Skip to content

Commit b562340

Browse files
Update profile screen and follow functionality
1 parent ae4bea0 commit b562340

File tree

7 files changed

+590
-364
lines changed

7 files changed

+590
-364
lines changed

android/app/build.gradle

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
plugins {
2+
id "com.android.application"
3+
// START: FlutterFire Configuration
4+
id 'com.google.gms.google-services'
5+
// END: FlutterFire Configuration
6+
id "kotlin-android"
7+
id "dev.flutter.flutter-gradle-plugin"
8+
}
9+
10+
def localProperties = new Properties()
11+
def localPropertiesFile = rootProject.file('local.properties')
12+
if (localPropertiesFile.exists()) {
13+
localPropertiesFile.withReader('UTF-8') { reader ->
14+
localProperties.load(reader)
15+
}
16+
}
17+
18+
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
19+
if (flutterVersionCode == null) {
20+
flutterVersionCode = '1'
21+
}
22+
23+
def flutterVersionName = localProperties.getProperty('flutter.versionName')
24+
if (flutterVersionName == null) {
25+
flutterVersionName = '1.0'
26+
}
27+
28+
android {
29+
namespace "org.aossie.monumento"
30+
compileSdk 35
31+
ndkVersion flutter.ndkVersion
32+
33+
compileOptions {
34+
sourceCompatibility JavaVersion.VERSION_1_8
35+
targetCompatibility JavaVersion.VERSION_1_8
36+
}
37+
38+
kotlinOptions {
39+
jvmTarget = '1.8'
40+
}
41+
42+
sourceSets {
43+
main.java.srcDirs += 'src/main/kotlin'
44+
}
45+
46+
defaultConfig {
47+
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
48+
applicationId "org.aossie.monumento"
49+
// You can update the following values to match your application needs.
50+
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
51+
minSdkVersion 23
52+
targetSdkVersion 33
53+
versionCode flutterVersionCode.toInteger()
54+
versionName flutterVersionName
55+
}
56+
57+
buildTypes {
58+
release {
59+
// TODO: Add your own signing config for the release build.
60+
// Signing with the debug keys for now, so `flutter run --release` works.
61+
signingConfig signingConfigs.debug
62+
}
63+
}
64+
65+
aaptOptions {
66+
noCompress 'tflite'
67+
noCompress 'lite'
68+
}
69+
}
70+
71+
flutter {
72+
source '../..'
73+
}
74+
75+
dependencies {
76+
implementation('com.google.firebase:firebase-iid:21.1.0')
77+
}

lib/application/authentication/authentication_bloc.dart

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,20 @@ class AuthenticationBloc
4444

4545
_mapLoggedInToState(
4646
AuthenticationEvent event, Emitter<AuthenticationState> emit) async {
47-
final (userLoggedIn, user) = await _authRepository.getUser();
48-
49-
if (userLoggedIn && user != null) {
50-
emit(Authenticated(user.toEntity()));
51-
} else if (userLoggedIn && user == null) {
52-
emit(OnboardingIncomplete());
53-
} else {
47+
try {
48+
await Future.delayed(const Duration(milliseconds: 500));
49+
final (userLoggedIn, user) = await _authRepository.getUser();
50+
log('User: $userLoggedIn, $user');
51+
if (userLoggedIn && user != null) {
52+
emit(Uninitialized());
53+
emit(Authenticated(user.toEntity()));
54+
} else if (userLoggedIn && user == null) {
55+
emit(OnboardingIncomplete());
56+
} else {
57+
emit(Unauthenticated());
58+
}
59+
} catch (e) {
60+
log('Error in _mapLoggedInToState: $e');
5461
emit(Unauthenticated());
5562
}
5663
}

lib/application/profile/follow/follow_bloc.dart

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@ import 'package:equatable/equatable.dart';
55
import 'package:flutter_bloc/flutter_bloc.dart';
66
import 'package:monumento/domain/entities/user_entity.dart';
77
import 'package:monumento/domain/repositories/social_repository.dart';
8+
import 'package:monumento/application/authentication/authentication_bloc.dart';
9+
import 'package:monumento/domain/repositories/authentication_repository.dart';
810

911
part 'follow_event.dart';
1012
part 'follow_state.dart';
1113

1214
class FollowBloc extends Bloc<FollowEvent, FollowState> {
1315
final SocialRepository _socialRepository;
16+
final AuthenticationBloc _authenticationBloc;
17+
final AuthenticationRepository _authenticationRepository;
18+
bool _currentFollowStatus = false;
1419

15-
FollowBloc(this._socialRepository) : super(FollowInitial()) {
20+
FollowBloc(this._socialRepository, this._authenticationBloc, this._authenticationRepository) : super(FollowInitial()) {
1621
on<FollowUser>(_mapFollowUserToState);
1722
on<UnfollowUser>(_mapUnfollowUserToState);
1823
on<GetFollowStatus>(_mapGetFollowStatusToState);
@@ -23,23 +28,42 @@ class FollowBloc extends Bloc<FollowEvent, FollowState> {
2328
try {
2429
emit(LoadingFollowState());
2530
await _socialRepository.followUser(targetUser: event.targetUser);
26-
add(GetFollowStatus(targetUser: event.targetUser));
31+
_currentFollowStatus = true;
32+
emit(FollowStatusRetrieved(following: _currentFollowStatus));
33+
34+
// Update authentication state
35+
_authenticationBloc.add(LoggedIn());
36+
37+
// Get the current user's following and followers lists
38+
final (userLoggedIn, user) = await _authenticationRepository.getUser();
39+
if (userLoggedIn && user != null) {
40+
add(LoadUser(following: user.following));
41+
add(LoadUser(following: user.followers));
42+
}
2743
} catch (e) {
2844
log('${e.toString()} follow');
29-
3045
emit(FollowStateError(e.toString()));
3146
}
3247
}
3348

3449
_mapUnfollowUserToState(UnfollowUser event, Emitter<FollowState> emit) async {
3550
try {
3651
emit(LoadingFollowState());
37-
3852
await _socialRepository.unfollowUser(targetUser: event.targetUser);
39-
add(GetFollowStatus(targetUser: event.targetUser));
53+
_currentFollowStatus = false;
54+
emit(FollowStatusRetrieved(following: _currentFollowStatus));
55+
56+
// Update authentication state
57+
_authenticationBloc.add(LoggedIn());
58+
59+
// Get the current user's following and followers lists
60+
final (userLoggedIn, user) = await _authenticationRepository.getUser();
61+
if (userLoggedIn && user != null) {
62+
add(LoadUser(following: user.following));
63+
add(LoadUser(following: user.followers));
64+
}
4065
} catch (e) {
4166
log('${e.toString()} unfollow');
42-
4367
emit(FollowStateError(e.toString()));
4468
}
4569
}
@@ -48,12 +72,11 @@ class FollowBloc extends Bloc<FollowEvent, FollowState> {
4872
GetFollowStatus event, Emitter<FollowState> emit) async {
4973
try {
5074
emit(LoadingFollowState());
51-
bool following =
75+
_currentFollowStatus =
5276
await _socialRepository.getFollowStatus(targetUser: event.targetUser);
53-
emit(FollowStatusRetrieved(following: following));
77+
emit(FollowStatusRetrieved(following: _currentFollowStatus));
5478
} catch (e) {
5579
log('${e.toString()} status');
56-
5780
emit(FollowStateError(e.toString()));
5881
}
5982
}
@@ -71,7 +94,6 @@ class FollowBloc extends Bloc<FollowEvent, FollowState> {
7194
emit(LoadedFollowUserListState(userData: userDataEntity));
7295
} catch (e) {
7396
log('${e.toString()} follow');
74-
7597
emit(FollowUserListErrorState(message: e.toString()));
7698
}
7799
}

0 commit comments

Comments
 (0)