11package org.openedx.core.ui
22
3- import android.os.Build
4- import android.os.Build.VERSION.SDK_INT
53import androidx.compose.foundation.BorderStroke
64import androidx.compose.foundation.ExperimentalFoundationApi
75import androidx.compose.foundation.background
@@ -19,7 +17,6 @@ import androidx.compose.foundation.layout.Spacer
1917import androidx.compose.foundation.layout.fillMaxSize
2018import androidx.compose.foundation.layout.fillMaxWidth
2119import androidx.compose.foundation.layout.height
22- import androidx.compose.foundation.layout.heightIn
2320import androidx.compose.foundation.layout.padding
2421import androidx.compose.foundation.layout.size
2522import androidx.compose.foundation.layout.width
@@ -81,7 +78,6 @@ import androidx.compose.ui.graphics.painter.Painter
8178import androidx.compose.ui.graphics.vector.ImageVector
8279import androidx.compose.ui.graphics.vector.rememberVectorPainter
8380import androidx.compose.ui.input.pointer.pointerInput
84- import androidx.compose.ui.layout.ContentScale
8581import androidx.compose.ui.platform.LocalContext
8682import androidx.compose.ui.platform.LocalFocusManager
8783import androidx.compose.ui.platform.LocalSoftwareKeyboardController
@@ -106,15 +102,10 @@ import androidx.compose.ui.unit.Dp
106102import androidx.compose.ui.unit.TextUnit
107103import androidx.compose.ui.unit.dp
108104import androidx.compose.ui.zIndex
109- import coil.ImageLoader
110- import coil.compose.AsyncImage
111- import coil.decode.GifDecoder
112- import coil.decode.ImageDecoderDecoder
113105import kotlinx.coroutines.launch
114106import org.openedx.core.NoContentScreenType
115107import org.openedx.core.R
116108import org.openedx.core.domain.model.RegistrationField
117- import org.openedx.core.extension.LinkedImageText
118109import org.openedx.core.presentation.global.ErrorType
119110import org.openedx.core.ui.theme.OpenEdXTheme
120111import org.openedx.core.ui.theme.appColors
@@ -542,131 +533,6 @@ fun HyperlinkText(
542533 )
543534}
544535
545- @Composable
546- fun HyperlinkImageText (
547- modifier : Modifier = Modifier ,
548- title : String = "",
549- imageText : LinkedImageText ,
550- textStyle : TextStyle = TextStyle .Default ,
551- linkTextColor : Color = MaterialTheme .appColors.primary,
552- linkTextFontWeight : FontWeight = FontWeight .Normal ,
553- linkTextDecoration : TextDecoration = TextDecoration .None ,
554- fontSize : TextUnit = TextUnit .Unspecified ,
555- ) {
556- val fullText = imageText.text
557- val hyperLinks = imageText.links
558- val annotatedString = buildAnnotatedString {
559- if (title.isNotEmpty()) {
560- append(title)
561- append(" \n\n " )
562- }
563- append(fullText)
564- addStyle(
565- style = SpanStyle (
566- color = MaterialTheme .appColors.textPrimary,
567- fontSize = fontSize
568- ),
569- start = 0 ,
570- end = this .length
571- )
572-
573- for ((key, value) in hyperLinks) {
574- val startIndex = this .toString().indexOf(key)
575- if (startIndex == - 1 ) continue
576- val endIndex = startIndex + key.length
577- addStyle(
578- style = SpanStyle (
579- color = linkTextColor,
580- fontSize = fontSize,
581- fontWeight = linkTextFontWeight,
582- textDecoration = linkTextDecoration
583- ),
584- start = startIndex,
585- end = endIndex
586- )
587- addStringAnnotation(
588- tag = " URL" ,
589- annotation = value,
590- start = startIndex,
591- end = endIndex
592- )
593- }
594- if (title.isNotEmpty()) {
595- addStyle(
596- style = SpanStyle (
597- color = MaterialTheme .appColors.textPrimary,
598- fontSize = MaterialTheme .appTypography.titleLarge.fontSize,
599- fontWeight = MaterialTheme .appTypography.titleLarge.fontWeight
600- ),
601- start = 0 ,
602- end = title.length
603- )
604- }
605- for (item in imageText.headers) {
606- val startIndex = this .toString().indexOf(item)
607- if (startIndex == - 1 ) continue
608- val endIndex = startIndex + item.length
609- addStyle(
610- style = SpanStyle (
611- color = MaterialTheme .appColors.textPrimary,
612- fontSize = MaterialTheme .appTypography.titleLarge.fontSize,
613- fontWeight = MaterialTheme .appTypography.titleLarge.fontWeight
614- ),
615- start = startIndex,
616- end = endIndex
617- )
618- }
619- addStyle(
620- style = SpanStyle (
621- fontSize = fontSize
622- ),
623- start = 0 ,
624- end = this .length
625- )
626- }
627-
628- val uriHandler = LocalUriHandler .current
629- val context = LocalContext .current
630- val imageLoader = ImageLoader .Builder (context)
631- .components {
632- if (SDK_INT >= Build .VERSION_CODES .P ) {
633- add(ImageDecoderDecoder .Factory ())
634- } else {
635- add(GifDecoder .Factory ())
636- }
637- }
638- .build()
639-
640- Column (Modifier .fillMaxWidth()) {
641- BasicText (
642- text = annotatedString,
643- modifier = modifier.pointerInput(Unit ) {
644- detectTapGestures { offset ->
645- val position = offset.x.toInt()
646- annotatedString.getStringAnnotations(" URL" , position, position)
647- .firstOrNull()?.let { stringAnnotation ->
648- uriHandler.openUri(stringAnnotation.item)
649- }
650- }
651- },
652- style = textStyle
653- )
654- imageText.imageLinks.values.forEach {
655- Spacer (Modifier .height(8 .dp))
656- AsyncImage (
657- modifier = Modifier
658- .fillMaxWidth()
659- .heightIn(0 .dp, 360 .dp),
660- contentScale = ContentScale .Fit ,
661- model = it,
662- contentDescription = null ,
663- imageLoader = imageLoader
664- )
665- }
666- Spacer (Modifier .height(16 .dp))
667- }
668- }
669-
670536@Composable
671537fun SheetContent (
672538 searchValue : TextFieldValue ,
0 commit comments