Skip to content

Commit

Permalink
Migrate from super.onBackPressed() to onBackPressedDispatcher.onBackP…
Browse files Browse the repository at this point in the history
…ressed()

- Replaced the deprecated super.onBackPressed() method with onBackPressedDispatcher.onBackPressed()
- Ensures compatibility with newer Android SDK versions
- Updated necessary activities and fragments to use the new back pressed dispatcher
- Verified that back navigation works correctly with the toolbar back arrow, system back button, and tablet-specific behaviors

Activities and fragments corrected:
- app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivity
- app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivityPresenter
- app/src/main/java/org/oppia/android/app/topic/questionplayer/QuestionPlayerActivityPresenter
- app/src/main/java/org/oppia/android/app/walkthrough/end/WalkthroughFinalFragmentPresenter

Fixes oppia#5404
  • Loading branch information
uphargaur committed Jun 22, 2024
1 parent dcde7b3 commit 0dc962c
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ class ProfileEditActivity : InjectableAutoLocalizedAppCompatActivity() {
override fun onBackPressed() {
val isMultipane = intent.extras!!.getBoolean(IS_MULTIPANE_EXTRA_KEY, false)
if (isMultipane) {
@Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher.
super.onBackPressed()
onBackPressedDispatcher.onBackPressed()
} else {
val intent = Intent(this, ProfileListActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ class ProfileEditActivityPresenter @Inject constructor(

val profileId = activity.intent.getIntExtra(PROFILE_EDIT_PROFILE_ID_EXTRA_KEY, 0)
val isMultipane = activity.intent.getBooleanExtra(IS_MULTIPANE_EXTRA_KEY, false)

toolbar.setNavigationOnClickListener {
if (isMultipane) {
@Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher.
activity.onBackPressed()
activity.onBackPressedDispatcher.onBackPressed()
} else {
val intent = Intent(activity, ProfileListActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ class QuestionPlayerActivityPresenter @Inject constructor(
activity.setSupportActionBar(binding.questionPlayerToolbar)

binding.questionPlayerToolbar.setNavigationOnClickListener {
@Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher.
activity.onBackPressed()
activity.onBackPressedDispatcher.onBackPressed()
}

if (getQuestionPlayerFragment() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ class WalkthroughFinalFragmentPresenter @Inject constructor(
}

override fun goBack() {
@Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher.
activity.onBackPressed()
activity.onBackPressedDispatcher.onBackPressed()
}
}

0 comments on commit 0dc962c

Please sign in to comment.