From c3665c9fb6468aade57cdc09b9258a39c6277f5d Mon Sep 17 00:00:00 2001 From: Tobi Date: Wed, 25 Dec 2024 00:40:58 +0100 Subject: [PATCH 1/3] refactor adminControl package to use profileId --- .../AdministratorControlsActivity.kt | 5 +++-- .../AdministratorControlsActivityPresenter.kt | 14 ++++++++------ .../AdministratorControlsFragmentPresenter.kt | 4 +--- .../LoadProfileEditListener.kt | 4 +++- .../LoadProfileEditDeletionDialogListener.kt | 4 +++- .../app/settings/profile/ProfileEditFragment.kt | 5 +++-- .../profile/ProfileListFragmentPresenter.kt | 2 +- .../AdministratorControlsFragmentTestActivity.kt | 2 +- 8 files changed, 23 insertions(+), 17 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 64beda78f53..4e0431373b8 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 @@ -20,6 +20,7 @@ import org.oppia.android.util.extensions.getProto import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId import javax.inject.Inject +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId /** Argument key used to identify [ProfileListFragment] in the backstack. */ const val PROFILE_LIST_FRAGMENT = "PROFILE_LIST_FRAGMENT" @@ -75,7 +76,7 @@ class AdministratorControlsActivity : // TODO(#661): Change the default fragment in the right hand side to be EditAccount fragment in the case of multipane controls. PROFILE_LIST_FRAGMENT } - val selectedProfileId = args?.selectedProfileId ?: -1 + val selectedProfileId = intent?.extractCurrentUserProfileId() ?: ProfileId.getDefaultInstance() administratorControlsActivityPresenter.handleOnCreate( extraControlsTitle, @@ -107,7 +108,7 @@ class AdministratorControlsActivity : startActivity(ProfileAndDeviceIdActivity.createIntent(this)) } - override fun loadProfileEdit(profileId: Int, profileName: String) { + override fun loadProfileEdit(profileId: ProfileId, profileName: String) { lastLoadedFragment = PROFILE_EDIT_FRAGMENT administratorControlsActivityPresenter.loadProfileEdit(profileId, profileName) } diff --git a/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivityPresenter.kt index 4802fc28ce9..7c4c381ffb0 100644 --- a/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivityPresenter.kt @@ -17,6 +17,8 @@ import org.oppia.android.app.translation.AppLanguageResourceHandler import org.oppia.android.databinding.AdministratorControlsActivityBinding import org.oppia.android.util.extensions.putProto import javax.inject.Inject +import org.oppia.android.app.model.ProfileId +import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId /** The presenter for [AdministratorControlsActivity]. */ @ActivityScope @@ -29,7 +31,7 @@ class AdministratorControlsActivityPresenter @Inject constructor( private lateinit var binding: AdministratorControlsActivityBinding private lateinit var lastLoadedFragment: String - private var selectedProfileId: Int = -1 + private var selectedProfileId: ProfileId = ProfileId.getDefaultInstance() private lateinit var extraControlsTitle: String private var isProfileDeletionDialogVisible: Boolean = false @@ -37,7 +39,7 @@ class AdministratorControlsActivityPresenter @Inject constructor( fun handleOnCreate( extraControlsTitle: String?, lastLoadedFragment: String, - selectedProfileId: Int, + selectedProfileId: ProfileId, isProfileDeletionDialogVisible: Boolean ) { binding = DataBindingUtil.setContentView( @@ -68,7 +70,7 @@ class AdministratorControlsActivityPresenter @Inject constructor( PROFILE_EDIT_FRAGMENT -> selectedProfileId.let { profileId -> if (extraControlsTitle != null) { activity.loadProfileEdit(profileId = profileId, profileName = extraControlsTitle) - if (isProfileDeletionDialogVisible && profileId != 0) { + if (isProfileDeletionDialogVisible) { val fragment = activity.supportFragmentManager.findFragmentById( R.id.administrator_controls_fragment_multipane_placeholder ) @@ -142,13 +144,13 @@ class AdministratorControlsActivityPresenter @Inject constructor( } /** Loads the [ProfileEditFragment] when the user clicks on a profile in tablet multipane mode. */ - fun loadProfileEdit(profileId: Int, profileName: String) { + fun loadProfileEdit(profileId: ProfileId, profileName: String) { lastLoadedFragment = PROFILE_EDIT_FRAGMENT selectedProfileId = profileId extraControlsTitle = profileName setExtraControlsTitle(extraControlsTitle) setMultipaneBackButtonVisibility(View.VISIBLE) - val fragment = ProfileEditFragment.newInstance(profileId, isMultipane) + val fragment = ProfileEditFragment.newInstance(profileId.internalId, isMultipane) activity.supportFragmentManager.beginTransaction().replace( R.id.administrator_controls_fragment_multipane_placeholder, fragment @@ -209,9 +211,9 @@ class AdministratorControlsActivityPresenter @Inject constructor( this@AdministratorControlsActivityPresenter.isProfileDeletionDialogVisible.let { isProfileDeletionDialogVisible = it } - selectedProfileId = this@AdministratorControlsActivityPresenter.selectedProfileId } .build() + outState.decorateWithUserProfileId(this@AdministratorControlsActivityPresenter.selectedProfileId) outState.putProto(ADMINISTRATOR_CONTROLS_ACTIVITY_STATE_KEY, args) } } diff --git a/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsFragmentPresenter.kt index 843b1dbc2fe..f1510eb8c44 100644 --- a/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsFragmentPresenter.kt @@ -36,7 +36,6 @@ class AdministratorControlsFragmentPresenter @Inject constructor( ) { private lateinit var binding: AdministratorControlsFragmentBinding private lateinit var linearLayoutManager: LinearLayoutManager - private var internalProfileId: Int = -1 private lateinit var profileId: ProfileId @Inject @@ -56,8 +55,7 @@ class AdministratorControlsFragmentPresenter @Inject constructor( /* attachToRoot= */ false ) - internalProfileId = activity.intent.extractCurrentUserProfileId().internalId - profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build() + profileId = activity.intent.extractCurrentUserProfileId() administratorControlsViewModel.setProfileId(profileId) linearLayoutManager = LinearLayoutManager(activity.applicationContext) diff --git a/app/src/main/java/org/oppia/android/app/administratorcontrols/LoadProfileEditListener.kt b/app/src/main/java/org/oppia/android/app/administratorcontrols/LoadProfileEditListener.kt index 0a8157990e7..a3cdec22d43 100644 --- a/app/src/main/java/org/oppia/android/app/administratorcontrols/LoadProfileEditListener.kt +++ b/app/src/main/java/org/oppia/android/app/administratorcontrols/LoadProfileEditListener.kt @@ -1,7 +1,9 @@ package org.oppia.android.app.administratorcontrols +import org.oppia.android.app.model.ProfileId + /** Listener for when an activity should load [ProfileEditFragment]. */ interface LoadProfileEditListener { /** Inflates [ProfileEditFragment] as part of a tablet mode a multipane fragment. */ - fun loadProfileEdit(profileId: Int, profileName: String) + fun loadProfileEdit(profileId: ProfileId, profileName: String) } diff --git a/app/src/main/java/org/oppia/android/app/settings/profile/LoadProfileEditDeletionDialogListener.kt b/app/src/main/java/org/oppia/android/app/settings/profile/LoadProfileEditDeletionDialogListener.kt index f371f7df372..c5f401d203f 100644 --- a/app/src/main/java/org/oppia/android/app/settings/profile/LoadProfileEditDeletionDialogListener.kt +++ b/app/src/main/java/org/oppia/android/app/settings/profile/LoadProfileEditDeletionDialogListener.kt @@ -1,10 +1,12 @@ package org.oppia.android.app.settings.profile +import org.oppia.android.app.model.ProfileId + /** Listener for when the activity should inflate [ProfileEditDeletionDialogFragment]. */ interface LoadProfileEditDeletionDialogListener { /** * Inflates [ProfileEditDeletionDialogFragment] for the configuration changes, i.e. rotating the device * from landscape to portrait, and saves the state of the dialog. */ - fun loadProfileEditDeletionDialog(internalProfileId: Int) + fun loadProfileEditDeletionDialog(profileId: ProfileId) } diff --git a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditFragment.kt b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditFragment.kt index a9b1a45969c..a11d698eb7d 100644 --- a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditFragment.kt +++ b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditFragment.kt @@ -11,6 +11,7 @@ import org.oppia.android.app.model.ProfileEditFragmentArguments import org.oppia.android.util.extensions.getProto import org.oppia.android.util.extensions.putProto import javax.inject.Inject +import org.oppia.android.app.model.ProfileId /** Fragment that contains Profile Edit Screen. */ class ProfileEditFragment : @@ -74,7 +75,7 @@ class ProfileEditFragment : profileEditFragmentPresenter.deleteProfile(internalProfileId) } - override fun loadProfileEditDeletionDialog(internalProfileId: Int) { - profileEditFragmentPresenter.handleLoadProfileDeletionDialog(internalProfileId) + override fun loadProfileEditDeletionDialog(profileId: ProfileId) { + profileEditFragmentPresenter.handleLoadProfileDeletionDialog(profileId.internalId) } } diff --git a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileListFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileListFragmentPresenter.kt index 91fd34399d1..cf14a94d520 100644 --- a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileListFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileListFragmentPresenter.kt @@ -72,7 +72,7 @@ class ProfileListFragmentPresenter @Inject constructor( routeToProfileEditListener.routeToProfileEditActivity(profile.id.internalId) } else { val loadProfileEditListener = (activity as LoadProfileEditListener) - loadProfileEditListener.loadProfileEdit(profile.id.internalId, profile.name) + loadProfileEditListener.loadProfileEdit(profile.id, profile.name) } } } diff --git a/app/src/main/java/org/oppia/android/app/testing/AdministratorControlsFragmentTestActivity.kt b/app/src/main/java/org/oppia/android/app/testing/AdministratorControlsFragmentTestActivity.kt index 6ddca1f95a0..98d0bc99a86 100644 --- a/app/src/main/java/org/oppia/android/app/testing/AdministratorControlsFragmentTestActivity.kt +++ b/app/src/main/java/org/oppia/android/app/testing/AdministratorControlsFragmentTestActivity.kt @@ -52,7 +52,7 @@ class AdministratorControlsFragmentTestActivity : override fun loadAppVersion() {} - override fun loadProfileEdit(profileId: Int, profileName: String) {} + override fun loadProfileEdit(profileId: ProfileId, profileName: String) {} override fun showLogoutDialog() {} From f8722fe1e210639d827c5516773cc687e5b1f87d Mon Sep 17 00:00:00 2001 From: Tobi Date: Wed, 25 Dec 2024 00:46:41 +0100 Subject: [PATCH 2/3] fix lint error --- .../AdministratorControlsActivity.kt | 2 +- .../AdministratorControlsActivityPresenter.kt | 8 +++++--- .../android/app/settings/profile/ProfileEditFragment.kt | 2 +- 3 files changed, 7 insertions(+), 5 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 4e0431373b8..57c89a0066e 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 @@ -19,8 +19,8 @@ import org.oppia.android.app.translation.AppLanguageResourceHandler import org.oppia.android.util.extensions.getProto import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId -import javax.inject.Inject import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId +import javax.inject.Inject /** Argument key used to identify [ProfileListFragment] in the backstack. */ const val PROFILE_LIST_FRAGMENT = "PROFILE_LIST_FRAGMENT" diff --git a/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivityPresenter.kt index 7c4c381ffb0..9542b4391cd 100644 --- a/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivityPresenter.kt @@ -10,15 +10,15 @@ import org.oppia.android.app.administratorcontrols.appversion.AppVersionFragment import org.oppia.android.app.administratorcontrols.learneranalytics.ProfileAndDeviceIdFragment import org.oppia.android.app.drawer.NavigationDrawerFragment import org.oppia.android.app.model.AdministratorControlActivityStateBundle +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.settings.profile.LoadProfileEditDeletionDialogListener import org.oppia.android.app.settings.profile.ProfileEditFragment import org.oppia.android.app.settings.profile.ProfileListFragment import org.oppia.android.app.translation.AppLanguageResourceHandler import org.oppia.android.databinding.AdministratorControlsActivityBinding import org.oppia.android.util.extensions.putProto -import javax.inject.Inject -import org.oppia.android.app.model.ProfileId import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId +import javax.inject.Inject /** The presenter for [AdministratorControlsActivity]. */ @ActivityScope @@ -213,7 +213,9 @@ class AdministratorControlsActivityPresenter @Inject constructor( } } .build() - outState.decorateWithUserProfileId(this@AdministratorControlsActivityPresenter.selectedProfileId) + outState.decorateWithUserProfileId( + this@AdministratorControlsActivityPresenter.selectedProfileId + ) outState.putProto(ADMINISTRATOR_CONTROLS_ACTIVITY_STATE_KEY, args) } } diff --git a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditFragment.kt b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditFragment.kt index a11d698eb7d..50cc7157511 100644 --- a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditFragment.kt +++ b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditFragment.kt @@ -8,10 +8,10 @@ import android.view.ViewGroup import org.oppia.android.app.fragment.FragmentComponentImpl import org.oppia.android.app.fragment.InjectableFragment import org.oppia.android.app.model.ProfileEditFragmentArguments +import org.oppia.android.app.model.ProfileId import org.oppia.android.util.extensions.getProto import org.oppia.android.util.extensions.putProto import javax.inject.Inject -import org.oppia.android.app.model.ProfileId /** Fragment that contains Profile Edit Screen. */ class ProfileEditFragment : From 51564937f8ae77156266a0cd601c5757bb4de089 Mon Sep 17 00:00:00 2001 From: Tobiloba Oyelekan Date: Thu, 30 Jan 2025 19:45:28 +0100 Subject: [PATCH 3/3] Update app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivityPresenter.kt Co-authored-by: Adhiambo Peres <59600948+adhiamboperes@users.noreply.github.com> --- .../AdministratorControlsActivityPresenter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivityPresenter.kt index 9542b4391cd..fc79cb30a82 100644 --- a/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivityPresenter.kt @@ -70,7 +70,7 @@ class AdministratorControlsActivityPresenter @Inject constructor( PROFILE_EDIT_FRAGMENT -> selectedProfileId.let { profileId -> if (extraControlsTitle != null) { activity.loadProfileEdit(profileId = profileId, profileName = extraControlsTitle) - if (isProfileDeletionDialogVisible) { + if (isProfileDeletionDialogVisible && profileId.internalId != 0) { val fragment = activity.supportFragmentManager.findFragmentById( R.id.administrator_controls_fragment_multipane_placeholder )