Skip to content

Commit

Permalink
Fix translation of next and previous button not working
Browse files Browse the repository at this point in the history
When Locale language is updated, it does not reflect the translation update of the next and previous button.
  • Loading branch information
FikriMilano committed Jan 23, 2025
1 parent 954fdae commit b813d03
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

package com.google.android.fhir.datacapture

import androidx.annotation.StringRes

sealed interface QuestionnaireNavigationViewUIState {
data object Hidden : QuestionnaireNavigationViewUIState

data class Enabled(val labelText: String? = null, val onClickAction: () -> Unit = {}) :
data class Enabled(val labelText: String? = null, @StringRes val stringResource: Int? = null, val onClickAction: () -> Unit = {}) :
QuestionnaireNavigationViewUIState
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ internal class QuestionnaireViewModel(application: Application, state: SavedStat
navCancel =
if (!isReadOnly && shouldShowCancelButton) {
QuestionnaireNavigationViewUIState.Enabled(
labelText = (getApplication() as Context).getString(R.string.cancel_questionnaire),
stringResource = R.string.cancel_questionnaire,
onClickAction = onCancelButtonClickListener,
)
} else {
Expand Down Expand Up @@ -838,8 +838,7 @@ internal class QuestionnaireViewModel(application: Application, state: SavedStat
when {
questionnairePagination.isPaginated && questionnairePagination.hasPreviousPage -> {
QuestionnaireNavigationViewUIState.Enabled(
labelText =
(getApplication() as Context).getString(R.string.button_pagination_previous),
stringResource = R.string.button_pagination_previous,
onClickAction = { goToPreviousPage() },
)
}
Expand All @@ -852,14 +851,11 @@ internal class QuestionnaireViewModel(application: Application, state: SavedStat
questionnairePagination.isPaginated &&
questionnairePagination.hasNextPage &&
isLoadingNextPage.value -> {
QuestionnaireNavigationViewUIState.Enabled(
labelText = null,
)
QuestionnaireNavigationViewUIState.Enabled()
}
questionnairePagination.isPaginated && questionnairePagination.hasNextPage -> {
QuestionnaireNavigationViewUIState.Enabled(
labelText =
(getApplication() as Context).getString(R.string.button_pagination_next),
stringResource = R.string.button_pagination_next,
onClickAction = { goToNextPage() },
)
}
Expand All @@ -879,7 +875,7 @@ internal class QuestionnaireViewModel(application: Application, state: SavedStat
navReview =
if (showReviewButton) {
QuestionnaireNavigationViewUIState.Enabled(
labelText = (getApplication() as Context).getString(R.string.button_review),
stringResource = R.string.button_review,
onClickAction = { setReviewMode(true) },
)
} else {
Expand All @@ -888,7 +884,7 @@ internal class QuestionnaireViewModel(application: Application, state: SavedStat
navCancel =
if (showCancelButton) {
QuestionnaireNavigationViewUIState.Enabled(
labelText = (getApplication() as Context).getString(R.string.cancel_questionnaire),
stringResource = R.string.cancel_questionnaire,
onClickAction = onCancelButtonClickListener,
)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class NavigationViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
is QuestionnaireNavigationViewUIState.Enabled -> {
visibility = View.VISIBLE
isEnabled = true
text = navigationViewState.labelText
text = navigationViewState.labelText ?: navigationViewState.stringResource?.let { context.getString(it) }
setOnClickListener { navigationViewState.onClickAction() }
}
QuestionnaireNavigationViewUIState.Hidden -> {
Expand Down

0 comments on commit b813d03

Please sign in to comment.