diff --git a/utility/src/main/java/org/oppia/android/util/parser/html/HtmlParser.kt b/utility/src/main/java/org/oppia/android/util/parser/html/HtmlParser.kt index ca7b8c0b661..cb37742ff19 100755 --- a/utility/src/main/java/org/oppia/android/util/parser/html/HtmlParser.kt +++ b/utility/src/main/java/org/oppia/android/util/parser/html/HtmlParser.kt @@ -75,16 +75,26 @@ class HtmlParser private constructor( supportsLinks: Boolean = false, supportsConceptCards: Boolean = false ): Spannable { + + var htmlContent = rawString + // Canvas does not support RTL, it always starts from left to right in RTL due to which compound drawables are // not center aligned. To avoid this situation check if RTL is enabled and set the textDirection. if (isRtl) { htmlContentTextView.textDirection = View.TEXT_DIRECTION_RTL + + val regex = Regex("""]*>.*?""") + val modifiedHtmlContent = rawString.replace(regex) { + val oppiaImageTag = it.value + """
$oppiaImageTag
""" + } + htmlContent = modifiedHtmlContent } else { htmlContentTextView.textDirection = View.TEXT_DIRECTION_LTR } + htmlContentTextView.invalidate() - var htmlContent = rawString if ("\n\t" in htmlContent) { htmlContent = htmlContent.replace("\n\t", "") } diff --git a/utility/src/main/java/org/oppia/android/util/parser/image/UrlImageParser.kt b/utility/src/main/java/org/oppia/android/util/parser/image/UrlImageParser.kt index b8dd69868a8..b18934a1897 100644 --- a/utility/src/main/java/org/oppia/android/util/parser/image/UrlImageParser.kt +++ b/utility/src/main/java/org/oppia/android/util/parser/image/UrlImageParser.kt @@ -15,6 +15,7 @@ import android.view.View import android.view.ViewGroup import android.view.ViewTreeObserver import android.widget.TextView +import androidx.core.view.ViewCompat import com.bumptech.glide.request.target.CustomTarget import com.bumptech.glide.request.transition.Transition import org.oppia.android.util.R @@ -234,6 +235,11 @@ class UrlImageParser private constructor( private val autoResizeImage: Boolean ) : AutoAdjustingImageTarget(targetConfiguration) { + private fun isRTLMode(): Boolean { + return ViewCompat.getLayoutDirection(htmlContentTextView) == ViewCompat + .LAYOUT_DIRECTION_RTL + } + override fun computeBounds( context: Context, drawable: D, @@ -304,11 +310,13 @@ class UrlImageParser private constructor( drawableWidth *= multipleFactor } } - val drawableLeft = if (imageCenterAlign) { + + val drawableLeft = if (imageCenterAlign && !isRTLMode()) { calculateInitialMargin(maxAvailableWidth, drawableWidth) } else { 0f } + val drawableTop = 0f val drawableRight = drawableLeft + drawableWidth val drawableBottom = drawableTop + drawableHeight