Skip to content

Commit

Permalink
Merge pull request #1201 from minvws/3970-link-text-dashboard-header
Browse files Browse the repository at this point in the history
different link texts dashboard header 0G on empty state
  • Loading branch information
aiden-shi authored Mar 17, 2022
2 parents d362b4f + cd4e57e commit d5b0824
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,24 +203,7 @@ class DashboardPageFragment : Fragment(R.layout.fragment_dashboard_page) {
adapterItems.add(
DashboardHeaderAdapterItem(
text = dashboardItem.text,
buttonInfo = if (greenCardType == GreenCardType.Eu) {
when (featureFlagUseCase.getDisclosurePolicy()) {
is DisclosurePolicy.ZeroG -> {
ButtonInfo(
R.string.holder_dashboard_international_0G_action_certificateNeeded ,
R.string.my_overview_description_eu_button_link
)
}
else -> {
ButtonInfo(
R.string.my_overview_description_eu_button_text,
R.string.my_overview_description_eu_button_link
)
}
}
} else {
null
},
buttonInfo = dashboardItem.buttonInfo
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,82 +9,106 @@ package nl.rijksoverheid.ctr.holder.dashboard.items

import nl.rijksoverheid.ctr.holder.R
import nl.rijksoverheid.ctr.holder.persistence.database.entities.GreenCardType
import nl.rijksoverheid.ctr.holder.ui.create_qr.models.DashboardItem
import nl.rijksoverheid.ctr.holder.usecase.HolderFeatureFlagUseCase
import nl.rijksoverheid.ctr.shared.models.DisclosurePolicy

interface DashboardHeaderAdapterItemUtil {
fun getText(
fun getHeaderItem(
greenCardType: GreenCardType,
emptyState: Boolean,
hasVisitorPassIncompleteItem: Boolean
): Int
): DashboardItem.HeaderItem
}

class DashboardHeaderAdapterItemUtilImpl(
private val featureFlagUseCase: HolderFeatureFlagUseCase
): DashboardHeaderAdapterItemUtil {
) : DashboardHeaderAdapterItemUtil {

/**
* Get the header item text to display in the domestic tab on the dashboard screen
* @param tabType The type of the tab that is currently selected
* @param emptyState If we should treat the dashboard as being empty state
* @param hasVisitorPassIncompleteItem If there is a incomplete visitor pass item currently showing on the dashboard
*/
override fun getText(
override fun getHeaderItem(
tabType: GreenCardType,
emptyState: Boolean,
hasVisitorPassIncompleteItem: Boolean): Int {

when (tabType) {
is GreenCardType.Domestic -> {
val emptyState = emptyState || hasVisitorPassIncompleteItem
hasVisitorPassIncompleteItem: Boolean
): DashboardItem.HeaderItem {
val empty = emptyState || hasVisitorPassIncompleteItem
val text = getHeaderText(tabType, empty)
val buttonInfo = getButtonInfo(tabType, empty)
return DashboardItem.HeaderItem(text, buttonInfo)
}

return when (featureFlagUseCase.getDisclosurePolicy()) {
is DisclosurePolicy.OneG -> {
if (emptyState) {
R.string.holder_dashboard_empty_domestic_only1Gaccess_message
} else {
R.string.holder_dashboard_intro_domestic_only1Gaccess
}
private fun getHeaderText(
tabType: GreenCardType,
emptyState: Boolean,
) = when (tabType) {
is GreenCardType.Domestic -> {
when (featureFlagUseCase.getDisclosurePolicy()) {
is DisclosurePolicy.OneG -> {
if (emptyState) {
R.string.holder_dashboard_empty_domestic_only1Gaccess_message
} else {
R.string.holder_dashboard_intro_domestic_only1Gaccess
}
is DisclosurePolicy.OneAndThreeG -> {
if (emptyState) {
R.string.holder_dashboard_empty_domestic_3Gand1Gaccess_message
} else {
R.string.holder_dashboard_intro_domestic_3Gand1Gaccess
}
}
is DisclosurePolicy.OneAndThreeG -> {
if (emptyState) {
R.string.holder_dashboard_empty_domestic_3Gand1Gaccess_message
} else {
R.string.holder_dashboard_intro_domestic_3Gand1Gaccess
}
is DisclosurePolicy.ThreeG -> {
if (emptyState) {
R.string.my_overview_qr_placeholder_description
} else {
R.string.my_overview_description
}
}
is DisclosurePolicy.ThreeG -> {
if (emptyState) {
R.string.my_overview_qr_placeholder_description
} else {
R.string.my_overview_description
}
is DisclosurePolicy.ZeroG -> R.string.app_name // TODO: implement 0G
}
is DisclosurePolicy.ZeroG -> R.string.app_name // Not applicable
}
is GreenCardType.Eu -> {
return if (emptyState) {
when (featureFlagUseCase.getDisclosurePolicy()) {
is DisclosurePolicy.ZeroG -> {
R.string.holder_dashboard_emptyState_international_0G_message
}
else -> {
R.string.my_overview_qr_placeholder_description_eu
}
}
is GreenCardType.Eu -> {
if (emptyState) {
when (featureFlagUseCase.getDisclosurePolicy()) {
is DisclosurePolicy.ZeroG -> {
R.string.holder_dashboard_emptyState_international_0G_message
}
else -> {
R.string.my_overview_qr_placeholder_description_eu
}
}
} else {
when (featureFlagUseCase.getDisclosurePolicy()) {
is DisclosurePolicy.ZeroG -> {
R.string.holder_dashboard_filledState_international_0G_message
}
} else {
when (featureFlagUseCase.getDisclosurePolicy()) {
is DisclosurePolicy.ZeroG -> {
R.string.holder_dashboard_filledState_international_0G_message
}
else -> {
R.string.my_overview_description_eu
}
else -> {
R.string.my_overview_description_eu
}
}
}
}
}

private fun getButtonInfo(tabType: GreenCardType, empty: Boolean) =
if (tabType == GreenCardType.Eu) {
if (featureFlagUseCase.getDisclosurePolicy() is DisclosurePolicy.ZeroG && !empty) {
ButtonInfo(
R.string.holder_dashboard_international_0G_action_certificateNeeded,
R.string.my_overview_description_eu_button_link
)
} else {
ButtonInfo(
R.string.my_overview_description_eu_button_text,
R.string.my_overview_description_eu_button_link
)
}
} else {
null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@ package nl.rijksoverheid.ctr.holder.ui.create_qr.models

import androidx.annotation.StringRes
import nl.rijksoverheid.ctr.holder.R
import nl.rijksoverheid.ctr.holder.dashboard.items.ButtonInfo
import nl.rijksoverheid.ctr.holder.persistence.database.DatabaseSyncerResult
import nl.rijksoverheid.ctr.holder.persistence.database.entities.*
import nl.rijksoverheid.ctr.holder.persistence.database.entities.CredentialEntity
import nl.rijksoverheid.ctr.holder.persistence.database.entities.GreenCardType
import nl.rijksoverheid.ctr.holder.persistence.database.entities.OriginEntity
import nl.rijksoverheid.ctr.holder.persistence.database.entities.OriginType
import nl.rijksoverheid.ctr.holder.persistence.database.models.GreenCard
import nl.rijksoverheid.ctr.holder.ui.create_qr.util.OriginState
import nl.rijksoverheid.ctr.shared.models.DisclosurePolicy
import nl.rijksoverheid.ctr.shared.models.GreenCardDisclosurePolicy

sealed class DashboardItem {

data class HeaderItem(@StringRes val text: Int) : DashboardItem()
data class HeaderItem(
@StringRes val text: Int,
val buttonInfo: ButtonInfo?
) : DashboardItem()

data class PlaceholderCardItem(val greenCardType: GreenCardType) : DashboardItem()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import nl.rijksoverheid.ctr.holder.ui.create_qr.models.DashboardItems
import nl.rijksoverheid.ctr.holder.ui.create_qr.util.*
import nl.rijksoverheid.ctr.holder.dashboard.items.DashboardHeaderAdapterItemUtil
import nl.rijksoverheid.ctr.holder.usecase.HolderFeatureFlagUseCase
import nl.rijksoverheid.ctr.shared.models.DisclosurePolicy
import org.koin.androidx.viewmodel.scope.emptyState

interface GetDashboardItemsUseCase {
suspend fun getItems(
Expand Down Expand Up @@ -85,13 +83,13 @@ class GetDashboardItemsUseCaseImpl(
.filter { it.greenCardEntity.type == GreenCardType.Eu }
.distinctBy { it.greenCardEntity.type }

val headerText = dashboardHeaderAdapterItemUtil.getText(
val headerItem = dashboardHeaderAdapterItemUtil.getHeaderItem(
emptyState = hasEmptyState,
greenCardType = GreenCardType.Domestic,
hasVisitorPassIncompleteItem = hasVisitorPassIncompleteItem,
)

dashboardItems.add(DashboardItem.HeaderItem(text = headerText))
dashboardItems.add(headerItem)

if (dashboardItemUtil.isAppUpdateAvailable()) {
dashboardItems.add(DashboardItem.InfoItem.AppUpdate)
Expand Down Expand Up @@ -204,15 +202,13 @@ class GetDashboardItemsUseCaseImpl(
disclosurePolicy = holderFeatureFlagUseCase.getDisclosurePolicy()
)

val headerText = dashboardHeaderAdapterItemUtil.getText(
val headerItem = dashboardHeaderAdapterItemUtil.getHeaderItem(
emptyState = hasEmptyState,
greenCardType = GreenCardType.Eu,
hasVisitorPassIncompleteItem = hasVisitorPassIncompleteItem,
)

dashboardItems.add(
DashboardItem.HeaderItem(text = headerText)
)
dashboardItems.add(headerItem)

if (dashboardItemUtil.isAppUpdateAvailable()) {
dashboardItems.add(DashboardItem.InfoItem.AppUpdate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class DashboardFragmentTest : AutoCloseKoinTest() {
title = R.string.travel_button_domestic,
greenCardType = GreenCardType.Domestic,
items = listOf(
DashboardItem.HeaderItem(text = R.string.my_overview_description)
DashboardItem.HeaderItem(text = R.string.my_overview_description, null)
)
))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class SortGreenCardItemsUseCaseImplTest: AutoCloseKoinTest() {
fun `Items have correct order`() {
val items = listOf(
DashboardItem.InfoItem.BoosterItem,
DashboardItem.HeaderItem(1),
DashboardItem.HeaderItem(1, null),
DashboardItem.InfoItem.ClockDeviationItem,
DashboardItem.CoronaMelderItem,
DashboardItem.InfoItem.OriginInfoItem(GreenCardType.Domestic, OriginType.Test),
Expand Down
Loading

0 comments on commit d5b0824

Please sign in to comment.