Skip to content

Commit

Permalink
Merge branch 'develop' into oppia#4419
Browse files Browse the repository at this point in the history
  • Loading branch information
adhiamboperes authored Oct 4, 2024
2 parents 4da3aa1 + 20c4cad commit 455134c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.oppia.android.app.settings.profile
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.OnBackPressedCallback
import org.oppia.android.app.activity.ActivityComponentImpl
import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity
import org.oppia.android.app.model.ProfileEditActivityParams
Expand Down Expand Up @@ -43,17 +44,25 @@ class ProfileEditActivity : InjectableAutoLocalizedAppCompatActivity() {
super.onCreate(savedInstanceState)
(activityComponent as ActivityComponentImpl).inject(this)
profileEditActivityPresenter.handleOnCreate()

onBackPressedDispatcher.addCallback(
this,
object : OnBackPressedCallback(/* enabled = */ true) {
override fun handleOnBackPressed() {
this@ProfileEditActivity.handleBackPress()
}
}
)
}

override fun onBackPressed() {
private fun handleBackPress() {
val args = intent.getProtoExtra(
PROFILE_EDIT_ACTIVITY_PARAMS_KEY,
ProfileEditActivityParams.getDefaultInstance()
)
val isMultipane = args?.isMultipane ?: false
if (isMultipane) {
@Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher.
super.onBackPressed()
finish()
} 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 @@ -31,8 +31,7 @@ class ProfileEditActivityPresenter @Inject constructor(

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 @@ -3,6 +3,7 @@ package org.oppia.android.app.topic.questionplayer
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.OnBackPressedCallback
import org.oppia.android.app.activity.ActivityComponentImpl
import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity
import org.oppia.android.app.hintsandsolution.HintsAndSolutionListener
Expand Down Expand Up @@ -56,11 +57,16 @@ class QuestionPlayerActivity :
val profileId =
intent.extractCurrentUserProfileId()
questionPlayerActivityPresenter.handleOnCreate(profileId)
}

override fun onBackPressed() {
showStopExplorationDialogFragment()
questionPlayerActivityPresenter.setReadingTextSizeNormal()
onBackPressedDispatcher.addCallback(
this,
object : OnBackPressedCallback(/* enabled = */ true) {
override fun handleOnBackPressed() {
showStopExplorationDialogFragment()
questionPlayerActivityPresenter.setReadingTextSizeNormal()
}
}
)
}

override fun restartSession() = questionPlayerActivityPresenter.restartSession()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,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()
}

retrieveReadingTextSize().observe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.oppia.android.app.walkthrough
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.OnBackPressedCallback
import org.oppia.android.app.activity.ActivityComponentImpl
import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity
import org.oppia.android.app.model.ProfileId
Expand All @@ -22,6 +23,15 @@ class WalkthroughActivity :
super.onCreate(savedInstanceState)
(activityComponent as ActivityComponentImpl).inject(this)
walkthroughActivityPresenter.handleOnCreate()

onBackPressedDispatcher.addCallback(
this,
object : OnBackPressedCallback(/* enabled = */ true) {
override fun handleOnBackPressed() {
walkthroughActivityPresenter.handleSystemBack()
}
}
)
}

override fun currentPage(walkthroughPage: Int) {
Expand All @@ -33,10 +43,6 @@ class WalkthroughActivity :
walkthroughActivityPresenter.changePage(walkthroughPage)
}

override fun onBackPressed() {
walkthroughActivityPresenter.handleSystemBack()
}

companion object {

fun createWalkthroughActivityIntent(context: Context, internalProfileId: Int): Intent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,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 455134c

Please sign in to comment.