-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the AuthActivity more robust by handling all the errors and ask …
…for location permission in HomeFragment
- Loading branch information
1 parent
4273519
commit 6d3e88f
Showing
40 changed files
with
1,146 additions
and
367 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.
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
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
8 changes: 8 additions & 0 deletions
8
app/src/main/kotlin/id/shaderboi/koffie/ui/auth/registration/view_model/RegistrationEvent.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,8 @@ | ||
package id.shaderboi.koffie.ui.auth.registration.view_model | ||
|
||
import android.app.Activity | ||
import com.google.firebase.auth.AuthResult | ||
|
||
sealed class RegistrationEvent { | ||
class Register(val displayName: String) : RegistrationEvent() | ||
} |
9 changes: 9 additions & 0 deletions
9
...rc/main/kotlin/id/shaderboi/koffie/ui/auth/registration/view_model/RegistrationUIEvent.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,9 @@ | ||
package id.shaderboi.koffie.ui.auth.registration.view_model | ||
|
||
import id.shaderboi.koffie.util.StringDisplay | ||
|
||
sealed class RegistrationUIEvent { | ||
class ShowErrorMessage(val message: StringDisplay): RegistrationUIEvent() | ||
class IsEnableInput(val enabled: Boolean) : RegistrationUIEvent() | ||
object Finished: RegistrationUIEvent() | ||
} |
51 changes: 51 additions & 0 deletions
51
.../main/kotlin/id/shaderboi/koffie/ui/auth/registration/view_model/RegistrationViewModel.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,51 @@ | ||
package id.shaderboi.koffie.ui.auth.registration.view_model | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.google.firebase.auth.FirebaseAuthException | ||
import com.google.firebase.auth.FirebaseAuthInvalidUserException | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import id.shaderboi.koffie.core.data.auth.Auth | ||
import id.shaderboi.koffie.util.StringDisplay | ||
import id.shaderboi.koffie.util.firebase.auth.errorCodeResId | ||
import kotlinx.coroutines.flow.MutableSharedFlow | ||
import kotlinx.coroutines.flow.asSharedFlow | ||
import kotlinx.coroutines.flow.catch | ||
import kotlinx.coroutines.flow.collectLatest | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class RegistrationViewModel @Inject constructor( | ||
private val auth: Auth | ||
) : ViewModel() { | ||
private val _uiFlow = MutableSharedFlow<RegistrationUIEvent>() | ||
val uiFlow = _uiFlow.asSharedFlow() | ||
|
||
fun onEvent(event: RegistrationEvent) { | ||
when (event) { | ||
is RegistrationEvent.Register -> { | ||
register(event.displayName) | ||
} | ||
} | ||
} | ||
|
||
private fun register(displayName: String) = viewModelScope.launch { | ||
_uiFlow.emit(RegistrationUIEvent.IsEnableInput(false)) | ||
auth.register(displayName) | ||
.catch { err -> | ||
val message = when(err) { | ||
is FirebaseAuthException -> err.errorCodeResId?.let { resId -> | ||
StringDisplay.StringRes(resId) | ||
} ?: StringDisplay.String("Uknown error. ${err.message}") | ||
else -> StringDisplay.String("Uknown error. ${err.message}") | ||
} | ||
_uiFlow.emit(RegistrationUIEvent.ShowErrorMessage(message)) | ||
_uiFlow.emit(RegistrationUIEvent.IsEnableInput(true)) | ||
} | ||
.collectLatest { | ||
_uiFlow.emit(RegistrationUIEvent.Finished) | ||
_uiFlow.emit(RegistrationUIEvent.IsEnableInput(true)) | ||
} | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
app/src/main/kotlin/id/shaderboi/koffie/ui/auth/signin/view_model/SignInEvent.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,10 @@ | ||
package id.shaderboi.koffie.ui.auth.signin.view_model | ||
|
||
import android.app.Activity | ||
|
||
sealed class SignInEvent { | ||
class SignIn( | ||
val phoneNumber: String, | ||
val activity: Activity | ||
) : SignInEvent() | ||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/kotlin/id/shaderboi/koffie/ui/auth/signin/view_model/SignInUIEvent.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,9 @@ | ||
package id.shaderboi.koffie.ui.auth.signin.view_model | ||
|
||
import id.shaderboi.koffie.util.StringDisplay | ||
|
||
sealed class SignInUIEvent { | ||
class ShowErrorMessage(val message: StringDisplay): SignInUIEvent() | ||
class Finished(val verificationId: String): SignInUIEvent() | ||
class IsEnableInput(val enable: Boolean): SignInUIEvent() | ||
} |
Oops, something went wrong.