Class LoginViewModel
- java.lang.Object
-
- androidx.lifecycle.ViewModel
-
- androidx.lifecycle.AndroidViewModel
-
- edu.cnm.deepdive.interviewprep.viewmodel.LoginViewModel
-
- All Implemented Interfaces:
DefaultLifecycleObserver
,LifecycleObserver
public class LoginViewModel extends AndroidViewModel implements DefaultLifecycleObserver
Implements the business logic behind the application. Interacts with the GoogleSignInRepository to sign a User into the application.
-
-
Constructor Summary
Constructors Constructor Description LoginViewModel(Application application)
Constructor for class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
completeSignIn(androidx.activity.result.ActivityResult result)
Interacts with the GoogleSignInRepository to sign a user into the application.LiveData<GoogleSignInAccount>
getAccount()
Returns the GoogleSignInAccount.LiveData<Throwable>
getThrowable()
Returns the throwable local variable.void
onStop(LifecycleOwner owner)
void
refresh()
Interacts with the GoogleSignInRepository to refresh user credentials from the cloud.void
signOut()
Interacts with the GoogleSignInRepository to sign the User out of their Google account.void
startSignIn(androidx.activity.result.ActivityResultLauncher<Intent> launcher)
Interacts with the GoogleSignInRepository to begins the application sign in process.-
Methods inherited from class androidx.lifecycle.AndroidViewModel
getApplication
-
-
-
-
Constructor Detail
-
LoginViewModel
public LoginViewModel(@NonNull Application application)
Constructor for class. Instantiates local variables and causes a silent refresh if necessary.- Parameters:
application
- an application
-
-
Method Detail
-
getAccount
public LiveData<GoogleSignInAccount> getAccount()
Returns the GoogleSignInAccount.- Returns:
- a reactivex
LiveData
object of typeGoogleSignInAccount
.
-
refresh
public void refresh()
Interacts with the GoogleSignInRepository to refresh user credentials from the cloud. If the refresh fails, it does not get reported as an error; The user has to log in again.
-
startSignIn
public void startSignIn(androidx.activity.result.ActivityResultLauncher<Intent> launcher)
Interacts with the GoogleSignInRepository to begins the application sign in process.- Parameters:
launcher
- anActivityResultLauncher
object of typeIntent
.
-
completeSignIn
public void completeSignIn(androidx.activity.result.ActivityResult result)
Interacts with the GoogleSignInRepository to sign a user into the application.- Parameters:
result
- the result of the SignIn process
-
signOut
public void signOut()
Interacts with the GoogleSignInRepository to sign the User out of their Google account.
-
onStop
public void onStop(@NonNull LifecycleOwner owner)
- Specified by:
onStop
in interfaceDefaultLifecycleObserver
-
-