Skip to content

Commit

Permalink
Refactor admin control to use profile (oppia#5619)
Browse files Browse the repository at this point in the history
<!-- READ ME FIRST: Please fill in the explanation section below and
check off every point from the Essential Checklist! -->
## Explanation

### Fixes part of oppia#4865
This PR aim to refactor `administratorcontrols` package to use ProfileId
Changes include `AdministratorControlsActivity`, Fragment and Presenters
Also updated the test classes.

## Essential Checklist
<!-- Please tick the relevant boxes by putting an "x" in them. -->
- [x] The PR title and explanation each start with "Fix #bugnum: " (If
this PR fixes part of an issue, prefix the title with "Fix part of
#bugnum: ...".)
- [x] Any changes to
[scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets)
files have their rationale included in the PR explanation.
- [x] The PR follows the [style
guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide).
- [x] The PR does not contain any unnecessary code changes from Android
Studio
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)).
- [x] The PR is made from a branch that's **not** called "develop" and
is up-to-date with "develop".
- [x] The PR is **assigned** to the appropriate reviewers
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)).

---------

Co-authored-by: Adhiambo Peres <59600948+adhiamboperes@users.noreply.github.com>
  • Loading branch information
tobioyelekan and adhiamboperes authored Jan 31, 2025
1 parent 4f58be9 commit 7b80e62
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ 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 org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId
import javax.inject.Inject

/** Argument key used to identify [ProfileListFragment] in the backstack. */
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ 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 org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.decorateWithUserProfileId
import javax.inject.Inject

/** The presenter for [AdministratorControlsActivity]. */
Expand All @@ -29,15 +31,15 @@ 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

/** Initializes the [AdministratorControlsActivity] and sets the navigation drawer. */
fun handleOnCreate(
extraControlsTitle: String?,
lastLoadedFragment: String,
selectedProfileId: Int,
selectedProfileId: ProfileId,
isProfileDeletionDialogVisible: Boolean
) {
binding = DataBindingUtil.setContentView(
Expand Down Expand Up @@ -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 && profileId.internalId != 0) {
val fragment = activity.supportFragmentManager.findFragmentById(
R.id.administrator_controls_fragment_multipane_placeholder
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -209,9 +211,11 @@ 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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}

Expand Down

0 comments on commit 7b80e62

Please sign in to comment.