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

Fixes a part of #2133: Prevent vanishing of input on configuration change. #5617

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
android:windowSoftInputMode="adjustResize" />
<activity
android:name=".app.profile.PinPasswordActivity"
android:configChanges="screenSize|orientation"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure whether this manifest change is required. Could you please explain the need?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks @adhiamboperes , I have tested without changing the manifest file but on configuration change changes does not persist as mentioned in the issue. I have tested many approaches like LiveData with the ViewModel but only this method could solve the issue.
Can you please suggest me any better approach so I can implement the same.

android:label="@string/pin_password_activity_title"
android:theme="@style/OppiaThemeWithoutActionBar"
android:windowSoftInputMode="adjustResize" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ class PinPasswordActivity :
override fun routeToSuccessDialog() {
pinPasswordActivityPresenter.handleRouteToSuccessDialog()
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
pinPasswordActivityPresenter.handleSaveInstanceState(outState)
}

override fun onRestoreInstanceState(outState: Bundle) {
super.onRestoreInstanceState(outState)
pinPasswordActivityPresenter.handleRestoreInstanceState(outState)
}

override fun onDestroy() {
super.onDestroy()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.oppia.android.app.profile

import android.os.Bundle
import android.text.method.PasswordTransformationMethod
import android.view.animation.AnimationUtils
import androidx.appcompat.app.AlertDialog
Expand Down Expand Up @@ -43,6 +44,7 @@ class PinPasswordActivityPresenter @Inject constructor(
private var profileId = ProfileId.getDefaultInstance()
private lateinit var alertDialog: AlertDialog
private var confirmedDeletion = false
private lateinit var binding: PinPasswordActivityBinding

fun handleOnCreate() {
val args = activity.intent.getProtoExtra(
Expand All @@ -54,7 +56,7 @@ class PinPasswordActivityPresenter @Inject constructor(
internalProfileId = args?.internalProfileId ?: -1
profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build()

val binding = DataBindingUtil.setContentView<PinPasswordActivityBinding>(
binding = DataBindingUtil.setContentView<PinPasswordActivityBinding>(
activity,
R.layout.pin_password_activity
)
Expand Down Expand Up @@ -247,6 +249,14 @@ class PinPasswordActivityPresenter @Inject constructor(
exitProcess(0)
}
}
fun handleSaveInstanceState(outState: Bundle) {
val enteredPin = binding.pinPasswordInputPinEditText.text.toString()
outState.putString("enteredPin", enteredPin)
}
Comment on lines +252 to +255
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are a couple of changes needed here in order to conform with Oppia Android coding patterns:

  1. We are nolonger using bundle functions such as getString(See Move all fragment arguments, activity intent extras, and saved instance state over to protos #4986). Instead, we are moving over to protos. e.g:
    outState.putProto( PINPASSWORD_ACTIVITY_STATE_KEY, args )
  2. We prefer using constants, such as PINPASSWORD_ACTIVITY_STATE_KEY, instead of string literals like "enteredPin".
  3. Go to arguments.proto, and add a new proto message for PinPasswordActivityStateBundle please look ad the code in that file for examples.

To retrieve the state, use:
outState.getProto( PINPASSWORD_ACTIVITY_STATE_KEY, pinPasswordActivityStateBundle.getDefaultInstance() )

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks @adhiamboperes , I'll implement the changes.

fun handleRestoreInstanceState(restoreInstanceState: Bundle) {
val restoredPin = restoreInstanceState.getString("enteredPin")
binding.pinPasswordInputPinEditText.setText(restoredPin)
}

private fun showSuccessDialog() {
AlertDialog.Builder(activity, R.style.OppiaAlertDialogTheme)
Expand Down
Loading