11package org.openedx.core.ui
22
3- import android.os.Build
4- import android.os.Build.VERSION.SDK_INT
5- import android.webkit.WebView
63import androidx.compose.foundation.BorderStroke
74import androidx.compose.foundation.ExperimentalFoundationApi
85import androidx.compose.foundation.background
@@ -20,7 +17,6 @@ import androidx.compose.foundation.layout.Spacer
2017import androidx.compose.foundation.layout.fillMaxSize
2118import androidx.compose.foundation.layout.fillMaxWidth
2219import androidx.compose.foundation.layout.height
23- import androidx.compose.foundation.layout.heightIn
2420import androidx.compose.foundation.layout.padding
2521import androidx.compose.foundation.layout.size
2622import androidx.compose.foundation.layout.width
@@ -82,7 +78,6 @@ import androidx.compose.ui.graphics.painter.Painter
8278import androidx.compose.ui.graphics.vector.ImageVector
8379import androidx.compose.ui.graphics.vector.rememberVectorPainter
8480import androidx.compose.ui.input.pointer.pointerInput
85- import androidx.compose.ui.layout.ContentScale
8681import androidx.compose.ui.platform.LocalContext
8782import androidx.compose.ui.platform.LocalFocusManager
8883import androidx.compose.ui.platform.LocalSoftwareKeyboardController
@@ -106,17 +101,11 @@ import androidx.compose.ui.tooling.preview.Preview
106101import androidx.compose.ui.unit.Dp
107102import androidx.compose.ui.unit.TextUnit
108103import androidx.compose.ui.unit.dp
109- import androidx.compose.ui.viewinterop.AndroidView
110104import androidx.compose.ui.zIndex
111- import coil.ImageLoader
112- import coil.compose.AsyncImage
113- import coil.decode.GifDecoder
114- import coil.decode.ImageDecoderDecoder
115105import kotlinx.coroutines.launch
116106import org.openedx.core.NoContentScreenType
117107import org.openedx.core.R
118108import org.openedx.core.domain.model.RegistrationField
119- import org.openedx.core.extension.LinkedImageText
120109import org.openedx.core.presentation.global.ErrorType
121110import org.openedx.core.ui.theme.OpenEdXTheme
122111import org.openedx.core.ui.theme.appColors
@@ -510,131 +499,6 @@ fun HyperlinkText(
510499 )
511500}
512501
513- @Composable
514- fun HyperlinkImageText (
515- modifier : Modifier = Modifier ,
516- title : String = "",
517- imageText : LinkedImageText ,
518- textStyle : TextStyle = TextStyle .Default ,
519- linkTextColor : Color = MaterialTheme .appColors.primary,
520- linkTextFontWeight : FontWeight = FontWeight .Normal ,
521- linkTextDecoration : TextDecoration = TextDecoration .None ,
522- fontSize : TextUnit = TextUnit .Unspecified ,
523- ) {
524- val fullText = imageText.text
525- val hyperLinks = imageText.links
526- val annotatedString = buildAnnotatedString {
527- if (title.isNotEmpty()) {
528- append(title)
529- append(" \n\n " )
530- }
531- append(fullText)
532- addStyle(
533- style = SpanStyle (
534- color = MaterialTheme .appColors.textPrimary,
535- fontSize = fontSize
536- ),
537- start = 0 ,
538- end = this .length
539- )
540-
541- for ((key, value) in hyperLinks) {
542- val startIndex = this .toString().indexOf(key)
543- if (startIndex == - 1 ) continue
544- val endIndex = startIndex + key.length
545- addStyle(
546- style = SpanStyle (
547- color = linkTextColor,
548- fontSize = fontSize,
549- fontWeight = linkTextFontWeight,
550- textDecoration = linkTextDecoration
551- ),
552- start = startIndex,
553- end = endIndex
554- )
555- addStringAnnotation(
556- tag = " URL" ,
557- annotation = value,
558- start = startIndex,
559- end = endIndex
560- )
561- }
562- if (title.isNotEmpty()) {
563- addStyle(
564- style = SpanStyle (
565- color = MaterialTheme .appColors.textPrimary,
566- fontSize = MaterialTheme .appTypography.titleLarge.fontSize,
567- fontWeight = MaterialTheme .appTypography.titleLarge.fontWeight
568- ),
569- start = 0 ,
570- end = title.length
571- )
572- }
573- for (item in imageText.headers) {
574- val startIndex = this .toString().indexOf(item)
575- if (startIndex == - 1 ) continue
576- val endIndex = startIndex + item.length
577- addStyle(
578- style = SpanStyle (
579- color = MaterialTheme .appColors.textPrimary,
580- fontSize = MaterialTheme .appTypography.titleLarge.fontSize,
581- fontWeight = MaterialTheme .appTypography.titleLarge.fontWeight
582- ),
583- start = startIndex,
584- end = endIndex
585- )
586- }
587- addStyle(
588- style = SpanStyle (
589- fontSize = fontSize
590- ),
591- start = 0 ,
592- end = this .length
593- )
594- }
595-
596- val uriHandler = LocalUriHandler .current
597- val context = LocalContext .current
598- val imageLoader = ImageLoader .Builder (context)
599- .components {
600- if (SDK_INT >= Build .VERSION_CODES .P ) {
601- add(ImageDecoderDecoder .Factory ())
602- } else {
603- add(GifDecoder .Factory ())
604- }
605- }
606- .build()
607-
608- Column (Modifier .fillMaxWidth()) {
609- BasicText (
610- text = annotatedString,
611- modifier = modifier.pointerInput(Unit ) {
612- detectTapGestures { offset ->
613- val position = offset.x.toInt()
614- annotatedString.getStringAnnotations(" URL" , position, position)
615- .firstOrNull()?.let { stringAnnotation ->
616- uriHandler.openUri(stringAnnotation.item)
617- }
618- }
619- },
620- style = textStyle
621- )
622- imageText.imageLinks.values.forEach {
623- Spacer (Modifier .height(8 .dp))
624- AsyncImage (
625- modifier = Modifier
626- .fillMaxWidth()
627- .heightIn(0 .dp, 360 .dp),
628- contentScale = ContentScale .Fit ,
629- model = it,
630- contentDescription = null ,
631- imageLoader = imageLoader
632- )
633- }
634- Spacer (Modifier .height(16 .dp))
635- }
636- }
637-
638502@Composable
639503fun SheetContent (
640504 searchValue : TextFieldValue ,
@@ -1406,20 +1270,6 @@ private fun RoundTab(
14061270 }
14071271}
14081272
1409- @Composable
1410- fun HtmlTextView (htmlContent : String , modifier : Modifier = Modifier ) {
1411- AndroidView (
1412- modifier = modifier,
1413- factory = { context ->
1414- WebView (context).apply {
1415- settings.javaScriptEnabled = false
1416- settings.loadsImagesAutomatically = true
1417- loadDataWithBaseURL(null , htmlContent, " text/html" , " UTF-8" , null )
1418- }
1419- },
1420- )
1421- }
1422-
14231273@Preview
14241274@Composable
14251275private fun StaticSearchBarPreview () {
0 commit comments