Skip to content

Commit

Permalink
refractored: ProfileEditActivity, ProfileEditActivityPresenter
Browse files Browse the repository at this point in the history
  • Loading branch information
Tejas-67 committed Jun 16, 2024
1 parent add9f74 commit dca38bf
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
android:icon="@mipmap/launcher_icon"
android:label="@string/app_name"
android:supportsRtl="true"
android:enableOnBackInvokedCallback="true"
android:theme="@style/OppiaTheme">
<!-- NOTE TO DEVELOPER: You can enable debug logs for fast upload & better inspection in Firebase console using https://support.google.com/analytics/answer/7201382. -->
<meta-data android:name="firebase_analytics_collection_deactivated" android:value="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -43,6 +36,9 @@ class ProfileEditActivityPresenter @Inject constructor(
}
}

private fun getProfileEditActivity(): ProfileEditActivity? {
return activity as ProfileEditActivity?
}
private fun setUpToolbar() {
toolbar = activity.findViewById<View>(R.id.profile_edit_toolbar) as Toolbar
activity.setSupportActionBar(toolbar)
Expand Down

0 comments on commit dca38bf

Please sign in to comment.