Skip to content

Commit

Permalink
Merge pull request #193 from terrakok/dev
Browse files Browse the repository at this point in the history
Android string/drawable resources -> Compose Multiplatform resources
  • Loading branch information
Hiebeler authored Feb 5, 2025
2 parents b5afe17 + 82ffb68 commit 5df04aa
Show file tree
Hide file tree
Showing 187 changed files with 1,083 additions and 964 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ kotlin {
implementation(compose.material)
implementation(compose.material3)
implementation(compose.materialIconsExtended)
implementation(compose.components.resources)
implementation(libs.compose.ui.graphics)

//logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import org.jetbrains.compose.resources.painterResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -107,6 +106,10 @@ import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.json.Json
import org.jetbrains.compose.resources.stringResource
import org.jetbrains.compose.resources.vectorResource
import pixelix.app.generated.resources.Res
import pixelix.app.generated.resources.default_avatar
import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
Expand Down Expand Up @@ -569,7 +572,7 @@ fun BottomBar(
Row(verticalAlignment = Alignment.CenterVertically) {
AsyncImage(
model = avatar,
error = painterResource(id = R.drawable.default_avatar),
error = painterResource(Res.drawable.default_avatar),
contentDescription = "",
modifier = Modifier
.height(30.dp)
Expand All @@ -583,13 +586,13 @@ fun BottomBar(
}
} else if (currentRoute?.startsWith(screen.route) == true) {
Icon(
imageVector = ImageVector.vectorResource(screen.activeIcon),
imageVector = vectorResource(screen.activeIcon),
modifier = Modifier.size(30.dp),
contentDescription = stringResource(screen.label)
)
} else {
Icon(
imageVector = ImageVector.vectorResource(screen.icon),
imageVector = vectorResource(screen.icon),
modifier = Modifier.size(30.dp),
contentDescription = stringResource(screen.label)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,58 @@
package com.daniebeler.pfpixelix.common

import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import com.daniebeler.pfpixelix.R
import org.jetbrains.compose.resources.DrawableResource
import org.jetbrains.compose.resources.StringResource
import pixelix.app.generated.resources.Res
import pixelix.app.generated.resources.add_circle
import pixelix.app.generated.resources.add_circle_outline
import pixelix.app.generated.resources.alerts
import pixelix.app.generated.resources.bookmark_outline
import pixelix.app.generated.resources.home
import pixelix.app.generated.resources.house
import pixelix.app.generated.resources.house_fill
import pixelix.app.generated.resources.notifications
import pixelix.app.generated.resources.notifications_outline
import pixelix.app.generated.resources.profile
import pixelix.app.generated.resources.search
import pixelix.app.generated.resources.search_outline

sealed class Destinations(
val route: String,
@DrawableRes
val icon: Int = R.drawable.bookmark_outline,
@DrawableRes
val activeIcon: Int = R.drawable.bookmark_outline,
@StringRes val label: Int = R.string.home
val icon: DrawableResource = Res.drawable.bookmark_outline,
val activeIcon: DrawableResource = Res.drawable.bookmark_outline,
val label: StringResource = Res.string.home
) {
data object HomeScreen : Destinations(
route = "home_screen",
icon = R.drawable.house,
activeIcon = R.drawable.house_fill,
label = R.string.home
icon = Res.drawable.house,
activeIcon = Res.drawable.house_fill,
label = Res.string.home
)

data object NotificationsScreen : Destinations(
route = "notifications_screen",
icon = R.drawable.notifications_outline,
activeIcon = R.drawable.notifications,
label = R.string.alerts
icon = Res.drawable.notifications_outline,
activeIcon = Res.drawable.notifications,
label = Res.string.alerts
)

data object OwnProfile : Destinations(
route = "own_profile_screen",
icon = R.drawable.bookmark_outline,
activeIcon = R.drawable.bookmark_outline,
label = R.string.profile
icon = Res.drawable.bookmark_outline,
activeIcon = Res.drawable.bookmark_outline,
label = Res.string.profile
)

data object NewPost : Destinations(
route = "new_post_screen", icon = R.drawable.add_circle_outline,
activeIcon = R.drawable.add_circle
route = "new_post_screen", icon = Res.drawable.add_circle_outline,
activeIcon = Res.drawable.add_circle
)

data object Search : Destinations(
route = "search_screen",
icon = R.drawable.search_outline,
activeIcon = R.drawable.search,
label = R.string.search
icon = Res.drawable.search_outline,
activeIcon = Res.drawable.search,
label = Res.string.search
)

data object Profile : Destinations(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import coil3.compose.AsyncImage
import com.daniebeler.pfpixelix.R
import pixelix.app.generated.resources.Res
import pixelix.app.generated.resources.*
import com.daniebeler.pfpixelix.domain.model.Post
import com.daniebeler.pfpixelix.utils.BlurHashDecoder
import com.daniebeler.pfpixelix.utils.Navigate
import org.jetbrains.compose.resources.vectorResource

@Composable
fun CustomPost(
Expand Down Expand Up @@ -125,7 +127,7 @@ fun CustomPost(
.align(Alignment.TopEnd)
) {
Icon(
imageVector = ImageVector.vectorResource(R.drawable.stack),
imageVector = vectorResource(Res.drawable.stack),
tint = Color.White,
contentDescription = null,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import org.jetbrains.compose.resources.stringResource
import androidx.compose.ui.unit.dp
import com.daniebeler.pfpixelix.R
import pixelix.app.generated.resources.Res
import pixelix.app.generated.resources.*

@Composable
fun FollowButton(
Expand Down Expand Up @@ -159,13 +160,13 @@ private fun TextFollowButton(
contentColor = MaterialTheme.colorScheme.onSecondaryContainer
)
) {
Text(text = stringResource(R.string.unfollow))
Text(text = stringResource(Res.string.unfollow))
}
} else {
Button(onClick = {
onFollowClick()
}, modifier = Modifier.width(120.dp)) {
Text(text = stringResource(R.string.follow))
Text(text = stringResource(Res.string.follow))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,20 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource
import org.jetbrains.compose.resources.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import com.daniebeler.pfpixelix.R
import pixelix.app.generated.resources.Res
import pixelix.app.generated.resources.*
import com.daniebeler.pfpixelix.ui.composables.timelines.global_timeline.GlobalTimelineComposable
import com.daniebeler.pfpixelix.ui.composables.timelines.home_timeline.HomeTimelineComposable
import com.daniebeler.pfpixelix.ui.composables.timelines.local_timeline.LocalTimelineComposable
import com.daniebeler.pfpixelix.utils.Navigate
import kotlinx.coroutines.launch
import org.jetbrains.compose.resources.vectorResource

@OptIn(ExperimentalMaterial3Api::class)
@Composable
Expand All @@ -61,11 +63,11 @@ fun HomeComposable(navController: NavController, openPreferencesDrawer: () -> Un
contentWindowInsets = WindowInsets.systemBars.only(WindowInsetsSides.Top),
topBar = {
CenterAlignedTopAppBar(title = {
Text(stringResource(id = R.string.app_name), fontWeight = FontWeight.Bold)
Text(stringResource(Res.string.app_name), fontWeight = FontWeight.Bold)
}, navigationIcon = {
IconButton(onClick = { showBottomSheet = true }) {
Icon(
imageVector = ImageVector.vectorResource(R.drawable.help_outline),
imageVector = vectorResource(Res.drawable.help_outline),
contentDescription = "Help"
)
}
Expand All @@ -79,15 +81,15 @@ fun HomeComposable(navController: NavController, openPreferencesDrawer: () -> Un
)
}) {
Icon(
imageVector = ImageVector.vectorResource(R.drawable.mail_outline),
imageVector = vectorResource(Res.drawable.mail_outline),
contentDescription = "Conversations"
)
}
IconButton(onClick = {
openPreferencesDrawer()
}) {
Icon(
imageVector = ImageVector.vectorResource(R.drawable.settings_outline),
imageVector = vectorResource(Res.drawable.settings_outline),
contentDescription = "Settings"
)
}
Expand All @@ -102,7 +104,7 @@ fun HomeComposable(navController: NavController, openPreferencesDrawer: () -> Un
) {

PrimaryTabRow(selectedTabIndex = pagerState.currentPage) {
Tab(text = { Text(stringResource(R.string.home)) },
Tab(text = { Text(stringResource(Res.string.home)) },
selected = pagerState.currentPage == 0,
selectedContentColor = MaterialTheme.colorScheme.primary,
unselectedContentColor = MaterialTheme.colorScheme.onBackground,
Expand All @@ -112,7 +114,7 @@ fun HomeComposable(navController: NavController, openPreferencesDrawer: () -> Un
}
})

Tab(text = { Text(stringResource(R.string.local)) },
Tab(text = { Text(stringResource(Res.string.local)) },
selected = pagerState.currentPage == 1,
selectedContentColor = MaterialTheme.colorScheme.primary,
unselectedContentColor = MaterialTheme.colorScheme.onBackground,
Expand All @@ -122,7 +124,7 @@ fun HomeComposable(navController: NavController, openPreferencesDrawer: () -> Un
}
})

Tab(text = { Text(stringResource(R.string.global)) },
Tab(text = { Text(stringResource(Res.string.global)) },
selected = pagerState.currentPage == 2,
selectedContentColor = MaterialTheme.colorScheme.primary,
unselectedContentColor = MaterialTheme.colorScheme.onBackground,
Expand Down Expand Up @@ -171,18 +173,18 @@ fun HomeComposable(navController: NavController, openPreferencesDrawer: () -> Un
Spacer(modifier = Modifier.height(18.dp))

SheetItem(
header = stringResource(id = R.string.home),
description = stringResource(R.string.home_timeline_explained)
header = stringResource(Res.string.home),
description = stringResource(Res.string.home_timeline_explained)
)

SheetItem(
header = stringResource(id = R.string.local),
description = stringResource(R.string.local_timeline_explained)
header = stringResource(Res.string.local),
description = stringResource(Res.string.local_timeline_explained)
)

SheetItem(
header = stringResource(id = R.string.global),
description = stringResource(R.string.global_timeline_explained)
header = stringResource(Res.string.global),
description = stringResource(Res.string.global_timeline_explained)
)
}
}
Expand Down
Loading

0 comments on commit 5df04aa

Please sign in to comment.