Skip to content

Commit

Permalink
feat: make the source url of images clickable
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnyro committed Nov 20, 2023
1 parent c506568 commit ff057e1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.ui.res.stringResource
import com.bnyro.wallpaper.R
import com.bnyro.wallpaper.db.obj.Wallpaper
import com.bnyro.wallpaper.ext.formatBinarySize
import com.bnyro.wallpaper.ui.components.dialogs.InfoDialog

@Composable
fun ImageInfoDialog(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,70 @@
package com.bnyro.wallpaper.ui.components
package com.bnyro.wallpaper.ui.components.dialogs

import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.bnyro.wallpaper.ui.components.DialogButton
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull

@Composable
fun InfoDialog(
title: String,
items: Map<String, String?>,
onDismissRequest: () -> Unit
) {
val localUriHandler = LocalUriHandler.current

AlertDialog(
title = {
Text(title)
},
text = {
Column {
items.forEach {
if (it.value != null) {
items.filter { it.value != null }.forEach {
Text(
text = it.key,
fontSize = 12.sp
)
val isUrl = remember { it.value?.toHttpUrlOrNull() != null }
if (isUrl) {
val interactionSource = remember {
MutableInteractionSource()
}
Text(
text = it.key,
fontSize = 12.sp
modifier = Modifier.clickable(interactionSource, indication = null) {
localUriHandler.openUri(it.value!!)
},
text = it.value!!,
style = TextStyle(
color = MaterialTheme.colorScheme.primary,
fontSize = 18.sp,
textDecoration = TextDecoration.Underline
)
)
} else {
Text(
text = it.value!!,
fontSize = 18.sp
)
Spacer(
modifier = Modifier
.height(8.dp)
)
}
Spacer(
modifier = Modifier
.height(8.dp)
)
}
}
},
Expand Down

0 comments on commit ff057e1

Please sign in to comment.