Skip to content

Commit

Permalink
refractor: MarkStoriesCompletedActivity.kt, MarkChaptersCompletedActi…
Browse files Browse the repository at this point in the history
…vity.kt
  • Loading branch information
Tejas-67 committed Jun 21, 2024
1 parent fe7e79e commit 1109437
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]. */
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.R
import org.oppia.android.app.activity.ActivityComponentImpl
import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity
Expand All @@ -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)
}
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.R
import org.oppia.android.app.activity.ActivityComponentImpl
import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity
Expand All @@ -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)
}
Expand Down

0 comments on commit 1109437

Please sign in to comment.