From 5c2f3d3682a9efb41b50fa6e9d8e95f7cc41337b Mon Sep 17 00:00:00 2001 From: Vishwajith-Shettigar Date: Sat, 23 Dec 2023 11:38:59 +0530 Subject: [PATCH 1/9] made concep card image block --- .../java/org/oppia/android/util/parser/html/HtmlParser.kt | 6 ++++++ .../org/oppia/android/util/parser/image/UrlImageParser.kt | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) 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 97db2dce9db..bdf3494bc86 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 @@ -94,6 +94,12 @@ class HtmlParser private constructor( htmlContent = modifiedHtmlContent } else { htmlContentTextView.textDirection = View.TEXT_DIRECTION_LTR + val regex = Regex("""]*>.*?""") + val modifiedHtmlContent = rawString.replace(regex) { + val oppiaImageTag = it.value + """
$oppiaImageTag
""" + } + htmlContent = modifiedHtmlContent } htmlContentTextView.invalidate() 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 137652bd013..f42f344d2b1 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 @@ -317,7 +317,7 @@ class UrlImageParser private constructor( } val drawableLeft = if (imageCenterAlign && !isRTLMode()) { - calculateInitialMargin(maxAvailableWidth, drawableWidth) + calculateInitialMargin(maxAvailableWidth - maxContentItemPadding, drawableWidth) } else { 0f } From 0f53710928aa41a40d29d037cfb253a2560c62b0 Mon Sep 17 00:00:00 2001 From: Vishwajith-Shettigar Date: Sat, 23 Dec 2023 12:28:30 +0530 Subject: [PATCH 2/9] test fixed --- .../java/org/oppia/android/app/parser/HtmlParserTest.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/sharedTest/java/org/oppia/android/app/parser/HtmlParserTest.kt b/app/src/sharedTest/java/org/oppia/android/app/parser/HtmlParserTest.kt index b0e82b25dcd..020b930b6a9 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/parser/HtmlParserTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/parser/HtmlParserTest.kt @@ -8,6 +8,7 @@ import android.content.Intent import android.text.Spannable import android.text.style.ClickableSpan import android.text.style.ImageSpan +import android.util.Log import android.view.View import android.widget.TextView import androidx.annotation.DimenRes @@ -508,9 +509,10 @@ class HtmlParserTest { val imageSpans = htmlResult.getSpansFromWholeString(ImageSpan::class) assertThat(imageSpans).hasLength(1) assertThat(imageSpans.first().source).isEqualTo("test.png") + // Verify that the image span does not start/end with a space since there is other text present. assertThat(htmlResult.toString()).startsWith("A") - assertThat(htmlResult.toString()).doesNotContain(" ") + assertThat(htmlResult.toString()[htmlResult.length-1].toString()).doesNotContain(" ") } @Test From 8a562f1e8483fbaefcfe79791282d8b3fb0212a4 Mon Sep 17 00:00:00 2001 From: Vishwajith-Shettigar Date: Sat, 23 Dec 2023 12:29:39 +0530 Subject: [PATCH 3/9] test fixed --- .../java/org/oppia/android/app/parser/HtmlParserTest.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/sharedTest/java/org/oppia/android/app/parser/HtmlParserTest.kt b/app/src/sharedTest/java/org/oppia/android/app/parser/HtmlParserTest.kt index 020b930b6a9..d2a037ce170 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/parser/HtmlParserTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/parser/HtmlParserTest.kt @@ -8,7 +8,6 @@ import android.content.Intent import android.text.Spannable import android.text.style.ClickableSpan import android.text.style.ImageSpan -import android.util.Log import android.view.View import android.widget.TextView import androidx.annotation.DimenRes @@ -512,7 +511,7 @@ class HtmlParserTest { // Verify that the image span does not start/end with a space since there is other text present. assertThat(htmlResult.toString()).startsWith("A") - assertThat(htmlResult.toString()[htmlResult.length-1].toString()).doesNotContain(" ") + assertThat(htmlResult.toString()[htmlResult.length - 1].toString()).doesNotContain(" ") } @Test From 6e46146c6500baaf3c6e5a95ca0876fde6efffe7 Mon Sep 17 00:00:00 2001 From: Vishwajith-Shettigar Date: Mon, 29 Jan 2024 20:04:43 +0530 Subject: [PATCH 4/9] addressed comments --- .../main/java/org/oppia/android/util/parser/html/HtmlParser.kt | 2 ++ 1 file changed, 2 insertions(+) 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 a6178d5af81..97e2398287e 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 @@ -93,6 +93,8 @@ class HtmlParser private constructor( htmlContent = modifiedHtmlContent } else { htmlContentTextView.textDirection = View.TEXT_DIRECTION_LTR + + // Images are wrapped inside `
` tag so that all images display in block mode. val regex = Regex("""]*>.*?""") val modifiedHtmlContent = rawString.replace(regex) { val oppiaImageTag = it.value From d71bf6d649cab702cfd6f3301a90f18f998c3287 Mon Sep 17 00:00:00 2001 From: Vishwajith-Shettigar Date: Mon, 29 Jan 2024 20:08:15 +0530 Subject: [PATCH 5/9] addressed comments --- .../java/org/oppia/android/util/parser/html/HtmlParser.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 97e2398287e..b484bd3d2b6 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 @@ -80,12 +80,13 @@ class HtmlParser private constructor( ): Spannable { var htmlContent = rawString + var regex: Regex? = null // 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("""]*>.*?""") + regex = Regex("""]*>.*?""") val modifiedHtmlContent = rawString.replace(regex) { val oppiaImageTag = it.value """
$oppiaImageTag
""" @@ -95,7 +96,7 @@ class HtmlParser private constructor( htmlContentTextView.textDirection = View.TEXT_DIRECTION_LTR // Images are wrapped inside `
` tag so that all images display in block mode. - val regex = Regex("""]*>.*?""") + regex = Regex("""]*>.*?""") val modifiedHtmlContent = rawString.replace(regex) { val oppiaImageTag = it.value """
$oppiaImageTag
""" From aada9ebad0f7de454f846391ba6bca53452fb3a0 Mon Sep 17 00:00:00 2001 From: Vishwajith-Shettigar Date: Tue, 30 Jan 2024 19:45:22 +0530 Subject: [PATCH 6/9] addressed comments --- .../java/org/oppia/android/util/parser/html/HtmlParser.kt | 7 +++---- wiki/Platform-Parameters-&-Feature-Flags.md | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) 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 b484bd3d2b6..0dddcacb0ac 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 @@ -79,14 +79,13 @@ class HtmlParser private constructor( supportsConceptCards: Boolean = false ): Spannable { var htmlContent = rawString + val regex = Regex("""]*>.*?""") - var regex: Regex? = null // 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 - regex = Regex("""]*>.*?""") val modifiedHtmlContent = rawString.replace(regex) { val oppiaImageTag = it.value """
$oppiaImageTag
""" @@ -95,8 +94,8 @@ class HtmlParser private constructor( } else { htmlContentTextView.textDirection = View.TEXT_DIRECTION_LTR - // Images are wrapped inside `
` tag so that all images display in block mode. - regex = Regex("""]*>.*?""") + // Images are wrapped inside a
tag, because the
tag is a block-level element, + // so that all images display in block mode and on a new line." val modifiedHtmlContent = rawString.replace(regex) { val oppiaImageTag = it.value """
$oppiaImageTag
""" diff --git a/wiki/Platform-Parameters-&-Feature-Flags.md b/wiki/Platform-Parameters-&-Feature-Flags.md index 2a2b66db027..e192c76bf57 100644 --- a/wiki/Platform-Parameters-&-Feature-Flags.md +++ b/wiki/Platform-Parameters-&-Feature-Flags.md @@ -72,7 +72,7 @@ In order to release these types of features in a smooth manner, we need to be ab ) ?: PlatformParameterValue.createDefaultParameter( SYNC_UP_WORKER_TIME_PERIOD_IN_HOURS_DEFAULT_VALUE ) - } + } } ``` From 2d4a51ca827e9cf71bb802a7bfb958801b6fb1bf Mon Sep 17 00:00:00 2001 From: Vishwajith-Shettigar Date: Tue, 30 Jan 2024 19:46:37 +0530 Subject: [PATCH 7/9] addressed comments --- wiki/Platform-Parameters-&-Feature-Flags.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wiki/Platform-Parameters-&-Feature-Flags.md b/wiki/Platform-Parameters-&-Feature-Flags.md index e192c76bf57..2a2b66db027 100644 --- a/wiki/Platform-Parameters-&-Feature-Flags.md +++ b/wiki/Platform-Parameters-&-Feature-Flags.md @@ -72,7 +72,7 @@ In order to release these types of features in a smooth manner, we need to be ab ) ?: PlatformParameterValue.createDefaultParameter( SYNC_UP_WORKER_TIME_PERIOD_IN_HOURS_DEFAULT_VALUE ) - } + } } ``` From fc1ac3583a547013744ce99caab5fa46b52ed3ff Mon Sep 17 00:00:00 2001 From: Vishwajith-Shettigar Date: Thu, 1 Feb 2024 09:45:11 +0530 Subject: [PATCH 8/9] test modified --- .../java/org/oppia/android/app/parser/HtmlParserTest.kt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/src/sharedTest/java/org/oppia/android/app/parser/HtmlParserTest.kt b/app/src/sharedTest/java/org/oppia/android/app/parser/HtmlParserTest.kt index 78801e1f530..d28b4c40e62 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/parser/HtmlParserTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/parser/HtmlParserTest.kt @@ -488,7 +488,7 @@ class HtmlParserTest { } @Test - fun testHtmlContent_imageWithText_noAdditionalSpacesAdded() { + fun testHtmlContent_imageWithText_imageSpanParsedCorrectly() { val htmlParser = htmlParserFactory.create( resourceBucketName, entityType = "", @@ -509,10 +509,6 @@ class HtmlParserTest { val imageSpans = htmlResult.getSpansFromWholeString(ImageSpan::class) assertThat(imageSpans).hasLength(1) assertThat(imageSpans.first().source).isEqualTo("test.png") - - // Verify that the image span does not start/end with a space since there is other text present. - assertThat(htmlResult.toString()).startsWith("A") - assertThat(htmlResult.toString()[htmlResult.length - 1].toString()).doesNotContain(" ") } @Test From c89df02dc57200f33b0b8785668d74e1bb24b89a Mon Sep 17 00:00:00 2001 From: Vishwajith-Shettigar Date: Fri, 2 Feb 2024 09:53:59 +0530 Subject: [PATCH 9/9] recalculate drawableLft and right --- .../android/util/parser/image/UrlImageParser.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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 f42f344d2b1..b3428dde9e4 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 @@ -316,14 +316,21 @@ class UrlImageParser private constructor( drawableWidth -= maxContentItemPadding } - val drawableLeft = if (imageCenterAlign && !isRTLMode()) { - calculateInitialMargin(maxAvailableWidth - maxContentItemPadding, drawableWidth) + var drawableLeft = if (imageCenterAlign && !isRTLMode()) { + calculateInitialMargin(maxAvailableWidth, drawableWidth) } else { 0f } val drawableTop = 0f - val drawableRight = drawableLeft + drawableWidth + var drawableRight = drawableLeft + drawableWidth + + // If the image is getting cut off, recalculate the positions of the drawableLeft and drawableRight. + if (drawableRight + maxContentItemPadding > maxAvailableWidth) { + drawableLeft -= maxContentItemPadding + drawableRight -= maxContentItemPadding + } + val drawableBottom = drawableTop + drawableHeight return Rect( drawableLeft.toInt(), drawableTop.toInt(), drawableRight.toInt(), drawableBottom.toInt()