From dca38bf4df1da04f42fe55c5472d2486f3f8e867 Mon Sep 17 00:00:00 2001 From: Tejas-67 Date: Mon, 17 Jun 2024 00:07:37 +0530 Subject: [PATCH 01/11] refractored: ProfileEditActivity, ProfileEditActivityPresenter --- app/src/main/AndroidManifest.xml | 1 + .../settings/profile/ProfileEditActivity.kt | 41 +++++++++++++++---- .../profile/ProfileEditActivityPresenter.kt | 12 ++---- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 41d1ce55918..97a3e32beda 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -14,6 +14,7 @@ android:icon="@mipmap/launcher_icon" android:label="@string/app_name" android:supportsRtl="true" + android:enableOnBackInvokedCallback="true" android:theme="@style/OppiaTheme"> diff --git a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivity.kt b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivity.kt index 2e42ba5bbff..65c1a36876c 100644 --- a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivity.kt +++ b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivity.kt @@ -2,7 +2,9 @@ package org.oppia.android.app.settings.profile import android.content.Context import android.content.Intent +import android.os.Build import android.os.Bundle +import android.util.Log import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity import org.oppia.android.app.model.ScreenName.PROFILE_EDIT_ACTIVITY @@ -41,19 +43,44 @@ class ProfileEditActivity : InjectableAutoLocalizedAppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + onBackInvokedDispatcher.registerOnBackInvokedCallback(1000){ + Log.w("profile-edit", "dispatch") + val isMultipane: Boolean = intent.extras!!.getBoolean(IS_MULTIPANE_EXTRA_KEY, false) + if (isMultipane) { + onBackPressedDispatcher.onBackPressed() + } else { + val intent = Intent(this, ProfileListActivity::class.java) + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) + startActivity(intent) + } + } + } (activityComponent as ActivityComponentImpl).inject(this) profileEditActivityPresenter.handleOnCreate() } 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() + Log.w("profile-edit", "back pressed") + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) { + val isMultipane: Boolean = intent.extras!!.getBoolean(IS_MULTIPANE_EXTRA_KEY, false) + if (isMultipane) { + @Suppress("DEPRECATION") + super.onBackPressed() + } else { + val intent = Intent(this, ProfileListActivity::class.java) + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) + startActivity(intent) + } + } + } + + fun handleBackPressFromPresenter(){ + Log.w("profile-edit", "here") + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + onBackPressedDispatcher.onBackPressed() } else { - val intent = Intent(this, ProfileListActivity::class.java) - intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) - startActivity(intent) + onBackPressed() } } } diff --git a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivityPresenter.kt index dd6b0f39e78..3316b266c98 100644 --- a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivityPresenter.kt @@ -25,14 +25,7 @@ class ProfileEditActivityPresenter @Inject constructor( 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() - } else { - val intent = Intent(activity, ProfileListActivity::class.java) - intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) - activity.startActivity(intent) - } + getProfileEditActivity()?.handleBackPressFromPresenter() } if (getProfileEditFragment() == null) { @@ -43,6 +36,9 @@ class ProfileEditActivityPresenter @Inject constructor( } } + private fun getProfileEditActivity(): ProfileEditActivity? { + return activity as ProfileEditActivity? + } private fun setUpToolbar() { toolbar = activity.findViewById(R.id.profile_edit_toolbar) as Toolbar activity.setSupportActionBar(toolbar) From cd2cf5d26ed85fd50b2e996a1801f926df344a4f Mon Sep 17 00:00:00 2001 From: Tejas-67 Date: Mon, 17 Jun 2024 00:09:31 +0530 Subject: [PATCH 02/11] fix ktlint issues --- .../android/app/settings/profile/ProfileEditActivity.kt | 8 ++------ .../app/settings/profile/ProfileEditActivityPresenter.kt | 1 - 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivity.kt b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivity.kt index 65c1a36876c..381d56a6bb7 100644 --- a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivity.kt +++ b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivity.kt @@ -4,7 +4,6 @@ import android.content.Context import android.content.Intent import android.os.Build import android.os.Bundle -import android.util.Log import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity import org.oppia.android.app.model.ScreenName.PROFILE_EDIT_ACTIVITY @@ -44,8 +43,7 @@ class ProfileEditActivity : InjectableAutoLocalizedAppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - onBackInvokedDispatcher.registerOnBackInvokedCallback(1000){ - Log.w("profile-edit", "dispatch") + onBackInvokedDispatcher.registerOnBackInvokedCallback(1000) { val isMultipane: Boolean = intent.extras!!.getBoolean(IS_MULTIPANE_EXTRA_KEY, false) if (isMultipane) { onBackPressedDispatcher.onBackPressed() @@ -61,7 +59,6 @@ class ProfileEditActivity : InjectableAutoLocalizedAppCompatActivity() { } override fun onBackPressed() { - Log.w("profile-edit", "back pressed") if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) { val isMultipane: Boolean = intent.extras!!.getBoolean(IS_MULTIPANE_EXTRA_KEY, false) if (isMultipane) { @@ -75,8 +72,7 @@ class ProfileEditActivity : InjectableAutoLocalizedAppCompatActivity() { } } - fun handleBackPressFromPresenter(){ - Log.w("profile-edit", "here") + fun handleBackPressFromPresenter() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { onBackPressedDispatcher.onBackPressed() } else { diff --git a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivityPresenter.kt index 3316b266c98..6b9715d2cd4 100644 --- a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivityPresenter.kt @@ -1,6 +1,5 @@ package org.oppia.android.app.settings.profile -import android.content.Intent import android.view.View import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.Toolbar From 53efd311f1f401077d8c5d02adb81ce98d808dff Mon Sep 17 00:00:00 2001 From: Tejas-67 Date: Mon, 17 Jun 2024 12:27:39 +0530 Subject: [PATCH 03/11] refractor: AdministratorControlActivity --- .../AdministratorControlsActivity.kt | 60 +++++++++++++------ .../settings/profile/ProfileEditActivity.kt | 37 +++++------- .../profile/ProfileEditActivityPresenter.kt | 2 +- 3 files changed, 58 insertions(+), 41 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivity.kt b/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivity.kt index f357a02a2ae..973f670d559 100644 --- a/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivity.kt +++ b/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivity.kt @@ -2,7 +2,9 @@ package org.oppia.android.app.administratorcontrols import android.content.Context import android.content.Intent +import android.os.Build import android.os.Bundle +import androidx.activity.OnBackPressedCallback import org.oppia.android.R import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity @@ -86,6 +88,46 @@ class AdministratorControlsActivity : isProfileDeletionDialogVisible ) title = resourceHandler.getStringInLocale(R.string.administrator_controls) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + onBackInvokedDispatcher.registerOnBackInvokedCallback(1000) { + val fragment = + supportFragmentManager.findFragmentById( + R.id.administrator_controls_fragment_multipane_placeholder + ) + /* + * If the current fragment is ProfileListFragment then the activity should end on back press. + * If it's instead ProfileEditFragment then profileListFragment should be inflated via + * handleOnBackPressed. + */ + if (fragment is ProfileEditFragment) { + administratorControlsActivityPresenter.handleOnBackPressed() + } else { + onBackPressedDispatcher.onBackPressed() + } + } + } else { + onBackPressedDispatcher.addCallback( + this@AdministratorControlsActivity, object: OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + val fragment = + supportFragmentManager.findFragmentById( + R.id.administrator_controls_fragment_multipane_placeholder + ) + /* + * If the current fragment is ProfileListFragment then the activity should end on back press. + * If it's instead ProfileEditFragment then profileListFragment should be inflated via + * handleOnBackPressed. + */ + if (fragment is ProfileEditFragment) { + administratorControlsActivityPresenter.handleOnBackPressed() + } else { + isEnabled = false + onBackPressedDispatcher.onBackPressed() + isEnabled = true + } + } + }) + } } override fun routeToAppVersion() { @@ -125,24 +167,6 @@ class AdministratorControlsActivity : } } - override fun onBackPressed() { - val fragment = - supportFragmentManager.findFragmentById( - R.id.administrator_controls_fragment_multipane_placeholder - ) - /* - * If the current fragment is ProfileListFragment then the activity should end on back press. - * If it's instead ProfileEditFragment then profileListFragment should be inflated via - * handleOnBackPressed. - */ - if (fragment is ProfileEditFragment) { - administratorControlsActivityPresenter.handleOnBackPressed() - } else { - @Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher. - super.onBackPressed() - } - } - override fun loadProfileList() { lastLoadedFragment = PROFILE_LIST_FRAGMENT administratorControlsActivityPresenter diff --git a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivity.kt b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivity.kt index 381d56a6bb7..12a276a9375 100644 --- a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivity.kt +++ b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivity.kt @@ -4,6 +4,7 @@ import android.content.Context import android.content.Intent import android.os.Build 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.ScreenName.PROFILE_EDIT_ACTIVITY @@ -53,30 +54,22 @@ class ProfileEditActivity : InjectableAutoLocalizedAppCompatActivity() { startActivity(intent) } } + } else { + onBackPressedDispatcher.addCallback( + this@ProfileEditActivity, object: OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + val isMultipane: Boolean = intent.extras!!.getBoolean(IS_MULTIPANE_EXTRA_KEY, false) + if (isMultipane) { + onBackPressedDispatcher.onBackPressed() + } else { + val intent = Intent(this@ProfileEditActivity, ProfileListActivity::class.java) + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) + startActivity(intent) + } + } + }) } (activityComponent as ActivityComponentImpl).inject(this) profileEditActivityPresenter.handleOnCreate() } - - override fun onBackPressed() { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) { - val isMultipane: Boolean = intent.extras!!.getBoolean(IS_MULTIPANE_EXTRA_KEY, false) - if (isMultipane) { - @Suppress("DEPRECATION") - super.onBackPressed() - } else { - val intent = Intent(this, ProfileListActivity::class.java) - intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) - startActivity(intent) - } - } - } - - fun handleBackPressFromPresenter() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - onBackPressedDispatcher.onBackPressed() - } else { - onBackPressed() - } - } } diff --git a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivityPresenter.kt index 6b9715d2cd4..63a565d7a31 100644 --- a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivityPresenter.kt @@ -24,7 +24,7 @@ class ProfileEditActivityPresenter @Inject constructor( val isMultipane = activity.intent.getBooleanExtra(IS_MULTIPANE_EXTRA_KEY, false) toolbar.setNavigationOnClickListener { - getProfileEditActivity()?.handleBackPressFromPresenter() + activity.onBackPressedDispatcher.onBackPressed() } if (getProfileEditFragment() == null) { From ace77394ee4364cabc09a56a2f1daff076cc2853 Mon Sep 17 00:00:00 2001 From: Tejas-67 Date: Thu, 20 Jun 2024 23:39:01 +0530 Subject: [PATCH 04/11] changes as per review --- app/src/main/AndroidManifest.xml | 1 - .../AdministratorControlsActivity.kt | 32 ++++--------- .../settings/profile/ProfileEditActivity.kt | 46 ++++++++----------- .../profile/ProfileEditActivityPresenter.kt | 3 -- 4 files changed, 30 insertions(+), 52 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 97a3e32beda..41d1ce55918 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -14,7 +14,6 @@ android:icon="@mipmap/launcher_icon" android:label="@string/app_name" android:supportsRtl="true" - android:enableOnBackInvokedCallback="true" android:theme="@style/OppiaTheme"> diff --git a/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivity.kt b/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivity.kt index 973f670d559..ac5d160a07b 100644 --- a/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivity.kt +++ b/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivity.kt @@ -4,6 +4,7 @@ import android.content.Context import android.content.Intent import android.os.Build import android.os.Bundle +import android.util.Log import androidx.activity.OnBackPressedCallback import org.oppia.android.R import org.oppia.android.app.activity.ActivityComponentImpl @@ -88,26 +89,13 @@ class AdministratorControlsActivity : isProfileDeletionDialogVisible ) title = resourceHandler.getStringInLocale(R.string.administrator_controls) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - onBackInvokedDispatcher.registerOnBackInvokedCallback(1000) { - val fragment = - supportFragmentManager.findFragmentById( - R.id.administrator_controls_fragment_multipane_placeholder - ) - /* - * If the current fragment is ProfileListFragment then the activity should end on back press. - * If it's instead ProfileEditFragment then profileListFragment should be inflated via - * handleOnBackPressed. - */ - if (fragment is ProfileEditFragment) { - administratorControlsActivityPresenter.handleOnBackPressed() - } else { - onBackPressedDispatcher.onBackPressed() - } - } - } else { - onBackPressedDispatcher.addCallback( - this@AdministratorControlsActivity, object: OnBackPressedCallback(true) { + handleBackPress() + } + + private fun handleBackPress() { + onBackPressedDispatcher.addCallback( + this@AdministratorControlsActivity, + object : OnBackPressedCallback(true) { override fun handleOnBackPressed() { val fragment = supportFragmentManager.findFragmentById( @@ -126,8 +114,8 @@ class AdministratorControlsActivity : isEnabled = true } } - }) - } + } + ) } override fun routeToAppVersion() { diff --git a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivity.kt b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivity.kt index 12a276a9375..2478fd77a14 100644 --- a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivity.kt +++ b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivity.kt @@ -4,6 +4,7 @@ import android.content.Context import android.content.Intent import android.os.Build import android.os.Bundle +import android.util.Log import androidx.activity.OnBackPressedCallback import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity @@ -43,33 +44,26 @@ class ProfileEditActivity : InjectableAutoLocalizedAppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - onBackInvokedDispatcher.registerOnBackInvokedCallback(1000) { - val isMultipane: Boolean = intent.extras!!.getBoolean(IS_MULTIPANE_EXTRA_KEY, false) - if (isMultipane) { - onBackPressedDispatcher.onBackPressed() - } else { - val intent = Intent(this, ProfileListActivity::class.java) - intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) - startActivity(intent) - } - } - } else { - onBackPressedDispatcher.addCallback( - this@ProfileEditActivity, object: OnBackPressedCallback(true) { - override fun handleOnBackPressed() { - val isMultipane: Boolean = intent.extras!!.getBoolean(IS_MULTIPANE_EXTRA_KEY, false) - if (isMultipane) { - onBackPressedDispatcher.onBackPressed() - } else { - val intent = Intent(this@ProfileEditActivity, ProfileListActivity::class.java) - intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) - startActivity(intent) - } - } - }) - } (activityComponent as ActivityComponentImpl).inject(this) profileEditActivityPresenter.handleOnCreate() + handleBackPress() + } + + private fun handleBackPress() { + onBackPressedDispatcher.addCallback( + this@ProfileEditActivity, + object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + val isMultipane: Boolean = intent.extras!!.getBoolean(IS_MULTIPANE_EXTRA_KEY, false) + if (isMultipane) { + onBackPressedDispatcher.onBackPressed() + } else { + val intent = Intent(this@ProfileEditActivity, ProfileListActivity::class.java) + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) + startActivity(intent) + } + } + } + ) } } diff --git a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivityPresenter.kt index 63a565d7a31..9f166e2f746 100644 --- a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivityPresenter.kt @@ -35,9 +35,6 @@ class ProfileEditActivityPresenter @Inject constructor( } } - private fun getProfileEditActivity(): ProfileEditActivity? { - return activity as ProfileEditActivity? - } private fun setUpToolbar() { toolbar = activity.findViewById(R.id.profile_edit_toolbar) as Toolbar activity.setSupportActionBar(toolbar) From acfb0f35d654c8cc777ff0790f27f772c27e4185 Mon Sep 17 00:00:00 2001 From: Tejas-67 Date: Thu, 20 Jun 2024 23:42:10 +0530 Subject: [PATCH 05/11] minor fixes --- .../app/administratorcontrols/AdministratorControlsActivity.kt | 2 -- .../oppia/android/app/settings/profile/ProfileEditActivity.kt | 2 -- 2 files changed, 4 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivity.kt b/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivity.kt index ac5d160a07b..8283c7dc74b 100644 --- a/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivity.kt +++ b/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivity.kt @@ -2,9 +2,7 @@ package org.oppia.android.app.administratorcontrols import android.content.Context import android.content.Intent -import android.os.Build import android.os.Bundle -import android.util.Log import androidx.activity.OnBackPressedCallback import org.oppia.android.R import org.oppia.android.app.activity.ActivityComponentImpl diff --git a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivity.kt b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivity.kt index 2478fd77a14..13c8ebb0b4e 100644 --- a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivity.kt +++ b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivity.kt @@ -2,9 +2,7 @@ package org.oppia.android.app.settings.profile import android.content.Context import android.content.Intent -import android.os.Build import android.os.Bundle -import android.util.Log import androidx.activity.OnBackPressedCallback import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity From 9390eef3679af9aaa9eab214881225e83faa1f64 Mon Sep 17 00:00:00 2001 From: Tejas-67 Date: Fri, 21 Jun 2024 00:20:02 +0530 Subject: [PATCH 06/11] refractor: ProfileAndDeviceActivity.kt, AppVersionActivity.kt --- .../appversion/AppVersionActivity.kt | 18 ++++++++++++++++-- .../ProfileAndDeviceIdActivity.kt | 17 +++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/administratorcontrols/appversion/AppVersionActivity.kt b/app/src/main/java/org/oppia/android/app/administratorcontrols/appversion/AppVersionActivity.kt index e41600bb929..781b17db19e 100644 --- a/app/src/main/java/org/oppia/android/app/administratorcontrols/appversion/AppVersionActivity.kt +++ b/app/src/main/java/org/oppia/android/app/administratorcontrols/appversion/AppVersionActivity.kt @@ -4,6 +4,7 @@ import android.content.Context import android.content.Intent import android.os.Bundle import android.view.MenuItem +import androidx.activity.OnBackPressedCallback import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity import org.oppia.android.app.model.ScreenName.APP_VERSION_ACTIVITY @@ -19,16 +20,29 @@ class AppVersionActivity : InjectableAutoLocalizedAppCompatActivity() { super.onCreate(savedInstanceState) (activityComponent as ActivityComponentImpl).inject(this) appVersionActivityPresenter.handleOnCreate() + handleBackPress() } override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - @Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher. - onBackPressed() + onBackPressedDispatcher.onBackPressed() } return super.onOptionsItemSelected(item) } + private fun handleBackPress() { + onBackPressedDispatcher.addCallback( + this@AppVersionActivity, + object: OnBackPressedCallback(true){ + override fun handleOnBackPressed() { + isEnabled = false + onBackPressedDispatcher.onBackPressed() + isEnabled = true + } + } + ) + } + companion object { /** Returns an [Intent] to start this activity. */ fun createAppVersionActivityIntent(context: Context): Intent { diff --git a/app/src/main/java/org/oppia/android/app/administratorcontrols/learneranalytics/ProfileAndDeviceIdActivity.kt b/app/src/main/java/org/oppia/android/app/administratorcontrols/learneranalytics/ProfileAndDeviceIdActivity.kt index cf6fb025db6..4e34a4d37d4 100644 --- a/app/src/main/java/org/oppia/android/app/administratorcontrols/learneranalytics/ProfileAndDeviceIdActivity.kt +++ b/app/src/main/java/org/oppia/android/app/administratorcontrols/learneranalytics/ProfileAndDeviceIdActivity.kt @@ -4,6 +4,7 @@ import android.content.Context import android.content.Intent import android.os.Bundle import android.view.MenuItem +import androidx.activity.OnBackPressedCallback import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity import org.oppia.android.app.model.ScreenName.PROFILE_AND_DEVICE_ID_ACTIVITY @@ -24,16 +25,28 @@ class ProfileAndDeviceIdActivity : InjectableAutoLocalizedAppCompatActivity() { super.onCreate(savedInstanceState) (activityComponent as ActivityComponentImpl).inject(this) profileAndDeviceIdActivityPresenter.handleOnCreate() + handleBackPress() } override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - @Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher. - onBackPressed() + onBackPressedDispatcher.onBackPressed() } return super.onOptionsItemSelected(item) } + private fun handleBackPress(){ + onBackPressedDispatcher.addCallback( + this@ProfileAndDeviceIdActivity, + object: OnBackPressedCallback(true){ + override fun handleOnBackPressed() { + isEnabled = false + onBackPressedDispatcher.onBackPressed() + isEnabled = true + } + } + ) + } companion object { /** Returns an [Intent] to launch [ProfileAndDeviceIdActivity]. */ fun createIntent(context: Context): Intent { From 1109437181dc648ada62e60ab50f4ac413e063d6 Mon Sep 17 00:00:00 2001 From: Tejas-67 Date: Sat, 22 Jun 2024 00:14:52 +0530 Subject: [PATCH 07/11] refractor: MarkStoriesCompletedActivity.kt, MarkChaptersCompletedActivity.kt --- .../appversion/AppVersionActivity.kt | 14 +++++++------- .../ProfileAndDeviceIdActivity.kt | 16 ++++++++-------- .../MarkChaptersCompletedActivity.kt | 19 +++++++++++++++++-- .../MarkStoriesCompletedActivity.kt | 18 ++++++++++++++++-- 4 files changed, 48 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/administratorcontrols/appversion/AppVersionActivity.kt b/app/src/main/java/org/oppia/android/app/administratorcontrols/appversion/AppVersionActivity.kt index 781b17db19e..eed542e207e 100644 --- a/app/src/main/java/org/oppia/android/app/administratorcontrols/appversion/AppVersionActivity.kt +++ b/app/src/main/java/org/oppia/android/app/administratorcontrols/appversion/AppVersionActivity.kt @@ -33,14 +33,14 @@ class AppVersionActivity : InjectableAutoLocalizedAppCompatActivity() { private fun handleBackPress() { onBackPressedDispatcher.addCallback( this@AppVersionActivity, - object: OnBackPressedCallback(true){ - override fun handleOnBackPressed() { - isEnabled = false - onBackPressedDispatcher.onBackPressed() - isEnabled = true - } + object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + isEnabled = false + onBackPressedDispatcher.onBackPressed() + isEnabled = true } - ) + } + ) } companion object { diff --git a/app/src/main/java/org/oppia/android/app/administratorcontrols/learneranalytics/ProfileAndDeviceIdActivity.kt b/app/src/main/java/org/oppia/android/app/administratorcontrols/learneranalytics/ProfileAndDeviceIdActivity.kt index 4e34a4d37d4..f30ea370552 100644 --- a/app/src/main/java/org/oppia/android/app/administratorcontrols/learneranalytics/ProfileAndDeviceIdActivity.kt +++ b/app/src/main/java/org/oppia/android/app/administratorcontrols/learneranalytics/ProfileAndDeviceIdActivity.kt @@ -35,17 +35,17 @@ class ProfileAndDeviceIdActivity : InjectableAutoLocalizedAppCompatActivity() { return super.onOptionsItemSelected(item) } - private fun handleBackPress(){ + private fun handleBackPress() { onBackPressedDispatcher.addCallback( this@ProfileAndDeviceIdActivity, - object: OnBackPressedCallback(true){ - override fun handleOnBackPressed() { - isEnabled = false - onBackPressedDispatcher.onBackPressed() - isEnabled = true - } + object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + isEnabled = false + onBackPressedDispatcher.onBackPressed() + isEnabled = true } - ) + } + ) } companion object { /** Returns an [Intent] to launch [ProfileAndDeviceIdActivity]. */ diff --git a/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedActivity.kt b/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedActivity.kt index 0c93279a099..5d192a8b96e 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedActivity.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedActivity.kt @@ -4,6 +4,7 @@ import android.content.Context import android.content.Intent import android.os.Bundle import android.view.MenuItem +import androidx.activity.OnBackPressedCallback import org.oppia.android.R import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity @@ -29,12 +30,26 @@ class MarkChaptersCompletedActivity : InjectableAutoLocalizedAppCompatActivity() intent.getBooleanExtra(SHOW_CONFIRMATION_NOTICE_EXTRA_KEY, /* defaultValue= */ false) markChaptersCompletedActivityPresenter.handleOnCreate(internalProfileId, showConfirmationNotice) title = resourceHandler.getStringInLocale(R.string.mark_chapters_completed_activity_title) + handleBackPress() + } + + private fun handleBackPress() { + onBackPressedDispatcher.addCallback( + this@MarkChaptersCompletedActivity, + object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + isEnabled = false + onBackPressedDispatcher.onBackPressed() + isEnabled = true + } + + } + ) } override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - @Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher. - onBackPressed() + onBackPressedDispatcher.onBackPressed() } return super.onOptionsItemSelected(item) } diff --git a/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedActivity.kt b/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedActivity.kt index 5c26e1408a4..56a7ff5f528 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedActivity.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedActivity.kt @@ -4,6 +4,7 @@ import android.content.Context import android.content.Intent import android.os.Bundle import android.view.MenuItem +import androidx.activity.OnBackPressedCallback import org.oppia.android.R import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity @@ -29,12 +30,25 @@ class MarkStoriesCompletedActivity : InjectableAutoLocalizedAppCompatActivity() internalProfileId = intent.getIntExtra(PROFILE_ID_EXTRA_KEY, -1) markStoriesCompletedActivityPresenter.handleOnCreate(internalProfileId) title = resourceHandler.getStringInLocale(R.string.mark_stories_completed_activity_title) + handleBackPress() + } + + private fun handleBackPress() { + onBackPressedDispatcher.addCallback( + this@MarkStoriesCompletedActivity, + object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + isEnabled = false + onBackPressedDispatcher.onBackPressed() + isEnabled = true + } + } + ) } override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - @Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher. - onBackPressed() + onBackPressedDispatcher.onBackPressed() } return super.onOptionsItemSelected(item) } From ca64d2f635c348d7309b29dd8c6f52d370b88d69 Mon Sep 17 00:00:00 2001 From: Tejas-67 Date: Sat, 22 Jun 2024 00:21:14 +0530 Subject: [PATCH 08/11] =?UTF-8?q?refractor:=20=C2=96MarkTopicsCompletedAct?= =?UTF-8?q?ivity.kt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MarkChaptersCompletedActivity.kt | 1 - .../MarkStoriesCompletedActivity.kt | 6 +++--- .../MarkTopicsCompletedActivity.kt | 18 ++++++++++++++++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedActivity.kt b/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedActivity.kt index 5d192a8b96e..f909c854626 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedActivity.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedActivity.kt @@ -42,7 +42,6 @@ class MarkChaptersCompletedActivity : InjectableAutoLocalizedAppCompatActivity() onBackPressedDispatcher.onBackPressed() isEnabled = true } - } ) } diff --git a/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedActivity.kt b/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedActivity.kt index 56a7ff5f528..e459d7c037b 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedActivity.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedActivity.kt @@ -38,9 +38,9 @@ class MarkStoriesCompletedActivity : InjectableAutoLocalizedAppCompatActivity() this@MarkStoriesCompletedActivity, object : OnBackPressedCallback(true) { override fun handleOnBackPressed() { - isEnabled = false - onBackPressedDispatcher.onBackPressed() - isEnabled = true + isEnabled = false + onBackPressedDispatcher.onBackPressed() + isEnabled = true } } ) diff --git a/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/MarkTopicsCompletedActivity.kt b/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/MarkTopicsCompletedActivity.kt index 6801d2fcea0..1daccc2a38b 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/MarkTopicsCompletedActivity.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/MarkTopicsCompletedActivity.kt @@ -4,6 +4,7 @@ import android.content.Context import android.content.Intent import android.os.Bundle import android.view.MenuItem +import androidx.activity.OnBackPressedCallback import org.oppia.android.R import org.oppia.android.app.activity.ActivityComponentImpl import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity @@ -30,12 +31,25 @@ class MarkTopicsCompletedActivity : InjectableAutoLocalizedAppCompatActivity() { internalProfileId = intent.getIntExtra(PROFILE_ID_EXTRA_KEY, -1) markTopicsCompletedActivityPresenter.handleOnCreate(internalProfileId) title = resourceHandler.getStringInLocale(R.string.mark_topics_completed_activity_title) + handleBackPress() + } + + private fun handleBackPress() { + onBackPressedDispatcher.addCallback( + this@MarkTopicsCompletedActivity, + object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + isEnabled = false + onBackPressedDispatcher.onBackPressed() + isEnabled = true + } + } + ) } override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - @Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher. - onBackPressed() + onBackPressedDispatcher.onBackPressed() } return super.onOptionsItemSelected(item) } From d436078320b286b2b42b5990ee343347800bc58a Mon Sep 17 00:00:00 2001 From: Tejas-67 Date: Sat, 22 Jun 2024 00:31:04 +0530 Subject: [PATCH 09/11] refractor: ReadingTextSizeActivityPresenter.kt, ExplorationActivityPresenter.kt --- .../app/options/ReadingTextSizeActivity.kt | 13 +++++++++++++ .../options/ReadingTextSizeActivityPresenter.kt | 5 +++-- .../app/player/exploration/ExplorationActivity.kt | 15 +++++++++++++++ .../exploration/ExplorationActivityPresenter.kt | 3 +-- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/options/ReadingTextSizeActivity.kt b/app/src/main/java/org/oppia/android/app/options/ReadingTextSizeActivity.kt index 6c8c14d87ae..cb6a3cc6923 100644 --- a/app/src/main/java/org/oppia/android/app/options/ReadingTextSizeActivity.kt +++ b/app/src/main/java/org/oppia/android/app/options/ReadingTextSizeActivity.kt @@ -3,6 +3,7 @@ package org.oppia.android.app.options 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.ReadingTextSize @@ -34,6 +35,18 @@ class ReadingTextSizeActivity : InjectableAutoLocalizedAppCompatActivity() { savedInstanceState?.retrieveStateBundle()?.selectedReadingTextSize ?: retrieveActivityParams().readingTextSize readingTextSizeActivityPresenter.handleOnCreate(readingTextSize) + handleBackPress() + } + + private fun handleBackPress() { + onBackPressedDispatcher.addCallback( + this@ReadingTextSizeActivity, + object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + onBackPressedDispatcher.onBackPressed() + } + } + ) } companion object { diff --git a/app/src/main/java/org/oppia/android/app/options/ReadingTextSizeActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/options/ReadingTextSizeActivityPresenter.kt index 85eedd9d379..165e554d7e9 100644 --- a/app/src/main/java/org/oppia/android/app/options/ReadingTextSizeActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/ReadingTextSizeActivityPresenter.kt @@ -1,7 +1,9 @@ package org.oppia.android.app.options +import androidx.activity.OnBackPressedCallback import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.Toolbar +import androidx.lifecycle.lifecycleScope import org.oppia.android.R import org.oppia.android.app.activity.ActivityScope import org.oppia.android.app.model.ReadingTextSize @@ -28,8 +30,7 @@ class ReadingTextSizeActivityPresenter @Inject constructor( private fun setToolbar() { val readingTextSizeToolbar: Toolbar = activity.findViewById(R.id.reading_text_size_toolbar) readingTextSizeToolbar.setNavigationOnClickListener { - @Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher. - activity.onBackPressed() + activity.onBackPressedDispatcher.onBackPressed() } } diff --git a/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationActivity.kt b/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationActivity.kt index c657a4a35fb..94bcbaeec86 100755 --- a/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationActivity.kt +++ b/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationActivity.kt @@ -3,6 +3,7 @@ package org.oppia.android.app.player.exploration 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.HintsAndSolutionDialogFragment @@ -62,6 +63,20 @@ class ExplorationActivity : params.parentScreen, params.isCheckpointingEnabled ) + handleBackPress() + } + + private fun handleBackPress() { + onBackPressedDispatcher.addCallback( + this@ExplorationActivity, + object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + isEnabled = true + onBackPressedDispatcher.onBackPressed() + isEnabled = false + } + } + ) } // TODO(#1655): Re-restrict access to fields in tests post-Gradle. diff --git a/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationActivityPresenter.kt index 54cde19b341..36788a06e1f 100644 --- a/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationActivityPresenter.kt @@ -111,8 +111,7 @@ class ExplorationActivityPresenter @Inject constructor( } binding.explorationToolbar.setNavigationOnClickListener { - @Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher. - activity.onBackPressed() + activity.onBackPressedDispatcher.onBackPressed() } binding.actionAudioPlayer.setOnClickListener { From cf628d714a53660d940cd29d5c399e2bf577a26d Mon Sep 17 00:00:00 2001 From: Tejas-67 Date: Sat, 22 Jun 2024 12:26:18 +0530 Subject: [PATCH 10/11] refractor: QuestionPlayerActivityPresenter, ResumeLessonActivityPresenter --- .../options/ReadingTextSizeActivityPresenter.kt | 2 -- .../app/resumelesson/ResumeLessonActivity.kt | 15 +++++++++++++++ .../ResumeLessonActivityPresenter.kt | 3 +-- .../questionplayer/QuestionPlayerActivity.kt | 16 ++++++++++++++-- .../QuestionPlayerActivityPresenter.kt | 3 +-- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/options/ReadingTextSizeActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/options/ReadingTextSizeActivityPresenter.kt index 165e554d7e9..491ad80fb11 100644 --- a/app/src/main/java/org/oppia/android/app/options/ReadingTextSizeActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/ReadingTextSizeActivityPresenter.kt @@ -1,9 +1,7 @@ package org.oppia.android.app.options -import androidx.activity.OnBackPressedCallback import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.Toolbar -import androidx.lifecycle.lifecycleScope import org.oppia.android.R import org.oppia.android.app.activity.ActivityScope import org.oppia.android.app.model.ReadingTextSize diff --git a/app/src/main/java/org/oppia/android/app/resumelesson/ResumeLessonActivity.kt b/app/src/main/java/org/oppia/android/app/resumelesson/ResumeLessonActivity.kt index 9ffbd1969e3..486edf748d3 100644 --- a/app/src/main/java/org/oppia/android/app/resumelesson/ResumeLessonActivity.kt +++ b/app/src/main/java/org/oppia/android/app/resumelesson/ResumeLessonActivity.kt @@ -3,6 +3,7 @@ package org.oppia.android.app.resumelesson 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.home.RouteToExplorationListener @@ -37,6 +38,20 @@ class ResumeLessonActivity : params.parentScreen, params.checkpoint ) + handleBackPress() + } + + private fun handleBackPress() { + onBackPressedDispatcher.addCallback( + this@ResumeLessonActivity, + object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + isEnabled = false + onBackPressedDispatcher.onBackPressed() + isEnabled = true + } + } + ) } // TODO(#1655): Re-restrict access to fields in tests post-Gradle. diff --git a/app/src/main/java/org/oppia/android/app/resumelesson/ResumeLessonActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/resumelesson/ResumeLessonActivityPresenter.kt index e6cbc39c507..3cabfab80e3 100644 --- a/app/src/main/java/org/oppia/android/app/resumelesson/ResumeLessonActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/resumelesson/ResumeLessonActivityPresenter.kt @@ -33,8 +33,7 @@ class ResumeLessonActivityPresenter @Inject constructor( activity.setSupportActionBar(resumeLessonToolbar) resumeLessonToolbar.setNavigationOnClickListener { - @Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher. - activity.onBackPressed() + activity.onBackPressedDispatcher.onBackPressed() } if (getResumeLessonFragment() == null) { diff --git a/app/src/main/java/org/oppia/android/app/topic/questionplayer/QuestionPlayerActivity.kt b/app/src/main/java/org/oppia/android/app/topic/questionplayer/QuestionPlayerActivity.kt index 51c02585ae5..53c1f47397c 100644 --- a/app/src/main/java/org/oppia/android/app/topic/questionplayer/QuestionPlayerActivity.kt +++ b/app/src/main/java/org/oppia/android/app/topic/questionplayer/QuestionPlayerActivity.kt @@ -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 @@ -55,10 +56,21 @@ class QuestionPlayerActivity : QUESTION_PLAYER_ACTIVITY_PROFILE_ID_ARGUMENT_KEY, ProfileId.getDefaultInstance() ) questionPlayerActivityPresenter.handleOnCreate(profileId) + handleBackPress() } - override fun onBackPressed() { - showStopExplorationDialogFragment() + private fun handleBackPress() { + onBackPressedDispatcher.addCallback( + this@QuestionPlayerActivity, + object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + isEnabled = false + showStopExplorationDialogFragment() + onBackPressedDispatcher.onBackPressed() + isEnabled = true + } + } + ) } override fun restartSession() = questionPlayerActivityPresenter.restartSession() diff --git a/app/src/main/java/org/oppia/android/app/topic/questionplayer/QuestionPlayerActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/topic/questionplayer/QuestionPlayerActivityPresenter.kt index a97d28ce138..2cb0f2344bd 100644 --- a/app/src/main/java/org/oppia/android/app/topic/questionplayer/QuestionPlayerActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/topic/questionplayer/QuestionPlayerActivityPresenter.kt @@ -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) { From 110bdfde5a7869b4b3a18189b7e8348a91ed3b70 Mon Sep 17 00:00:00 2001 From: Tejas-67 Date: Sat, 22 Jun 2024 12:27:34 +0530 Subject: [PATCH 11/11] fix: identation issues --- .../questionplayer/QuestionPlayerActivity.kt | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/topic/questionplayer/QuestionPlayerActivity.kt b/app/src/main/java/org/oppia/android/app/topic/questionplayer/QuestionPlayerActivity.kt index 53c1f47397c..83bec8c4c73 100644 --- a/app/src/main/java/org/oppia/android/app/topic/questionplayer/QuestionPlayerActivity.kt +++ b/app/src/main/java/org/oppia/android/app/topic/questionplayer/QuestionPlayerActivity.kt @@ -60,17 +60,17 @@ class QuestionPlayerActivity : } private fun handleBackPress() { - onBackPressedDispatcher.addCallback( - this@QuestionPlayerActivity, - object : OnBackPressedCallback(true) { - override fun handleOnBackPressed() { - isEnabled = false - showStopExplorationDialogFragment() - onBackPressedDispatcher.onBackPressed() - isEnabled = true - } - } - ) + onBackPressedDispatcher.addCallback( + this@QuestionPlayerActivity, + object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + isEnabled = false + showStopExplorationDialogFragment() + onBackPressedDispatcher.onBackPressed() + isEnabled = true + } + } + ) } override fun restartSession() = questionPlayerActivityPresenter.restartSession()