Advertisement
Kostiggig

Untitled

Jul 18th, 2022
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.22 KB | None | 0 0
  1.  
  2. interface Repository  {
  3.     fun firebaseAuthWithGoogle(idToken: String,callback: AuthCallback)
  4. }
  5.  
  6. interface AuthCallback {
  7.     fun onSuccess()
  8.  
  9.     fun onError(error: String)
  10. }
  11.  
  12. class RepositoryImpl(auth: FirebaseAuth) : Repository {
  13.  
  14.     override fun firebaseAuthWithGoogle(idToken: String,callback: AuthCallback) {
  15.         auth.singInWithCredential().addOnCompleteListener() { task ->
  16.             if (task.isSuccessful) {
  17.                 callback.onSuccess()
  18.             } else {
  19.                 callback.onError(error: String)
  20.             }
  21.         }
  22.     }
  23.  
  24. }
  25.  
  26. interface Interactor {
  27.    fun firebaseAuthWithGoogle(idToken: String,callback: AuthCallback)
  28.  
  29. }
  30.  
  31. class InteractorImpl(private val repository: Repository) : Interactor {
  32.  
  33.     override fun firebaseAuthWithGoogle(idToken: String,callback: AuthCallback) {
  34.         repository. firebaseAuthWithGoogle(idToken,callback)
  35.     }
  36. }
  37.  
  38.  
  39. class MainViewModel(private val interactor: Interactor) {
  40.    
  41.     fun firebaseAuthWithGoogle(idToken: String,callback: AuthCallback) {
  42.         interactor.firebaseAuthWithGoogle(idToken,callback)
  43.     }
  44.  
  45. }
  46.  
  47. class MainActivity {
  48.  
  49.     mainViewModel. firebaseAuthWithGoogle("token",object : AuthCalback {
  50.  
  51.         override fun onSuccess() {
  52.             toast.show()
  53.         }
  54.  
  55.         override fun onError() {
  56.             toast.show()
  57.         }
  58.     })
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement