Skip to content

Commit

Permalink
androidApp: SessionScreen: Open URLs using custom tabs too
Browse files Browse the repository at this point in the history
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
  • Loading branch information
theimpulson committed Oct 11, 2024
1 parent a567b2b commit 13e3fe1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.platform.UriHandler
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
Expand All @@ -37,6 +40,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavHostController
import app.opass.ccip.android.R
import app.opass.ccip.android.ui.components.TopAppBar
import app.opass.ccip.android.ui.extensions.browse
import app.opass.ccip.android.ui.navigation.Screen
import app.opass.ccip.network.models.schedule.Session
import com.mikepenz.markdown.m3.Markdown
Expand Down Expand Up @@ -141,12 +145,21 @@ private fun SessionDescItem(description: String) {
containerColor = MaterialTheme.colorScheme.surfaceContainer
)
) {
Markdown(
modifier = Modifier
.fillMaxWidth()
.padding(10.dp),
content = description
)
val context = LocalContext.current
val uriHandler = object : UriHandler {
override fun openUri(uri: String) {
context.browse(uri)
}

}
CompositionLocalProvider(LocalUriHandler provides uriHandler) {
Markdown(
modifier = Modifier
.fillMaxWidth()
.padding(10.dp),
content = description
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package app.opass.ccip.android.utils

import android.graphics.Rect
import android.net.Uri
import android.os.Parcel
import android.text.Spannable
import android.text.Spanned
Expand All @@ -16,7 +15,7 @@ import android.text.util.Linkify
import android.util.Log
import android.view.View
import android.widget.TextView
import androidx.browser.customtabs.CustomTabsIntent
import app.opass.ccip.android.ui.extensions.browse

open class LinkTransformationMethod : TransformationMethod {

Expand All @@ -28,9 +27,7 @@ open class LinkTransformationMethod : TransformationMethod {

override fun onClick(widget: View) {
try {
CustomTabsIntent.Builder()
.build()
.launchUrl(widget.context, Uri.parse(url))
widget.context.browse(url)
} catch (exception: Exception) {
Log.e(TAG, "Failed to open link in custom tab!", exception)
super.onClick(widget)
Expand Down

0 comments on commit 13e3fe1

Please sign in to comment.