Skip to content

Commit

Permalink
Merge pull request #167 from DroidKaigi/takahirom/introduce-compose-m…
Browse files Browse the repository at this point in the history
…ultiplatform-string-resource/2024-07-27

Introduce Compose Multiplatform string resource
  • Loading branch information
takahirom authored Jul 28, 2024
2 parents d210788 + 88401f2 commit b3b972f
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package io.github.droidkaigi.confsched.primitive
import io.github.droidkaigi.confsched.convention.buildComposeMetricsParameters
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.withType
import org.jetbrains.compose.resources.ResourcesExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

@Suppress("unused")
Expand All @@ -23,6 +25,9 @@ class KmpComposePlugin : Plugin<Project> {
}
}
val compose = extensions.get("compose") as org.jetbrains.compose.ComposeExtension
compose.extensions.configure<ResourcesExtension> {
publicResClass = true
}
kotlin {
with(sourceSets) {
getByName("commonMain").apply {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<resources>
<string name="content_description_schedule_icon">スケジュール</string>
<string name="content_description_user_icon">ユーザー</string>
<string name="content_description_error_icon">エラー</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<resources>
<string name="content_description_schedule_icon">Schedule</string>
<string name="content_description_user_icon">User</string>
<string name="content_description_error_icon">Error</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.github.droidkaigi.confsched.sessions

import conference_app_2024.feature.sessions.generated.resources.Res

object SessionRes {
val string = Res.string
val drawable = Res.drawable
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import conference_app_2024.feature.sessions.generated.resources.content_description_error_icon
import conference_app_2024.feature.sessions.generated.resources.content_description_schedule_icon
import conference_app_2024.feature.sessions.generated.resources.content_description_user_icon
import io.github.droidkaigi.confsched.designsystem.theme.KaigiTheme
import io.github.droidkaigi.confsched.designsystem.theme.LocalRoomTheme
import io.github.droidkaigi.confsched.designsystem.theme.ProvideRoomTheme
Expand All @@ -51,9 +54,7 @@ import io.github.droidkaigi.confsched.model.TimetableRoom
import io.github.droidkaigi.confsched.model.TimetableSessionType
import io.github.droidkaigi.confsched.model.TimetableSpeaker
import io.github.droidkaigi.confsched.model.fake
import io.github.droidkaigi.confsched.sessions.SessionsStrings
import io.github.droidkaigi.confsched.sessions.SessionsStrings.ScheduleIcon
import io.github.droidkaigi.confsched.sessions.SessionsStrings.UserIcon
import io.github.droidkaigi.confsched.sessions.SessionRes
import io.github.droidkaigi.confsched.sessions.section.TimetableSizes
import io.github.droidkaigi.confsched.ui.previewOverride
import io.github.droidkaigi.confsched.ui.rememberAsyncImagePainter
Expand All @@ -64,6 +65,7 @@ import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.TimeZone
import kotlinx.datetime.minus
import kotlinx.datetime.toInstant
import org.jetbrains.compose.resources.stringResource
import org.jetbrains.compose.ui.tooling.preview.Preview
import kotlin.math.ceil
import kotlin.math.roundToInt
Expand Down Expand Up @@ -128,7 +130,7 @@ fun TimetableGridItem(
Icon(
modifier = Modifier.height(TimetableGridItemSizes.scheduleHeight),
imageVector = Icons.Default.Schedule,
contentDescription = ScheduleIcon.asString(),
contentDescription = stringResource(SessionRes.string.content_description_schedule_icon),
)
Spacer(modifier = Modifier.width(4.dp))
var scheduleTextStyle = MaterialTheme.typography.bodySmall
Expand Down Expand Up @@ -180,7 +182,7 @@ fun TimetableGridItem(
modifier = Modifier
.size(TimetableGridItemSizes.errorHeight),
imageVector = Icons.Default.Error,
contentDescription = SessionsStrings.ErrorIcon.asString(),
contentDescription = stringResource(SessionRes.string.content_description_error_icon),
tint = MaterialTheme.colorScheme.errorContainer,
)
}
Expand Down Expand Up @@ -236,7 +238,7 @@ private fun SpeakerIcon(
painter = previewOverride(previewPainter = { rememberVectorPainter(image = Icons.Default.Person) }) {
rememberAsyncImagePainter(iconUrl)
},
contentDescription = UserIcon.asString(),
contentDescription = stringResource(SessionRes.string.content_description_user_icon),
modifier = modifier
.size(TimetableGridItemSizes.speakerHeight)
.clip(RoundedCornerShape(8.dp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import conference_app_2024.feature.sessions.generated.resources.Res
import conference_app_2024.feature.sessions.generated.resources.calendar_add_on
import io.github.droidkaigi.confsched.designsystem.theme.KaigiTheme
import io.github.droidkaigi.confsched.model.TimetableItem
import io.github.droidkaigi.confsched.model.fake
import io.github.droidkaigi.confsched.sessions.SessionRes
import io.github.droidkaigi.confsched.sessions.TimetableItemDetailBookmarkIconTestTag
import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.ui.tooling.preview.Preview
Expand All @@ -42,7 +42,7 @@ fun TimetableItemDetailBottomAppBar(
}
IconButton(onClick = { onCalendarRegistrationClick(timetableItem) }) {
Icon(
painter = painterResource(Res.drawable.calendar_add_on),
painter = painterResource(SessionRes.drawable.calendar_add_on),
contentDescription = "Calendar",
)
}
Expand Down

0 comments on commit b3b972f

Please sign in to comment.