Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #4845: Dark mode support to Equations Text #4866

Merged
merged 36 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
bf9ad69
Fixed Equation dark mode color added colors in utility res.
MohitGupta121 Feb 2, 2023
51af3aa
Merge remote-tracking branch 'upstream/develop' into darkmode-equations
MohitGupta121 Feb 2, 2023
58f42f0
Workflow fixed
MohitGupta121 Feb 2, 2023
b188c40
Lint import error fixed
MohitGupta121 Feb 2, 2023
3b78da0
Merge remote-tracking branch 'upstream/develop' into darkmode-equations
MohitGupta121 Feb 7, 2023
88928cf
Point Kotlitex to latest commit, improve readability of parameters.
MohitGupta121 Feb 7, 2023
0ff1366
Refac: Link Bazel Migration Issue with this PR.
MohitGupta121 Feb 8, 2023
7b868e0
Fixed Unresolved resources R. in Bazel
MohitGupta121 Feb 8, 2023
55f3bfc
Lint Check Fixed under math bazel
MohitGupta121 Feb 8, 2023
49cced4
Minor Lint check fixed
MohitGupta121 Feb 8, 2023
561fc78
bazel resources visibility fixed
MohitGupta121 Feb 8, 2023
e79ebea
bazel lint fixed
MohitGupta121 Feb 8, 2023
7e761c0
bazel visiblity try
MohitGupta121 Feb 8, 2023
6fb63cc
bazel visiblity fixed
MohitGupta121 Feb 8, 2023
82b7392
bazel visiblity fixed
MohitGupta121 Feb 8, 2023
e4bdab2
fixed bazel visibility fixed
MohitGupta121 Feb 9, 2023
66087bd
fixed bazel visibility fixed
MohitGupta121 Feb 9, 2023
0080d67
Merge branch 'develop' into darkmode-equations
MohitGupta121 Feb 14, 2023
b33c906
Fixed visibility error in bazel build
MohitGupta121 Feb 14, 2023
f384445
Fixed Missing argument in MathTagHandlerTest
MohitGupta121 Feb 14, 2023
069db1d
Fixed 100 lines lint error.
MohitGupta121 Feb 14, 2023
46e4f7f
Merge branch 'develop' into darkmode-equations
MohitGupta121 Feb 22, 2023
644a583
Merge branch 'develop' into darkmode-equations
MohitGupta121 Feb 27, 2023
ce92dfd
Added Test for equation color
MohitGupta121 Mar 1, 2023
d2c5ce1
Fixed Lint Failures
MohitGupta121 Mar 1, 2023
dc86ff6
Merge branch 'develop' into darkmode-equations
MohitGupta121 Mar 3, 2023
8882b81
Updated MathTagHandlerTest for Day and Night Mode.
MohitGupta121 Mar 3, 2023
5a14a66
Fixed Lint Test
MohitGupta121 Mar 3, 2023
b0eda2a
Merge branch 'develop' into darkmode-equations
MohitGupta121 Mar 10, 2023
8aa9357
Merge branch 'develop' into darkmode-equations
MohitGupta121 Mar 10, 2023
78d7b56
Merge branch 'develop' into darkmode-equations
MohitGupta121 Mar 11, 2023
92c8692
Fix some review changes.
MohitGupta121 Mar 11, 2023
3b2cf1f
Merge branch 'develop' into darkmode-equations
MohitGupta121 Mar 14, 2023
cc263b5
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
MohitGupta121 Mar 15, 2023
dc0dfd8
Fixed Ben's Review changes
MohitGupta121 Mar 15, 2023
dffff4f
Merge branch 'develop' into darkmode-equations
BenHenning Mar 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ git_repository(
# min target SDK version to be compatible with Oppia.
git_repository(
name = "kotlitex",
commit = "6b7db8ff9e0f4a70bdaa25f482143e038fd0c301",
commit = "43139c140833c7120f351d63d74b42c253d2b213",
remote = "https://github.com/oppia/kotlitex",
shallow_since = "1647554845 -0700",
)
Expand Down
1 change: 1 addition & 0 deletions utility/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ android_library(
custom_package = "org.oppia.android.util",
manifest = "src/main/AndroidManifest.xml",
resource_files = glob(["src/main/res/**/*.xml"]),
visibility = ["//visibility:public"],
)

# Visibility for migrated utility tests.
Expand Down
2 changes: 1 addition & 1 deletion utility/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ dependencies {
'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0-alpha03',
'androidx.work:work-runtime-ktx:2.4.0',
'com.github.oppia:androidsvg:4bc1d26412f0fb9fd4ef263fa93f6a64f4d4dbcf',
'com.github.oppia:kotlitex:6b7db8ff9e0f4a70bdaa25f482143e038fd0c301',
'com.github.oppia:kotlitex:43139c140833c7120f351d63d74b42c253d2b213',
'com.github.bumptech.glide:glide:4.11.0',
'com.google.dagger:dagger:2.24',
'com.google.firebase:firebase-analytics-ktx:17.5.0',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.oppia.android.util.parser.html

import android.app.Application
import android.content.Context
import android.text.Spannable
import android.text.SpannableStringBuilder
Expand Down Expand Up @@ -134,7 +135,8 @@ class HtmlParser private constructor(
consoleLogger,
context.assets,
htmlContentTextView.lineHeight.toFloat(),
cacheLatexRendering
cacheLatexRendering,
context as? Application ?: context.applicationContext as Application
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
)
if (supportsConceptCards) {
handlersMap[CUSTOM_CONCEPT_CARD_TAG] = conceptCardTagHandler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.oppia.android.util.parser.html

import android.app.Application
import android.content.res.AssetManager
import android.text.Editable
import android.text.Spannable
import android.text.style.ImageSpan
import androidx.core.content.res.ResourcesCompat
import io.github.karino2.kotlitex.view.MathExpressionSpan
import org.json.JSONObject
import org.oppia.android.util.R
import org.oppia.android.util.logging.ConsoleLogger
import org.oppia.android.util.parser.html.CustomHtmlContentHandler.ImageRetriever.Type.BLOCK_IMAGE
import org.oppia.android.util.parser.html.CustomHtmlContentHandler.ImageRetriever.Type.INLINE_TEXT_IMAGE
Expand All @@ -24,7 +27,8 @@ class MathTagHandler(
private val consoleLogger: ConsoleLogger,
private val assetManager: AssetManager,
private val lineHeight: Float,
private val cacheLatexRendering: Boolean
private val cacheLatexRendering: Boolean,
private val application: Application
) : CustomHtmlContentHandler.CustomTagHandler {
override fun handleTag(
attributes: Attributes,
Expand Down Expand Up @@ -65,7 +69,15 @@ class MathTagHandler(
)
} else {
MathExpressionSpan(
content.rawLatex, lineHeight, assetManager, isMathMode = !useInlineRendering
content.rawLatex,
lineHeight,
assetManager,
isMathMode = !useInlineRendering,
ResourcesCompat.getColor(
application.resources,
R.color.component_color_shared_equation_color,
/* theme = */ null
)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ kt_android_library(
":math_latex_model",
"//third_party:com_github_bumptech_glide_glide",
"//third_party:io_github_karino2_kotlitex",
"//utility:resources",
"//utility/src/main/java/org/oppia/android/util/logging:console_logger_injector_provider",
"//utility/src/main/java/org/oppia/android/util/threading:dispatcher_injector_provider",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.StaticLayout
import android.text.TextPaint
import androidx.core.content.res.ResourcesCompat
import com.bumptech.glide.Priority
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.Options
Expand All @@ -26,6 +27,7 @@ import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.oppia.android.util.R
import org.oppia.android.util.logging.ConsoleLogger
import org.oppia.android.util.logging.ConsoleLoggerInjectorProvider
import org.oppia.android.util.threading.DispatcherInjectorProvider
Expand Down Expand Up @@ -109,7 +111,16 @@ class MathBitmapModelLoader private constructor(
// creation can still happen in parallel, and those are the more expensive steps.
val span = withContext(CoroutineScope(blockingDispatcher).coroutineContext) {
MathExpressionSpan(
model.rawLatex, model.lineHeight, application.assets, !model.useInlineRendering
model.rawLatex,
model.lineHeight,
application.assets,
!model.useInlineRendering,
// TODO(#1523): Test color parameter in MathBitmapModelLoader
ResourcesCompat.getColor(
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
application.resources,
R.color.component_color_shared_equation_color,
/* theme = */null
)
).also { it.ensureDrawable() }
}
val renderableText = SpannableStringBuilder("\uFFFC").apply {
Expand All @@ -121,6 +132,7 @@ class MathBitmapModelLoader private constructor(
// since the width isn't necessarily known ahead of time).
// Any TextPaint can be used since the span will use its own.
val textPaint = TextPaint()

@Suppress("DEPRECATION") // This call is necessary for the supported min API version.
val staticTextLayout =
StaticLayout(
Expand Down
5 changes: 5 additions & 0 deletions utility/src/main/res/values-night/color_palette.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- TODO(#59): Consolidate color resource files once Bazel migration is done -->
<resources>
<color name="color_palette_shared_equation_color">@color/color_def_white</color>
</resources>
6 changes: 6 additions & 0 deletions utility/src/main/res/values/color_defs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- TODO(#59): Consolidate color resource files once Bazel migration is done -->
<resources>
<color name="color_def_black">#000000</color>
<color name="color_def_white">#FFFFFF</color>
</resources>
5 changes: 5 additions & 0 deletions utility/src/main/res/values/color_palette.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- TODO(#59): Consolidate color resource files once Bazel migration is done -->
<resources>
<color name="color_palette_shared_equation_color">@color/color_def_black</color>
</resources>
5 changes: 5 additions & 0 deletions utility/src/main/res/values/component_colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- TODO(#59): Consolidate color resource files once Bazel migration is done -->
<resources>
<color name="component_color_shared_equation_color">@color/color_palette_shared_equation_color</color>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.oppia.android.util.parser.html

import android.app.Application
import android.content.Context
import android.graphics.Color
import android.text.Html
import android.text.Spannable
import android.text.style.ImageSpan
Expand Down Expand Up @@ -34,6 +35,7 @@ import org.oppia.android.util.logging.ConsoleLogger
import org.oppia.android.util.logging.LoggerModule
import org.oppia.android.util.parser.html.CustomHtmlContentHandler.CustomTagHandler
import org.oppia.android.util.parser.html.CustomHtmlContentHandler.ImageRetriever
import org.robolectric.annotation.Config
import org.robolectric.annotation.LooperMode
import javax.inject.Inject
import javax.inject.Singleton
Expand Down Expand Up @@ -246,6 +248,33 @@ class MathTagHandlerTest {
verifyNoMoreInteractions(mockImageRetriever) // No cached image loading.
}

@Test
fun testParseHtmlDayColor_withMathMarkup_cachingOff_getEquationDayColor() {
val parsedHtml =
CustomHtmlContentHandler.fromHtml(
html = MATH_WITHOUT_FILENAME_MARKUP,
imageRetriever = mockImageRetriever,
customTagHandlers = tagHandlersWithUncachedMathSupport
)

val equationColor = parsedHtml.getSpansFromWholeString(MathExpressionSpan::class)
assertThat(equationColor[0].equationColor).isEqualTo(Color.BLACK)
}

@Config(qualifiers = "night")
@Test
fun testParseHtmlNightColor_withMathMarkup_cachingOff_getEquationNightColor() {
val parsedHtml =
CustomHtmlContentHandler.fromHtml(
html = MATH_WITHOUT_FILENAME_MARKUP,
imageRetriever = mockImageRetriever,
customTagHandlers = tagHandlersWithUncachedMathSupport
)

val equationColor = parsedHtml.getSpansFromWholeString(MathExpressionSpan::class)
assertThat(equationColor[0].equationColor).isEqualTo(Color.WHITE)
}

@Test
fun testParseHtml_noTagHandler_withMathMarkup_doesNotIncludeImageSpan() {
val parsedHtml =
Expand Down Expand Up @@ -306,7 +335,13 @@ class MathTagHandlerTest {

private fun createMathTagHandler(cacheLatexRendering: Boolean): MathTagHandler {
// Pick an arbitrary line height since rendering doesn't actually happen in tests.
return MathTagHandler(consoleLogger, context.assets, lineHeight = 10.0f, cacheLatexRendering)
return MathTagHandler(
consoleLogger,
context.assets,
lineHeight = 10.0f,
cacheLatexRendering,
application = context.applicationContext as Application
)
}

private fun <T : Any> Spannable.getSpansFromWholeString(spanClass: KClass<T>): Array<T> =
Expand Down