Skip to content

Commit

Permalink
Handle two recent Compose deprecations (#4879)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpelgrom authored Dec 6, 2024
1 parent 65bf378 commit c176601
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.ClickableText
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.LinkAnnotation
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.TextLinkStyles
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.text.withLink
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
Expand Down Expand Up @@ -57,25 +57,22 @@ fun WelcomeView(
modifier = Modifier.fillMaxWidth().padding(vertical = 16.dp)
)
val annotatedString = buildAnnotatedString {
pushStringAnnotation("learn", "https://www.home-assistant.io")
withStyle(
style = SpanStyle(
color = MaterialTheme.colors.primary,
textDecoration = TextDecoration.Underline
withLink(
LinkAnnotation.Url(
url = "https://www.home-assistant.io",
styles = TextLinkStyles(
SpanStyle(
color = MaterialTheme.colors.primary,
textDecoration = TextDecoration.Underline
)
)
)
) {
append(stringResource(id = commonR.string.learn_more))
}
pop()
}
val uriHandler = LocalUriHandler.current
ClickableText(
Text(
text = annotatedString,
onClick = {
annotatedString.getStringAnnotations("learn", it, it).firstOrNull()?.let { link ->
uriHandler.openUri(link.item)
}
},
modifier = Modifier.padding(bottom = 16.dp)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ fun ManageControlsView(
value = panelPath,
onValueChange = { panelPath = it },
label = { Text(stringResource(id = R.string.lovelace_view_dashboard)) },
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done, autoCorrect = false, keyboardType = KeyboardType.Uri),
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done, autoCorrectEnabled = false, keyboardType = KeyboardType.Uri),
modifier = Modifier
.fillMaxWidth()
.padding(all = 16.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private fun CreateShortcutView(
value = viewModel.shortcuts[i].path.value,
onValueChange = { viewModel.shortcuts[i].path.value = it },
label = { Text(stringResource(id = R.string.lovelace_view_dashboard)) },
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done, autoCorrect = false, keyboardType = KeyboardType.Uri),
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done, autoCorrectEnabled = false, keyboardType = KeyboardType.Uri),
modifier = Modifier.fillMaxWidth().padding(bottom = 16.dp)
)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fun ExternalUrlInputView(
urlInput = it
urlError = false
},
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done, autoCorrect = false, keyboardType = KeyboardType.Uri),
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done, autoCorrectEnabled = false, keyboardType = KeyboardType.Uri),
keyboardActions = KeyboardActions(
onDone = {
urlError = !performUrlUpdate(urlInput?.trim(), url, onSaveUrl)
Expand Down

0 comments on commit c176601

Please sign in to comment.