Browse Source

Migrate the chat sample to the new compose resources

pull/4386/head
Konstantin Tskhovrebov 3 months ago
parent
commit
f3c5514fd9
  1. 8
      examples/chat/shared/build.gradle.kts
  2. 0
      examples/chat/shared/src/commonMain/composeResources/drawable/background.jpg
  3. 0
      examples/chat/shared/src/commonMain/composeResources/drawable/stock1.jpg
  4. 0
      examples/chat/shared/src/commonMain/composeResources/drawable/stock2.jpg
  5. 0
      examples/chat/shared/src/commonMain/composeResources/drawable/stock3.jpg
  6. 0
      examples/chat/shared/src/commonMain/composeResources/drawable/stock4.jpg
  7. 11
      examples/chat/shared/src/commonMain/kotlin/ChatApp.kt
  8. 4
      examples/chat/shared/src/commonMain/kotlin/Data.kt

8
examples/chat/shared/build.gradle.kts

@ -46,12 +46,16 @@ kotlin {
}
sourceSets {
all {
languageSettings {
optIn("org.jetbrains.compose.resources.ExperimentalResourceApi")
}
}
val commonMain by getting {
dependencies {
implementation(compose.ui)
implementation(compose.foundation)
implementation(compose.material)
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
implementation(compose.components.resources)
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.5.0")
}
@ -97,8 +101,6 @@ android {
compileSdk = 34
namespace = "org.jetbrains.chat"
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
sourceSets["main"].res.srcDirs("src/androidMain/res")
sourceSets["main"].resources.srcDirs("src/commonMain/resources")
defaultConfig {
minSdk = 26

0
examples/chat/shared/src/commonMain/resources/background.jpg → examples/chat/shared/src/commonMain/composeResources/drawable/background.jpg

Before

Width:  |  Height:  |  Size: 468 KiB

After

Width:  |  Height:  |  Size: 468 KiB

0
examples/chat/shared/src/commonMain/resources/stock1.jpg → examples/chat/shared/src/commonMain/composeResources/drawable/stock1.jpg

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

0
examples/chat/shared/src/commonMain/resources/stock2.jpg → examples/chat/shared/src/commonMain/composeResources/drawable/stock2.jpg

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

0
examples/chat/shared/src/commonMain/resources/stock3.jpg → examples/chat/shared/src/commonMain/composeResources/drawable/stock3.jpg

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

0
examples/chat/shared/src/commonMain/resources/stock4.jpg → examples/chat/shared/src/commonMain/composeResources/drawable/stock4.jpg

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

11
examples/chat/shared/src/commonMain/kotlin/ChatApp.kt

@ -18,6 +18,9 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.sp
import chat_mpp.shared.generated.resources.*
import chat_mpp.shared.generated.resources.Res
import chat_mpp.shared.generated.resources.background
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.delay
@ -26,9 +29,9 @@ import org.jetbrains.compose.resources.painterResource
val myUser = User("Me", picture = null)
val friends = listOf(
User("Alex", picture = "stock1.jpg"),
User("Casey", picture = "stock2.jpg"),
User("Sam", picture = "stock3.jpg")
User("Alex", picture = Res.drawable.stock1),
User("Casey", picture = Res.drawable.stock2),
User("Sam", picture = Res.drawable.stock3)
)
val friendMessages = listOf(
"How's everybody doing today?",
@ -66,7 +69,7 @@ fun ChatApp(displayTextField: Boolean = true) {
Theme {
Surface {
Box(modifier = Modifier.fillMaxSize()) {
Image(painterResource("background.jpg"), null, contentScale = ContentScale.Crop)
Image(painterResource(Res.drawable.background), null, contentScale = ContentScale.Crop)
Column(
modifier = Modifier.fillMaxSize()
) {

4
examples/chat/shared/src/commonMain/kotlin/Data.kt

@ -1,5 +1,7 @@
import androidx.compose.ui.graphics.Color
import kotlinx.datetime.Clock
import org.jetbrains.compose.resources.DrawableResource
import org.jetbrains.compose.resources.ExperimentalResourceApi
import kotlin.random.Random
import kotlin.random.nextInt
@ -23,7 +25,7 @@ data class Message(
data class User(
val name: String,
val color: Color = ColorProvider.getColor(),
val picture: String?
val picture: DrawableResource?
)
object ColorProvider {

Loading…
Cancel
Save