-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…#270) * Attempt to rebase content-card onto develop. * Manually apply rejections and remove rej files. * Add missing pieces implied in merge-fix that are needed for this branch. * Maunally apply multiple-single-input-interaction changes to develop branch (with patch rejections). * Manually apply rejected diffs. * Fix broken build after merges. * Add missing changes from merge-fix that are needed to enable state content binding. * Resolve unresolved conflicts. * Make an exploration with all prototype interactions work end-to-end. This includes: - Introducing an exploration with all prototype interactions - Introducing support for binding all interaction types - Fixing some parsing issues with fractions - Rewiring the interaction object creation for views to be generic - Removing temporary answer handling everywhere - Other random fixes This includes no tests, and there are a few other fixes still necessary for the core learning experience to fully work. * Add support for displaying feedback items. * Add support for reshowing submitted answers. * Make 'Continue' button a separate interaction (but keep the existing general 'Continue' navigation button). Rework how navigation buttons behave. Introduce automatic answer submission for some interactions (Continue, ItemSelection if it shows radio buttons, and MultipleChoice). * Move audio functionality to a custom toolbar, remove the dummy audio button, and remove the transient state name at the top of the state fragment. * Simplify the presenter by updating ExplorationProgressController to feed information about the next and current state to allow the state presenter to only focus on rendering the current state. * First batch of work corresponding to moving the entirety of state fragment's recycler view (and child views/recycler view) to be bound via data-binding. * Finish updating item selection recycler view to use data binding. This required introducing a ViewComponent that inherits from FragmentComponent in the Dagger dependency graph. This also involved updating the app to use a newer AndroidX fragment library that's still pre-release in order to gain access to the necessary functionality to associate views with their fragments. The two custom adapters have been removed in this change. * Some minor fixes to polish up the experience a bit and reduce jank. * Fix broken voiceover audio button. * Address one TODO to generalize adding interactions by leveraging a Dagger module. * Fix broken test. * Fix broken domain tests by allowing feedback to be either a string or an object, and loading about_oppia instead of oppia_exploration since the former is expected by ExplorationProgressControllerTest. * Fix broken app test builds (tests still fail, but at least run now). * Add TODO to fix feedback parsing hack. * Remove TODOs in StringToFractionParser. * Resolve open TODOs for the state portion of the player, or associate them with issues. * Associate 2 more TODOs with issues. * Add tests for new next state behavior in ExplorationProgressController, and resolve last unattributed TODO. * Remove number with units support. * Post-merge fixes and clean-ups. * Post-merge fix. * Remove number with units tests. * First round of addressing reviewer comments. * Remove view scope & component. * Second round of addressing reviewer comments. Includes a project-wide optimization of all imports. * Round 3 of addressing reviewer changes: removed UrlImageParserTest since it was pulled in with earlier, unfinalized changes and we have since realized it's not possible to test the image parser based on the current project setup. * Round 4 of addressing reviewer comments: reformat all layout XML files. * Round 5 of addressing reviewer comments. * Revert "Remove view scope & component." This reverts commit 99783d5. * Post-clean up fixes and other minor adjustments. * Ensure ExplorationActivityTest passes even though it doesn't have interesting tests yet. * Temporary workaround to make the prototype exploration accessible with recent topic & home fragment changes. Also, hide the topic button in the home fragment since the topic is accessible directly via the home fragment tiles. * Round 6 of addressing review comments. * Update prototype exploration to provide feedback after the multi-item item selection state for the correct answer so that the player doesn't seem broken.
- Loading branch information
1 parent
2944a67
commit a23de65
Showing
195 changed files
with
2,570 additions
and
1,527 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
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
8 changes: 0 additions & 8 deletions
8
app/src/main/java/org/oppia/app/customview/interaction/InteractionAnswerRetriever.kt
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.oppia.app.fragment | ||
|
||
import dagger.Module | ||
import org.oppia.app.view.ViewComponent | ||
|
||
/** Root fragment module. */ | ||
@Module(subcomponents = [ViewComponent::class]) class FragmentModule |
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
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
72 changes: 47 additions & 25 deletions
72
app/src/main/java/org/oppia/app/parser/StringToFractionParser.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 |
---|---|---|
@@ -1,34 +1,56 @@ | ||
package org.oppia.app.parser | ||
|
||
import org.oppia.app.model.Fraction | ||
import org.oppia.domain.util.normalizeWhitespace | ||
|
||
/** This class contains method that helps to parse string to fraction. */ | ||
class StringToFractionParser { | ||
private val wholeNumberOnlyRegex = """^-? ?(\d+)$""".toRegex() | ||
private val fractionOnlyRegex = """^-? ?(\d+) ?/ ?(\d)+$""".toRegex() | ||
private val mixedNumberRegex = """^-? ?(\d)+ ?(\d+) ?/ ?(\d)+$""".toRegex() | ||
|
||
fun getFractionFromString(text: String): Fraction { | ||
var inputText: String = text | ||
var isNegative = false | ||
var numerator = "0" | ||
var denominator = "0" | ||
var wholeNumber = "0" | ||
val fractionObjectBuilder = Fraction.newBuilder() | ||
if (inputText.startsWith("-")) | ||
isNegative = true | ||
inputText = inputText.replace("-", "").trim() | ||
wholeNumber = if (inputText.contains("/") && inputText.contains(" ")) { | ||
inputText.substringBefore(" ") | ||
} else if (inputText.contains("/")) { | ||
wholeNumber | ||
} else { | ||
inputText | ||
} | ||
inputText = | ||
if (inputText.contains(" ")) inputText.substringAfter(" ").replace(" ", "") else inputText.replace(" ", "") | ||
if (inputText.contains("/")) { | ||
numerator = inputText.substringBefore("/") | ||
denominator = inputText.substringAfter("/") | ||
} | ||
fractionObjectBuilder.setIsNegative(isNegative).setNumerator(numerator.toInt()) | ||
.setDenominator(denominator.toInt()).wholeNumber = wholeNumber.toInt() | ||
return fractionObjectBuilder.build() | ||
// Normalize whitespace to ensure that answer follows a simpler subset of possible patterns. | ||
val inputText: String = text.normalizeWhitespace() | ||
return parseMixedNumber(inputText) | ||
?: parseFraction(inputText) | ||
?: parseWholeNumber(inputText) | ||
?: throw IllegalArgumentException("Incorrectly formatted fraction: $text") | ||
} | ||
|
||
private fun parseMixedNumber(inputText: String): Fraction? { | ||
val mixedNumberMatch = mixedNumberRegex.matchEntire(inputText) ?: return null | ||
val (_, wholeNumberText, numeratorText, denominatorText) = mixedNumberMatch.groupValues | ||
return Fraction.newBuilder() | ||
.setIsNegative(isInputNegative(inputText)) | ||
.setWholeNumber(wholeNumberText.toInt()) | ||
.setNumerator(numeratorText.toInt()) | ||
.setDenominator(denominatorText.toInt()) | ||
.build() | ||
} | ||
|
||
private fun parseFraction(inputText: String): Fraction? { | ||
val fractionOnlyMatch = fractionOnlyRegex.matchEntire(inputText) ?: return null | ||
val (_, numeratorText, denominatorText) = fractionOnlyMatch.groupValues | ||
// Fraction-only numbers imply no whole number. | ||
return Fraction.newBuilder() | ||
.setIsNegative(isInputNegative(inputText)) | ||
.setNumerator(numeratorText.toInt()) | ||
.setDenominator(denominatorText.toInt()) | ||
.build() | ||
} | ||
|
||
private fun parseWholeNumber(inputText: String): Fraction? { | ||
val wholeNumberMatch = wholeNumberOnlyRegex.matchEntire(inputText) ?: return null | ||
val (_, wholeNumberText) = wholeNumberMatch.groupValues | ||
// Whole number fractions imply '0/1' fractional parts. | ||
return Fraction.newBuilder() | ||
.setIsNegative(isInputNegative(inputText)) | ||
.setWholeNumber(wholeNumberText.toInt()) | ||
.setNumerator(0) | ||
.setDenominator(1) | ||
.build() | ||
} | ||
|
||
private fun isInputNegative(inputText: String): Boolean = inputText.startsWith("-") | ||
} |
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.