Skip to content

Commit

Permalink
refractor: ProfileAndDeviceActivity.kt, AppVersionActivity.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
Tejas-67 committed Jun 20, 2024
1 parent daeb26b commit 9390eef
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 9390eef

Please sign in to comment.