Skip to content

Commit

Permalink
fix lint error
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth Agarwal committed Oct 5, 2023
1 parent 9df11bf commit 838df9a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ fun ImageBlockScreen() {
@Composable
private fun provideSampleImage(): Painter =
painterResource("drawable/sample.png")

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.hisp.dhis.mobile.ui.designsystem.component

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
Expand All @@ -16,7 +15,6 @@ import androidx.compose.runtime.produceState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.testTag
Expand Down Expand Up @@ -44,46 +42,46 @@ fun <T> ImageBlock(
downloadButtonVisible: Boolean = true,
onClick: () -> Unit,
) {
Box(
modifier = modifier
.padding(vertical = Spacing.Spacing8)
.testTag("IMAGE_BLOCK_CONTAINER"),
) {
val image: T? by produceState<T?>(null) {
value = withContext(Dispatchers.IO) {
try {
load()
} catch (e: IOException) {
null
}
val image: T? by produceState<T?>(null) {
value = withContext(Dispatchers.IO) {
try {
load()
} catch (e: IOException) {
null
}
}
}

if (image != null) {
if (image != null) {
Box(
modifier = modifier
.padding(vertical = Spacing.Spacing8)
.testTag("IMAGE_BLOCK_CONTAINER"),
) {
Image(
painter = painterFor(image!!),
contentDescription = null,
contentScale = ContentScale.FillBounds,
modifier = Modifier
.fillMaxWidth()
.clip(shape = RoundedCornerShape(Radius.S))
.height(160.dp)
.height(160.dp),
)
}
if (downloadButtonVisible) {
SquareIconButton(
enabled = true,
modifier = Modifier
.align(Alignment.BottomEnd)
.padding(Spacing.Spacing4),
icon = {
Icon(
imageVector = Icons.Outlined.FileDownload,
contentDescription = "File download Button",
)
},
) {
onClick.invoke()
if (downloadButtonVisible) {
SquareIconButton(
enabled = true,
modifier = Modifier
.align(Alignment.BottomEnd)
.padding(Spacing.Spacing4),
icon = {
Icon(
imageVector = Icons.Outlined.FileDownload,
contentDescription = "File download Button",
)
},
) {
onClick.invoke()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.hisp.dhis.mobile.ui.designsystem.component

import androidx.compose.ui.graphics.painter.BitmapPainter
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import org.hisp.dhis.mobile.ui.designsystem.component.internal.image.provideImage
import org.junit.Rule
import org.junit.Test
import java.io.File
Expand All @@ -14,7 +16,11 @@ class ImageBlockTest {
@Test
fun shouldNotRenderImageBlockIfFileIsNotValid() {
rule.setContent {
ImageBlock(file = File("")) {}
ImageBlock(
load = { provideImage(File("")) },
painterFor = { BitmapPainter(it!!) },
onClick = {},
)
}

rule.onNodeWithTag("IMAGE_BLOCK_CONTAINER").assertDoesNotExist()
Expand Down

0 comments on commit 838df9a

Please sign in to comment.