Skip to content

Commit 6243b01

Browse files
Move hardcoded strings to strings.xml for internationalization and fix Android Gradle Plugin version (#55)
* Initial plan * Move hardcoded strings to strings.xml Co-authored-by: yogeshpaliyal <[email protected]> * Fix invalid Android Gradle Plugin version from 8.11.1 to 8.1.4 Co-authored-by: yogeshpaliyal <[email protected]> * feat: run lint:kotlin * fix: incorrect string import --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: yogeshpaliyal <[email protected]> Co-authored-by: Yogesh Choudhary Paliyal <[email protected]>
1 parent 6eb6746 commit 6243b01

File tree

7 files changed

+112
-46
lines changed

7 files changed

+112
-46
lines changed

app/src/main/java/com/yogeshpaliyal/deepr/backup/ExportRepositoryImpl.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.os.Environment
77
import android.provider.MediaStore
88
import com.yogeshpaliyal.deepr.Deepr
99
import com.yogeshpaliyal.deepr.DeeprQueries
10+
import com.yogeshpaliyal.deepr.R
1011
import com.yogeshpaliyal.deepr.util.Constants
1112
import com.yogeshpaliyal.deepr.util.RequestResult
1213
import kotlinx.coroutines.Dispatchers
@@ -25,11 +26,11 @@ class ExportRepositoryImpl(
2526
override suspend fun exportToCsv(): RequestResult<String> {
2627
val count = deeprQueries.countDeepr().executeAsOne()
2728
if (count == 0L) {
28-
return RequestResult.Error("No data found in the database to export.")
29+
return RequestResult.Error(context.getString(R.string.no_data_to_export))
2930
}
3031
val dataToExportInCsvFormat = deeprQueries.listDeeprAsc().executeAsList()
3132
if (dataToExportInCsvFormat.isEmpty()) {
32-
return RequestResult.Error("No data available to export after mapping.")
33+
return RequestResult.Error(context.getString(R.string.no_data_available_export))
3334
}
3435

3536
val timeStamp = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(Date())
@@ -55,9 +56,9 @@ class ExportRepositoryImpl(
5556
resolver.openOutputStream(uri)?.use { outputStream ->
5657
writeCsvData(outputStream, dataToExportInCsvFormat)
5758
}
58-
RequestResult.Success("Successfully exported to ${Environment.DIRECTORY_DOWNLOADS}/Deepr/$fileName")
59+
RequestResult.Success(context.getString(R.string.export_success, "${Environment.DIRECTORY_DOWNLOADS}/Deepr/$fileName"))
5960
} else {
60-
RequestResult.Error("Failed to create CSV file.")
61+
RequestResult.Error(context.getString(R.string.export_failed))
6162
}
6263
} else {
6364
val downloadsDir =
@@ -72,7 +73,7 @@ class ExportRepositoryImpl(
7273
FileOutputStream(file).use { outputStream ->
7374
writeCsvData(outputStream, dataToExportInCsvFormat)
7475
}
75-
RequestResult.Success("Successfully exported to $downloadsDir/${file.absolutePath}")
76+
RequestResult.Success(context.getString(R.string.export_success, file.absolutePath))
7677
}
7778
}
7879
}

app/src/main/java/com/yogeshpaliyal/deepr/ui/screens/AboutUs.kt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import androidx.compose.ui.Modifier
2929
import androidx.compose.ui.draw.clip
3030
import androidx.compose.ui.platform.LocalUriHandler
3131
import androidx.compose.ui.res.painterResource
32+
import androidx.compose.ui.res.stringResource
3233
import androidx.compose.ui.text.style.TextAlign
3334
import androidx.compose.ui.unit.dp
3435
import com.yogeshpaliyal.deepr.BuildConfig
@@ -51,15 +52,15 @@ fun AboutUsScreen(
5152
Column {
5253
TopAppBar(
5354
title = {
54-
Text("About Us")
55+
Text(stringResource(R.string.about_us))
5556
},
5657
navigationIcon = {
5758
IconButton(onClick = {
5859
backStack.removeLastOrNull()
5960
}) {
6061
Icon(
6162
TablerIcons.ArrowLeft,
62-
contentDescription = "Back",
63+
contentDescription = stringResource(R.string.back),
6364
)
6465
}
6566
},
@@ -78,24 +79,24 @@ fun AboutUsScreen(
7879
Spacer(modifier = Modifier.height(32.dp))
7980
Image(
8081
painter = painterResource(id = R.drawable.app_logo),
81-
contentDescription = "App Logo",
82+
contentDescription = stringResource(R.string.app_logo),
8283
modifier =
8384
Modifier
8485
.size(120.dp)
8586
.clip(CircleShape),
8687
)
8788
Spacer(modifier = Modifier.height(16.dp))
8889
Text(
89-
text = "Deepr",
90+
text = stringResource(R.string.app_name),
9091
style = MaterialTheme.typography.headlineLarge,
9192
)
9293
Text(
93-
text = "Version ${BuildConfig.VERSION_NAME}",
94+
text = stringResource(R.string.version_format, BuildConfig.VERSION_NAME),
9495
style = MaterialTheme.typography.bodyMedium,
9596
)
9697
Spacer(modifier = Modifier.height(16.dp))
9798
Text(
98-
text = "A simple app to save, organize, and launch deeplinks.",
99+
text = stringResource(R.string.app_description),
99100
style = MaterialTheme.typography.bodyLarge,
100101
textAlign = TextAlign.Center,
101102
modifier = Modifier.padding(horizontal = 16.dp),
@@ -104,26 +105,26 @@ fun AboutUsScreen(
104105
Card(modifier = Modifier.fillMaxWidth()) {
105106
Column(modifier = Modifier.padding(16.dp)) {
106107
Text(
107-
text = "Author",
108+
text = stringResource(R.string.author),
108109
style = MaterialTheme.typography.titleLarge,
109110
)
110111
Spacer(modifier = Modifier.height(8.dp))
111112
Text(
112-
text = "Yogesh Choudhary",
113+
text = stringResource(R.string.author_name),
113114
style = MaterialTheme.typography.bodyLarge,
114115
)
115116
Spacer(modifier = Modifier.height(8.dp))
116117
Row(horizontalArrangement = Arrangement.spacedBy(16.dp)) {
117118
val uriHandler = LocalUriHandler.current
118119

119120
IconButton(onClick = { uriHandler.openUri("https://twitter.com/yogeshpaliyal") }) {
120-
Icon(TablerIcons.BrandTwitter, contentDescription = "Twitter")
121+
Icon(TablerIcons.BrandTwitter, contentDescription = stringResource(R.string.twitter))
121122
}
122123
IconButton(onClick = { uriHandler.openUri("https://www.linkedin.com/in/yogeshpaliyal/") }) {
123-
Icon(TablerIcons.BrandLinkedin, contentDescription = "LinkedIn")
124+
Icon(TablerIcons.BrandLinkedin, contentDescription = stringResource(R.string.linkedin))
124125
}
125126
IconButton(onClick = { uriHandler.openUri("https://github.com/yogeshpaliyal") }) {
126-
Icon(TablerIcons.BrandGithub, contentDescription = "GitHub")
127+
Icon(TablerIcons.BrandGithub, contentDescription = stringResource(R.string.github))
127128
}
128129
}
129130
}
@@ -133,10 +134,10 @@ fun AboutUsScreen(
133134
Button(onClick = { uriHandler.openUri("https://github.com/yogeshpaliyal/Deepr") }) {
134135
Icon(
135136
TablerIcons.BrandGithub,
136-
contentDescription = "GitHub",
137+
contentDescription = stringResource(R.string.github),
137138
modifier = Modifier.padding(end = 8.dp),
138139
)
139-
Text("View on GitHub")
140+
Text(stringResource(R.string.view_on_github))
140141
}
141142

142143
Spacer(modifier = Modifier.height(16.dp))

app/src/main/java/com/yogeshpaliyal/deepr/ui/screens/Settings.kt

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ import androidx.compose.runtime.snapshots.SnapshotStateList
3535
import androidx.compose.ui.Alignment
3636
import androidx.compose.ui.Modifier
3737
import androidx.compose.ui.platform.LocalContext
38+
import androidx.compose.ui.res.stringResource
3839
import androidx.compose.ui.text.style.TextAlign
3940
import androidx.compose.ui.unit.dp
4041
import com.google.accompanist.permissions.ExperimentalPermissionsApi
4142
import com.google.accompanist.permissions.isGranted
4243
import com.google.accompanist.permissions.rememberPermissionState
4344
import com.yogeshpaliyal.deepr.BuildConfig
45+
import com.yogeshpaliyal.deepr.R
4446
import com.yogeshpaliyal.deepr.viewmodel.AccountViewModel
4547
import compose.icons.TablerIcons
4648
import compose.icons.tablericons.ArrowLeft
@@ -100,15 +102,15 @@ fun SettingsScreen(
100102
Column {
101103
TopAppBar(
102104
title = {
103-
Text("Settings")
105+
Text(stringResource(R.string.settings))
104106
},
105107
navigationIcon = {
106108
IconButton(onClick = {
107109
backStack.removeLastOrNull()
108110
}) {
109111
Icon(
110112
TablerIcons.ArrowLeft,
111-
contentDescription = "Back",
113+
contentDescription = stringResource(R.string.back),
112114
)
113115
}
114116
},
@@ -137,12 +139,12 @@ fun SettingsScreen(
137139
),
138140
)
139141
},
140-
headlineContent = { Text("Import Deeplinks") },
141-
supportingContent = { Text("Import Deeplinks from CSV file") },
142+
headlineContent = { Text(stringResource(R.string.import_deeplinks)) },
143+
supportingContent = { Text(stringResource(R.string.import_deeplinks_description)) },
142144
leadingContent = {
143145
Icon(
144146
TablerIcons.Download,
145-
contentDescription = "Import Deeplinks",
147+
contentDescription = stringResource(R.string.import_deeplinks),
146148
)
147149
},
148150
)
@@ -159,12 +161,12 @@ fun SettingsScreen(
159161
}
160162
}
161163
},
162-
headlineContent = { Text("Export Deeplinks") },
163-
supportingContent = { Text("Export Deeplinks to CSV file") },
164+
headlineContent = { Text(stringResource(R.string.export_deeplinks)) },
165+
supportingContent = { Text(stringResource(R.string.export_deeplinks_description)) },
164166
leadingContent = {
165167
Icon(
166168
TablerIcons.Upload,
167-
contentDescription = "Export Deeplinks",
169+
contentDescription = stringResource(R.string.export_deeplinks),
168170
)
169171
},
170172
)
@@ -178,14 +180,22 @@ fun SettingsScreen(
178180
// Toggle the preference
179181
viewModel.setUseLinkBasedIcons(!useLinkBasedIcons)
180182
},
181-
headlineContent = { Text("Shortcut Icon") },
183+
headlineContent = { Text(stringResource(R.string.shortcut_icon)) },
182184
supportingContent = {
183-
Text(if (useLinkBasedIcons) "Use link supporting app icon" else "Use Deepr app icon")
185+
Text(
186+
if (useLinkBasedIcons) {
187+
stringResource(
188+
R.string.use_link_app_icon,
189+
)
190+
} else {
191+
stringResource(R.string.use_deepr_app_icon)
192+
},
193+
)
184194
},
185195
leadingContent = {
186196
Icon(
187197
TablerIcons.Settings,
188-
contentDescription = "Shortcut Icon Setting",
198+
contentDescription = stringResource(R.string.shortcut_icon_setting),
189199
)
190200
},
191201
trailingContent = {
@@ -202,11 +212,11 @@ fun SettingsScreen(
202212
Modifier.clickable(true) {
203213
backStack.add(AboutUs)
204214
},
205-
headlineContent = { Text("About Us") },
215+
headlineContent = { Text(stringResource(R.string.about_us)) },
206216
leadingContent = {
207217
Icon(
208218
TablerIcons.InfoCircle,
209-
contentDescription = "About Us",
219+
contentDescription = stringResource(R.string.about_us),
210220
)
211221
},
212222
)
@@ -218,14 +228,14 @@ fun SettingsScreen(
218228
verticalArrangement = Arrangement.Center,
219229
) {
220230
Text(
221-
"App Version: ${BuildConfig.VERSION_NAME}",
231+
stringResource(R.string.app_version, BuildConfig.VERSION_NAME),
222232
style = MaterialTheme.typography.bodyMedium,
223233
textAlign = TextAlign.Center,
224234
modifier = Modifier.fillMaxWidth(),
225235
)
226236
Spacer(modifier = Modifier.height(8.dp))
227237
Text(
228-
"Made with ❤️ in India",
238+
stringResource(R.string.made_with_love),
229239
style = MaterialTheme.typography.bodyMedium,
230240
textAlign = TextAlign.Center,
231241
modifier = Modifier.fillMaxWidth(),

app/src/main/java/com/yogeshpaliyal/deepr/ui/screens/home/HomeBottomContent.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ import androidx.compose.runtime.setValue
2222
import androidx.compose.ui.Modifier
2323
import androidx.compose.ui.draw.clip
2424
import androidx.compose.ui.platform.LocalContext
25+
import androidx.compose.ui.res.stringResource
2526
import androidx.compose.ui.unit.dp
27+
import com.yogeshpaliyal.deepr.R
2628
import com.yogeshpaliyal.deepr.util.isValidDeeplink
2729
import com.yogeshpaliyal.deepr.util.openDeeplink
2830
import com.yogeshpaliyal.deepr.viewmodel.AccountViewModel
@@ -54,7 +56,7 @@ fun HomeBottomContent(
5456
}
5557
if (!isError) {
5658
inputText.value = ""
57-
Toast.makeText(context, "Saved", Toast.LENGTH_SHORT).show()
59+
Toast.makeText(context, R.string.saved, Toast.LENGTH_SHORT).show()
5860
viewModel.insertAccount(result.link, result.name, result.executeAfterSave)
5961
}
6062
}
@@ -91,11 +93,11 @@ fun HomeBottomContent(
9193
Modifier
9294
.fillMaxWidth()
9395
.padding(bottom = 8.dp),
94-
placeholder = { Text("Enter deeplink or command") },
96+
placeholder = { Text(stringResource(R.string.enter_deeplink_command)) },
9597
isError = isError,
9698
supportingText = {
9799
if (isError) {
98-
Text(text = "Invalid or empty deeplink.")
100+
Text(text = stringResource(R.string.invalid_empty_deeplink))
99101
}
100102
},
101103
)
@@ -112,12 +114,12 @@ fun HomeBottomContent(
112114
isError = true
113115
}
114116
}) {
115-
Text("Save")
117+
Text(stringResource(R.string.save))
116118
}
117119
OutlinedButton(onClick = {
118120
isError = !openDeeplink(context, inputText.value)
119121
}) {
120-
Text("Execute")
122+
Text(stringResource(R.string.execute))
121123
}
122124
Button(onClick = {
123125
if (isValidDeeplink(inputText.value)) {
@@ -126,7 +128,7 @@ fun HomeBottomContent(
126128
isError = true
127129
}
128130
}) {
129-
Text("Save & Execute")
131+
Text(stringResource(R.string.save_and_execute))
130132
}
131133
}
132134
}

app/src/main/java/com/yogeshpaliyal/deepr/ui/screens/home/SaveCompleteDialog.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import androidx.compose.runtime.mutableStateOf
1313
import androidx.compose.runtime.remember
1414
import androidx.compose.runtime.setValue
1515
import androidx.compose.ui.Modifier
16+
import androidx.compose.ui.res.stringResource
1617
import androidx.compose.ui.unit.dp
18+
import com.yogeshpaliyal.deepr.R
1719

1820
data class SaveDialogInfo(
1921
val link: String,
@@ -41,10 +43,10 @@ fun SaveCompleteDialog(
4143
},
4244
modifier = modifier,
4345
title = {
44-
Text("Save Deeplink")
46+
Text(stringResource(R.string.save_deeplink))
4547
},
4648
text = {
47-
Text("Save the deeplink: ${localSaveDialogInfo.link} ?")
49+
Text(stringResource(R.string.save_deeplink_message, localSaveDialogInfo.link))
4850
TextField(
4951
value = linkName.value,
5052
onValueChange = {
@@ -55,10 +57,10 @@ fun SaveCompleteDialog(
5557
Modifier
5658
.fillMaxWidth()
5759
.padding(bottom = 8.dp),
58-
placeholder = { Text("Please enter name for the link") },
60+
placeholder = { Text(stringResource(R.string.enter_link_name)) },
5961
supportingText = {
6062
if (isError) {
61-
Text(text = "Please enter name for the link.")
63+
Text(text = stringResource(R.string.enter_link_name_error))
6264
}
6365
},
6466
)
@@ -71,14 +73,14 @@ fun SaveCompleteDialog(
7173
}
7274
onDismiss(SaveDialogSuccessInfo(localSaveDialogInfo.executeAfterSave, localSaveDialogInfo.link, linkName.value))
7375
}) {
74-
Text(if (localSaveDialogInfo.executeAfterSave) "Save & Execute" else "Save")
76+
Text(if (localSaveDialogInfo.executeAfterSave) stringResource(R.string.save_and_execute) else stringResource(R.string.save))
7577
}
7678
},
7779
dismissButton = {
7880
OutlinedButton(onClick = {
7981
onDismiss(null)
8082
}) {
81-
Text("Cancel")
83+
Text(stringResource(R.string.cancel))
8284
}
8385
},
8486
)

app/src/main/java/com/yogeshpaliyal/deepr/util/Utils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fun openDeeplink(
2121
true
2222
} catch (e: Exception) {
2323
e.printStackTrace()
24-
Toast.makeText(context, "Invalid deeplink: $link", Toast.LENGTH_SHORT).show()
24+
Toast.makeText(context, context.getString(R.string.invalid_deeplink_toast, link), Toast.LENGTH_SHORT).show()
2525
// Optionally, show a toast or a dialog to the user that the link is invalid
2626
false
2727
}

0 commit comments

Comments
 (0)