From 2edbec7bf75c5e7ff8ff0ce587e839c978d1b89b Mon Sep 17 00:00:00 2001 From: AmadeyKuspakov Date: Mon, 10 Jul 2023 03:28:22 +0400 Subject: [PATCH] Major refactoring of architecture #6 --- .../java/jp/co/soramitsu/card/MainActivity.kt | 4 +- .../soramitsu/oauth/base/SoraCardNavGraph.kt | 18 +++---- .../oauth/base/navigation/NavigationExt.kt | 9 ---- .../co/soramitsu/oauth/base/sdk/SdkConfig.kt | 2 +- .../account/impl/AccountInteractorImpl.kt | 16 +++++-- .../impl/NavigationCoordinatorImpl.kt | 16 +++++-- .../flow/login/api/LoginDestination.kt | 7 +++ .../flow/login/impl/LoginFlowImpl.kt | 26 ++++++---- .../session/api/UserSessionRepository.kt | 10 ++++ .../session/impl/UserSessionRepositoryImpl.kt | 11 +++++ .../activityresult/impl/ActivityResultImpl.kt | 18 ++----- .../preferences/api/KeyValuePreferences.kt | 6 ++- .../impl/KeyValuePreferencesImpl.kt | 16 ++++++- .../oauth/feature/login/web/WebPageScreen.kt | 10 +--- .../feature/login/web/WebPageViewModel.kt | 48 ++++++++++--------- 15 files changed, 128 insertions(+), 89 deletions(-) diff --git a/app/src/main/java/jp/co/soramitsu/card/MainActivity.kt b/app/src/main/java/jp/co/soramitsu/card/MainActivity.kt index 8be4d1ca..133bb4e7 100644 --- a/app/src/main/java/jp/co/soramitsu/card/MainActivity.kt +++ b/app/src/main/java/jp/co/soramitsu/card/MainActivity.kt @@ -74,7 +74,7 @@ class MainActivity : ComponentActivity() { ) }, client = buildClient(), - userAvailableXorAmount = 1.9 + userAvailableXorAmount = 120.0 ) ) } @@ -89,7 +89,7 @@ class MainActivity : ComponentActivity() { soraCardInfo = null, kycCredentials = SoraCardKycCredentials("", "", ""), client = buildClient(), - userAvailableXorAmount = 1.9 + userAvailableXorAmount = 120.0 ) ) } diff --git a/oauth/src/main/java/jp/co/soramitsu/oauth/base/SoraCardNavGraph.kt b/oauth/src/main/java/jp/co/soramitsu/oauth/base/SoraCardNavGraph.kt index 057a356e..525e5701 100644 --- a/oauth/src/main/java/jp/co/soramitsu/oauth/base/SoraCardNavGraph.kt +++ b/oauth/src/main/java/jp/co/soramitsu/oauth/base/SoraCardNavGraph.kt @@ -19,6 +19,7 @@ import jp.co.soramitsu.oauth.core.engines.router.api.SoraCardDestinations import jp.co.soramitsu.oauth.feature.login.terms.TermsAndConditionsScreen import jp.co.soramitsu.oauth.feature.login.enterphone.EnterPhoneNumberScreen import jp.co.soramitsu.oauth.feature.login.enterotp.VerifyPhoneNumberScreen +import jp.co.soramitsu.oauth.feature.login.web.WebPageScreen import jp.co.soramitsu.oauth.feature.registration.enternames.RegisterUserScreen import jp.co.soramitsu.oauth.feature.registration.enteremail.EnterEmailScreen import jp.co.soramitsu.oauth.feature.registration.sendverificationemail.VerifyEmailScreen @@ -87,18 +88,11 @@ internal fun SoraCardNavGraph( GetPreparedScreen() } -// animatedComposable( -// route = Destination.WEB_PAGE.route -// .plus(Argument.TITLE.path()) -// .plus(Argument.URL.path()) -// ) { backStackEntry -> -// WebPageScreen( -// title = backStackEntry.requireArguments() -// .requireString(Argument.TITLE.arg), -// webUrl = backStackEntry.requireArguments() -// .requireString(Argument.URL.arg) -// ) -// } + animatedComposable( + route = LoginDestination.WebPage.route + ) { + WebPageScreen() + } animatedComposable( route = VerificationDestination.VerificationFailed.route diff --git a/oauth/src/main/java/jp/co/soramitsu/oauth/base/navigation/NavigationExt.kt b/oauth/src/main/java/jp/co/soramitsu/oauth/base/navigation/NavigationExt.kt index 44fdf79b..28e59d96 100644 --- a/oauth/src/main/java/jp/co/soramitsu/oauth/base/navigation/NavigationExt.kt +++ b/oauth/src/main/java/jp/co/soramitsu/oauth/base/navigation/NavigationExt.kt @@ -1,13 +1,8 @@ package jp.co.soramitsu.oauth.base.navigation -import android.os.Bundle import androidx.compose.animation.AnimatedVisibilityScope import androidx.compose.animation.ExperimentalAnimationApi -import androidx.compose.animation.core.CubicBezierEasing import androidx.compose.animation.core.tween -import androidx.compose.animation.expandVertically -import androidx.compose.animation.scaleIn -import androidx.compose.animation.shrinkVertically import androidx.compose.animation.slideInHorizontally import androidx.compose.animation.slideOutHorizontally import androidx.compose.runtime.Composable @@ -31,28 +26,24 @@ fun NavGraphBuilder.animatedComposable( arguments = arguments, deepLinks = deepLinks, enterTransition = { - println("This is checkpoint: enterTransition - ${this.initialState.destination.route} to ${this.targetState.destination.route}") slideInHorizontally( initialOffsetX = { it }, animationSpec = tween(TRANSITION_DURATION) ) }, popEnterTransition = { - println("This is checkpoint: popEnterTransition - ${this.initialState.destination.route} to ${this.targetState.destination.route}") slideInHorizontally( initialOffsetX = { -it }, animationSpec = tween(TRANSITION_DURATION) ) }, exitTransition = { - println("This is checkpoint: exitTransition - ${this.initialState.destination.route} to ${this.targetState.destination.route}") slideOutHorizontally( targetOffsetX = { -it }, animationSpec = tween(TRANSITION_DURATION) ) }, popExitTransition = { - println("This is checkpoint: popExitTransition - ${this.initialState.destination.route} to ${this.targetState.destination.route}") slideOutHorizontally( targetOffsetX = { it }, animationSpec = tween(TRANSITION_DURATION) diff --git a/oauth/src/main/java/jp/co/soramitsu/oauth/base/sdk/SdkConfig.kt b/oauth/src/main/java/jp/co/soramitsu/oauth/base/sdk/SdkConfig.kt index 133bea09..614c784a 100644 --- a/oauth/src/main/java/jp/co/soramitsu/oauth/base/sdk/SdkConfig.kt +++ b/oauth/src/main/java/jp/co/soramitsu/oauth/base/sdk/SdkConfig.kt @@ -14,7 +14,7 @@ class InMemoryRepo @Inject constructor() { var mode: Mode? = null var environment: SoraCardEnvironmentType = SoraCardEnvironmentType.NOT_DEFINED var client: String = BuildConfig.LIBRARY_PACKAGE_NAME - var userAvailableXorAmount: Double = 0.toDouble() + var userAvailableXorAmount: Double = 120.toDouble() val euroLiquidityThreshold = 100 val euroCardIssuancePrice = 20 diff --git a/oauth/src/main/java/jp/co/soramitsu/oauth/common/interactors/account/impl/AccountInteractorImpl.kt b/oauth/src/main/java/jp/co/soramitsu/oauth/common/interactors/account/impl/AccountInteractorImpl.kt index 7cbaa546..7c6ea347 100644 --- a/oauth/src/main/java/jp/co/soramitsu/oauth/common/interactors/account/impl/AccountInteractorImpl.kt +++ b/oauth/src/main/java/jp/co/soramitsu/oauth/common/interactors/account/impl/AccountInteractorImpl.kt @@ -66,9 +66,12 @@ class AccountInteractorImpl @Inject constructor( val kycStatusToSave = tachiRepository.getKycStatus(header, it.accessToken).getOrThrow() - ?: KycStatus.NotInitialized + ?: KycStatus.Started - userSessionRepository.setKycStatus(kycStatusToSave) + userSessionRepository.apply { + setKycStatus(kycStatusToSave) + setFirstTimeUsage(true) + } } AccountOperationResult.Executed @@ -83,9 +86,12 @@ class AccountInteractorImpl @Inject constructor( val kycStatusToSave = tachiRepository.getKycStatus(header, it.accessToken).getOrThrow() - ?: KycStatus.NotInitialized + ?: KycStatus.Started - userSessionRepository.setKycStatus(kycStatusToSave) + userSessionRepository.apply { + setKycStatus(kycStatusToSave) + setFirstTimeUsage(true) + } } AccountOperationResult.Executed @@ -221,7 +227,7 @@ class AccountInteractorImpl @Inject constructor( val kycStatusToSave = tachiRepository.getKycStatus(header, accessToken).getOrThrow() - ?: KycStatus.NotInitialized + ?: KycStatus.Started userSessionRepository.setKycStatus(kycStatusToSave) } diff --git a/oauth/src/main/java/jp/co/soramitsu/oauth/common/navigation/coordinator/impl/NavigationCoordinatorImpl.kt b/oauth/src/main/java/jp/co/soramitsu/oauth/common/navigation/coordinator/impl/NavigationCoordinatorImpl.kt index 4d8ad7a0..a91e2cf7 100644 --- a/oauth/src/main/java/jp/co/soramitsu/oauth/common/navigation/coordinator/impl/NavigationCoordinatorImpl.kt +++ b/oauth/src/main/java/jp/co/soramitsu/oauth/common/navigation/coordinator/impl/NavigationCoordinatorImpl.kt @@ -12,18 +12,22 @@ import jp.co.soramitsu.oauth.common.navigation.flow.verification.api.Verificatio import jp.co.soramitsu.oauth.core.datasources.paywings.api.PayWingsRepository import jp.co.soramitsu.oauth.core.datasources.paywings.api.PayWingsResponse import jp.co.soramitsu.oauth.core.datasources.session.api.UserSessionRepository +import jp.co.soramitsu.oauth.core.engines.coroutines.api.CoroutinesStorage import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.merge +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext import javax.inject.Inject class NavigationCoordinatorImpl @Inject constructor( payWingsRepository: PayWingsRepository, userSessionRepository: UserSessionRepository, inMemoryRepo: InMemoryRepo, + coroutinesStorage: CoroutinesStorage, private val loginFlow: LoginFlow, private val registrationFlow: RegistrationFlow, private val verificationFlow: VerificationFlow, @@ -88,9 +92,15 @@ class NavigationCoordinatorImpl @Inject constructor( is PayWingsResponse.NavigationIncentive -> { when(payWingsResponse) { is PayWingsResponse.NavigationIncentive.OnUserSignInRequiredScreen -> { - loginFlow.onStart( - destination = LoginDestination.EnterPhone - ) + coroutinesStorage.unsupervisedUiScope.launch { + val isFirstTimeUsage = withContext(coroutinesStorage.dispatcherIo) { + userSessionRepository.isFirstTimeUsage() + } + + if (isFirstTimeUsage) + loginFlow.onStart(destination = LoginDestination.TermsAndConditions) else + loginFlow.onStart(destination = LoginDestination.EnterPhone) + } } is PayWingsResponse.NavigationIncentive.OnVerificationOtpBeenSent -> { loginFlow.onStart( diff --git a/oauth/src/main/java/jp/co/soramitsu/oauth/common/navigation/flow/login/api/LoginDestination.kt b/oauth/src/main/java/jp/co/soramitsu/oauth/common/navigation/flow/login/api/LoginDestination.kt index 0dd0363e..6339f9ba 100644 --- a/oauth/src/main/java/jp/co/soramitsu/oauth/common/navigation/flow/login/api/LoginDestination.kt +++ b/oauth/src/main/java/jp/co/soramitsu/oauth/common/navigation/flow/login/api/LoginDestination.kt @@ -8,6 +8,13 @@ sealed interface LoginDestination: SoraCardDestinations { override val route: String = "TERMS_AND_CONDITIONS" } + object WebPage: LoginDestination { + override val route: String = "WebPage" + + const val TITLE_STRING_RES_KEY = "TITLE_STRING_RES_KEY" + const val URL_KEY = "URL_KEY" + } + object EnterPhone: LoginDestination { override val route: String = "ENTER_PHONE" } diff --git a/oauth/src/main/java/jp/co/soramitsu/oauth/common/navigation/flow/login/impl/LoginFlowImpl.kt b/oauth/src/main/java/jp/co/soramitsu/oauth/common/navigation/flow/login/impl/LoginFlowImpl.kt index f73b81ae..8f423404 100644 --- a/oauth/src/main/java/jp/co/soramitsu/oauth/common/navigation/flow/login/impl/LoginFlowImpl.kt +++ b/oauth/src/main/java/jp/co/soramitsu/oauth/common/navigation/flow/login/impl/LoginFlowImpl.kt @@ -2,13 +2,12 @@ package jp.co.soramitsu.oauth.common.navigation.flow.login.impl import android.os.Bundle import androidx.core.os.bundleOf +import jp.co.soramitsu.oauth.R import jp.co.soramitsu.oauth.core.engines.activityresult.api.SoraCardResult import jp.co.soramitsu.oauth.common.navigation.flow.login.api.LoginDestination import jp.co.soramitsu.oauth.common.navigation.flow.login.api.LoginFlow -import jp.co.soramitsu.oauth.common.navigation.flow.registration.api.RegistrationDestination import jp.co.soramitsu.oauth.core.engines.activityresult.api.ActivityResult import jp.co.soramitsu.oauth.core.engines.router.api.ComposeRouter -import jp.co.soramitsu.oauth.core.engines.router.api.SoraCardDestinations import javax.inject.Inject class LoginFlowImpl @Inject constructor( @@ -22,10 +21,6 @@ class LoginFlowImpl @Inject constructor( override fun onStart(destination: LoginDestination) = when(destination) { - is LoginDestination.TermsAndConditions -> - composeRouter.setNewStartDestination(destination) - is LoginDestination.EnterPhone -> - composeRouter.setNewStartDestination(destination) is LoginDestination.EnterOtp -> { _args[destination::class.java.name] = bundleOf().apply { putInt( @@ -35,6 +30,7 @@ class LoginFlowImpl @Inject constructor( } composeRouter.setNewStartDestination(destination) } + else -> composeRouter.setNewStartDestination(destination) } override fun onBack() { @@ -46,11 +42,25 @@ class LoginFlowImpl @Inject constructor( } override fun onGeneralTermsClicked() { - // TODO open WebView + val title = R.string.terms_and_conditions_general_terms + val url = "https://soracard.com/terms/" + + _args[LoginDestination.WebPage::class.java.name] = Bundle().apply { + putInt(LoginDestination.WebPage.TITLE_STRING_RES_KEY, title) + putString(LoginDestination.WebPage.URL_KEY, url) + } + composeRouter.navigateTo(LoginDestination.WebPage) } override fun onPrivacyPolicyClicked() { - // TODO open WebView + val title = R.string.terms_and_conditions_privacy_policy + val url = "https://soracard.com/privacy/" + + _args[LoginDestination.WebPage::class.java.name] = Bundle().apply { + putInt(LoginDestination.WebPage.TITLE_STRING_RES_KEY, title) + putString(LoginDestination.WebPage.URL_KEY, url) + } + composeRouter.navigateTo(LoginDestination.WebPage) } override fun onAcceptTermsAndConditions() { diff --git a/oauth/src/main/java/jp/co/soramitsu/oauth/core/datasources/session/api/UserSessionRepository.kt b/oauth/src/main/java/jp/co/soramitsu/oauth/core/datasources/session/api/UserSessionRepository.kt index e84ce205..a6702c01 100644 --- a/oauth/src/main/java/jp/co/soramitsu/oauth/core/datasources/session/api/UserSessionRepository.kt +++ b/oauth/src/main/java/jp/co/soramitsu/oauth/core/datasources/session/api/UserSessionRepository.kt @@ -22,9 +22,19 @@ interface UserSessionRepository { status: KycStatus ) + suspend fun setKycFailureDescription( + description: String + ) + + suspend fun setFirstTimeUsage( + isTrue: Boolean + ) + suspend fun getAccessToken(): String suspend fun getAccessTokenExpirationTime(): Long suspend fun getRefreshToken(): String + + suspend fun isFirstTimeUsage(): Boolean } diff --git a/oauth/src/main/java/jp/co/soramitsu/oauth/core/datasources/session/impl/UserSessionRepositoryImpl.kt b/oauth/src/main/java/jp/co/soramitsu/oauth/core/datasources/session/impl/UserSessionRepositoryImpl.kt index 0370efd7..21a1d956 100644 --- a/oauth/src/main/java/jp/co/soramitsu/oauth/core/datasources/session/impl/UserSessionRepositoryImpl.kt +++ b/oauth/src/main/java/jp/co/soramitsu/oauth/core/datasources/session/impl/UserSessionRepositoryImpl.kt @@ -18,6 +18,7 @@ class UserSessionRepositoryImpl @Inject constructor( const val REFRESH_TOKEN_KEY = "REFRESH_TOKEN_KEY" const val KYC_STATUS_KEY = "KYC_STATUS_KEY" const val ADDITIONAL_VERIFICATION_INFO_KEY = "ADDITIONAL_VERIFICATION_INFO_KEY" + const val IS_FIRST_TIME_USAGE_KEY = "IS_FIRST_TIME_USAGE_KEY" } override val kycStatusFlow: Flow = preferences.dataFlow.map { @@ -43,6 +44,13 @@ class UserSessionRepositoryImpl @Inject constructor( override suspend fun setKycStatus(status: KycStatus) = preferences.putString(KYC_STATUS_KEY, status.name) + override suspend fun setKycFailureDescription(description: String) = + preferences.putString(ADDITIONAL_VERIFICATION_INFO_KEY, description) + + override suspend fun setFirstTimeUsage(isTrue: Boolean) { + preferences.putBoolean(IS_FIRST_TIME_USAGE_KEY, isTrue) + } + override suspend fun getAccessToken(): String = preferences.getString(ACCESS_TOKEN_KEY) @@ -51,4 +59,7 @@ class UserSessionRepositoryImpl @Inject constructor( override suspend fun getRefreshToken(): String = preferences.getString(REFRESH_TOKEN_KEY) + + override suspend fun isFirstTimeUsage(): Boolean = + preferences.getBoolean(IS_FIRST_TIME_USAGE_KEY, true) } diff --git a/oauth/src/main/java/jp/co/soramitsu/oauth/core/engines/activityresult/impl/ActivityResultImpl.kt b/oauth/src/main/java/jp/co/soramitsu/oauth/core/engines/activityresult/impl/ActivityResultImpl.kt index 52313da0..6adeeaae 100644 --- a/oauth/src/main/java/jp/co/soramitsu/oauth/core/engines/activityresult/impl/ActivityResultImpl.kt +++ b/oauth/src/main/java/jp/co/soramitsu/oauth/core/engines/activityresult/impl/ActivityResultImpl.kt @@ -5,34 +5,22 @@ import android.content.Intent import android.os.Looper import androidx.activity.result.ActivityResultLauncher import com.paywings.onboarding.kyc.android.sdk.data.model.KycContractData -import com.paywings.onboarding.kyc.android.sdk.data.model.KycCredentials -import com.paywings.onboarding.kyc.android.sdk.data.model.KycSettings -import com.paywings.onboarding.kyc.android.sdk.data.model.KycUserData -import com.paywings.onboarding.kyc.android.sdk.data.model.UserCredentials -import jp.co.soramitsu.oauth.base.sdk.InMemoryRepo import jp.co.soramitsu.oauth.base.sdk.SoraCardConstants import jp.co.soramitsu.oauth.core.engines.activityresult.api.SoraCardResult import jp.co.soramitsu.oauth.core.engines.activityresult.api.ActivityResult import java.lang.ref.WeakReference -import java.util.UUID import javax.inject.Inject class ActivityResultImpl @Inject constructor(): ActivityResult { - private var kycContractWeakRef: WeakReference>? = null - get() = if (!Looper.getMainLooper().isCurrentThread) - throw IllegalAccessError(NOT_MAIN_THREAD_ACCESS) else - field + private var kycContractRef: ActivityResultLauncher? = null override fun setKycContract(launcher: ActivityResultLauncher) { - if (!Looper.getMainLooper().isCurrentThread) - throw IllegalAccessError(NOT_MAIN_THREAD_ACCESS) - - kycContractWeakRef = WeakReference(launcher) + kycContractRef = launcher } override fun launchKycContract(kycContractData: KycContractData): Boolean { - kycContractWeakRef?.get()?.launch(kycContractData) + kycContractRef?.launch(kycContractData) ?: return false return true } diff --git a/oauth/src/main/java/jp/co/soramitsu/oauth/core/engines/preferences/api/KeyValuePreferences.kt b/oauth/src/main/java/jp/co/soramitsu/oauth/core/engines/preferences/api/KeyValuePreferences.kt index 501333cb..3c7f1b04 100644 --- a/oauth/src/main/java/jp/co/soramitsu/oauth/core/engines/preferences/api/KeyValuePreferences.kt +++ b/oauth/src/main/java/jp/co/soramitsu/oauth/core/engines/preferences/api/KeyValuePreferences.kt @@ -11,9 +11,13 @@ interface KeyValuePreferences { suspend fun getString(field: String): String + suspend fun putLong(field: String, value: Long) + suspend fun getLong(field: String, defaultValue: Long): Long - suspend fun putLong(field: String, value: Long) + suspend fun putBoolean(field: String, value: Boolean) + + suspend fun getBoolean(field: String, defaultValue: Boolean): Boolean suspend fun clear(field: String) diff --git a/oauth/src/main/java/jp/co/soramitsu/oauth/core/engines/preferences/impl/KeyValuePreferencesImpl.kt b/oauth/src/main/java/jp/co/soramitsu/oauth/core/engines/preferences/impl/KeyValuePreferencesImpl.kt index 4744a365..fd36dd81 100644 --- a/oauth/src/main/java/jp/co/soramitsu/oauth/core/engines/preferences/impl/KeyValuePreferencesImpl.kt +++ b/oauth/src/main/java/jp/co/soramitsu/oauth/core/engines/preferences/impl/KeyValuePreferencesImpl.kt @@ -2,6 +2,7 @@ package jp.co.soramitsu.oauth.core.engines.preferences.impl import androidx.datastore.core.DataStore import androidx.datastore.preferences.core.Preferences +import androidx.datastore.preferences.core.booleanPreferencesKey import androidx.datastore.preferences.core.edit import androidx.datastore.preferences.core.longPreferencesKey import androidx.datastore.preferences.core.stringPreferencesKey @@ -29,17 +30,28 @@ class KeyValuePreferencesImpl @Inject constructor( it[stringPreferencesKey(field)] ?: "" }.first() + override suspend fun putLong(field: String, value: Long) { + dataStore.edit { + it[longPreferencesKey(field)] = value + } + } + override suspend fun getLong(field: String, defaultValue: Long): Long = dataStore.data.map { it[longPreferencesKey(field)] ?: defaultValue }.first() - override suspend fun putLong(field: String, value: Long) { + override suspend fun putBoolean(field: String, value: Boolean) { dataStore.edit { - it[longPreferencesKey(field)] = value + it[booleanPreferencesKey(field)] = value } } + override suspend fun getBoolean(field: String, defaultValue: Boolean): Boolean = + dataStore.data.map { + it[booleanPreferencesKey(field)] ?: defaultValue + }.first() + override suspend fun clear(field: String) { dataStore.edit { it.remove(stringPreferencesKey(field)) diff --git a/oauth/src/main/java/jp/co/soramitsu/oauth/feature/login/web/WebPageScreen.kt b/oauth/src/main/java/jp/co/soramitsu/oauth/feature/login/web/WebPageScreen.kt index 2012fc3c..1e083949 100644 --- a/oauth/src/main/java/jp/co/soramitsu/oauth/feature/login/web/WebPageScreen.kt +++ b/oauth/src/main/java/jp/co/soramitsu/oauth/feature/login/web/WebPageScreen.kt @@ -28,14 +28,8 @@ import jp.co.soramitsu.ui_core.theme.customColors @SuppressLint("SetJavaScriptEnabled") @Composable fun WebPageScreen( - title: String, - webUrl: String, viewModel: WebPageViewModel = hiltViewModel() ) { - LaunchedEffect(Unit) { - viewModel.setArgs(title, webUrl) - } - Screen( viewModel = viewModel ) { @@ -56,12 +50,12 @@ fun WebPageScreen( } } settings.javaScriptEnabled = true - loadUrl(WebUrl.valueOf(webUrl).url) + loadUrl(state.url) } } ) - if (state.value.loading) { + if (state.loading) { ProgressDialog() } } diff --git a/oauth/src/main/java/jp/co/soramitsu/oauth/feature/login/web/WebPageViewModel.kt b/oauth/src/main/java/jp/co/soramitsu/oauth/feature/login/web/WebPageViewModel.kt index 0c45e233..2d292e69 100644 --- a/oauth/src/main/java/jp/co/soramitsu/oauth/feature/login/web/WebPageViewModel.kt +++ b/oauth/src/main/java/jp/co/soramitsu/oauth/feature/login/web/WebPageViewModel.kt @@ -1,13 +1,14 @@ package jp.co.soramitsu.oauth.feature.login.web +import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue import dagger.hilt.android.lifecycle.HiltViewModel import javax.inject.Inject import jp.co.soramitsu.oauth.R import jp.co.soramitsu.oauth.base.BaseViewModel -import jp.co.soramitsu.oauth.base.navigation.MainRouter +import jp.co.soramitsu.oauth.common.navigation.flow.login.api.LoginDestination import jp.co.soramitsu.oauth.common.navigation.flow.login.api.LoginFlow -import jp.co.soramitsu.oauth.common.navigation.flow.verification.api.VerificationFlow import jp.co.soramitsu.oauth.feature.login.web.model.WebPageState import jp.co.soramitsu.oauth.feature.login.web.model.WebUrl import jp.co.soramitsu.ui_core.component.toolbar.BasicToolbarState @@ -19,36 +20,37 @@ class WebPageViewModel @Inject constructor( private val loginFlow: LoginFlow ) : BaseViewModel() { - var state = mutableStateOf(WebPageState()) + var state by mutableStateOf(WebPageState()) private set init { - _toolbarState.value = SoramitsuToolbarState( - type = SoramitsuToolbarType.Small(), - basic = BasicToolbarState( - title = "", - visibility = true, - navIcon = R.drawable.ic_toolbar_back - ), - ) + loginFlow.args[LoginDestination.WebPage::class.java.name] + .apply { + if (this == null) + return@apply + + + _toolbarState.value = SoramitsuToolbarState( + type = SoramitsuToolbarType.Small(), + basic = BasicToolbarState( + title = getInt(LoginDestination.WebPage.TITLE_STRING_RES_KEY), + visibility = true, + navIcon = R.drawable.ic_toolbar_back + ), + ) + + state = state.copy( + url = getString(LoginDestination.WebPage.URL_KEY)!!, + loading = true + ) + } } override fun onToolbarNavigation() { loginFlow.onBack() } - fun setArgs(title: String, webUrl: String) { - _toolbarState.value = _toolbarState.value?.copy( - basic = BasicToolbarState( - title = title, - visibility = true, - navIcon = R.drawable.ic_toolbar_back - ) - ) - state.value = state.value.copy(url = WebUrl.valueOf(webUrl).url) - } - fun onFinishLoading() { - state.value = state.value.copy(loading = false) + state = state.copy(loading = false) } }