-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b92a7b
commit b986fb7
Showing
62 changed files
with
1,239 additions
and
217 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
app/src/main/java/com/mobilebreakero/destigo/di/AppModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.mobilebreakero.destigo.di | ||
|
||
import com.mobilebreakero.domain.repo.AuthRepository | ||
import com.mobilebreakero.domain.usecase.AuthUseCase | ||
import com.mobilebreakero.domain.usecase.CurrentUser | ||
import com.mobilebreakero.domain.usecase.GetAuthState | ||
import com.mobilebreakero.domain.usecase.ReloadUser | ||
import com.mobilebreakero.domain.usecase.SendEmailVerification | ||
import com.mobilebreakero.domain.usecase.SendPasswordResetEmail | ||
import com.mobilebreakero.domain.usecase.SignInWithEmailAndPassword | ||
import com.mobilebreakero.domain.usecase.SignInAnnonymously | ||
import com.mobilebreakero.domain.usecase.SignOut | ||
import com.mobilebreakero.domain.usecase.SignUpWithEmailAndPassword | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object AppModule { | ||
|
||
@Provides | ||
fun provideUseCases( | ||
repo: AuthRepository | ||
) = AuthUseCase( | ||
getAuthState = GetAuthState(repo), | ||
signInWithEmailAndPassword = SignInWithEmailAndPassword(repo), | ||
signUpWithEmailAndPassword = SignUpWithEmailAndPassword(repo), | ||
signOut = SignOut(repo), | ||
SignInAnnonymously = SignInAnnonymously(repo), | ||
sendEmailVerification = SendEmailVerification(repo), | ||
sendPasswordResetEmail = SendPasswordResetEmail(repo), | ||
currentUser = CurrentUser(repo), | ||
reloadUser = ReloadUser(repo) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
common-ui/src/main/java/com/mobilebreakero/common_ui/components/ErrorHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.mobilebreakero.common_ui.components | ||
|
||
class ErrorHandler { | ||
} |
21 changes: 21 additions & 0 deletions
21
common-ui/src/main/java/com/mobilebreakero/common_ui/components/LoadingIndicator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.mobilebreakero.common_ui.components | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material3.CircularProgressIndicator | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.unit.dp | ||
|
||
@Composable | ||
fun LoadingIndicator(){ | ||
Column { | ||
Text("Loading...") | ||
CircularProgressIndicator( | ||
modifier = Modifier.size(30.dp), | ||
color = Color.Blue | ||
) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
common-ui/src/main/java/com/mobilebreakero/common_ui/navigation/NavigationRoutes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.mobilebreakero.common_ui.navigation | ||
|
||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
object NavigationRoutes { | ||
|
||
const val WELCOME_SCREEN = "WelcomeScreen" | ||
const val SIGN_IN_SCREEN = "LoginScreen" | ||
const val SIGN_UP_SCREEN = "SignUpScreen" | ||
const val START_SCREEN = "StartAuthScreen" | ||
const val HOME_SCREEN = "Home" | ||
const val PROFILE_SCREEN = "Profile" | ||
const val INTERESTED_PLACES_SCREEN = "InterestedPlacesScreen" | ||
const val TRIPS_SCREEN = "Trips" | ||
const val SCAN_SCREEN = "Scan" | ||
const val EMAIL_VERIFICATION_SCREEN = "emailVerification" | ||
const val RESET_PASSWORD = "resetPassword" | ||
|
||
} |
91 changes: 69 additions & 22 deletions
91
core/data/src/main/java/com/mobilebreakero/data/repoimpl/AuthRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,91 @@ | ||
package com.mobilebreakero.data.repoimpl | ||
|
||
|
||
import com.google.firebase.auth.FirebaseAuth | ||
import com.google.firebase.auth.FirebaseUser | ||
import com.google.firebase.auth.UserProfileChangeRequest | ||
import com.google.firebase.auth.FirebaseAuth.AuthStateListener | ||
import com.mobilebreakero.domain.repo.AuthRepository | ||
import com.mobilebreakero.domain.util.Resource | ||
import com.mobilebreakero.domain.repo.ReloadUserResponse | ||
import com.mobilebreakero.domain.util.Response.Success | ||
import com.mobilebreakero.domain.util.Response.Failure | ||
import com.mobilebreakero.domain.util.await | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.channels.awaitClose | ||
import kotlinx.coroutines.flow.SharingStarted | ||
import kotlinx.coroutines.flow.callbackFlow | ||
import kotlinx.coroutines.flow.stateIn | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class AuthRepositoryImpl @Inject constructor( | ||
private val firebaseAuth: FirebaseAuth | ||
private val auth: FirebaseAuth | ||
) : AuthRepository { | ||
|
||
override val currentUser: FirebaseUser? | ||
get() = firebaseAuth.currentUser | ||
override val currentUser get() = auth.currentUser | ||
|
||
override suspend fun sendEmailVerification() = try { | ||
auth.currentUser?.sendEmailVerification()?.await() | ||
Success(true) | ||
} catch (e: Exception) { | ||
Failure(e) | ||
} | ||
|
||
override suspend fun login(email: String, password: String): Resource<FirebaseUser> { | ||
override suspend fun reloadFirebaseUser(): ReloadUserResponse { | ||
return try { | ||
val result = firebaseAuth.signInWithEmailAndPassword(email, password).await() | ||
Resource.Success(result.user!!) | ||
auth.currentUser?.reload()?.await() | ||
Success(true) | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
Resource.Failure(e) | ||
Failure(e) | ||
} | ||
} | ||
|
||
override suspend fun signup(name: String, email: String, password: String): Resource<FirebaseUser> { | ||
return try { | ||
val result = firebaseAuth.createUserWithEmailAndPassword(email, password).await() | ||
result.user?.updateProfile(UserProfileChangeRequest.Builder().setDisplayName(name).build())?.await() | ||
return Resource.Success(result.user!!) | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
Resource.Failure(e) | ||
override suspend fun sendPasswordResetEmail(email: String) = try { | ||
auth.sendPasswordResetEmail(email).await() | ||
Success(true) | ||
} catch (e: Exception) { | ||
Failure(e) | ||
} | ||
|
||
override fun getAuthState(viewModelScope: CoroutineScope) = callbackFlow { | ||
val authStateListener = AuthStateListener { auth -> | ||
trySend(auth.currentUser == null) | ||
} | ||
auth.addAuthStateListener(authStateListener) | ||
awaitClose { | ||
auth.removeAuthStateListener(authStateListener) | ||
} | ||
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), auth.currentUser == null) | ||
|
||
override suspend fun signInAnonymously() = try { | ||
auth.signInAnonymously().await() | ||
Success(true) | ||
} catch (e: Exception) { | ||
Failure(e) | ||
} | ||
|
||
override fun logout() { | ||
firebaseAuth.signOut() | ||
override suspend fun signInWithEmailAndPassword( | ||
email: String, | ||
password: String | ||
) = try { | ||
auth.signInWithEmailAndPassword(email, password).await() | ||
Success(true) | ||
} catch (e: Exception) { | ||
Failure(e) | ||
} | ||
|
||
override suspend fun signUpWithEmailAndPassword( | ||
email: String, | ||
password: String | ||
) = try { | ||
auth.createUserWithEmailAndPassword(email, password).await() | ||
Success(true) | ||
} catch (e: Exception) { | ||
Failure(e) | ||
} | ||
|
||
override suspend fun signOut() = try { | ||
auth.signOut() | ||
Success(true) | ||
} catch (e: Exception) { | ||
Failure(e) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.