Skip to content

Commit

Permalink
Fix #150, #155: TextInputInteractionView and FractionInputInteraction…
Browse files Browse the repository at this point in the history
…View low-fi (#246)

* NumberInputInteractionView dynamically created on state interaction id NumericInput from dummy data welcome.json ,welcome.json file "init_state_name"modified to "Numeric input",

* NumberInputInteractionView dynamically created on state interaction id NumericInput from dummy data welcome.json

* added fetch button, and fetch textview to fetch the data from dynamic numbertextinputlayout onbutton click. on button click listner implemented

* nit changes

* nit changes

* nit changes

* nit changes

* nit changes

* numericInputTypeView test case is in progress

* numericInputTypeView test case is in progress

* nit changes as per #223

* nit changes as per #223

* On configuration changes save and restore the text of numericInputType

* Test Cases for NumericInputInteractionView,
Moved test case to StateFragment

* Test Cases for NumericInputInteractionView,
Moved test case to StateFragment,PR suggestions updated

* PR suggestions updated

* PR suggestions updated

* Merge branch 'develop' of https://github.com/oppia/oppia-android into topic-player-multiple-tabs

# Conflicts:
#	app/build.gradle
#	app/src/main/AndroidManifest.xml
#	app/src/main/res/values/styles.xml

* nit changes as per PR review

* nit changes as per PR review

* nit changes as per PR review

* nit changes as per PR review

* Number input test Activity test cases

* nit changes

* nit changes

* nit changes

* nit changes

* nit changes

* nit changes

* nit changes

* nit changes

* nit changes

* nit changes

* nit changes

* setReal type in getPendingAnswer

* updated test cases, disabled long click to prevent pasting value

* nit changes

* nit changes

* nit changes

* nit changes

* nit changes

* nit changes

* nit changes

* nit changes

* nit changes

* NumericInputInteractionViewTestActivity renamed to InputInteractionViewTestActivity and test case updated

* nit changes

* nit changes

* nit changes

* nit

* NumericInputInteractionView attributes are moved to xml,testcases updated as per PR review of Ben, other nit changes

* NumericInputInteractionView attributes are moved to xml,testcases updated as per PR review of Ben, other nit changes

* TextInputInteractionView

* TextInputInteractionView

* test cases

* nit

* nit

* nit

* nit

* nit

* Merge branches 'develop' and 'lowfi-input-interaction-views' of https://github.com/oppia/oppia-android into lowfi-input-interaction-views

# Conflicts:
#	app/src/main/java/org/oppia/app/activity/InputInteractionViewTestActivity.kt
#	app/src/main/java/org/oppia/app/customview/interaction/NumericInputInteractionView.kt
#	app/src/main/res/layout/activity_numeric_input_interaction_view_test.xml
#	app/src/main/res/values/dimens.xml
#	app/src/sharedTest/java/org/oppia/app/activity/InputInteractionViewTestActivityTest.kt

* nit

* nit

* nit

* nit

* Merge branches 'develop' and 'text-input-lowfi-numeric-input-interaction-view-part-2' of https://github.com/oppia/oppia-android into text-input-lowfi-numeric-input-interaction-view-part-2

# Conflicts:
#	app/src/sharedTest/java/org/oppia/app/activity/InputInteractionViewTestActivityTest.kt

* nit

* NumberWithUnitsInputInteractionView

* nit

* nit

* NumberWithUnitsInputInteractionView

* moved InputInteractionViewTestActivityTest to testing folder
  • Loading branch information
nikitamarysolomanpvt authored Oct 23, 2019
1 parent e167176 commit a37e090
Show file tree
Hide file tree
Showing 8 changed files with 350 additions and 88 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.oppia.app.customview.interaction

import android.content.Context
import android.util.AttributeSet
import android.widget.EditText
import org.oppia.app.model.InteractionObject
import org.oppia.app.parser.StringToFractionParser

// TODO(#249): These are the attributes which should be defined in XML, that are required for this interaction view to work correctly
// digits="0123456789/-"
// hint="Write fraction here."
// inputType="text"
// background="@drawable/edit_text_background"
// maxLength="200".

/** The custom EditText class for fraction input interaction view. */
class FractionInputInteractionView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyle: Int = android.R.attr.editTextStyle
) : EditText(context, attrs, defStyle), InteractionAnswerRetriever {

override fun getPendingAnswer(): InteractionObject {
val interactionObjectBuilder = InteractionObject.newBuilder()
if (!text.isNullOrEmpty()) {
interactionObjectBuilder.fraction = StringToFractionParser().getFractionFromString(text = text.toString())
}
return interactionObjectBuilder.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class NumericInputInteractionView @JvmOverloads constructor(
override fun getPendingAnswer(): InteractionObject {
val interactionObjectBuilder = InteractionObject.newBuilder()
if (!text.isNullOrEmpty()) {
interactionObjectBuilder.setReal(text.toString().toDouble())
interactionObjectBuilder.real = text.toString().toDouble()
}
return interactionObjectBuilder.build()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.oppia.app.customview.interaction

import android.content.Context
import android.util.AttributeSet
import android.widget.EditText
import org.oppia.app.model.InteractionObject

// TODO(#249): These are the attributes which should be defined in XML, that are required for this interaction view to work correctly
// hint="Write here."
// inputType="text"
// background="@drawable/edit_text_background"
// maxLength="200".

/** The custom EditText class for text input interaction view. */
class TextInputInteractionView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyle: Int = android.R.attr.editTextStyle
) : EditText(context, attrs, defStyle), InteractionAnswerRetriever {

override fun getPendingAnswer(): InteractionObject {
val interactionObjectBuilder = InteractionObject.newBuilder()
if (!text.isNullOrEmpty()) {
interactionObjectBuilder.normalizedString = text.toString()
}
return interactionObjectBuilder.build()
}
}
34 changes: 34 additions & 0 deletions app/src/main/java/org/oppia/app/parser/StringToFractionParser.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.oppia.app.parser

import org.oppia.app.model.Fraction

/** This class contains method that helps to parse string to fraction. */
class StringToFractionParser {
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()
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package org.oppia.app.activity
package org.oppia.app.testing

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import org.oppia.app.R
import org.oppia.app.customview.interaction.NumericInputInteractionView
import org.oppia.app.customview.interaction.TextInputInteractionView
import org.oppia.app.customview.interaction.FractionInputInteractionView

/**
* This is a dummy activity to test input interaction views.
* It contains [NumericInputInteractionView] .
* It contains [NumericInputInteractionView], [TextInputInteractionView] and [FractionInputInteractionView].
*/
class InputInteractionViewTestActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context=".activity.InputInteractionViewTestActivity">
tools:context=".testing.InputInteractionViewTestActivity">

<org.oppia.app.customview.interaction.NumericInputInteractionView
android:id="@+id/test_number_input_interaction_view"
Expand All @@ -21,4 +21,31 @@
android:maxLength="200"
android:padding="8dp"
android:singleLine="true" />
<org.oppia.app.customview.interaction.TextInputInteractionView
android:id="@+id/test_text_input_interaction_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:background="@drawable/edit_text_background"
android:focusable="true"
android:hint="Write here."
android:inputType="text"
android:longClickable="false"
android:maxLength="200"
android:padding="8dp"
android:singleLine="true" />
<org.oppia.app.customview.interaction.FractionInputInteractionView
android:id="@+id/test_fraction_input_interaction_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:background="@drawable/edit_text_background"
android:focusable="true"
android:digits="0123456789/- "
android:hint="Write fraction here."
android:inputType="number"
android:longClickable="false"
android:maxLength="200"
android:padding="8dp"
android:singleLine="true" />
</LinearLayout>

This file was deleted.

Loading

0 comments on commit a37e090

Please sign in to comment.