Skip to content

Commit

Permalink
fix: [CUSTOM-ICONS] use default color if not defined (#3576)
Browse files Browse the repository at this point in the history
* fix: [CUSTOM-ICONS] use default color if not defined

* fix: [CUSTOM-ICONS] update design system
  • Loading branch information
xavimolloy authored Apr 9, 2024
1 parent 04d679c commit 0c49910
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ import org.hisp.dhis.android.core.D2
import org.hisp.dhis.android.core.common.ObjectStyle
import org.hisp.dhis.android.core.icon.Icon
import org.hisp.dhis.mobile.ui.designsystem.component.internal.ImageCardData
import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor
import timber.log.Timber
import java.io.File
class MetadataIconProvider(private val d2: D2) {
operator fun invoke(style: ObjectStyle) = style.icon()?.let {

operator fun invoke(style: ObjectStyle) = invoke(style, SurfaceColor.Primary)

operator fun invoke(style: ObjectStyle, defaultColor: Color?) = style.icon()?.let {
d2.iconModule().icons().key(it).blockingGet()
}.let { icon ->
val imageCardData = when {
Expand All @@ -29,7 +33,7 @@ class MetadataIconProvider(private val d2: D2) {
uid = "",
label = "",
iconRes = FILE_NOT_LOADED,
iconTint = style.color()?.toColor() ?: Color.Unspecified,
iconTint = style.color()?.toColor() ?: defaultColor ?: Color.Unspecified,
)
}

Expand All @@ -42,7 +46,7 @@ class MetadataIconProvider(private val d2: D2) {
}
MetadataIconData(
imageCardData = imageCardData,
color = style.color()?.toColor() ?: Color.Unspecified,
color = style.color()?.toColor() ?: defaultColor ?: Color.Unspecified,
)
}

Expand Down
11 changes: 10 additions & 1 deletion form/src/main/java/org/dhis2/form/data/EventRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.reactivex.Flowable
import io.reactivex.Single
import org.dhis2.bindings.blockingGetValueCheck
import org.dhis2.bindings.userFriendlyValue
import org.dhis2.commons.bindings.program
import org.dhis2.commons.date.DateUtils
import org.dhis2.commons.extensions.inDateRange
import org.dhis2.commons.extensions.inOrgUnit
Expand All @@ -19,6 +20,7 @@ import org.dhis2.form.model.FieldUiModel
import org.dhis2.form.model.OptionSetConfiguration
import org.dhis2.form.model.PeriodSelector
import org.dhis2.form.ui.FieldViewModelFactory
import org.dhis2.ui.toColor
import org.hisp.dhis.android.core.D2
import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope
import org.hisp.dhis.android.core.category.Category
Expand All @@ -36,6 +38,7 @@ import org.hisp.dhis.android.core.program.Program
import org.hisp.dhis.android.core.program.ProgramStageDataElement
import org.hisp.dhis.android.core.program.ProgramStageSection
import org.hisp.dhis.android.core.program.SectionRenderingType
import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor
import java.util.Date

class EventRepository(
Expand All @@ -60,6 +63,12 @@ class EventRepository(
.blockingGet()
}

private val defaultStyleColor by lazy {
programStage?.program()?.uid()?.let {
d2.program(it)?.style()?.color()?.toColor()
} ?: SurfaceColor.Primary
}

override fun firstSectionToOpen(): String? {
return when (eventMode) {
EventMode.NEW -> super.firstSectionToOpen()
Expand Down Expand Up @@ -558,7 +567,7 @@ class EventRepository(
.orderBySortOrder(RepositoryScope.OrderByDirection.ASC).blockingGet()

val metadataIconMap =
options.associate { it.uid() to metadataIconProvider(it.style()) }
options.associate { it.uid() to metadataIconProvider(it.style(), defaultStyleColor) }

OptionSetConfiguration.OptionConfigData(
options = options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import org.dhis2.commons.bindings.teiAttribute
import org.dhis2.commons.bindings.trackedEntityType
import org.dhis2.commons.resources.MetadataIconProvider
import org.dhis2.form.model.OptionSetConfiguration
import org.dhis2.ui.toColor
import org.hisp.dhis.android.core.D2
import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope
import org.hisp.dhis.android.core.enrollment.Enrollment
import org.hisp.dhis.android.core.organisationunit.OrganisationUnit
import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor

class EnrollmentConfiguration(
private val d2: D2,
Expand All @@ -30,6 +32,10 @@ class EnrollmentConfiguration(
d2.program(it)
}

private val defaultStyleColor by lazy {
program()?.style()?.color()?.toColor() ?: SurfaceColor.Primary
}

fun tei() = enrollment()?.trackedEntityInstance()?.let { d2.tei(it) }
fun trackedEntityType() = d2.trackedEntityType(program()?.trackedEntityType()?.uid()!!)
fun sections() = d2.programModule().programSections()
Expand Down Expand Up @@ -126,7 +132,7 @@ class EnrollmentConfiguration(
.orderBySortOrder(RepositoryScope.OrderByDirection.ASC)
.blockingGet()

val metadataIconMap = options.associate { it.uid() to metadataIconProvider(it.style()) }
val metadataIconMap = options.associate { it.uid() to metadataIconProvider(it.style(), defaultStyleColor) }

OptionSetConfiguration.OptionConfigData(
options = options,
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ kotlin = '1.9.21'
hilt = '2.47'
hiltCompiler = '1.0.0'
jacoco = '0.8.10'
designSystem = "0.2-20240314.101140-42"
designSystem = "0.2-20240405.110637-52"
dhis2sdk = "1.10.0-20240318.115339-36"
ruleEngine = "3.0.0-20240119.134348-12"
expressionParser = "1.1.0-20240219.115041-14"
Expand Down

0 comments on commit 0c49910

Please sign in to comment.