From 8a6fae0f852bc233fce6aaee6f3d5f31ca2dfbcb Mon Sep 17 00:00:00 2001 From: Anselmo Alexandre Date: Tue, 16 May 2023 12:30:44 +0200 Subject: [PATCH 1/3] Added abstract provider of authentication viewmodel --- .../com/hover/stax/login/AbstractGoogleAuthActivity.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/hover/stax/login/AbstractGoogleAuthActivity.kt b/app/src/main/java/com/hover/stax/login/AbstractGoogleAuthActivity.kt index f4da969c0..ead27cb72 100644 --- a/app/src/main/java/com/hover/stax/login/AbstractGoogleAuthActivity.kt +++ b/app/src/main/java/com/hover/stax/login/AbstractGoogleAuthActivity.kt @@ -38,7 +38,6 @@ import com.hover.stax.core.Utils import com.hover.stax.presentation.bounties.BountyApplicationFragmentDirections import com.hover.stax.utils.UIHelper import timber.log.Timber -import javax.inject.Inject const val FORCED_VERSION = "force_update_app_version" @@ -46,8 +45,7 @@ abstract class AbstractGoogleAuthActivity : AppCompatActivity(), StaxGoogleLoginInterface { - @Inject - lateinit var loginViewModel: LoginViewModel + private lateinit var loginViewModel: LoginViewModel private lateinit var staxGoogleLoginInterface: StaxGoogleLoginInterface private lateinit var updateManager: AppUpdateManager @@ -55,6 +53,9 @@ abstract class AbstractGoogleAuthActivity : override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + + loginViewModel = provideAuthenticationViewModel() + initGoogleAuth() setLoginObserver() @@ -82,6 +83,8 @@ abstract class AbstractGoogleAuthActivity : this.staxGoogleLoginInterface = staxGoogleLoginInterface } + abstract fun provideAuthenticationViewModel(): LoginViewModel + private fun initGoogleAuth() { val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken(getString(R.string.google_server_client_id)).requestEmail().build() From c942a3a8ee80ee7d40fcb7ff2e94819bddc8773f Mon Sep 17 00:00:00 2001 From: Anselmo Alexandre Date: Tue, 16 May 2023 12:31:24 +0200 Subject: [PATCH 2/3] Overrided the provider method and added Hilt entry point annotaiton --- app/src/main/java/com/hover/stax/home/MainActivity.kt | 8 ++++++++ .../java/com/hover/stax/onboarding/OnBoardingActivity.kt | 8 ++++++++ .../hover/stax/presentation/welcome/WelcomeFragment.kt | 2 ++ 3 files changed, 18 insertions(+) diff --git a/app/src/main/java/com/hover/stax/home/MainActivity.kt b/app/src/main/java/com/hover/stax/home/MainActivity.kt index bcca18722..7f7f63d80 100644 --- a/app/src/main/java/com/hover/stax/home/MainActivity.kt +++ b/app/src/main/java/com/hover/stax/home/MainActivity.kt @@ -18,6 +18,7 @@ package com.hover.stax.home import android.content.Intent import android.os.Bundle import androidx.activity.viewModels +import androidx.lifecycle.ViewModel import androidx.navigation.NavDirections import com.hover.sdk.actions.HoverAction import com.hover.sdk.api.Hover @@ -27,6 +28,7 @@ import com.hover.stax.MainNavigationDirections import com.hover.stax.R import com.hover.stax.databinding.ActivityMainBinding import com.hover.stax.login.AbstractGoogleAuthActivity +import com.hover.stax.login.LoginViewModel import com.hover.stax.notifications.PushNotificationTopicsInterface import com.hover.stax.presentation.financial_tips.FinancialTipsFragment import com.hover.stax.requests.NewRequestViewModel @@ -38,12 +40,16 @@ import com.hover.stax.transactions.TransactionHistoryViewModel import com.hover.stax.transfers.TransferViewModel import com.hover.stax.utils.UIHelper import com.hover.stax.views.StaxDialog +import dagger.hilt.android.AndroidEntryPoint import timber.log.Timber +@AndroidEntryPoint class MainActivity : AbstractGoogleAuthActivity(), BiometricChecker.AuthListener, PushNotificationTopicsInterface, RequestSenderInterface { lateinit var navHelper: NavHelper + private val loginViewModel : LoginViewModel by viewModels() + private val transferViewModel: TransferViewModel by viewModels() private val requestViewModel: NewRequestViewModel by viewModels() private val historyViewModel: TransactionHistoryViewModel by viewModels() @@ -76,6 +82,8 @@ class MainActivity : AbstractGoogleAuthActivity(), BiometricChecker.AuthListener navHelper.setUpNav() } + override fun provideAuthenticationViewModel(): LoginViewModel = loginViewModel + fun checkPermissionsAndNavigate(navDirections: NavDirections) { navHelper.checkPermissionsAndNavigate(navDirections) } diff --git a/app/src/main/java/com/hover/stax/onboarding/OnBoardingActivity.kt b/app/src/main/java/com/hover/stax/onboarding/OnBoardingActivity.kt index 3b6cb33e8..d43aabedd 100644 --- a/app/src/main/java/com/hover/stax/onboarding/OnBoardingActivity.kt +++ b/app/src/main/java/com/hover/stax/onboarding/OnBoardingActivity.kt @@ -17,6 +17,7 @@ package com.hover.stax.onboarding import android.content.Intent import android.os.Bundle +import androidx.activity.viewModels import androidx.navigation.NavController import androidx.navigation.fragment.NavHostFragment import com.hover.sdk.permissions.PermissionHelper @@ -32,12 +33,17 @@ import com.hover.stax.permissions.PermissionUtils import com.hover.stax.utils.NavUtil import com.hover.stax.utils.UIHelper import com.hover.stax.core.Utils +import com.hover.stax.login.LoginViewModel +import dagger.hilt.android.AndroidEntryPoint +@AndroidEntryPoint class OnBoardingActivity : AbstractGoogleAuthActivity() { private lateinit var binding: OnboardingLayoutBinding private lateinit var navController: NavController + private val loginViewModel: LoginViewModel by viewModels() + override fun onCreate(savedInstanceState: Bundle?) { UIHelper.setFullscreenView(this) super.onCreate(savedInstanceState) @@ -51,6 +57,8 @@ class OnBoardingActivity : AbstractGoogleAuthActivity() { setGoogleLoginInterface(this) } + override fun provideAuthenticationViewModel(): LoginViewModel = loginViewModel + private fun setupNavigation() { val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment_onboarding) as NavHostFragment navController = navHostFragment.navController diff --git a/app/src/main/java/com/hover/stax/presentation/welcome/WelcomeFragment.kt b/app/src/main/java/com/hover/stax/presentation/welcome/WelcomeFragment.kt index 2e2f873fb..e3576a239 100644 --- a/app/src/main/java/com/hover/stax/presentation/welcome/WelcomeFragment.kt +++ b/app/src/main/java/com/hover/stax/presentation/welcome/WelcomeFragment.kt @@ -30,7 +30,9 @@ import com.hover.stax.onboarding.OnBoardingActivity import com.hover.stax.utils.NavUtil import com.hover.stax.utils.UIHelper import com.hover.stax.views.StaxDialog +import dagger.hilt.android.AndroidEntryPoint +@AndroidEntryPoint class WelcomeFragment : Fragment() { private var dialog: StaxDialog? = null From 495105e7dcd4e891720779fc49c31f0066ddb86f Mon Sep 17 00:00:00 2001 From: Juma Allan Date: Tue, 16 May 2023 14:23:42 +0300 Subject: [PATCH 3/3] fixed a few things --- app/src/main/java/com/hover/stax/home/MainActivity.kt | 5 ++--- .../java/com/hover/stax/login/AbstractGoogleAuthActivity.kt | 3 +++ .../stax/presentation/bounties/BountyApplicationFragment.kt | 2 +- .../main/java/com/hover/stax/settings/SettingsFragment.kt | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/hover/stax/home/MainActivity.kt b/app/src/main/java/com/hover/stax/home/MainActivity.kt index 57dbe6dcb..f50c3a554 100644 --- a/app/src/main/java/com/hover/stax/home/MainActivity.kt +++ b/app/src/main/java/com/hover/stax/home/MainActivity.kt @@ -61,9 +61,8 @@ class MainActivity : AbstractGoogleAuthActivity(), BiometricChecker.AuthListener val loginViewModel: LoginViewModel by viewModels() return loginViewModel } - lateinit var navHelper: NavHelper - private val loginViewModel : LoginViewModel by viewModels() + lateinit var navHelper: NavHelper private val transferViewModel: TransferViewModel by viewModels() private val requestViewModel: NewRequestViewModel by viewModels() @@ -143,7 +142,7 @@ class MainActivity : AbstractGoogleAuthActivity(), BiometricChecker.AuthListener } } - fun signIn() = loginForResult.launch(loginViewModel.signInClient.signInIntent) + fun signInUser() = loginForResult.launch(loginViewModel.signInClient.signInIntent) private val loginForResult = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> diff --git a/app/src/main/java/com/hover/stax/login/AbstractGoogleAuthActivity.kt b/app/src/main/java/com/hover/stax/login/AbstractGoogleAuthActivity.kt index 56728834d..5bdcd370c 100644 --- a/app/src/main/java/com/hover/stax/login/AbstractGoogleAuthActivity.kt +++ b/app/src/main/java/com/hover/stax/login/AbstractGoogleAuthActivity.kt @@ -17,8 +17,11 @@ package com.hover.stax.login import android.content.Intent import android.os.Bundle +import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat +import com.google.android.gms.auth.api.signin.GoogleSignIn +import com.google.android.gms.auth.api.signin.GoogleSignInOptions import com.google.android.material.snackbar.Snackbar import com.google.android.play.core.appupdate.AppUpdateInfo import com.google.android.play.core.appupdate.AppUpdateManager diff --git a/app/src/main/java/com/hover/stax/presentation/bounties/BountyApplicationFragment.kt b/app/src/main/java/com/hover/stax/presentation/bounties/BountyApplicationFragment.kt index 09cb33c6a..863d91794 100644 --- a/app/src/main/java/com/hover/stax/presentation/bounties/BountyApplicationFragment.kt +++ b/app/src/main/java/com/hover/stax/presentation/bounties/BountyApplicationFragment.kt @@ -122,7 +122,7 @@ class BountyApplicationFragment : Fragment(), View.OnClickListener { private fun startGoogleSignIn() { logAnalyticsEvent(getString(R.string.clicked_bounty_email_continue_btn), requireContext()) updateProgress(0) - (activity as MainActivity).signIn() + (activity as MainActivity).signInUser() } // TODO - delete me diff --git a/app/src/main/java/com/hover/stax/settings/SettingsFragment.kt b/app/src/main/java/com/hover/stax/settings/SettingsFragment.kt index c9c87e475..864ec954d 100644 --- a/app/src/main/java/com/hover/stax/settings/SettingsFragment.kt +++ b/app/src/main/java/com/hover/stax/settings/SettingsFragment.kt @@ -376,7 +376,7 @@ class SettingsFragment : Fragment() { private fun startGoogleLogin() { binding.staxSupport.contactCard.showProgressIndicator() optInMarketing = true - (requireActivity() as MainActivity).signIn() + (requireActivity() as MainActivity).signInUser() } private fun marketingOptIn(optedIn: Boolean) {