Browse Source

Update resources library in imageViewer sample (#3931)

compiler/test-cases-with-kotlin2 v1.6.0-dev1276
Konstantin 12 months ago committed by GitHub
parent
commit
89f21eb99e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      examples/imageviewer/shared/build.gradle.kts
  2. 4
      examples/imageviewer/shared/src/androidMain/kotlin/example/imageviewer/storage/AndroidImageStorage.kt
  3. 4
      examples/imageviewer/shared/src/androidMain/kotlin/example/imageviewer/view/CameraView.android.kt
  4. 8
      examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/Dependencies.kt
  5. 9
      examples/imageviewer/shared/src/desktopMain/kotlin/example/imageviewer/view/CameraView.desktop.kt

3
examples/imageviewer/shared/build.gradle.kts

@ -32,8 +32,7 @@ kotlin {
implementation(compose.foundation)
implementation(compose.material)
//implementation(compose.materialIconsExtended) // TODO not working on iOS for now
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
implementation(compose.components.resources)
implementation("org.jetbrains.compose.components:components-resources:1.6.0-dev1275")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")

4
examples/imageviewer/shared/src/androidMain/kotlin/example/imageviewer/storage/AndroidImageStorage.kt

@ -21,7 +21,7 @@ import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.resource
import org.jetbrains.compose.resources.readResourceBytes
import java.io.File
private const val maxStorableImageSizePx = 2000
@ -117,7 +117,7 @@ class AndroidImageStorage(
if (!tempFileToShare.exists()) {
tempFileToShare.createNewFile()
}
tempFileToShare.writeBytes(resource(picture.resource).readBytes())
tempFileToShare.writeBytes(readResourceBytes(picture.resource))
}
}
FileProvider.getUriForFile(

4
examples/imageviewer/shared/src/androidMain/kotlin/example/imageviewer/view/CameraView.android.kt

@ -37,7 +37,7 @@ import example.imageviewer.model.createCameraPictureData
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.resource
import org.jetbrains.compose.resources.readResourceBytes
import java.nio.ByteBuffer
import java.util.*
import java.util.concurrent.Executors
@ -176,7 +176,7 @@ private fun CameraWithGrantedPermission(
delay(5000)
if (capturePhotoStarted) {
addLocationInfoAndReturnResult(
resource("android-emulator-photo.jpg").readBytes().toImageBitmap()
readResourceBytes("android-emulator-photo.jpg").toImageBitmap()
)
}
}

8
examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/Dependencies.kt

@ -5,11 +5,11 @@ import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.graphics.ImageBitmap
import example.imageviewer.filter.PlatformContext
import example.imageviewer.model.*
import example.imageviewer.model.PictureData
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.emptyFlow
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.resource
import org.jetbrains.compose.resources.readResourceBytes
@OptIn(ExperimentalResourceApi::class)
abstract class Dependencies {
@ -22,7 +22,7 @@ abstract class Dependencies {
val imageProvider: ImageProvider = object : ImageProvider {
override suspend fun getImage(picture: PictureData): ImageBitmap = when (picture) {
is PictureData.Resource -> {
resource(picture.resource).readBytes().toImageBitmap()
readResourceBytes(picture.resource).toImageBitmap()
}
is PictureData.Camera -> {
@ -32,7 +32,7 @@ abstract class Dependencies {
override suspend fun getThumbnail(picture: PictureData): ImageBitmap = when (picture) {
is PictureData.Resource -> {
resource(picture.thumbnailResource).readBytes().toImageBitmap()
readResourceBytes(picture.thumbnailResource).toImageBitmap()
}
is PictureData.Camera -> {

9
examples/imageviewer/shared/src/desktopMain/kotlin/example/imageviewer/view/CameraView.desktop.kt

@ -18,10 +18,7 @@ import example.imageviewer.icon.IconPhotoCamera
import example.imageviewer.model.PictureData
import example.imageviewer.model.createCameraPictureData
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.orEmpty
import org.jetbrains.compose.resources.rememberImageBitmap
import org.jetbrains.compose.resources.resource
import java.util.*
import org.jetbrains.compose.resources.imageResource
@OptIn(ExperimentalResourceApi::class)
@Composable
@ -30,10 +27,10 @@ actual fun CameraView(
onCapture: (picture: PictureData.Camera, image: PlatformStorableImage) -> Unit
) {
val randomPicture = remember { resourcePictures.random() }
val imageBitmap = resource(randomPicture.resource).rememberImageBitmap().orEmpty()
val imageBitmap = imageResource(randomPicture.resource)
Box(Modifier.fillMaxSize().background(Color.Black)) {
Image(
bitmap = imageBitmap,
bitmap = imageResource(randomPicture.resource),
contentDescription = "Camera stub",
Modifier.fillMaxSize()
)

Loading…
Cancel
Save