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 part of #4044: Prepare for supporting math expressions (math utility refactor) #4046

Merged
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
17472e7
Copy proto-based changes from #2173.
BenHenning Dec 14, 2021
fe73a2f
Introduce math.proto & refactor math extensions.
BenHenning Dec 15, 2021
d17e3dc
Migrate tests & remove unneeded prefix.
BenHenning Dec 15, 2021
fb61e39
Add needed newline.
BenHenning Dec 15, 2021
acab98b
Some needed Fraction changes.
BenHenning Dec 15, 2021
7c36fdf
Lint fix.
BenHenning Dec 15, 2021
d5dd596
Fix broken test post-refactor.
BenHenning Dec 16, 2021
a1d481d
Merge branch 'develop' into add-support-for-math-expressions-pt1-fix-…
BenHenning Jan 13, 2022
7740c81
Post-merge fix.
BenHenning Jan 13, 2022
929de4f
Add regex check, docs, and resolve TODOs.
BenHenning Jan 14, 2022
e50a50f
Lint fix.
BenHenning Jan 14, 2022
c2726ac
Merge branch 'add-support-for-math-expressions-pt1-fix-proto-imports'…
BenHenning Jan 14, 2022
ec575b7
Fix failing static checks.
BenHenning Jan 14, 2022
444d3d0
Merge branch 'develop' into add-support-for-math-expressions-pt1-fix-…
BenHenning Jan 26, 2022
cb5c5d1
Merge branch 'add-support-for-math-expressions-pt1-fix-proto-imports'…
BenHenning Jan 27, 2022
cfe6cab
Move StringExtensions & fraction parsing.
BenHenning Jan 27, 2022
0287f19
Add missing KDocs.
BenHenning Jan 27, 2022
924214d
Merge branch 'develop' into add-support-for-math-expressions-pt1-fix-…
BenHenning Feb 5, 2022
686c4b6
Merge branch 'add-support-for-math-expressions-pt1-fix-proto-imports'…
BenHenning Feb 5, 2022
ecc836e
Merge branch 'develop' into add-support-for-math-expressions-pt1-fix-…
BenHenning Feb 18, 2022
b183d67
Merge branch 'add-support-for-math-expressions-pt1-fix-proto-imports'…
BenHenning Feb 18, 2022
fd9ec1f
Fix broken build.
BenHenning Feb 18, 2022
960287d
Merge branch 'add-support-for-math-expressions-pt1-fix-proto-imports'…
BenHenning Feb 18, 2022
0fc8a1b
Fix broken build post-merge.
BenHenning Feb 18, 2022
c01f939
Merge branch 'develop' into add-support-for-math-expressions-pt1-fix-…
BenHenning Feb 24, 2022
14f7057
Merge branch 'add-support-for-math-expressions-pt1-fix-proto-imports'…
BenHenning Feb 24, 2022
1d74aed
Merge branch 'develop' into add-support-for-math-expressions-pt1-fix-…
BenHenning Mar 7, 2022
2ae10ec
Merge branch 'add-support-for-math-expressions-pt1-fix-proto-imports'…
BenHenning Mar 7, 2022
8945c3a
Merge branch 'develop' into add-support-for-math-expressions-pt1-fix-…
BenHenning Mar 17, 2022
391cf22
Post-merge fix.
BenHenning Mar 17, 2022
7918001
Merge branch 'add-support-for-math-expressions-pt1-fix-proto-imports'…
BenHenning Mar 17, 2022
c29a47c
More post-merge fixes.
BenHenning Mar 17, 2022
52862d6
Merge branch 'develop' into add-support-for-math-expressions-pt1-fix-…
BenHenning Mar 25, 2022
cd31247
Merge branch 'develop' into add-support-for-math-expressions-pt1-fix-…
BenHenning Mar 25, 2022
4dbd838
Merge branch 'add-support-for-math-expressions-pt1-fix-proto-imports'…
BenHenning Mar 25, 2022
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
15 changes: 8 additions & 7 deletions app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ VIEW_MODELS_WITH_RESOURCE_IMPORTS = [
"src/main/java/org/oppia/android/app/onboarding/OnboardingViewModel.kt",
"src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicItemViewModel.kt",
"src/main/java/org/oppia/android/app/options/TextSizeItemViewModel.kt",
"src/main/java/org/oppia/android/app/parser/StringToFractionParser.kt",
"src/main/java/org/oppia/android/app/parser/FractionParsingUiError.kt",
"src/main/java/org/oppia/android/app/parser/StringToNumberParser.kt",
"src/main/java/org/oppia/android/app/parser/StringToRatioParser.kt",
"src/main/java/org/oppia/android/app/player/state/itemviewmodel/DragDropInteractionContentViewModel.kt",
Expand Down Expand Up @@ -546,8 +546,8 @@ android_library(
":views",
"//app/src/main/java/org/oppia/android/app/translation:app_language_activity_injector_provider",
"//app/src/main/java/org/oppia/android/app/translation:app_language_resource_handler",
"//model:interaction_object_java_proto_lite",
"//model:thumbnail_java_proto_lite",
"//model/src/main/proto:interaction_object_java_proto_lite",
"//model/src/main/proto:thumbnail_java_proto_lite",
"//third_party:androidx_annotation_annotation",
"//third_party:androidx_constraintlayout_constraintlayout",
"//third_party:androidx_core_core",
Expand Down Expand Up @@ -578,8 +578,8 @@ kt_android_library(
deps = [
":dagger",
"//domain/src/main/java/org/oppia/android/domain/audio:cellular_audio_dialog_controller",
"//model:question_java_proto_lite",
"//model:topic_java_proto_lite",
"//model/src/main/proto:question_java_proto_lite",
"//model/src/main/proto:topic_java_proto_lite",
"//third_party:androidx_recyclerview_recyclerview",
],
)
Expand Down Expand Up @@ -658,6 +658,7 @@ kt_android_library(
"//utility/src/main/java/org/oppia/android/util/extensions:context_extensions",
"//utility/src/main/java/org/oppia/android/util/logging/firebase:debug_event_logger",
"//utility/src/main/java/org/oppia/android/util/logging/firebase:debug_module",
"//utility/src/main/java/org/oppia/android/util/math:fraction_parser",
# TODO(#59): Remove 'debug_util_module' once we completely migrate to Bazel from Gradle as
# we can then directly exclude debug files from the build and thus won't be requiring this module.
"//utility/src/main/java/org/oppia/android/util/networking:debug_util_module",
Expand Down Expand Up @@ -686,7 +687,7 @@ android_library(
":view_models",
"//app/src/main/java/org/oppia/android/app/translation:app_language_activity_injector_provider",
"//app/src/main/java/org/oppia/android/app/translation:app_language_resource_handler",
"//model:thumbnail_java_proto_lite",
"//model/src/main/proto:thumbnail_java_proto_lite",
"//third_party:androidx_annotation_annotation",
"//third_party:androidx_constraintlayout_constraintlayout",
"//third_party:androidx_lifecycle_lifecycle-livedata-core",
Expand Down Expand Up @@ -738,8 +739,8 @@ kt_android_library(
"//domain/src/main/java/org/oppia/android/domain/oppialogger:startup_listener",
"//domain/src/main/java/org/oppia/android/domain/oppialogger/exceptions:logger_module",
"//domain/src/main/java/org/oppia/android/domain/oppialogger/loguploader:worker_module",
"//model/src/main/proto:arguments_java_proto_lite",
"//domain/src/main/java/org/oppia/android/domain/profile:profile_management_controller",
"//model:arguments_java_proto_lite",
"//app/src/main/java/org/oppia/android/app/testing/activity:test_activity",
"//third_party:androidx_databinding_databinding-adapters",
"//third_party:androidx_databinding_databinding-common",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ kt_android_library(
"//app:app_visibility",
],
deps = [
"//model:profile_java_proto_lite",
"//model/src/main/proto:profile_java_proto_lite",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import org.oppia.android.app.utility.KeyboardHelper.Companion.showSoftKeyboard
// background="@drawable/edit_text_background"
// maxLength="200".

// TODO(#4135): Add a dedicated test suite for this class.

/** The custom EditText class for fraction input interaction view. */
class FractionInputInteractionView @JvmOverloads constructor(
context: Context,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.oppia.android.app.parser

import androidx.annotation.StringRes
import org.oppia.android.R
import org.oppia.android.app.translation.AppLanguageResourceHandler
import org.oppia.android.util.math.FractionParser.FractionParsingError

/** Enum to store the errors of [FractionInputInteractionView]. */
enum class FractionParsingUiError(@StringRes private var error: Int?) {
/** Corresponds to [FractionParsingError.VALID]. */
VALID(error = null),

/** Corresponds to [FractionParsingError.INVALID_CHARS]. */
INVALID_CHARS(error = R.string.fraction_error_invalid_chars),

/** Corresponds to [FractionParsingError.INVALID_FORMAT]. */
INVALID_FORMAT(error = R.string.fraction_error_invalid_format),

/** Corresponds to [FractionParsingError.DIVISION_BY_ZERO]. */
DIVISION_BY_ZERO(error = R.string.fraction_error_divide_by_zero),

/** Corresponds to [FractionParsingError.NUMBER_TOO_LONG]. */
NUMBER_TOO_LONG(error = R.string.fraction_error_larger_than_seven_digits);

/**
* Returns the string corresponding to this error's string resources, or null if there is none.
*/
fun getErrorMessageFromStringRes(resourceHandler: AppLanguageResourceHandler): String? =
error?.let(resourceHandler::getStringInLocale)

companion object {
/**
* Returns the [FractionParsingUiError] corresponding to the specified [FractionParsingError].
*/
fun createFromParsingError(parsingError: FractionParsingError): FractionParsingUiError {
return when (parsingError) {
FractionParsingError.VALID -> VALID
FractionParsingError.INVALID_CHARS -> INVALID_CHARS
FractionParsingError.INVALID_FORMAT -> INVALID_FORMAT
FractionParsingError.DIVISION_BY_ZERO -> DIVISION_BY_ZERO
FractionParsingError.NUMBER_TOO_LONG -> NUMBER_TOO_LONG
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.oppia.android.app.parser
import androidx.annotation.StringRes
import org.oppia.android.R
import org.oppia.android.app.translation.AppLanguageResourceHandler
import org.oppia.android.domain.util.normalizeWhitespace
import org.oppia.android.util.extensions.normalizeWhitespace

/**
* This class contains methods that help to parse string to number, check realtime and submit time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import androidx.annotation.StringRes
import org.oppia.android.R
import org.oppia.android.app.model.RatioExpression
import org.oppia.android.app.translation.AppLanguageResourceHandler
import org.oppia.android.domain.util.normalizeWhitespace
import org.oppia.android.domain.util.removeWhitespace
import org.oppia.android.util.extensions.normalizeWhitespace
import org.oppia.android.util.extensions.removeWhitespace

/**
* Utility for parsing [RatioExpression]s from strings and validating strings can be parsed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import org.oppia.android.app.model.Interaction
import org.oppia.android.app.model.InteractionObject
import org.oppia.android.app.model.UserAnswer
import org.oppia.android.app.model.WrittenTranslationContext
import org.oppia.android.app.parser.StringToFractionParser
import org.oppia.android.app.parser.FractionParsingUiError
import org.oppia.android.app.player.state.answerhandling.AnswerErrorCategory
import org.oppia.android.app.player.state.answerhandling.InteractionAnswerErrorOrAvailabilityCheckReceiver
import org.oppia.android.app.player.state.answerhandling.InteractionAnswerHandler
import org.oppia.android.app.translation.AppLanguageResourceHandler
import org.oppia.android.domain.translation.TranslationController
import org.oppia.android.util.math.FractionParser

/** [StateItemViewModel] for the fraction input interaction. */
class FractionInteractionViewModel(
Expand All @@ -32,7 +33,7 @@ class FractionInteractionViewModel(
var errorMessage = ObservableField<String>("")

val hintText: CharSequence = deriveHintText(interaction)
private val stringToFractionParser: StringToFractionParser = StringToFractionParser()
private val fractionParser = FractionParser()

init {
val callback: Observable.OnPropertyChangedCallback =
Expand All @@ -52,7 +53,7 @@ class FractionInteractionViewModel(
if (answerText.isNotEmpty()) {
val answerTextString = answerText.toString()
answer = InteractionObject.newBuilder().apply {
fraction = stringToFractionParser.parseFractionFromString(answerTextString)
fraction = fractionParser.parseFractionFromString(answerTextString)
}.build()
plainAnswer = answerTextString
this.writtenTranslationContext = [email protected]
Expand All @@ -63,14 +64,18 @@ class FractionInteractionViewModel(
override fun checkPendingAnswerError(category: AnswerErrorCategory): String? {
if (answerText.isNotEmpty()) {
when (category) {
AnswerErrorCategory.REAL_TIME ->
AnswerErrorCategory.REAL_TIME -> {
pendingAnswerError =
stringToFractionParser.getRealTimeAnswerError(answerText.toString())
.getErrorMessageFromStringRes(resourceHandler)
AnswerErrorCategory.SUBMIT_TIME ->
FractionParsingUiError.createFromParsingError(
fractionParser.getRealTimeAnswerError(answerText.toString())
).getErrorMessageFromStringRes(resourceHandler)
}
AnswerErrorCategory.SUBMIT_TIME -> {
pendingAnswerError =
stringToFractionParser.getSubmitTimeError(answerText.toString())
.getErrorMessageFromStringRes(resourceHandler)
FractionParsingUiError.createFromParsingError(
fractionParser.getSubmitTimeError(answerText.toString())
).getErrorMessageFromStringRes(resourceHandler)
}
}
errorMessage.set(pendingAnswerError)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.oppia.android.app.player.state.answerhandling.InteractionAnswerHandle
import org.oppia.android.app.translation.AppLanguageResourceHandler
import org.oppia.android.app.utility.toAccessibleAnswerString
import org.oppia.android.domain.translation.TranslationController
import org.oppia.android.domain.util.toAnswerString
import org.oppia.android.util.math.toAnswerString

/** [StateItemViewModel] for the ratio expression input interaction. */
class RatioExpressionInputInteractionViewModel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ class InputInteractionViewTestActivityTest {
ApplicationProvider.getApplicationContext<TestApplication>().inject(this)
}

// TODO(#4135): Move fraction input tests to a dedicated test suite.

@Test
fun testFractionInput_withNoInput_hasCorrectPendingAnswerType() {
val activityScenario = ActivityScenario.launch(
Expand Down
Loading