Skip to content

Commit

Permalink
Create openInBrowser extension
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcoding810 committed Dec 27, 2024
1 parent 478cc89 commit 7c5f0b1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
10 changes: 10 additions & 0 deletions app/src/main/java/com/paulcoding/hviewer/extensions/Activity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.paulcoding.hviewer.extensions

import android.app.Activity
import android.content.Intent
import android.net.Uri

fun Activity.openInBrowser(url: String) {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
startActivity(intent)
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.paulcoding.hviewer.ui.page.post

import android.annotation.SuppressLint
import android.content.Intent
import android.net.Uri
import android.widget.Toast
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.gestures.detectTapGestures
Expand Down Expand Up @@ -40,6 +38,7 @@ import com.paulcoding.hviewer.MainActivity
import com.paulcoding.hviewer.MainApp.Companion.appContext
import com.paulcoding.hviewer.extensions.isScrolledToEnd
import com.paulcoding.hviewer.extensions.isScrollingUp
import com.paulcoding.hviewer.extensions.openInBrowser
import com.paulcoding.hviewer.helper.makeToast
import com.paulcoding.hviewer.ui.component.HBackIcon
import com.paulcoding.hviewer.ui.component.HGoTop
Expand Down Expand Up @@ -120,8 +119,7 @@ fun PostPage(appViewModel: AppViewModel, navToWebView: (String) -> Unit, goBack:
DropdownMenuItem(
onClick = {
showMenu.value = false
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(image))
context.startActivity(intent)
context.openInBrowser(image)
},
text = {
Text("Open in browser")
Expand Down
23 changes: 17 additions & 6 deletions app/src/main/java/com/paulcoding/hviewer/ui/page/posts/PostCard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.paulcoding.hviewer.MainActivity
import com.paulcoding.hviewer.extensions.openInBrowser
import com.paulcoding.hviewer.model.PostItem
import com.paulcoding.hviewer.model.Tag
import com.paulcoding.hviewer.ui.component.HFavoriteIcon
Expand Down Expand Up @@ -69,6 +72,7 @@ fun PostCard(
) {
var isBottomSheetVisible by remember { mutableStateOf(false) }
val bottomSheetState = rememberModalBottomSheetState()
val context = LocalContext.current as MainActivity

LaunchedEffect(isBottomSheetVisible) {
if (isBottomSheetVisible) {
Expand Down Expand Up @@ -123,12 +127,19 @@ fun PostCard(
SelectionContainer {
Text(text = name, fontSize = 20.sp)
}
Text(
text = url,
textDecoration = TextDecoration.Underline,
fontSize = 12.sp,
color = Color.Blue
)
TextButton(
onClick = {
isBottomSheetVisible = false
context.openInBrowser(url)
},
) {
Text(
text = url,
textDecoration = TextDecoration.Underline,
fontSize = 12.sp,
color = Color.Blue
)
}
if (size != null) {
Text(text = "Size: $size")
}
Expand Down

0 comments on commit 7c5f0b1

Please sign in to comment.