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 #151: Lowfi numeric input interaction view part 2 #223

Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
faca25a
NumberInputInteractionView dynamically created on state interaction i…
nikitamarysolomanpvt Oct 9, 2019
c9b5919
NumberInputInteractionView dynamically created on state interaction i…
nikitamarysolomanpvt Oct 10, 2019
6235dfb
added fetch button, and fetch textview to fetch the data from dynamic…
nikitamarysolomanpvt Oct 10, 2019
3ab9ae3
nit changes
nikitamarysolomanpvt Oct 10, 2019
ceb27a4
nit changes
nikitamarysolomanpvt Oct 10, 2019
6b3daed
nit changes
nikitamarysolomanpvt Oct 10, 2019
b0fa8b4
nit changes
nikitamarysolomanpvt Oct 10, 2019
ce34219
nit changes
nikitamarysolomanpvt Oct 10, 2019
6755d5c
numericInputTypeView test case is in progress
nikitamarysolomanpvt Oct 11, 2019
acff28d
numericInputTypeView test case is in progress
nikitamarysolomanpvt Oct 11, 2019
7fb5ea4
nit changes as per #223
nikitamarysolomanpvt Oct 11, 2019
ba3be9b
nit changes as per #223
nikitamarysolomanpvt Oct 11, 2019
b474a73
On configuration changes save and restore the text of numericInputType
nikitamarysolomanpvt Oct 11, 2019
fc60566
Test Cases for NumericInputInteractionView,
nikitamarysolomanpvt Oct 11, 2019
9e5dc2e
Test Cases for NumericInputInteractionView,
nikitamarysolomanpvt Oct 14, 2019
a7ef482
PR suggestions updated
nikitamarysolomanpvt Oct 14, 2019
69b0b8c
PR suggestions updated
nikitamarysolomanpvt Oct 14, 2019
3578a0c
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
nikitamarysolomanpvt Oct 14, 2019
e7a6411
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
nikitamarysolomanpvt Oct 14, 2019
5d1c769
nit changes as per PR review
nikitamarysolomanpvt Oct 14, 2019
ed31dd5
nit changes as per PR review
nikitamarysolomanpvt Oct 14, 2019
65c41ca
nit changes as per PR review
nikitamarysolomanpvt Oct 15, 2019
5d4db81
nit changes as per PR review
nikitamarysolomanpvt Oct 15, 2019
fed8c7f
Number input test Activity test cases
nikitamarysolomanpvt Oct 15, 2019
ac13a74
nit changes
nikitamarysolomanpvt Oct 15, 2019
cce10c1
nit changes
nikitamarysolomanpvt Oct 15, 2019
41650b4
nit changes
nikitamarysolomanpvt Oct 15, 2019
0664bc6
nit changes
nikitamarysolomanpvt Oct 15, 2019
f55b8a8
nit changes
nikitamarysolomanpvt Oct 15, 2019
e652e42
nit changes
nikitamarysolomanpvt Oct 15, 2019
30f7ce0
nit changes
nikitamarysolomanpvt Oct 15, 2019
1737a33
nit changes
nikitamarysolomanpvt Oct 15, 2019
9920380
nit changes
nikitamarysolomanpvt Oct 15, 2019
7b86a0c
nit changes
nikitamarysolomanpvt Oct 15, 2019
46d37e6
nit changes
nikitamarysolomanpvt Oct 15, 2019
107e154
setReal type in getPendingAnswer
nikitamarysolomanpvt Oct 16, 2019
b7a406f
updated test cases, disabled long click to prevent pasting value
nikitamarysolomanpvt Oct 16, 2019
3b6c56d
nit changes
nikitamarysolomanpvt Oct 16, 2019
3b7a01f
Merge branches 'develop' and 'text-input-lowfi-numeric-input-interact…
nikitamarysolomanpvt Oct 16, 2019
326d3a9
nit changes
nikitamarysolomanpvt Oct 16, 2019
3aa6724
nit changes
nikitamarysolomanpvt Oct 16, 2019
7f51265
nit changes
nikitamarysolomanpvt Oct 16, 2019
a3cbe65
nit changes
nikitamarysolomanpvt Oct 16, 2019
6c18922
nit changes
nikitamarysolomanpvt Oct 16, 2019
eda21ad
nit changes
nikitamarysolomanpvt Oct 16, 2019
b72961c
nit changes
nikitamarysolomanpvt Oct 16, 2019
ade8a73
nit changes
nikitamarysolomanpvt Oct 16, 2019
0f033d9
NumericInputInteractionViewTestActivity renamed to InputInteractionVi…
nikitamarysolomanpvt Oct 16, 2019
b4fc329
nit changes
nikitamarysolomanpvt Oct 16, 2019
966f84d
nit changes
nikitamarysolomanpvt Oct 16, 2019
0b82bbf
nit changes
nikitamarysolomanpvt Oct 17, 2019
719a4db
nit
nikitamarysolomanpvt Oct 18, 2019
dd9163b
NumericInputInteractionView attributes are moved to xml,testcases upd…
nikitamarysolomanpvt Oct 18, 2019
910ec00
NumericInputInteractionView attributes are moved to xml,testcases upd…
nikitamarysolomanpvt Oct 18, 2019
d20c12e
TextInputInteractionView
nikitamarysolomanpvt Oct 18, 2019
2bc3292
TextInputInteractionView
nikitamarysolomanpvt Oct 19, 2019
61abbe9
nit
nikitamarysolomanpvt Oct 20, 2019
38d8e14
nit
nikitamarysolomanpvt Oct 20, 2019
9dae69d
nit
nikitamarysolomanpvt Oct 20, 2019
1c1e4cb
nit
nikitamarysolomanpvt Oct 20, 2019
16d4543
nit
nikitamarysolomanpvt Oct 21, 2019
fb2c026
nit
nikitamarysolomanpvt Oct 21, 2019
d729e43
nit
nikitamarysolomanpvt Oct 21, 2019
f27c017
nit
nikitamarysolomanpvt Oct 21, 2019
13a2013
Merge branches 'develop' and 'text-input-lowfi-numeric-input-interact…
nikitamarysolomanpvt Oct 21, 2019
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
18 changes: 8 additions & 10 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 17 additions & 17 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.oppia.app">
<uses-permission android:name="android.permission.INTERNET"/>
package="org.oppia.app">

<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".application.OppiaApplication"
android:allowBackup="true"
Expand All @@ -10,27 +11,26 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/OppiaTheme">
<activity android:name="org.oppia.app.topic.conceptcard.testing.ConceptCardFragmentTestActivity"/>
<activity android:name="org.oppia.app.player.state.testing.StateFragmentTestActivity"/>
<activity android:name=".player.exploration.ExplorationActivity"/>
<activity android:name=".topic.questionplayer.QuestionPlayerActivity"/>
<activity android:name=".topic.TopicActivity"/>
<activity android:name=".player.audio.testing.AudioFragmentTestActivity"/>
<activity android:name="org.oppia.app.player.state.testing.StateFragmentTestActivity"/>
<activity android:name="org.oppia.app.home.HomeActivity">
<activity android:name="org.oppia.app.topic.conceptcard.testing.ConceptCardFragmentTestActivity" />
<activity android:name="org.oppia.app.player.state.testing.StateFragmentTestActivity" />
<activity android:name=".player.exploration.ExplorationActivity" />
<activity android:name=".topic.questionplayer.QuestionPlayerActivity" />
<activity android:name=".topic.TopicActivity" />
<activity android:name=".player.audio.testing.AudioFragmentTestActivity" />
<activity android:name="org.oppia.app.home.HomeActivity" />
<activity android:name=".activity.InputInteractionViewTestActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".splash.SplashActivity"
android:theme="@style/SplashScreenTheme">
</activity>
<activity android:name=".testing.BindableAdapterTestActivity"/>
android:theme="@style/SplashScreenTheme"></activity>
<activity android:name=".testing.BindableAdapterTestActivity" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.oppia.app.activity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import org.oppia.app.R
import org.oppia.app.customview.inputInteractionView.NumericInputInteractionView

private const val KEY_DIGIT_ID = "DIGIT_ID"

/** This is a dummy activity to test [NumericInputInteractionView]. */
class InputInteractionViewTestActivity : AppCompatActivity() {
private lateinit var digit: String
private lateinit var contentComponent: NumericInputInteractionView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_numeric_input_interaction_view_test)
contentComponent = findViewById(R.id.test_number_input_interaction_view) as NumericInputInteractionView
if (savedInstanceState != null) {
digit = savedInstanceState.getString(KEY_DIGIT_ID)
} else {
digit = ""
}
contentComponent.setText(digit)
nikitamarysolomanpvt marked this conversation as resolved.
Show resolved Hide resolved
}

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putString(KEY_DIGIT_ID, getNumberTextInputText())
}

fun getNumberTextInputText(): String {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be returning a double since number input are reals?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's removed it was just for saving state for configuration change

return contentComponent.getPendingAnswer().normalizedString
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.oppia.app.customview.inputInteractionView

import org.oppia.app.model.InteractionObject

/** This interface helps to get PendingAnswer of [NumericInputInteractionView]. */
interface InteractionAnswerRetriever {
fun getPendingAnswer(): InteractionObject
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.oppia.app.customview.inputInteractionView
nikitamarysolomanpvt marked this conversation as resolved.
Show resolved Hide resolved

import android.content.Context
import android.text.InputFilter
import android.text.method.DigitsKeyListener
import android.util.AttributeSet
import android.widget.EditText
import org.oppia.app.R
import org.oppia.app.model.InteractionObject

/** The custom EditText class for numeric input interaction view. */
class NumericInputInteractionView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyle: Int = android.R.attr.editTextStyle
, private var placeholder: String = "Write the digit here."
nikitamarysolomanpvt marked this conversation as resolved.
Show resolved Hide resolved
) : EditText(context, attrs, defStyle), InteractionAnswerRetriever {
init {
attributes()
}

constructor(context: Context?, placeholder: String) : this(context!!) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this constructor.
It is safe to remove this constructor now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is created for dynamically creating the view . In this sample code we are using xml to create them, whereas we would be using this constructor for dynamically creating the view. If you use default constructor you need to pass many more parameters, in order to avoid that this constructor is created.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to dynamically create the view? I wouldn't expect that since we're inflating it using LayoutInflater rather than directly constructing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per the interaction model we need to dynamically (programmatically )add view isn’t ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

this.placeholder = placeholder
attributes()
}

/** This function contains default attributes of [NumericInputInteractionView]. */
private fun attributes() {
nikitamarysolomanpvt marked this conversation as resolved.
Show resolved Hide resolved
setBackgroundResource(R.drawable.edit_text_background)
val paddingPixel = context.resources.getDimension(R.dimen.padding_8)
val density = resources.displayMetrics.density
val paddingDp = (paddingPixel * density).toInt()
setPadding(paddingDp, paddingDp, paddingDp, paddingDp)
hint = placeholder
keyListener = DigitsKeyListener.getInstance("0123456789.")
this.setEditTextMaxLength(length = 200)
setLongClickable(false)
nikitamarysolomanpvt marked this conversation as resolved.
Show resolved Hide resolved
}

private fun setEditTextMaxLength(length: Int) {
nikitamarysolomanpvt marked this conversation as resolved.
Show resolved Hide resolved
val filterArray = arrayOfNulls<InputFilter>(1)
filterArray[0] = InputFilter.LengthFilter(length)
filters = filterArray
}

override fun getPendingAnswer(): InteractionObject {
if (text.isEmpty()) {
return InteractionObject.newBuilder().build()
} else {
return InteractionObject.newBuilder().setReal(text.toString().toDouble()).build()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.InputInteractionViewTestActivity">

<org.oppia.app.customview.inputInteractionView.NumericInputInteractionView
android:id="@+id/test_number_input_interaction_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/padding_8"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this just be 8dp?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package org.oppia.app.activity

import android.app.Activity
import android.content.Intent
import android.content.pm.ActivityInfo
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import org.junit.Assert.*
nikitamarysolomanpvt marked this conversation as resolved.
Show resolved Hide resolved
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.oppia.app.R
import org.oppia.app.model.InteractionObject
import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withText
import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.Matchers.instanceOf
import org.oppia.app.customview.inputInteractionView.NumericInputInteractionView

/** Tests for [InputInteractionViewTestActivity]. */
@RunWith(AndroidJUnit4::class)
class InputInteractionViewTestActivityTest {
nikitamarysolomanpvt marked this conversation as resolved.
Show resolved Hide resolved
private lateinit var launchedActivity: Activity
@get:Rule
var activityTestRule: ActivityTestRule<InputInteractionViewTestActivity> = ActivityTestRule(
InputInteractionViewTestActivity::class.java, /* initialTouchMode= */ true, /* launchActivity= */ false
)

@Test
fun testNumericInputInteractionView_withNoInputText_hasCorrectPendingAnswerType() {
nikitamarysolomanpvt marked this conversation as resolved.
Show resolved Hide resolved
val activityScenario = ActivityScenario.launch(InputInteractionViewTestActivity::class.java)
activityScenario.onActivity { activity ->
val textAnswerRetriever =
activity.findViewById(R.id.test_number_input_interaction_view) as NumericInputInteractionView
assertThat(textAnswerRetriever.getPendingAnswer(), instanceOf(InteractionObject::class.java))
}
}

@Test
fun testNumericInputInteractionView_withInputtedText_hasCorrectPendingAnswer() {
val activityScenario = ActivityScenario.launch(InputInteractionViewTestActivity::class.java)
onView(withId(R.id.test_number_input_interaction_view)).perform(ViewActions.clearText(), ViewActions.typeText("9"))
activityScenario.onActivity { activity ->
val textAnswerRetriever =
activity.findViewById(R.id.test_number_input_interaction_view) as NumericInputInteractionView
assertEquals(textAnswerRetriever.getPendingAnswer().objectTypeCase, InteractionObject.ObjectTypeCase.REAL)
assertThat(textAnswerRetriever.getPendingAnswer().real, `is`("9".toDouble()))
nikitamarysolomanpvt marked this conversation as resolved.
Show resolved Hide resolved
}
}

@Test
fun testNumericInputInteractionView_withInputtedText_hasCorrectPendingAnswerWithDecimalValues() {
val activityScenario = ActivityScenario.launch(InputInteractionViewTestActivity::class.java)
onView(withId(R.id.test_number_input_interaction_view)).perform(
ViewActions.clearText(),
nikitamarysolomanpvt marked this conversation as resolved.
Show resolved Hide resolved
ViewActions.typeText("9.5")
nikitamarysolomanpvt marked this conversation as resolved.
Show resolved Hide resolved
)
activityScenario.onActivity { activity ->
val textAnswerRetriever =
activity.findViewById(R.id.test_number_input_interaction_view) as NumericInputInteractionView
assertEquals(textAnswerRetriever.getPendingAnswer().objectTypeCase, InteractionObject.ObjectTypeCase.REAL)
assertThat(textAnswerRetriever.getPendingAnswer().real, `is`(9.5))
}
}

@Test
fun testNumericInputInteractionView_withInputtedText_onConfigurationChange_hasCorrectPendingAnswer() {
Intents.init()
val intent = Intent(Intent.ACTION_PICK)
launchedActivity = activityTestRule.launchActivity(intent)
onView(withId(R.id.test_number_input_interaction_view)).perform(ViewActions.clearText(), ViewActions.typeText("9"))
activityTestRule.activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
activityTestRule.activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't sufficient to trigger a configuration change. We can use ActivityScenario.recreate() for this purpose. The orientation change actually may not be needed; recreate may be enough to fully recreate the activity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikitamarysolomanpvt Check TopicTrainFragmentTest file you can do this similarly here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its pending

onView(withId(R.id.test_number_input_interaction_view)).check(matches(isDisplayed())).check(matches(withText("9")))
Intents.release()
nikitamarysolomanpvt marked this conversation as resolved.
Show resolved Hide resolved
}
}