mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2026-01-17 13:44:23 +01:00
use string resource
This commit is contained in:
13
lib_utils/src/main/res/values/string.xml
Normal file
13
lib_utils/src/main/res/values/string.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="dfu_app_name">Device Firmware Update</string>
|
||||
<string name="dfu_short_name">DFU</string>
|
||||
<string name="smp_app_name">nRF Connect Device Manager</string>
|
||||
<string name="smp_short_name">SMP</string>
|
||||
<string name="mds_app_name">nRF Connect Device Manager</string>
|
||||
<string name="mds_short_name">MDS</string>
|
||||
<string name="legacy_dfu_app_name">Legacy DFU</string>
|
||||
<string name="legacy_dfu_short_name">Legacy DFU</string>
|
||||
<string name="buttonless_dfu_app_name">Buttonless DFU</string>
|
||||
<string name="buttonless_dfu_short_name">Buttonless DFU</string>
|
||||
</resources>
|
||||
@@ -20,6 +20,7 @@ import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalUriHandler
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
@@ -33,9 +34,17 @@ internal fun DFUScreen() {
|
||||
val dfuServiceState by dfuViewModel.dfuServiceState.collectAsStateWithLifecycle()
|
||||
val context = LocalContext.current
|
||||
val uriHandler = LocalUriHandler.current
|
||||
|
||||
dfuServiceState.dfuAppName?.let { dfuApp ->
|
||||
val intent = context.packageManager.getLaunchIntentForPackage(dfuApp.packageName)
|
||||
val description = intent?.let { "Open ${dfuApp.appName}" } ?: "Download from Play Store"
|
||||
val description =
|
||||
intent?.let {
|
||||
stringResource(
|
||||
R.string.dfu_description_open,
|
||||
stringResource(dfuApp.appName)
|
||||
)
|
||||
}
|
||||
?: stringResource(R.string.dfu_description_download)
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
@@ -52,20 +61,26 @@ internal fun DFUScreen() {
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
Icon(
|
||||
painter = painterResource(R.drawable.ic_dfu),
|
||||
painter = painterResource(dfuApp.appIcon),
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.size(56.dp)
|
||||
)
|
||||
|
||||
Text(
|
||||
text = "DFU is not supported",
|
||||
text = stringResource(
|
||||
R.string.dfu_not_supported_title,
|
||||
stringResource(dfuApp.appShortName)
|
||||
),
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
)
|
||||
|
||||
Text(
|
||||
text = "DFU service is not available in the current version of the app. " +
|
||||
"Please use the DFU app from Nordic Semiconductor to update your device’s firmware.",
|
||||
text = stringResource(
|
||||
R.string.dfu_not_supported_text,
|
||||
stringResource(dfuApp.appShortName),
|
||||
stringResource(dfuApp.appName)
|
||||
),
|
||||
textAlign = TextAlign.Center,
|
||||
style = MaterialTheme.typography.bodyMedium
|
||||
)
|
||||
@@ -80,13 +95,12 @@ internal fun DFUScreen() {
|
||||
) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
val icon = intent?.let { dfuApp.appIcon } ?: R.drawable.google_play_2022_icon
|
||||
val size = if (intent != null) 56.dp else 28.dp
|
||||
|
||||
Icon(
|
||||
painter = painterResource(icon),
|
||||
contentDescription = null,
|
||||
modifier = Modifier
|
||||
.size(size)
|
||||
.size(40.dp)
|
||||
.padding(end = 8.dp),
|
||||
tint = if (intent == null) Color.Unspecified else MaterialTheme.colorScheme.onPrimary
|
||||
)
|
||||
|
||||
8
profile/src/main/res/values/dfuStrings.xml
Normal file
8
profile/src/main/res/values/dfuStrings.xml
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="dfu_description_open">Open %s</string>
|
||||
<string name="dfu_description_download">Download from Play Store</string>
|
||||
<string name="dfu_not_supported_title">%s is not supported</string>
|
||||
<string name="dfu_not_supported_text">%1s service is not available in the current version of the app. Please use the %2s app from Nordic Semiconductor to update your device’s firmware.</string>
|
||||
|
||||
</resources>
|
||||
@@ -1,6 +1,7 @@
|
||||
package no.nordicsemi.android.toolbox.profile.data
|
||||
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.StringRes
|
||||
import no.nordicsemi.android.toolbox.lib.utils.Profile
|
||||
import no.nordicsemi.android.toolbox.lib.utils.R
|
||||
|
||||
@@ -20,37 +21,43 @@ data class DFUServiceData(
|
||||
enum class DFUsAvailable(
|
||||
val packageName: String,
|
||||
val appLink: String,
|
||||
val appName: String,
|
||||
@DrawableRes val appIcon: Int
|
||||
@param:StringRes val appName: Int,
|
||||
@param:DrawableRes val appIcon: Int,
|
||||
@param:StringRes val appShortName: Int,
|
||||
) {
|
||||
DFU_SERVICE(
|
||||
packageName = DFU_PACKAGE_NAME,
|
||||
appLink = DFU_APP_LINK,
|
||||
appName = "DFU",
|
||||
appIcon = R.drawable.ic_dfu
|
||||
appName = R.string.dfu_app_name,
|
||||
appIcon = R.drawable.ic_dfu,
|
||||
appShortName = R.string.dfu_short_name,
|
||||
),
|
||||
SMP_SERVICE(
|
||||
packageName = SMP_PACKAGE_NAME,
|
||||
appLink = SMP_APP_LINK,
|
||||
appName = "nRF Connect Device Manager",
|
||||
appIcon = R.drawable.ic_device_manager
|
||||
appName = R.string.smp_app_name,
|
||||
appIcon = R.drawable.ic_device_manager,
|
||||
appShortName = R.string.smp_short_name,
|
||||
),
|
||||
MDS_SERVICE(
|
||||
packageName = SMP_PACKAGE_NAME,
|
||||
appLink = SMP_APP_LINK,
|
||||
appName = "nRF Connect Device Manager",
|
||||
appIcon = R.drawable.ic_device_manager
|
||||
appName = R.string.mds_app_name,
|
||||
appIcon = R.drawable.ic_device_manager,
|
||||
appShortName = R.string.mds_app_name,
|
||||
),
|
||||
LEGACY_DFU_SERVICE(
|
||||
packageName = DFU_PACKAGE_NAME,
|
||||
appLink = DFU_APP_LINK,
|
||||
appName = "DFU",
|
||||
appIcon = R.drawable.ic_dfu
|
||||
appName = R.string.legacy_dfu_app_name,
|
||||
appIcon = R.drawable.ic_dfu,
|
||||
appShortName = R.string.legacy_dfu_short_name,
|
||||
),
|
||||
EXPERIMENTAL_BUTTONLESS_DFU_SERVICE(
|
||||
packageName = DFU_PACKAGE_NAME,
|
||||
appLink = DFU_APP_LINK,
|
||||
appName = "DFU",
|
||||
appIcon = R.drawable.ic_dfu
|
||||
appName = R.string.buttonless_dfu_app_name,
|
||||
appIcon = R.drawable.ic_dfu,
|
||||
appShortName = R.string.buttonless_dfu_short_name,
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user