diff --git a/core/locale/src/main/java/com/twofasapp/locale/Strings.kt b/core/locale/src/main/java/com/twofasapp/locale/Strings.kt index 0e842656..de38399e 100644 --- a/core/locale/src/main/java/com/twofasapp/locale/Strings.kt +++ b/core/locale/src/main/java/com/twofasapp/locale/Strings.kt @@ -208,7 +208,6 @@ class Strings(c: Context) { val guidesSelectDescription = c.getString(R.string.guides__select_description) val guidesSelectProvideGuide = c.getString(R.string.guides__select_provide_guide) val guidesSelectProvideGuideCta = c.getString(R.string.guides__select_provide_guide_cta) - val guideInitTitle = c.getString(R.string.guides__guide_init_title) val guideTitle = c.getString(R.string.guides__guide_title) val guideUniversalTitle = c.getString(R.string.guides__guide_universal_title) diff --git a/data/services/src/main/java/com/twofasapp/data/services/ServicesRepository.kt b/data/services/src/main/java/com/twofasapp/data/services/ServicesRepository.kt index a95195a4..b5b85354 100644 --- a/data/services/src/main/java/com/twofasapp/data/services/ServicesRepository.kt +++ b/data/services/src/main/java/com/twofasapp/data/services/ServicesRepository.kt @@ -30,5 +30,7 @@ interface ServicesRepository { suspend fun addService(service: Service): Long fun observeAddServiceAdvancedExpanded(): Flow fun pushAddServiceAdvancedExpanded(expanded: Boolean) + fun setManualGuideSelectedPrefill(prefill: String?) + fun getManualGuideSelectedPrefill(): String? suspend fun revealService(id: Long) } \ No newline at end of file diff --git a/data/services/src/main/java/com/twofasapp/data/services/ServicesRepositoryImpl.kt b/data/services/src/main/java/com/twofasapp/data/services/ServicesRepositoryImpl.kt index ee950f76..259eae72 100644 --- a/data/services/src/main/java/com/twofasapp/data/services/ServicesRepositoryImpl.kt +++ b/data/services/src/main/java/com/twofasapp/data/services/ServicesRepositoryImpl.kt @@ -39,6 +39,7 @@ internal class ServicesRepositoryImpl( ) : ServicesRepository { private val isTickerEnabled = MutableStateFlow(true) + private var guideManualPrefill: String? = null override fun observeServices(): Flow> { return combine( @@ -292,4 +293,12 @@ internal class ServicesRepositoryImpl( local.revealService(id) } } + + override fun setManualGuideSelectedPrefill(prefill: String?) { + guideManualPrefill = prefill + } + + override fun getManualGuideSelectedPrefill(): String? { + return guideManualPrefill + } } \ No newline at end of file diff --git a/feature/home/src/main/java/com/twofasapp/feature/home/ui/guideinit/GuideInitScreen.kt b/feature/home/src/main/java/com/twofasapp/feature/home/ui/guideinit/GuideInitScreen.kt index 2e3ad251..60461b85 100644 --- a/feature/home/src/main/java/com/twofasapp/feature/home/ui/guideinit/GuideInitScreen.kt +++ b/feature/home/src/main/java/com/twofasapp/feature/home/ui/guideinit/GuideInitScreen.kt @@ -58,7 +58,7 @@ internal fun GuideInitScreen( } Scaffold( - topBar = { TwTopAppBar(titleText = TwLocale.strings.guideInitTitle) } + topBar = { TwTopAppBar(titleText = TwLocale.strings.guideTitle.format(guide.name)) } ) { padding -> guideJson?.let { guideJson -> diff --git a/feature/home/src/main/java/com/twofasapp/feature/home/ui/guidepager/GuidePagerScreen.kt b/feature/home/src/main/java/com/twofasapp/feature/home/ui/guidepager/GuidePagerScreen.kt index 55b36835..3b52e955 100644 --- a/feature/home/src/main/java/com/twofasapp/feature/home/ui/guidepager/GuidePagerScreen.kt +++ b/feature/home/src/main/java/com/twofasapp/feature/home/ui/guidepager/GuidePagerScreen.kt @@ -1,6 +1,5 @@ package com.twofasapp.feature.home.ui.guidepager -import androidx.activity.compose.BackHandler import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.Image import androidx.compose.foundation.background @@ -37,6 +36,7 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import com.twofasapp.data.services.ServicesRepository import com.twofasapp.designsystem.TwTheme import com.twofasapp.designsystem.common.TwButton import com.twofasapp.designsystem.common.TwTopAppBar @@ -54,6 +54,7 @@ import org.koin.compose.koinInject @Composable internal fun GuidePagerScreen( json: Json = koinInject(), + servicesRepository: ServicesRepository = koinInject(), guide: Guide, guideVariantIndex: Int, openAddScan: () -> Unit, @@ -85,10 +86,12 @@ internal fun GuidePagerScreen( modifier = Modifier .fillMaxSize() .padding(padding), - guide = guide, steps = guideJson.flow.menu.items[guideVariantIndex].steps, openAddScan = openAddScan, - openAddManually = openAddManually, + openAddManually = { + servicesRepository.setManualGuideSelectedPrefill(it) + openAddManually() + }, ) } } @@ -98,22 +101,16 @@ internal fun GuidePagerScreen( @Composable private fun Content( modifier: Modifier = Modifier, - guide: Guide, steps: List, openAddScan: () -> Unit = {}, - openAddManually: () -> Unit = {}, + openAddManually: (String?) -> Unit = {}, ) { val scope = rememberCoroutineScope() val stepsCount = steps.size val pagerState = rememberPagerState(pageCount = { stepsCount }) - val isFirstStep by remember { derivedStateOf { pagerState.currentPage == 0 } } val isLastStep by remember { derivedStateOf { pagerState.currentPage == stepsCount - 1 } } - BackHandler(enabled = isFirstStep.not()) { - scope.launch { pagerState.animateScrollToPage(pagerState.currentPage - 1) } - } - Column( modifier = modifier, horizontalAlignment = Alignment.CenterHorizontally, @@ -204,7 +201,7 @@ private fun Content( if (isLastStep) { when (steps[pagerState.currentPage].cta?.action) { "open_scanner" -> openAddScan() - "open_manually" -> openAddManually() + "open_manually" -> openAddManually(steps[pagerState.currentPage].cta?.data) else -> Unit } } else { @@ -222,7 +219,6 @@ private fun Preview() { modifier = Modifier .fillMaxSize() .background(TwTheme.color.background), - guide = Guide.Universal, steps = PreviewGuide.flow.menu.items.first().steps, ) } \ No newline at end of file diff --git a/feature/home/src/main/java/com/twofasapp/feature/home/ui/services/add/manual/AddServiceManualViewModel.kt b/feature/home/src/main/java/com/twofasapp/feature/home/ui/services/add/manual/AddServiceManualViewModel.kt index c2e6f22b..8b27d6cf 100644 --- a/feature/home/src/main/java/com/twofasapp/feature/home/ui/services/add/manual/AddServiceManualViewModel.kt +++ b/feature/home/src/main/java/com/twofasapp/feature/home/ui/services/add/manual/AddServiceManualViewModel.kt @@ -50,6 +50,9 @@ internal class AddServiceManualViewModel( uiState.update { it.copy(advancedExpanded = expanded) } } } + + servicesRepository.getManualGuideSelectedPrefill()?.let { updateName(it) } + servicesRepository.setManualGuideSelectedPrefill(null) } fun updateAuthType(authType: Service.AuthType) {