Skip to content

Commit

Permalink
Fix #4206 Create New HtmlParser Factory Method (#5277)
Browse files Browse the repository at this point in the history
<!-- READ ME FIRST: Please fill in the explanation section below and
check off every point from the Essential Checklist! -->
## Explanation

Fix #4206 Create New HtmlParser Factory Method to only take
customOppiaTagActionListener and displayLocale as parameter and replace
factory method usage in MathExpressionParserViewModel with this new
implementation
<!--
- Explain what your PR does. If this PR fixes an existing bug, please
include
- "Fixes #bugnum:" in the explanation so that GitHub can auto-close the
issue
  - when this PR is merged.
  -->

## Essential Checklist
<!-- Please tick the relevant boxes by putting an "x" in them. -->
- [x] The PR title and explanation each start with "Fix #bugnum: " (If
this PR fixes part of an issue, prefix the title with "Fix part of
#bugnum: ...".)
- [x] Any changes to
[scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets)
files have their rationale included in the PR explanation.
- [x] The PR follows the [style
guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide).
- [x] The PR does not contain any unnecessary code changes from Android
Studio
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)).
- [x] The PR is made from a branch that's **not** called "develop" and
is up-to-date with "develop".
- [x] The PR is **assigned** to the appropriate reviewers
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)).

## For UI-specific PRs only

- Add a screenshot demonstrating that you ran affected Espresso tests
locally & that they're passing
![Screenshot 2024-01-07
142738](https://github.com/oppia/oppia-android/assets/74568012/70cb0448-2ed5-458f-bbba-cf8877e11ef1)

![Screenshot 2024-01-07
145604](https://github.com/oppia/oppia-android/assets/74568012/e465d9de-8153-456b-a1db-28428cc04ad8)

---------

Co-authored-by: Adhiambo Peres <[email protected]>
  • Loading branch information
XichengSpencer and adhiamboperes authored Jan 22, 2024
1 parent bb69b22 commit b173a2a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ class MathExpressionParserViewModel @Inject constructor(
private val htmlParserFactory: HtmlParser.Factory
) : ObservableViewModel() {
private val htmlParser by lazy {
// TODO(#4206): Replace this with the variant that doesn't require GCS properties.
htmlParserFactory.create(
gcsResourceName = "",
entityType = "",
entityId = "",
imageCenterAlign = false,
displayLocale = appLanguageResourceHandler.getDisplayLocale()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ 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
Expand Down Expand Up @@ -124,11 +123,17 @@ class HtmlParser private constructor(
}

val imageGetter = urlImageParserFactory?.create(
htmlContentTextView, gcsResourceName, entityType, entityId, imageCenterAlign
htmlContentTextView,
gcsResourceName,
entityType,
entityId,
imageCenterAlign
)

val htmlSpannable = CustomHtmlContentHandler.fromHtml(
htmlContent, imageGetter, computeCustomTagHandlers(supportsConceptCards, htmlContentTextView)
htmlContent,
imageGetter,
computeCustomTagHandlers(supportsConceptCards, htmlContentTextView)
)

val urlPattern = Patterns.WEB_URL
Expand Down Expand Up @@ -226,17 +231,40 @@ class HtmlParser private constructor(
displayLocale: OppiaLocale.DisplayLocale
): HtmlParser {
return HtmlParser(
context,
urlImageParserFactory,
gcsResourceName,
entityType,
entityId,
imageCenterAlign,
consoleLogger,
context = context,
urlImageParserFactory = urlImageParserFactory,
gcsResourceName = gcsResourceName,
entityType = entityType,
entityId = entityId,
imageCenterAlign = imageCenterAlign,
consoleLogger = consoleLogger,
cacheLatexRendering = enableCacheLatexRendering.value,
customOppiaTagActionListener,
null,
displayLocale
customOppiaTagActionListener = customOppiaTagActionListener,
policyOppiaTagActionListener = null,
displayLocale = displayLocale
)
}

/**
* Returns a new [HtmlParser] with the empty entity type and ID for loading images,
* doesn't require GCS properties and imageCenterAlign set to false
* optionally specified [CustomOppiaTagActionListener] for handling custom Oppia tag events.
*/
fun create(
displayLocale: OppiaLocale.DisplayLocale
): HtmlParser {
return HtmlParser(
context = context,
urlImageParserFactory = urlImageParserFactory,
gcsResourceName = "",
entityType = "",
entityId = "",
imageCenterAlign = false,
consoleLogger = consoleLogger,
cacheLatexRendering = enableCacheLatexRendering.value,
customOppiaTagActionListener = null,
policyOppiaTagActionListener = null,
displayLocale = displayLocale
)
}

Expand Down

0 comments on commit b173a2a

Please sign in to comment.