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 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)

View File

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

View File

@ -39,6 +39,7 @@ internal class ServicesRepositoryImpl(
) : ServicesRepository {
private val isTickerEnabled = MutableStateFlow(true)
private var guideManualPrefill: String? = null
override fun observeServices(): Flow<List<Service>> {
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
}
}

View File

@ -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 ->

View File

@ -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<GuideJson.Step>,
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,
)
}

View File

@ -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) {