Guided fixes

This commit is contained in:
Rafał Kobyłko 2023-09-02 21:28:53 +02:00
parent 5bb8dcf50f
commit 8f6e360869
6 changed files with 23 additions and 14 deletions

View File

@ -208,7 +208,6 @@ class Strings(c: Context) {
val guidesSelectDescription = c.getString(R.string.guides__select_description) val guidesSelectDescription = c.getString(R.string.guides__select_description)
val guidesSelectProvideGuide = c.getString(R.string.guides__select_provide_guide) val guidesSelectProvideGuide = c.getString(R.string.guides__select_provide_guide)
val guidesSelectProvideGuideCta = c.getString(R.string.guides__select_provide_guide_cta) 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 guideTitle = c.getString(R.string.guides__guide_title)
val guideUniversalTitle = c.getString(R.string.guides__guide_universal_title) val guideUniversalTitle = c.getString(R.string.guides__guide_universal_title)

View File

@ -30,5 +30,7 @@ interface ServicesRepository {
suspend fun addService(service: Service): Long suspend fun addService(service: Service): Long
fun observeAddServiceAdvancedExpanded(): Flow<Boolean> fun observeAddServiceAdvancedExpanded(): Flow<Boolean>
fun pushAddServiceAdvancedExpanded(expanded: Boolean) fun pushAddServiceAdvancedExpanded(expanded: Boolean)
fun setManualGuideSelectedPrefill(prefill: String?)
fun getManualGuideSelectedPrefill(): String?
suspend fun revealService(id: Long) suspend fun revealService(id: Long)
} }

View File

@ -39,6 +39,7 @@ internal class ServicesRepositoryImpl(
) : ServicesRepository { ) : ServicesRepository {
private val isTickerEnabled = MutableStateFlow(true) private val isTickerEnabled = MutableStateFlow(true)
private var guideManualPrefill: String? = null
override fun observeServices(): Flow<List<Service>> { override fun observeServices(): Flow<List<Service>> {
return combine( return combine(
@ -292,4 +293,12 @@ internal class ServicesRepositoryImpl(
local.revealService(id) local.revealService(id)
} }
} }
override fun setManualGuideSelectedPrefill(prefill: String?) {
guideManualPrefill = prefill
}
override fun getManualGuideSelectedPrefill(): String? {
return guideManualPrefill
}
} }

View File

@ -58,7 +58,7 @@ internal fun GuideInitScreen(
} }
Scaffold( Scaffold(
topBar = { TwTopAppBar(titleText = TwLocale.strings.guideInitTitle) } topBar = { TwTopAppBar(titleText = TwLocale.strings.guideTitle.format(guide.name)) }
) { padding -> ) { padding ->
guideJson?.let { guideJson -> guideJson?.let { guideJson ->

View File

@ -1,6 +1,5 @@
package com.twofasapp.feature.home.ui.guidepager package com.twofasapp.feature.home.ui.guidepager
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.background 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.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.twofasapp.data.services.ServicesRepository
import com.twofasapp.designsystem.TwTheme import com.twofasapp.designsystem.TwTheme
import com.twofasapp.designsystem.common.TwButton import com.twofasapp.designsystem.common.TwButton
import com.twofasapp.designsystem.common.TwTopAppBar import com.twofasapp.designsystem.common.TwTopAppBar
@ -54,6 +54,7 @@ import org.koin.compose.koinInject
@Composable @Composable
internal fun GuidePagerScreen( internal fun GuidePagerScreen(
json: Json = koinInject(), json: Json = koinInject(),
servicesRepository: ServicesRepository = koinInject(),
guide: Guide, guide: Guide,
guideVariantIndex: Int, guideVariantIndex: Int,
openAddScan: () -> Unit, openAddScan: () -> Unit,
@ -85,10 +86,12 @@ internal fun GuidePagerScreen(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
.padding(padding), .padding(padding),
guide = guide,
steps = guideJson.flow.menu.items[guideVariantIndex].steps, steps = guideJson.flow.menu.items[guideVariantIndex].steps,
openAddScan = openAddScan, openAddScan = openAddScan,
openAddManually = openAddManually, openAddManually = {
servicesRepository.setManualGuideSelectedPrefill(it)
openAddManually()
},
) )
} }
} }
@ -98,22 +101,16 @@ internal fun GuidePagerScreen(
@Composable @Composable
private fun Content( private fun Content(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
guide: Guide,
steps: List<GuideJson.Step>, steps: List<GuideJson.Step>,
openAddScan: () -> Unit = {}, openAddScan: () -> Unit = {},
openAddManually: () -> Unit = {}, openAddManually: (String?) -> Unit = {},
) { ) {
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
val stepsCount = steps.size val stepsCount = steps.size
val pagerState = rememberPagerState(pageCount = { stepsCount }) val pagerState = rememberPagerState(pageCount = { stepsCount })
val isFirstStep by remember { derivedStateOf { pagerState.currentPage == 0 } }
val isLastStep by remember { derivedStateOf { pagerState.currentPage == stepsCount - 1 } } val isLastStep by remember { derivedStateOf { pagerState.currentPage == stepsCount - 1 } }
BackHandler(enabled = isFirstStep.not()) {
scope.launch { pagerState.animateScrollToPage(pagerState.currentPage - 1) }
}
Column( Column(
modifier = modifier, modifier = modifier,
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
@ -204,7 +201,7 @@ private fun Content(
if (isLastStep) { if (isLastStep) {
when (steps[pagerState.currentPage].cta?.action) { when (steps[pagerState.currentPage].cta?.action) {
"open_scanner" -> openAddScan() "open_scanner" -> openAddScan()
"open_manually" -> openAddManually() "open_manually" -> openAddManually(steps[pagerState.currentPage].cta?.data)
else -> Unit else -> Unit
} }
} else { } else {
@ -222,7 +219,6 @@ private fun Preview() {
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
.background(TwTheme.color.background), .background(TwTheme.color.background),
guide = Guide.Universal,
steps = PreviewGuide.flow.menu.items.first().steps, steps = PreviewGuide.flow.menu.items.first().steps,
) )
} }

View File

@ -50,6 +50,9 @@ internal class AddServiceManualViewModel(
uiState.update { it.copy(advancedExpanded = expanded) } uiState.update { it.copy(advancedExpanded = expanded) }
} }
} }
servicesRepository.getManualGuideSelectedPrefill()?.let { updateName(it) }
servicesRepository.setManualGuideSelectedPrefill(null)
} }
fun updateAuthType(authType: Service.AuthType) { fun updateAuthType(authType: Service.AuthType) {