Skip to content

Commit

Permalink
Hardcoded strings have been moved to resource file strings.xml (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sushant-Hande authored May 18, 2024
1 parent 5d7007f commit 393f089
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 19 deletions.
11 changes: 11 additions & 0 deletions shared/src/commonMain/composeResources/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
<resources>
<string name="featured_playlist">Featured Playlist</string>
<string name="explore_details">Explore details</string>
<string name="likes">Likes</string>
<string name="tracks">tracks</string>
<string name="favorite">Favorite</string>
<string name="new_releases">New releases</string>
<string name="go_back">Go back</string>
<string name="songs">songs</string>
<string name="play_all">Play All</string>
<string name="forward">Forward</string>
<string name="back">Back</string>
<string name="play">Play</string>
</resources>
19 changes: 14 additions & 5 deletions shared/src/commonMain/kotlin/musicapp/chartdetails/ChartDetails.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,18 @@ import musicapp.decompose.ChartDetailsComponent
import musicapp.network.models.topfiftycharts.Item
import musicapp.network.models.topfiftycharts.TopFiftyCharts
import com.seiko.imageloader.rememberAsyncImagePainter
import musicapp_kmp.shared.generated.resources.Res
import musicapp_kmp.shared.generated.resources.go_back
import musicapp_kmp.shared.generated.resources.play_all
import musicapp_kmp.shared.generated.resources.songs
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.stringResource


/**
* Created by abdulbasit on 28/02/2023.
*/
@OptIn(ExperimentalResourceApi::class)
@Composable
internal fun ChartDetailsScreen(
chartDetailsComponent: ChartDetailsComponent,
Expand Down Expand Up @@ -80,7 +87,7 @@ internal fun ChartDetailsScreen(
) {
Icon(
Icons.Filled.ArrowBack,
contentDescription = "Go back",
contentDescription = stringResource(Res.string.go_back),
tint = Color(0xFFFACD66),
)
}
Expand All @@ -104,6 +111,7 @@ internal fun Failure(message: String) {
}


@OptIn(ExperimentalResourceApi::class)
@Composable
internal fun ChartDetailsView(
chartDetails: TopFiftyCharts,
Expand Down Expand Up @@ -158,7 +166,7 @@ internal fun ChartDetailsView(
modifier = Modifier.padding(top = 8.dp)
)
Text(
text = "${chartDetails.tracks?.items?.size ?: 0} songs",
text = "${chartDetails.tracks?.items?.size ?: 0} ${stringResource(Res.string.songs)}",
style = MaterialTheme.typography.body2.copy(color = Color(0XFFEFEEE0)),
modifier = Modifier.padding(top = 8.dp)
)
Expand Down Expand Up @@ -206,7 +214,7 @@ internal fun ChartDetailsView(
Icon(
imageVector = Icons.Default.PlayArrow,
tint = Color(0xFFFACD66),
contentDescription = "Play All",
contentDescription = stringResource(Res.string.play_all),
modifier = Modifier.size(40.dp)
.clip(RoundedCornerShape(5.dp))
.background(Color.Black.copy(alpha = 0.7f))
Expand Down Expand Up @@ -250,6 +258,7 @@ internal fun ChartDetailsView(
}
}

@OptIn(ExperimentalResourceApi::class)
@Composable
internal fun OptionChips(onPlayAllClicked: (List<Item>) -> Unit, items: List<Item>) {
Box(
Expand All @@ -262,12 +271,12 @@ internal fun OptionChips(onPlayAllClicked: (List<Item>) -> Unit, items: List<Ite
Icon(
imageVector = Icons.Default.PlayArrow,
tint = Color(0xFFFACD66),
contentDescription = "Play All",
contentDescription = stringResource(Res.string.play_all),
modifier = Modifier.padding(end = 8.dp).size(16.dp)
.align(Alignment.CenterVertically)
)
Text(
text = "Play All",
text = stringResource(Res.string.play_all),
style = MaterialTheme.typography.caption.copy(color = Color(0XFFEFEEE0))
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,18 @@ import musicapp.decompose.ChartDetailsComponent
import musicapp.network.models.topfiftycharts.Item
import musicapp.network.models.topfiftycharts.TopFiftyCharts
import com.seiko.imageloader.rememberAsyncImagePainter
import musicapp_kmp.shared.generated.resources.Res
import musicapp_kmp.shared.generated.resources.forward
import musicapp_kmp.shared.generated.resources.play_all
import musicapp_kmp.shared.generated.resources.songs
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.stringResource


/**
* Created by abdulbasit on 28/02/2023.
*/
@OptIn(ExperimentalResourceApi::class)
@Composable
internal fun ChartDetailsScreenLarge(
chartDetailsComponent: ChartDetailsComponent,
Expand All @@ -70,7 +77,7 @@ internal fun ChartDetailsScreenLarge(
IconButton(onClick = { chartDetailsComponent.onOutPut(ChartDetailsComponent.Output.GoBack) }) {
Icon(
Icons.Filled.ArrowBack,
contentDescription = "Forward",
contentDescription = stringResource(Res.string.forward),
tint = Color(0xFFFACD66),
modifier = Modifier.padding(all = 16.dp).size(32.dp)
)
Expand All @@ -86,6 +93,7 @@ internal fun ChartDetailsScreenLarge(
)*/
}

@OptIn(ExperimentalResourceApi::class)
@Composable
internal fun ChartDetailsViewLarge(
chartDetails: TopFiftyCharts,
Expand Down Expand Up @@ -149,7 +157,7 @@ internal fun ChartDetailsViewLarge(
modifier = Modifier.padding(top = 8.dp)
)
Text(
text = "${chartDetails.tracks?.items?.size ?: 0} songs",
text = "${chartDetails.tracks?.items?.size ?: 0} ${stringResource(Res.string.songs)}}",
style = MaterialTheme.typography.body2.copy(color = Color(0XFFEFEEE0)),
modifier = Modifier.padding(top = 10.dp)
)
Expand Down Expand Up @@ -190,7 +198,7 @@ internal fun ChartDetailsViewLarge(
Icon(
imageVector = Icons.Default.PlayArrow,
tint = Color(0xFFFACD66),
contentDescription = "Play All",
contentDescription = stringResource(Res.string.play_all),
modifier = Modifier.size(40.dp)
.clip(RoundedCornerShape(5.dp))
.background(Color.Black.copy(alpha = 0.7f))
Expand Down
19 changes: 13 additions & 6 deletions shared/src/commonMain/kotlin/musicapp/dashboard/DashboardScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ import musicapp.network.models.newreleases.NewReleasedAlbums
import musicapp.network.models.topfiftycharts.TopFiftyCharts
import com.seiko.imageloader.rememberAsyncImagePainter
import musicapp_kmp.shared.generated.resources.Res
import musicapp_kmp.shared.generated.resources.explore_details
import musicapp_kmp.shared.generated.resources.favorite
import musicapp_kmp.shared.generated.resources.featured_playlist
import musicapp_kmp.shared.generated.resources.likes
import musicapp_kmp.shared.generated.resources.new_releases
import musicapp_kmp.shared.generated.resources.tracks
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.stringResource

Expand Down Expand Up @@ -106,6 +111,7 @@ internal fun DashboardView(
}
}

@OptIn(ExperimentalResourceApi::class)
@Composable
internal fun TopChartView(topFiftyCharts: TopFiftyCharts, navigateToDetails: (String) -> Unit) {
Box(
Expand Down Expand Up @@ -140,11 +146,11 @@ internal fun TopChartView(topFiftyCharts: TopFiftyCharts, navigateToDetails: (St
Icon(
imageVector = Icons.Filled.FavoriteBorder,
tint = Color(0xFFFACD66),
contentDescription = "Explore details",
contentDescription = stringResource(Res.string.explore_details),
modifier = Modifier.size(30.dp).align(Alignment.Top)
)
Text(
text = "${topFiftyCharts.followers?.total ?: 0} Likes",
text = "${topFiftyCharts.followers?.total ?: 0} ${stringResource(Res.string.likes)}",
style = MaterialTheme.typography.h5,
color = Color.White,
modifier = Modifier.padding(start = 16.dp)
Expand Down Expand Up @@ -215,15 +221,15 @@ internal fun FeaturedPlayLists(
maxLines = 1
)
Text(
text = "${(playList.tracks?.total ?: 0)} tracks",
text = "${(playList.tracks?.total ?: 0)} ${stringResource(Res.string.tracks)}",
style = MaterialTheme.typography.body2.copy(color = Color.White),
modifier = Modifier.padding(top = 24.dp)
)
}
Icon(
imageVector = Icons.Default.Favorite,
tint = Color(0xFFFACD66),
contentDescription = "Favorite",
contentDescription = stringResource(Res.string.favorite),
modifier = Modifier.padding(top = 16.dp, end = 16.dp).size(30.dp)
.align(Alignment.TopEnd)
)
Expand All @@ -233,14 +239,15 @@ internal fun FeaturedPlayLists(
}
}

@OptIn(ExperimentalResourceApi::class)
@Composable
internal fun NewReleases(
newReleasedAlbums: NewReleasedAlbums,
navigateToDetails: (String) -> Unit
) {
Column(modifier = Modifier.padding(top = 46.dp).fillMaxWidth()) {
Text(
"New releases",
stringResource(Res.string.new_releases),
style = MaterialTheme.typography.h6.copy(
fontWeight = FontWeight.Bold,
color = Color(0xFFEFEEE0)
Expand Down Expand Up @@ -277,7 +284,7 @@ internal fun NewReleases(
maxLines = 1
)
Text(
text = "${(album.totalTracks ?: 0)} tracks",
text = "${(album.totalTracks ?: 0)} ${stringResource(Res.string.tracks)}",
style = MaterialTheme.typography.caption.copy(
color = Color.White.copy(
alpha = 0.5f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ import androidx.compose.ui.unit.dp
import musicapp.decompose.DashboardMainComponent
import musicapp.network.models.topfiftycharts.TopFiftyCharts
import com.seiko.imageloader.rememberAsyncImagePainter
import musicapp_kmp.shared.generated.resources.Res
import musicapp_kmp.shared.generated.resources.explore_details
import musicapp_kmp.shared.generated.resources.likes
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.stringResource


/**
Expand Down Expand Up @@ -71,6 +76,7 @@ internal fun DashboardViewLarge(
}


@OptIn(ExperimentalResourceApi::class)
@Composable
internal fun TopChartViewLarge(
topFiftyCharts: TopFiftyCharts, navigateToDetails: (String) -> Unit
Expand Down Expand Up @@ -104,11 +110,11 @@ internal fun TopChartViewLarge(
Icon(
imageVector = Icons.Filled.FavoriteBorder,
tint = Color(0xFFFACD66),
contentDescription = "Explore details",
contentDescription = stringResource(Res.string.explore_details),
modifier = Modifier.size(30.dp).align(Alignment.Top)
)
Text(
text = "${topFiftyCharts.followers?.total ?: 0} Likes",
text = "${topFiftyCharts.followers?.total ?: 0} ${stringResource(Res.string.likes)}",
style = MaterialTheme.typography.h5,
color = Color.White,
modifier = Modifier.padding(start = 16.dp)
Expand Down
13 changes: 10 additions & 3 deletions shared/src/commonMain/kotlin/musicapp/playerview/PlayerView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@ import musicapp.decompose.PlayerComponent
import musicapp.network.models.topfiftycharts.Item
import musicapp.player.MediaPlayerController
import musicapp.player.MediaPlayerListener
import musicapp_kmp.shared.generated.resources.Res
import musicapp_kmp.shared.generated.resources.back
import musicapp_kmp.shared.generated.resources.forward
import musicapp_kmp.shared.generated.resources.play
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.stringResource


@OptIn(ExperimentalResourceApi::class)
@Composable
internal fun PlayerView(playerComponent: PlayerComponent) {
val state = playerComponent.viewModel.playerViewState.collectAsState()
Expand Down Expand Up @@ -117,7 +124,7 @@ internal fun PlayerView(playerComponent: PlayerComponent) {
Icon(
imageVector = Icons.Default.ArrowBack,
tint = Color(0xFFFACD66),
contentDescription = "Back",
contentDescription = stringResource(Res.string.back),
modifier = Modifier.padding(end = 8.dp).size(32.dp)
.align(Alignment.CenterVertically)
.clickable(onClick = {
Expand All @@ -129,7 +136,7 @@ internal fun PlayerView(playerComponent: PlayerComponent) {
Icon(
imageVector = Icons.Filled.PlayArrow,
tint = Color(0xFFFACD66),
contentDescription = "Play",
contentDescription = stringResource(Res.string.play),
modifier = Modifier.padding(end = 8.dp).size(32.dp)
.align(Alignment.CenterVertically)
.clickable(onClick = {
Expand All @@ -143,7 +150,7 @@ internal fun PlayerView(playerComponent: PlayerComponent) {
Icon(
imageVector = Icons.Default.ArrowForward,
tint = Color(0xFFFACD66),
contentDescription = "Forward",
contentDescription = stringResource(Res.string.forward),
modifier = Modifier.padding(end = 8.dp).size(32.dp)
.align(Alignment.CenterVertically)
.clickable(onClick = {
Expand Down

0 comments on commit 393f089

Please sign in to comment.