-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix part of #4044: Prepare for supporting math expressions (math util…
…ity refactor) (#4046) ## Explanation Fix part of #4044 Originally copied from #2173 when it was in proof-of-concept form This PR introduces a new math.proto and math utility package for upcoming protos & utilities coming in later PRs as part of the broader math expressions project. This includes moving some pure math protos & utilities to the new package, but not quite everything can be moved yet due to resource dependencies for RatioExtensions and the ratio/fraction parsers. These could be split up and partly moved to the new package in a future PR, but it's not a prerequisite for any of the math expressions work. This PR also moves most of fraction parsing to utility and extracts just the UI-specific portion (i.e. accessing app strings). Consequently, there are now two test suites to verify the fraction parsing functionality. StringExtensions needed to be moved out of app due to it being needed in FractionParser. This move is needed for a downstream PR that will utilize the fraction parser in tests. The new test file exemption changes are just updates since there are moved files. ## Essential Checklist - [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 N/A refactor with no side effects to affect user flows. Commit history: * Copy proto-based changes from #2173. * Introduce math.proto & refactor math extensions. Much of this is copied from #2173. * Migrate tests & remove unneeded prefix. * Add needed newline. * Some needed Fraction changes. * Lint fix. * Fix broken test post-refactor. * Post-merge fix. * Add regex check, docs, and resolve TODOs. This also changes regex handling in the check to be more generic for better flexibility when matching files. * Lint fix. * Fix failing static checks. * Move StringExtensions & fraction parsing. This splits fraction parsing between UI & utility components. * Add missing KDocs. * Fix broken build. * Fix broken build post-merge. * Post-merge fix. * More post-merge fixes.
- Loading branch information
1 parent
edcfe94
commit 240bdb6
Showing
44 changed files
with
824 additions
and
613 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
app/src/main/java/org/oppia/android/app/parser/FractionParsingUiError.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.