Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor navigation view UI state #2644

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package com.google.android.fhir.datacapture
sealed interface QuestionnaireNavigationViewUIState {
data object Hidden : QuestionnaireNavigationViewUIState

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.android.fhir.datacapture

import android.app.Application
import android.content.Context
import android.net.Uri
import androidx.annotation.VisibleForTesting
import androidx.lifecycle.AndroidViewModel
Expand Down Expand Up @@ -728,15 +729,16 @@ internal class QuestionnaireViewModel(application: Application, state: SavedStat
navSubmit =
if (showSubmitButton) {
QuestionnaireNavigationViewUIState.Enabled(
submitButtonText,
onSubmitButtonClickListener,
labelText = submitButtonText,
onClickAction = onSubmitButtonClickListener,
)
} else {
QuestionnaireNavigationViewUIState.Hidden
},
navCancel =
if (!isReadOnly && shouldShowCancelButton) {
QuestionnaireNavigationViewUIState.Enabled(
labelText = (getApplication() as Context).getString(R.string.cancel_questionnaire),
onClickAction = onCancelButtonClickListener,
)
} else {
Expand Down Expand Up @@ -794,7 +796,11 @@ internal class QuestionnaireViewModel(application: Application, state: SavedStat
navPrevious =
when {
questionnairePagination.isPaginated && questionnairePagination.hasPreviousPage -> {
QuestionnaireNavigationViewUIState.Enabled { goToPreviousPage() }
QuestionnaireNavigationViewUIState.Enabled(
labelText =
(getApplication() as Context).getString(R.string.button_pagination_previous),
onClickAction = { goToPreviousPage() },
)
}
else -> {
QuestionnaireNavigationViewUIState.Hidden
Expand All @@ -803,7 +809,11 @@ internal class QuestionnaireViewModel(application: Application, state: SavedStat
navNext =
when {
questionnairePagination.isPaginated && questionnairePagination.hasNextPage -> {
QuestionnaireNavigationViewUIState.Enabled { goToNextPage() }
QuestionnaireNavigationViewUIState.Enabled(
labelText =
(getApplication() as Context).getString(R.string.button_pagination_next),
onClickAction = { goToNextPage() },
)
}
else -> {
QuestionnaireNavigationViewUIState.Hidden
Expand All @@ -812,21 +822,27 @@ internal class QuestionnaireViewModel(application: Application, state: SavedStat
navSubmit =
if (showSubmitButton) {
QuestionnaireNavigationViewUIState.Enabled(
submitButtonText,
onSubmitButtonClickListener,
labelText = submitButtonText,
onClickAction = onSubmitButtonClickListener,
)
} else {
QuestionnaireNavigationViewUIState.Hidden
},
navReview =
if (showReviewButton) {
QuestionnaireNavigationViewUIState.Enabled { setReviewMode(true) }
QuestionnaireNavigationViewUIState.Enabled(
labelText = (getApplication() as Context).getString(R.string.button_review),
onClickAction = { setReviewMode(true) },
)
} else {
QuestionnaireNavigationViewUIState.Hidden
},
navCancel =
if (showCancelButton) {
QuestionnaireNavigationViewUIState.Enabled(onClickAction = onCancelButtonClickListener)
QuestionnaireNavigationViewUIState.Enabled(
labelText = (getApplication() as Context).getString(R.string.cancel_questionnaire),
onClickAction = onCancelButtonClickListener,
)
} else {
QuestionnaireNavigationViewUIState.Hidden
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ class NavigationViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
is QuestionnaireNavigationViewUIState.Enabled -> {
visibility = View.VISIBLE
isEnabled = true
if (navigationViewState.labelText.isNullOrBlank().not() && this is Button) {
text = navigationViewState.labelText
}
jingtang10 marked this conversation as resolved.
Show resolved Hide resolved
text = navigationViewState.labelText
setOnClickListener { navigationViewState.onClickAction() }
}
QuestionnaireNavigationViewUIState.Hidden -> {
Expand Down
Loading