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 #380: Hi fi input interaction views #405

Merged
merged 34 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
acf2610
nit
nikitamarysolomanpvt Nov 11, 2019
b760c44
UI hi-fi for text,number,and fraction input views
nikitamarysolomanpvt Nov 11, 2019
deaa102
UI hi-fi for text,number,and fraction input views
nikitamarysolomanpvt Nov 11, 2019
5f30564
UI hi-fi for text,number,and fraction input views nit
nikitamarysolomanpvt Nov 12, 2019
8484f34
nit
nikitamarysolomanpvt Nov 12, 2019
33e1232
nit
nikitamarysolomanpvt Nov 12, 2019
d108ff0
test cases update
nikitamarysolomanpvt Nov 13, 2019
fc2355f
accent color
nikitamarysolomanpvt Nov 13, 2019
adc0fbf
input type in fraction input type
nikitamarysolomanpvt Nov 13, 2019
e0a7c5a
input type in fraction input type
nikitamarysolomanpvt Nov 13, 2019
47b7aad
Merge branches 'develop' and 'hi-fi-input-interaction-views' of https…
nikitamarysolomanpvt Nov 13, 2019
1e3ed3a
Merge branches 'develop' and 'hi-fi-input-interaction-views' of https…
nikitamarysolomanpvt Nov 13, 2019
fe0f1d8
text color in input type views
nikitamarysolomanpvt Nov 13, 2019
8a489a0
changed inputtype in edit text
nikitamarysolomanpvt Nov 13, 2019
0eff2ef
margin updated in input views
nikitamarysolomanpvt Nov 14, 2019
9d8f704
margin updated in input views
nikitamarysolomanpvt Nov 14, 2019
b429ec8
nit
nikitamarysolomanpvt Nov 18, 2019
9981d81
keyboardhelper to handle softinoutkeyboard
nikitamarysolomanpvt Nov 18, 2019
321facd
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
nikitamarysolomanpvt Nov 18, 2019
ef864b2
Edit text focus removed.
nikitamarysolomanpvt Nov 18, 2019
70d4c73
as per review suggestion added binding.stateRecyclerView.smoothScroll…
nikitamarysolomanpvt Nov 18, 2019
6d01b40
nit
nikitamarysolomanpvt Nov 18, 2019
8289c5e
Fix-406
Nov 18, 2019
900d248
nit changes and keybord helper class renamed.
nikitamarysolomanpvt Nov 18, 2019
4c6a0db
Merge branches 'fix-406' and 'hi-fi-input-interaction-views' of https…
nikitamarysolomanpvt Nov 18, 2019
1c94120
nit
nikitamarysolomanpvt Nov 19, 2019
8e88592
merged with develop, inputviews test cases fix
nikitamarysolomanpvt Nov 19, 2019
f9f5149
kdoc for keyboardhelper.nit changes
nikitamarysolomanpvt Nov 19, 2019
7922ce3
kdoc for keyboardhelper
nikitamarysolomanpvt Nov 19, 2019
c288193
nit
nikitamarysolomanpvt Nov 19, 2019
16ed76d
nit
nikitamarysolomanpvt Nov 19, 2019
03ddc53
Merge branches 'develop' and 'hi-fi-input-interaction-views' of https…
nikitamarysolomanpvt Nov 19, 2019
9984a6d
nit
nikitamarysolomanpvt Nov 19, 2019
fbfb1c0
nit
nikitamarysolomanpvt Nov 19, 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ package org.oppia.app.customview.interaction
import android.content.Context
import android.graphics.Typeface
import android.util.AttributeSet
import android.view.KeyEvent
import android.view.KeyEvent.ACTION_UP
import android.view.KeyEvent.KEYCODE_BACK
import android.view.View
import android.widget.EditText
import org.oppia.app.utility.KeyboardHelper.Companion.hideSoftKeyboard
import org.oppia.app.utility.KeyboardHelper.Companion.showSoftKeyboard

// TODO(#249): These are the attributes which should be defined in XML, that are required for this interaction view to work correctly
// digits="0123456789/-"
Expand All @@ -26,11 +31,19 @@ class FractionInputInteractionView @JvmOverloads constructor(
hintText = hint.toString()
}

override fun onFocusChange(v: View?, hasFocus: Boolean) = if (hasFocus) {
override fun onFocusChange(v: View, hasFocus: Boolean) = if (hasFocus) {
hint = ""
typeface = Typeface.DEFAULT
showSoftKeyboard(v, context)
} else {
hint = hintText
setTypeface(typeface, Typeface.ITALIC)
if (text.isEmpty()) setTypeface(typeface, Typeface.ITALIC)
hideSoftKeyboard(v, context)
}

override fun onKeyPreIme(keyCode: Int, event: KeyEvent): Boolean {
if (event.keyCode == KEYCODE_BACK && event.action == ACTION_UP)
this.clearFocus()
return super.onKeyPreIme(keyCode, event)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ package org.oppia.app.customview.interaction
import android.content.Context
import android.graphics.Typeface
import android.util.AttributeSet
import android.view.KeyEvent
import android.view.KeyEvent.ACTION_UP
import android.view.KeyEvent.KEYCODE_BACK
import android.view.View
import android.widget.EditText
import org.oppia.app.utility.KeyboardHelper.Companion.hideSoftKeyboard
import org.oppia.app.utility.KeyboardHelper.Companion.showSoftKeyboard

// TODO(#249): These are the attributes which should be defined in XML, that are required for this interaction view to work correctly
// digits="0123456789."
Expand All @@ -26,11 +31,20 @@ class NumericInputInteractionView @JvmOverloads constructor(
hintText = hint.toString()
}

override fun onFocusChange(v: View?, hasFocus: Boolean) = if (hasFocus) {
override fun onFocusChange(v: View, hasFocus: Boolean) = if (hasFocus) {
hint = ""
typeface = Typeface.DEFAULT
showSoftKeyboard(v, context)
} else {
hint = hintText
setTypeface(typeface, Typeface.ITALIC)
if (text.isEmpty()) setTypeface(typeface, Typeface.ITALIC)
hideSoftKeyboard(v, context)
}

override fun onKeyPreIme(keyCode: Int, event: KeyEvent): Boolean {
if (event.keyCode == KEYCODE_BACK && event.action == ACTION_UP)
this.clearFocus()
return super.onKeyPreIme(keyCode, event)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package org.oppia.app.customview.interaction
import android.content.Context
import android.graphics.Typeface
import android.util.AttributeSet
import android.view.KeyEvent
import android.view.View
import android.widget.EditText
import org.oppia.app.utility.KeyboardHelper.Companion.hideSoftKeyboard
import org.oppia.app.utility.KeyboardHelper.Companion.showSoftKeyboard

// 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."
Expand All @@ -25,11 +28,20 @@ class TextInputInteractionView @JvmOverloads constructor(
hintText = hint.toString()
}

override fun onFocusChange(v: View?, hasFocus: Boolean) = if (hasFocus) {
override fun onFocusChange(v: View, hasFocus: Boolean) = if (hasFocus) {
hint = ""
typeface = Typeface.DEFAULT
showSoftKeyboard(v, context)
} else {
hint = hintText
setTypeface(typeface, Typeface.ITALIC)
if (text.isEmpty()) setTypeface(typeface, Typeface.ITALIC)
hideSoftKeyboard(v, context)
}

override fun onKeyPreIme(keyCode: Int, event: KeyEvent): Boolean {
if (event.keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_UP)
this.clearFocus()
return super.onKeyPreIme(keyCode, event)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ class StateFragmentPresenter @Inject constructor(
}

val ephemeralState = result.getOrThrow()

val scrollToTop = ::currentStateName.isInitialized && currentStateName != ephemeralState.state.name

currentStateName = ephemeralState.state.name
val pendingItemList = mutableListOf<StateItemViewModel>()
addContentItem(pendingItemList, ephemeralState)
Expand Down Expand Up @@ -315,6 +318,10 @@ class StateFragmentPresenter @Inject constructor(

viewModel.itemList.clear()
viewModel.itemList += pendingItemList

if (scrollToTop) {
binding.stateRecyclerView.smoothScrollToPosition(0)
}
}

/**
Expand Down
32 changes: 32 additions & 0 deletions app/src/main/java/org/oppia/app/utility/KeyboardHelper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.oppia.app.utility

import android.content.Context
import android.view.View
import android.view.inputmethod.InputMethodManager

/** KeyboardHelper helps to change the visibility of softinputkeybord. */
class KeyboardHelper {
companion object {
/**
* This method hides softinputkeybord
* @param view is the input view
* @param context context of the activity
*/
fun hideSoftKeyboard(view: View, context: Context) {
nikitamarysolomanpvt marked this conversation as resolved.
Show resolved Hide resolved
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(view.windowToken, InputMethodManager.HIDE_IMPLICIT_ONLY)
}

/**
* This method shows softinputkeybord
* @param view is the input view
* @param context context of the activity
*/
fun showSoftKeyboard(view: View, context: Context) {
if (view.requestFocus()) {
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@
<variable
name="numericInputViewModel"
type="org.oppia.app.player.state.itemviewmodel.NumericInputViewModel" />
<variable
name="textInputViewModel"
type="org.oppia.app.player.state.itemviewmodel.TextInputViewModel" />
<variable
name="fractionInteractionViewModel"
type="org.oppia.app.player.state.itemviewmodel.FractionInteractionViewModel" />
</data>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="vertical"
tools:context=".testing.InputInteractionViewTestActivity">

Expand Down Expand Up @@ -42,6 +50,7 @@
android:focusable="true"
android:hint="Write here."
android:inputType="text"
android:text="@={textInputViewModel.answerText}"
android:longClickable="false"
android:maxLength="200"
android:padding="8dp"
Expand All @@ -54,6 +63,7 @@
android:layout_margin="8dp"
android:background="@drawable/edit_text_background"
android:digits="0123456789/- "
android:text="@={fractionInteractionViewModel.answerText}"
android:focusable="true"
android:hint="Write fraction here."
android:inputType="date"
Expand Down
72 changes: 32 additions & 40 deletions app/src/main/res/layout/fraction_interaction_item.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<layout xmlns:android="http://schemas.android.com/apk/res/android">

<data>

Expand All @@ -9,46 +8,39 @@
type="org.oppia.app.player.state.itemviewmodel.FractionInteractionViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:layout_marginStart="28dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="28dp"
android:layout_marginBottom="24dp"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="vertical">

<FrameLayout
<org.oppia.app.customview.interaction.FractionInputInteractionView
android:id="@+id/fraction_input_interaction_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginBottom="24dp"
android:layout_marginStart="28dp"
android:layout_marginEnd="28dp"
android:background="@color/oppiaLightGreen"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent">

<org.oppia.app.customview.interaction.FractionInputInteractionView
android:id="@+id/fraction_input_interaction_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/edit_text_background"
android:digits="0123456789/- "
android:enabled="@{!viewModel.isReadOnly}"
android:focusable="true"
android:fontFamily="sans-serif"
android:hint="@string/fractions_hint_text"
android:imeOptions="actionDone"
android:inputType="date"
android:longClickable="false"
android:maxLength="200"
android:minHeight="48dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingBottom="8dp"
android:singleLine="true"
android:text="@={viewModel.answerText}"
android:textColor="@color/oppiaPrimaryText"
android:textColorHint="@color/edit_text_hint"
android:textSize="16sp"
android:textStyle="italic" />
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
android:background="@drawable/edit_text_background"
android:digits="0123456789/- "
android:enabled="@{!viewModel.isReadOnly}"
android:fontFamily="sans-serif"
android:hint="@string/fractions_hint_text"
android:imeOptions="actionDone"
android:inputType="date"
android:longClickable="false"
android:maxLength="200"
android:minHeight="48dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingBottom="8dp"
android:singleLine="true"
android:text="@={viewModel.answerText}"
android:textColor="@color/oppiaPrimaryText"
android:textColorHint="@color/edit_text_hint"
android:textSize="16sp"
android:textStyle="italic" />
</FrameLayout>
</layout>
11 changes: 6 additions & 5 deletions app/src/main/res/layout/numeric_input_interaction_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginBottom="24dp"
android:layout_marginStart="28dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="28dp"
android:layout_marginBottom="24dp"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="vertical">

<org.oppia.app.customview.interaction.NumericInputInteractionView
Expand All @@ -23,21 +25,20 @@
android:layout_height="wrap_content"
android:background="@drawable/edit_text_background"
android:digits="0123456789."
android:textColor="@color/oppiaPrimaryText"
android:enabled="@{!viewModel.isReadOnly}"
android:focusable="true"
android:fontFamily="sans-serif"
android:hint="@string/number_input_hint_text"
android:imeOptions="actionDone"
android:inputType="numberDecimal"
android:longClickable="false"
android:imeOptions="actionDone"
android:maxLength="200"
android:minHeight="48dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingBottom="8dp"
android:singleLine="true"
android:text="@={viewModel.answerText}"
android:textColor="@color/oppiaPrimaryText"
android:textColorHint="@color/edit_text_hint"
android:textSize="16sp"
android:textStyle="italic" />
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/res/layout/text_input_interaction_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginBottom="24dp"
android:layout_marginStart="28dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="28dp"
android:background="@color/oppiaLightGreen"
android:layout_marginBottom="24dp"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="vertical">

<org.oppia.app.customview.interaction.TextInputInteractionView
Expand All @@ -24,20 +25,19 @@
android:layout_height="wrap_content"
android:background="@drawable/edit_text_background"
android:enabled="@{!viewModel.isReadOnly}"
android:textColor="@color/oppiaPrimaryText"
android:focusable="true"
android:fontFamily="sans-serif"
android:hint="@string/text_input_hint_text"
android:imeOptions="actionDone"
android:inputType="text"
android:longClickable="false"
android:maxLength="200"
android:minHeight="48dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingBottom="8dp"
android:imeOptions="actionDone"
android:singleLine="true"
android:text="@={viewModel.answerText}"
android:textColor="@color/oppiaPrimaryText"
android:textColorHint="@color/edit_text_hint"
android:textSize="16sp"
android:textStyle="italic" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CellularDataDialogFragmentTest {
@Test
fun testCellularDataDialogFragment_loadCellularDialogFragment_clickOkButton_audioFragmentIsDisplayed() {
ActivityScenario.launch(StateFragmentTestActivity::class.java).use {
onView(withId(R.id.enable_audio_playback_button)).perform(click())
onView(withId(R.id.action_audio_player)).perform(click())
onView(withText(R.string.cellular_data_alert_dialog_title)).check(matches(isDisplayed()))
onView(withText(R.string.cellular_data_alert_dialog_okay_button)).perform(click())
onView(withId(R.id.ivPlayPauseAudio)).check(matches(isDisplayed()))
Expand All @@ -42,7 +42,7 @@ class CellularDataDialogFragmentTest {
@Test
fun testCellularDataDialogFragment_loadCellularDialogFragment_clickCancelButton_audioFragmentIsNotDisplayed() {
ActivityScenario.launch(StateFragmentTestActivity::class.java).use {
onView(withId(R.id.enable_audio_playback_button)).perform(click())
onView(withId(R.id.action_audio_player)).perform(click())
onView(withText(R.string.cellular_data_alert_dialog_title)).check(matches(isDisplayed()))
onView(withText(R.string.cellular_data_alert_dialog_cancel_button)).perform(click())
onView(withId(R.id.ivPlayPauseAudio)).check(doesNotExist())
Expand Down
Loading