Skip to content

Commit bb00b0a

Browse files
committed
chore: Use compose resources for strings
1 parent 2f4bdc1 commit bb00b0a

File tree

10 files changed

+159
-111
lines changed

10 files changed

+159
-111
lines changed

composeApp/src/androidMain/kotlin/dev/ishubhamsingh/splashy/core/utils/FileUtils.kt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,19 @@ import android.provider.MediaStore
3131
import android.widget.Toast
3232
import com.eygraber.uri.toAndroidUri
3333
import com.eygraber.uri.toUri
34-
import dev.ishubhamsingh.splashy.core.presentation.CommonRes
3534
import dev.ishubhamsingh.splashy.features.details.WallpaperScreenType
35+
import dev.ishubhamsingh.splashy.resources.Res
36+
import dev.ishubhamsingh.splashy.resources.applying_wallpaper_failed_message
37+
import dev.ishubhamsingh.splashy.resources.applying_wallpaper_success_message
38+
import dev.ishubhamsingh.splashy.resources.downloading_file_failed_message
39+
import dev.ishubhamsingh.splashy.resources.downloading_file_success_message
40+
import dev.ishubhamsingh.splashy.resources.opening_file_failed_message
41+
import dev.ishubhamsingh.splashy.resources.wallpaper_chooser_title
3642
import kotlin.coroutines.coroutineContext
3743
import kotlinx.coroutines.CoroutineScope
3844
import kotlinx.coroutines.Dispatchers
3945
import kotlinx.coroutines.launch
46+
import org.jetbrains.compose.resources.getString
4047

4148
/** Created by Shubham Singh on 19/08/23. */
4249
actual class FileUtils(private val context: Context) {
@@ -78,19 +85,16 @@ actual class FileUtils(private val context: Context) {
7885
openFile(uri?.toUri(), fileName)
7986
} else {
8087
result =
81-
CommonRes.downloading_file_success_message.replace(
82-
"%path",
83-
Environment.DIRECTORY_PICTURES
84-
)
88+
getString(Res.string.downloading_file_success_message, Environment.DIRECTORY_PICTURES)
8589
updateMessage.invoke(result)
8690
}
8791
}
8892
.onFailure {
8993
result =
9094
if (shouldOpenFile) {
91-
CommonRes.opening_file_failed_message
95+
getString(Res.string.opening_file_failed_message)
9296
} else {
93-
CommonRes.downloading_file_failed_message
97+
getString(Res.string.downloading_file_failed_message)
9498
}
9599
updateMessage.invoke(result)
96100
it.printStackTrace()
@@ -105,7 +109,7 @@ actual class FileUtils(private val context: Context) {
105109
intent.setDataAndType(uri?.toAndroidUri(), "image/jpeg")
106110
intent.putExtra("mimeType", "image/jpeg")
107111
val chooserIntent =
108-
Intent.createChooser(intent, CommonRes.wallpaper_chooser_title.replace("%fileName", fileName))
112+
Intent.createChooser(intent, getString(Res.string.wallpaper_chooser_title, fileName))
109113
chooserIntent.addFlags(FLAG_ACTIVITY_NEW_TASK)
110114
context.startActivity(chooserIntent)
111115
}
@@ -131,11 +135,11 @@ actual class FileUtils(private val context: Context) {
131135
wallpaperManager.setBitmap(imageBitmap, null, true, flag)
132136
}
133137
.onSuccess {
134-
result = CommonRes.applying_wallpaper_success_message
138+
result = getString(Res.string.applying_wallpaper_success_message)
135139
updateMessage.invoke(result)
136140
}
137141
.onFailure {
138-
result = CommonRes.applying_wallpaper_failed_message
142+
result = getString(Res.string.applying_wallpaper_failed_message)
139143
showMessage(result)
140144
updateMessage.invoke(result)
141145
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<resources>
2+
<string name="app_name">Splashy</string>
3+
<string name="lbl_filter">Filter by Categories</string>
4+
<string name="save_to_photos">Save to Gallery</string>
5+
<string name="lbl_download">Download</string>
6+
<string name="lbl_apply_wallpaper">Set Wallpaper</string>
7+
<string name="lbl_details_caps">DETAILS</string>
8+
<string name="lbl_desc">Description:</string>
9+
<string name="lbl_posted_on">Posted on:</string>
10+
<string name="lbl_size">Size:</string>
11+
<string name="lbl_likes">Likes:</string>
12+
<string name="lbl_color">Color:</string>
13+
<string name="lbl_topics">Categories:</string>
14+
<string name="lbl_search">Search</string>
15+
16+
<string name="title_apply_wallpaper_dialog">Set Wallpaper</string>
17+
<string name="desc_apply_wallpaper_dialog">Please select how you want to set the wallpaper</string>
18+
<string name="lbl_apply_wall_other_app">Set using other app</string>
19+
<string name="lbl_apply_wall_homescreen">Set on Homescreen</string>
20+
<string name="lbl_apply_wall_lockscreen">Set on Lockscreen</string>
21+
<string name="lbl_apply_wall_both">Set on both screens</string>
22+
23+
<string name="lbl_home">Home</string>
24+
<string name="lbl_categories">Categories</string>
25+
<string name="lbl_favourites">Favorites</string>
26+
<string name="lbl_details">Photo Details</string>
27+
<string name="lbl_categories_photos">Category Photos</string>
28+
<string name="lbl_settings">Settings</string>
29+
30+
<string name="saved_success_message">Saved to gallery successfully</string>
31+
<string name="saved_failure_message">Saving to gallery failed!</string>
32+
<string name="opening_file_failed_message">Opening file failed!</string>
33+
<string name="downloading_file_success_message">File saved successfully in %1$s</string>
34+
<string name="downloading_file_failed_message">Saving file failed!</string>
35+
<string name="applying_wallpaper_success_message">Wallpaper set successfully</string>
36+
<string name="applying_wallpaper_failed_message">Setting wallpaper failed!</string>
37+
<string name="wallpaper_chooser_title">Set %1$s as:</string>
38+
39+
<string name="lbl_collections_title">Collections</string>
40+
<string name="lbl_topics_title">Categories</string>
41+
<string name="lbl_photos_count">%1$d Photos</string>
42+
43+
<string name="lbl_select_theme">Select Theme</string>
44+
<string name="lbl_material_you_title">Use Material You</string>
45+
<string name="lbl_material_you_desc">Apply wallpaper based colors</string>
46+
<string-array name="themes_array">
47+
<item>System</item>
48+
<item>Light</item>
49+
<item>Dark</item>
50+
</string-array>
51+
<string name="lbl_back">back</string>
52+
</resources>

composeApp/src/commonMain/kotlin/dev/ishubhamsingh/splashy/core/navigation/TopLevelScreen.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ import compose.icons.EvaIcons
5858
import compose.icons.evaicons.Outline
5959
import compose.icons.evaicons.outline.Menu2
6060
import compose.icons.evaicons.outline.Person
61-
import dev.ishubhamsingh.splashy.core.presentation.CommonRes
6261
import dev.ishubhamsingh.splashy.core.utils.isChristmasNewYearWeek
6362
import dev.ishubhamsingh.splashy.features.categories.ui.CategoriesTab
6463
import dev.ishubhamsingh.splashy.features.favourites.ui.FavouritesTab
6564
import dev.ishubhamsingh.splashy.features.home.ui.HomeTab
6665
import dev.ishubhamsingh.splashy.features.settings.ui.SettingsScreen
6766
import dev.ishubhamsingh.splashy.resources.Res
67+
import dev.ishubhamsingh.splashy.resources.app_name
6868
import dev.ishubhamsingh.splashy.resources.hat
6969
import dev.ishubhamsingh.splashy.ui.components.SnowFallComponent
7070
import dev.ishubhamsingh.splashy.ui.components.getKamelConfig
@@ -73,6 +73,7 @@ import dev.ishubhamsingh.splashy.ui.theme.getLobsterRegular
7373
import io.kamel.image.config.LocalKamelConfig
7474
import org.jetbrains.compose.resources.ExperimentalResourceApi
7575
import org.jetbrains.compose.resources.painterResource
76+
import org.jetbrains.compose.resources.stringResource
7677

7778
/** Created by Shubham Singh on 29/09/23. */
7879
class TopLevelScreen : Screen {
@@ -173,7 +174,7 @@ class TopLevelScreen : Screen {
173174
title = {
174175
Box {
175176
Text(
176-
CommonRes.app_name,
177+
stringResource(Res.string.app_name),
177178
fontFamily = getLobsterRegular(),
178179
fontSize = 32.sp,
179180
fontWeight = FontWeight.Normal

composeApp/src/commonMain/kotlin/dev/ishubhamsingh/splashy/core/presentation/CommonRes.kt

Lines changed: 0 additions & 60 deletions
This file was deleted.

composeApp/src/commonMain/kotlin/dev/ishubhamsingh/splashy/features/categories/ui/CategoriesTab.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ import compose.icons.evaicons.Fill
5555
import compose.icons.evaicons.Outline
5656
import compose.icons.evaicons.fill.Folder
5757
import compose.icons.evaicons.outline.Folder
58-
import dev.ishubhamsingh.splashy.core.presentation.CommonRes
5958
import dev.ishubhamsingh.splashy.core.utils.UpdateSystemBars
6059
import dev.ishubhamsingh.splashy.core.utils.getNonPremiumCollections
6160
import dev.ishubhamsingh.splashy.features.categories.CategoriesScreenModel
@@ -64,7 +63,13 @@ import dev.ishubhamsingh.splashy.features.categoriesPhotos.ui.CategoryType
6463
import dev.ishubhamsingh.splashy.isDarkThemeState
6564
import dev.ishubhamsingh.splashy.models.CollectionItem
6665
import dev.ishubhamsingh.splashy.models.Topic
66+
import dev.ishubhamsingh.splashy.resources.Res
67+
import dev.ishubhamsingh.splashy.resources.lbl_categories
68+
import dev.ishubhamsingh.splashy.resources.lbl_collections_title
69+
import dev.ishubhamsingh.splashy.resources.lbl_photos_count
70+
import dev.ishubhamsingh.splashy.resources.lbl_topics_title
6771
import dev.ishubhamsingh.splashy.ui.components.CategoriesCardItem
72+
import org.jetbrains.compose.resources.stringResource
6873

6974
/** Created by Shubham Singh on 29/09/23. */
7075
object CategoriesTab : Tab {
@@ -73,7 +78,7 @@ object CategoriesTab : Tab {
7378
@Composable
7479
get() {
7580
val isSelected = LocalTabNavigator.current.current == this
76-
val title = CommonRes.lbl_categories
81+
val title = stringResource(Res.string.lbl_categories)
7782
val icon =
7883
rememberVectorPainter(if (isSelected) EvaIcons.Fill.Folder else EvaIcons.Outline.Folder)
7984

@@ -141,7 +146,7 @@ object CategoriesTab : Tab {
141146
item(
142147
content = {
143148
Text(
144-
text = CommonRes.lbl_collections_title,
149+
text = stringResource(Res.string.lbl_collections_title),
145150
style = MaterialTheme.typography.displayMedium
146151
)
147152
}
@@ -150,7 +155,10 @@ object CategoriesTab : Tab {
150155
item(content = { Spacer(modifier = Modifier.size(16.dp)) })
151156
item(
152157
content = {
153-
Text(text = CommonRes.lbl_topics_title, style = MaterialTheme.typography.displayMedium)
158+
Text(
159+
text = stringResource(Res.string.lbl_topics_title),
160+
style = MaterialTheme.typography.displayMedium
161+
)
154162
}
155163
)
156164
items(topics) {
@@ -166,7 +174,7 @@ object CategoriesTab : Tab {
166174
modifier = Modifier.fillMaxWidth(),
167175
shouldShowOverlay = true,
168176
overlayTitle = it.title ?: "",
169-
overlaySubtitle = CommonRes.lbl_photos_count.replace("%count", it.totalPhotos.toString())
177+
overlaySubtitle = stringResource(Res.string.lbl_photos_count, it.totalPhotos.toString())
170178
)
171179
}
172180
}

0 commit comments

Comments
 (0)