Skip to content

Commit c7e9450

Browse files
Fixed possible crash when opening a URL
1 parent 9b024b7 commit c7e9450

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

app/src/main/java/at/techbee/jtx/ui/detail/DetailsCardUrl.kt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,27 @@ package at.techbee.jtx.ui.detail
1010

1111
import android.content.ActivityNotFoundException
1212
import android.util.Log
13+
import android.widget.Toast
1314
import androidx.compose.animation.Crossfade
1415
import androidx.compose.foundation.layout.Column
1516
import androidx.compose.foundation.layout.fillMaxWidth
1617
import androidx.compose.foundation.layout.padding
1718
import androidx.compose.material.icons.Icons
1819
import androidx.compose.material.icons.outlined.Clear
1920
import androidx.compose.material.icons.outlined.Link
20-
import androidx.compose.material3.*
21-
import androidx.compose.runtime.*
21+
import androidx.compose.material3.ElevatedCard
22+
import androidx.compose.material3.Icon
23+
import androidx.compose.material3.IconButton
24+
import androidx.compose.material3.MaterialTheme
25+
import androidx.compose.material3.OutlinedTextField
26+
import androidx.compose.material3.Text
27+
import androidx.compose.runtime.Composable
28+
import androidx.compose.runtime.getValue
29+
import androidx.compose.runtime.mutableStateOf
2230
import androidx.compose.runtime.saveable.rememberSaveable
31+
import androidx.compose.runtime.setValue
2332
import androidx.compose.ui.Modifier
33+
import androidx.compose.ui.platform.LocalContext
2434
import androidx.compose.ui.platform.LocalUriHandler
2535
import androidx.compose.ui.res.stringResource
2636
import androidx.compose.ui.tooling.preview.Preview
@@ -30,7 +40,6 @@ import at.techbee.jtx.ui.reusable.elements.HeadlineWithIcon
3040
import at.techbee.jtx.util.UiUtil
3141

3242

33-
@OptIn(ExperimentalMaterial3Api::class)
3443
@Composable
3544
fun DetailsCardUrl(
3645
initialUrl: String,
@@ -42,13 +51,18 @@ fun DetailsCardUrl(
4251
val headline = stringResource(id = R.string.url)
4352
var url by rememberSaveable { mutableStateOf(initialUrl) }
4453
val uriHandler = LocalUriHandler.current
54+
val context = LocalContext.current
4555

4656
ElevatedCard(modifier = modifier, onClick = {
4757
try {
4858
if (url.isNotBlank() && !isEditMode)
4959
uriHandler.openUri(url)
5060
} catch (e: ActivityNotFoundException) {
5161
Log.d("PropertyCardUrl", "Failed opening Uri $url\n$e")
62+
Toast.makeText(context, e.message?:"", Toast.LENGTH_LONG).show()
63+
} catch (e: IllegalArgumentException) {
64+
Log.d("PropertyCardUrl", "Failed opening Uri $url$e")
65+
Toast.makeText(context, e.message?:"", Toast.LENGTH_LONG).show()
5266
}
5367
}) {
5468
Column(

0 commit comments

Comments
 (0)