Skip to content

Commit

Permalink
Merge branch 'airqo-platform:staging' into NetManagerMapFunc
Browse files Browse the repository at this point in the history
  • Loading branch information
AKATWIJUKA-ELIA authored Feb 19, 2025
2 parents 041591c + 75924ef commit 2bd8495
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 90 deletions.
8 changes: 4 additions & 4 deletions mobile-v3/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ if (localPropertiesFile.exists()) {
}
}

def googleMapApiKey = appProperties.getProperty('google.maps.key')
def googleMapApiKey = appProperties.getProperty('google.maps.key') ?: secrets.getProperty('MAPS_API_KEY')
if (googleMapApiKey == null) {
throw new GradleException("Google Maps Key not found. Define google.maps.key in the key.properties file.")
throw new GradleException("Google Maps Key not found. Define either google.maps.key in key.properties or MAPS_API_KEY in secrets.properties")
}

def googleMapApiKeyDev = appProperties.getProperty('google.maps.key.dev')
def googleMapApiKeyDev = appProperties.getProperty('google.maps.key.dev') ?: secrets.getProperty('MAPS_API_KEY_DEV')
if (googleMapApiKeyDev == null) {
throw new GradleException("Google Maps Key not found. Define google.maps.key_dev in the key.properties file.")
throw new GradleException("Google Maps Dev Key not found. Define either google.maps.key.dev in key.properties or MAPS_API_KEY_DEV in secrets.properties")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
Expand Down
7 changes: 6 additions & 1 deletion mobile-v3/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@

<!-- TODO: Add your Google Maps API key here -->
<meta-data android:name="com.google.android.geo.API_KEY"
android:value="${MAPS_API_KEY}" />
android:value="${googleMapsKey}" />

<!-- Google Places API key -->
<meta-data
android:name="com.google.android.places.API_KEY"
android:value="${PLACES_API_KEY}" />
<activity
android:name=".MainActivity"
android:exported="true"
Expand Down
70 changes: 19 additions & 51 deletions mobile-v3/lib/src/app/auth/bloc/auth_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,65 +9,21 @@ import '../../shared/repository/hive_repository.dart';
part 'auth_event.dart';
part 'auth_state.dart';

// class AuthBloc extends Bloc<AuthEvent, AuthState> {
// final AuthRepository authRepository;
// AuthBloc(this.authRepository) : super(AuthInitial()) {
// on<AuthEvent>((event, emit) async {
// if (event is LoginUser) {
// try {
// emit(AuthLoading());
// await authRepository.loginWithEmailAndPassword(
// event.username, event.password);
//
// emit(AuthLoaded(AuthPurpose.LOGIN));
// } catch (e) {
// debugPrint(e.toString());
// emit(
// AuthLoadingError(
// e.toString(),
// ),
// );
// }
// } else if (event is RegisterUser) {
// try {
// emit(AuthLoading());
//
// await authRepository.registerWithEmailAndPassword(event.model);
//
// emit(AuthLoaded(AuthPurpose.REGISTER));
// } catch (e) {
// debugPrint(e.toString());
// emit(
// AuthLoadingError(
// e.toString(),
// ),
// );
// }
// } else if (event is UseAsGuest) {
// emit(GuestUser());
// }
// });
// }
// }
class AuthBloc extends Bloc<AuthEvent, AuthState> {
final AuthRepository authRepository;

AuthBloc(this.authRepository) : super(AuthInitial()) {
//debugPrint("AuthBloc initialized");

on<AppStarted>(_onAppStarted);


on<LoginUser>(_onLoginUser);


on<RegisterUser>(_onRegisterUser);

on<LogoutUser>(_onLogoutUser);

on<UseAsGuest>((event, emit) => emit(GuestUser()));
}


Future<void> _onAppStarted(AppStarted event, Emitter<AuthState> emit) async {
emit(AuthLoading());
try {
Expand All @@ -85,15 +41,15 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
}
}


Future<void> _onLoginUser(LoginUser event, Emitter<AuthState> emit) async {
emit(AuthLoading());
try {

final token = await authRepository.loginWithEmailAndPassword(event.username, event.password);
final token = await authRepository.loginWithEmailAndPassword(
event.username, event.password);
await HiveRepository.saveData(HiveBoxNames.authBox, 'token', token);
// Save token in Hive
final savedToken = await HiveRepository.getData('token', HiveBoxNames.authBox);
final savedToken =
await HiveRepository.getData('token', HiveBoxNames.authBox);
//debugPrint("Saved token: $savedToken");

emit(AuthLoaded(AuthPurpose.LOGIN));
Expand All @@ -103,8 +59,8 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
}
}


Future<void> _onRegisterUser(RegisterUser event, Emitter<AuthState> emit) async {
Future<void> _onRegisterUser(
RegisterUser event, Emitter<AuthState> emit) async {
emit(AuthLoading());
try {
await authRepository.registerWithEmailAndPassword(event.model);
Expand All @@ -116,6 +72,18 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
}


Future<void> _onLogoutUser(LogoutUser event, Emitter<AuthState> emit) async {
emit(AuthLoading());
try {
await HiveRepository.deleteData(
'token', HiveBoxNames.authBox); // Remove token from Hive
emit(GuestUser()); // Emit guest state after logout
} catch (e) {
debugPrint("Logout error: $e");
emit(AuthLoadingError("Failed to log out. Please try again."));
}
}

String _extractErrorMessage(dynamic e) {
if (e is Exception) {
return e.toString().replaceAll("Exception:", "").trim();
Expand Down
4 changes: 4 additions & 0 deletions mobile-v3/lib/src/app/auth/bloc/auth_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ class RegisterUser extends AuthEvent {
class UseAsGuest extends AuthEvent {
const UseAsGuest();
}

class LogoutUser extends AuthEvent {
const LogoutUser();
}
34 changes: 17 additions & 17 deletions mobile-v3/lib/src/app/dashboard/pages/dashboard_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,24 @@ class _DashboardPageState extends State<DashboardPage> {
),
SizedBox(width: 8),
GestureDetector(
onTap: () {
final authState = context.read<AuthBloc>().state;
if (authState is GuestUser) {
// onTap: () {
// final authState = context.read<AuthBloc>().state;
// if (authState is GuestUser) {

Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => GuestProfilePage(),
),
);
} else {
// Navigate to the regular profile page
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => ProfilePage(),
),
);
}
},
// Navigator.of(context).push(
// MaterialPageRoute(
// builder: (context) => GuestProfilePage(),
// ),
// );
// } else {
// // Navigate to the regular profile page
// Navigator.of(context).push(
// MaterialPageRoute(
// builder: (context) => ProfilePage(),
// ),
// );
// }
// },
child: BlocBuilder<AuthBloc, AuthState>(
builder: (context, authState) {
if (authState is GuestUser) {
Expand Down
20 changes: 10 additions & 10 deletions mobile-v3/lib/src/app/learn/pages/lesson_finished.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ class LessonFinishedWidget extends StatelessWidget {
Text("👋🏼 Great Job !",
style: TextStyle(fontSize: 20, fontWeight: FontWeight.w700)),
Text(
"You can invite your friends to learn a thing about Air Pollution",
"You can now teach your friends to learn a thing about Air Pollution",
textAlign: TextAlign.center,
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w500)),
SizedBox(height: 64),
SmallRoundedButton(
label: "Share",
imagePath: "assets/images/shared/share_icon.svg",
),
SizedBox(height: 16),
SmallRoundedButton(
label: "Rate the App",
imagePath: "assets/images/shared/bookmark_icon.svg",
),
// SmallRoundedButton(
// label: "Share",
// imagePath: "assets/images/shared/share_icon.svg",
// ),
// SizedBox(height: 16),
// SmallRoundedButton(
// label: "Rate the App",
// imagePath: "assets/images/shared/bookmark_icon.svg",
// ),
],
),
);
Expand Down
55 changes: 48 additions & 7 deletions mobile-v3/lib/src/app/profile/pages/widgets/settings_widget.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import 'package:airqo/src/app/auth/pages/welcome_screen.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:airqo/src/app/auth/bloc/auth_bloc.dart';
import 'package:flutter/material.dart';
import 'package:airqo/src/app/profile/pages/widgets/settings_tile.dart';
import 'package:flutter_svg/svg.dart';
Expand All @@ -9,6 +12,7 @@ class SettingsWidget extends StatefulWidget {
@override
State<SettingsWidget> createState() => _SettingsWidgetState();
}

class _SettingsWidgetState extends State<SettingsWidget> {
String _appVersion = '';
bool _locationEnabled = true;
Expand All @@ -30,27 +34,64 @@ class _SettingsWidgetState extends State<SettingsWidget> {
void _showLogoutConfirmation() {
showDialog(
context: context,
builder: (context) => AlertDialog(
builder: (dialogContext) => AlertDialog(
title: const Text('Confirm Logout'),
content: const Text('Are you sure you want to log out?'),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
onPressed: () => Navigator.pop(dialogContext),
child: const Text('Cancel'),
),
ElevatedButton(
onPressed: () {
// TODO: Implement actual logout logic
// e.g., clear user session, revoke tokens
Navigator.of(context).pushReplacementNamed('/login');
},
onPressed: () => _handleLogout(dialogContext),
child: const Text('Log Out'),
),
],
),
);
}

Future<void> _handleLogout(BuildContext dialogContext) async {
Navigator.pop(dialogContext); // Close confirmation dialog

showDialog(
context: context,
barrierDismissible: false,
builder: (_) => const Center(child: CircularProgressIndicator()),
);

try {
context.read<AuthBloc>().add(LogoutUser());

await for (final state in context.read<AuthBloc>().stream) {
if (state is GuestUser) {
Navigator.pop(context);

await Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (_) => WelcomeScreen()),
(route) => false,
);
break;
} else if (state is AuthLoadingError) {
Navigator.pop(context);

ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(state.message)),
);
break;
}
}
} catch (e) {
Navigator.pop(context);

ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('An unexpected error occurred')),
);
}
}


void _showDeleteAccountDialog() {
final TextEditingController passwordController = TextEditingController();

Expand Down

0 comments on commit 2bd8495

Please sign in to comment.