diff --git a/app/src/main/java/org/oppia/app/customview/interaction/FractionInputInteractionView.kt b/app/src/main/java/org/oppia/app/customview/interaction/FractionInputInteractionView.kt index 7c0b83de37b..6227a99f868 100644 --- a/app/src/main/java/org/oppia/app/customview/interaction/FractionInputInteractionView.kt +++ b/app/src/main/java/org/oppia/app/customview/interaction/FractionInputInteractionView.kt @@ -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/-" @@ -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) } } diff --git a/app/src/main/java/org/oppia/app/customview/interaction/NumericInputInteractionView.kt b/app/src/main/java/org/oppia/app/customview/interaction/NumericInputInteractionView.kt index 1d75c280bcb..dcfc801f681 100644 --- a/app/src/main/java/org/oppia/app/customview/interaction/NumericInputInteractionView.kt +++ b/app/src/main/java/org/oppia/app/customview/interaction/NumericInputInteractionView.kt @@ -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." @@ -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) } } + diff --git a/app/src/main/java/org/oppia/app/customview/interaction/TextInputInteractionView.kt b/app/src/main/java/org/oppia/app/customview/interaction/TextInputInteractionView.kt index e42ad974030..f23ddcb907e 100644 --- a/app/src/main/java/org/oppia/app/customview/interaction/TextInputInteractionView.kt +++ b/app/src/main/java/org/oppia/app/customview/interaction/TextInputInteractionView.kt @@ -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." @@ -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) } } + diff --git a/app/src/main/java/org/oppia/app/player/state/StateFragmentPresenter.kt b/app/src/main/java/org/oppia/app/player/state/StateFragmentPresenter.kt index 8c4b2d6178d..8875cce1866 100755 --- a/app/src/main/java/org/oppia/app/player/state/StateFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/app/player/state/StateFragmentPresenter.kt @@ -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() addContentItem(pendingItemList, ephemeralState) @@ -315,6 +318,10 @@ class StateFragmentPresenter @Inject constructor( viewModel.itemList.clear() viewModel.itemList += pendingItemList + + if (scrollToTop) { + binding.stateRecyclerView.smoothScrollToPosition(0) + } } /** diff --git a/app/src/main/java/org/oppia/app/utility/KeyboardHelper.kt b/app/src/main/java/org/oppia/app/utility/KeyboardHelper.kt new file mode 100644 index 00000000000..919627c4408 --- /dev/null +++ b/app/src/main/java/org/oppia/app/utility/KeyboardHelper.kt @@ -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) { + 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) + } + } + } +} diff --git a/app/src/main/res/layout/activity_numeric_input_interaction_view_test.xml b/app/src/main/res/layout/activity_numeric_input_interaction_view_test.xml index c6e0de4d05e..ea8b72e1078 100644 --- a/app/src/main/res/layout/activity_numeric_input_interaction_view_test.xml +++ b/app/src/main/res/layout/activity_numeric_input_interaction_view_test.xml @@ -7,12 +7,20 @@ + + @@ -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" @@ -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" diff --git a/app/src/main/res/layout/fraction_interaction_item.xml b/app/src/main/res/layout/fraction_interaction_item.xml index bd4d2b24b71..6879a999f2f 100644 --- a/app/src/main/res/layout/fraction_interaction_item.xml +++ b/app/src/main/res/layout/fraction_interaction_item.xml @@ -1,6 +1,5 @@ - + @@ -9,46 +8,39 @@ type="org.oppia.app.player.state.itemviewmodel.FractionInteractionViewModel" /> - + 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"> - - - - - + 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" /> + diff --git a/app/src/main/res/layout/numeric_input_interaction_item.xml b/app/src/main/res/layout/numeric_input_interaction_item.xml index bb893cb6073..c4e0f2474bc 100644 --- a/app/src/main/res/layout/numeric_input_interaction_item.xml +++ b/app/src/main/res/layout/numeric_input_interaction_item.xml @@ -11,10 +11,12 @@ diff --git a/app/src/main/res/layout/text_input_interaction_item.xml b/app/src/main/res/layout/text_input_interaction_item.xml index 08071d27016..5c0ec6b8893 100644 --- a/app/src/main/res/layout/text_input_interaction_item.xml +++ b/app/src/main/res/layout/text_input_interaction_item.xml @@ -11,11 +11,12 @@ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index cfbed0c986c..d90606f3101 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri Sep 13 18:15:04 IST 2019 +#Tue Nov 19 15:14:08 IST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip