Skip to content

Commit

Permalink
ANDROAPP-5632-mobile-ui-Manage-MissingResourceException-for-dhis2-ico…
Browse files Browse the repository at this point in the history
…ns (#103)

* Manage missing resources through expect -> actual

* modify missing resource check
  • Loading branch information
xavimolloy authored Oct 16, 2023
1 parent 4d58883 commit a597283
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fun InputMatrixScreen() {
IconCardData(
uid = "3eea3133-8a2f-4bba-a259-8b4b457d5ad0",
label = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas dolor lacus, aliquam.",
iconRes = "dhis2_microscope_positive",
iconRes = "dhis2_boy_0510y_outline",
iconTint = SurfaceColor.Primary,
),
IconCardData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fun InputSequentialScreen() {
IconCardData(
uid = "3eea3133-8a2f-4bba-a259-8b4b457d5ad0",
label = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas dolor lacus, aliquam.",
iconRes = "dhis2_microscope_positive",
iconRes = "dhis2_boy_0510y_outline",
iconTint = SurfaceColor.Primary,
),
IconCardData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ actual fun provideQuantityStringResource(id: String, quantity: Int): String {
}
return provideStringResource("${id}_$appendToId").format(quantity)
}

@Composable
actual fun resourceExists(resourceName: String, resourceType: String): Boolean {
val context = LocalContext.current
val resourceId = context.resources.getIdentifier(resourceName, resourceType, context.packageName)
return resourceId != 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ import org.jetbrains.compose.resources.painterResource
*/
@OptIn(ExperimentalResourceApi::class)
@Composable
fun provideDHIS2Icon(resourceName: String): Painter =
painterResource("drawable/$resourceName.xml")
fun provideDHIS2Icon(resourceName: String): Painter {
val iconName = if (!resourceExists(resourceName)) {
"dhis2_default_outline"
} else {
resourceName
}
return painterResource("drawable/$iconName.xml")
}

@OptIn(ExperimentalResourceApi::class)
@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ expect fun provideStringResource(id: String): String

@Composable
expect fun provideQuantityStringResource(id: String, quantity: Int): String

@Composable
expect fun resourceExists(resourceName: String, resourceType: String = "drawable"): Boolean
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.hisp.dhis.mobile.ui.designsystem.resource

import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.res.useResource
Expand Down Expand Up @@ -42,3 +41,8 @@ private fun getResources(): Map<String, String> {
}
return stringsResources
}

@Composable
actual fun resourceExists(resourceName: String, resourceType: String): Boolean {
return false
}

0 comments on commit a597283

Please sign in to comment.