Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change profile id defaulting to invalid profile #5482

Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,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
Expand Up @@ -42,7 +42,7 @@ class ClassroomListActivity :
@Inject
lateinit var activityRouter: ActivityRouter

private var internalProfileId: Int = -1
private lateinit var profileId: ProfileId

companion object {
/** Returns a new [Intent] to route to [ClassroomListActivity] for a specified [profileId]. */
Expand All @@ -58,7 +58,7 @@ class ClassroomListActivity :
super.onCreate(savedInstanceState)
(activityComponent as ActivityComponentImpl).inject(this)

internalProfileId = intent.extractCurrentUserProfileId().internalId
profileId = intent.extractCurrentUserProfileId()
classroomListActivityPresenter.handleOnCreate()
title = resourceHandler.getStringInLocale(R.string.classroom_list_activity_title)
}
Expand Down Expand Up @@ -88,7 +88,7 @@ class ClassroomListActivity :
val recentlyPlayedActivityParams =
RecentlyPlayedActivityParams
.newBuilder()
.setProfileId(ProfileId.newBuilder().setInternalId(internalProfileId).build())
.setProfileId(profileId)
.setActivityTitle(recentlyPlayedActivityTitle).build()

activityRouter.routeToScreen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class ClassroomListFragmentPresenter @Inject constructor(
/* attachToRoot= */ false
)

internalProfileId = profileId.internalId
internalProfileId = profileId.loggedInInternalProfileId

logHomeActivityEvent()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class ClassroomListViewModel(
private val dateTimeUtil: DateTimeUtil,
private val translationController: TranslationController
) : ObservableViewModel() {
private val profileId: ProfileId = ProfileId.newBuilder().setInternalId(internalProfileId).build()
private val profileId: ProfileId =
ProfileId.newBuilder().setLoggedInInternalProfileId(internalProfileId).build()
private val promotedStoryListLimit = activity.resources.getInteger(
R.integer.promoted_story_list_limit
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class CompletedStoryListActivity : InjectableAutoLocalizedAppCompatActivity() {
super.onCreate(savedInstanceState)
(activityComponent as ActivityComponentImpl).inject(this)

val internalProfileId: Int = intent?.extractCurrentUserProfileId()?.internalId ?: -1
val internalProfileId: Int =
intent?.extractCurrentUserProfileId()?.loggedInInternalProfileId ?: -1
completedStoryListActivityPresenter.handleOnCreate(internalProfileId)
}

Expand All @@ -30,7 +31,7 @@ class CompletedStoryListActivity : InjectableAutoLocalizedAppCompatActivity() {

/** Returns a new [Intent] to route to [CompletedStoryListActivity] for a specified profile ID. */
fun createCompletedStoryListActivityIntent(context: Context, internalProfileId: Int): Intent {
val profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build()
val profileId = ProfileId.newBuilder().setLoggedInInternalProfileId(internalProfileId).build()
val intent = Intent(context, CompletedStoryListActivity::class.java).apply {
decorateWithUserProfileId(profileId)
decorateWithScreenName(COMPLETED_STORY_LIST_ACTIVITY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CompletedStoryListFragment : InjectableFragment() {

/** Returns a new [CompletedStoryListFragment] to display corresponding to the specified profile ID. */
fun newInstance(internalProfileId: Int): CompletedStoryListFragment {
val profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build()
val profileId = ProfileId.newBuilder().setLoggedInInternalProfileId(internalProfileId).build()
return CompletedStoryListFragment().apply {
arguments = Bundle().apply {
decorateWithUserProfileId(profileId)
Expand All @@ -47,11 +47,10 @@ class CompletedStoryListFragment : InjectableFragment() {
"Expected arguments to be passed to CompletedStoryListFragment"
}
val profileId = arguments.extractCurrentUserProfileId()
val internalProfileId = profileId.internalId
return completedStoryListFragmentPresenter.handleCreateView(
inflater,
container,
internalProfileId
profileId
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.GridLayoutManager
import org.oppia.android.R
import org.oppia.android.app.model.ProfileId
import org.oppia.android.app.recyclerview.BindableAdapter
import org.oppia.android.databinding.CompletedStoryItemBinding
import org.oppia.android.databinding.CompletedStoryListFragmentBinding
Expand All @@ -26,9 +27,9 @@ class CompletedStoryListFragmentPresenter @Inject constructor(
fun handleCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
internalProfileId: Int
profileId: ProfileId
): View? {
viewModel.setProfileId(internalProfileId)
viewModel.setProfileId(profileId)

binding = CompletedStoryListFragmentBinding
.inflate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ class CompletedStoryListViewModel @Inject constructor(
private val translationController: TranslationController,
@StoryHtmlParserEntityType private val entityType: String
) : ObservableViewModel() {
/** [internalProfileId] needs to be set before any of the live data members can be accessed. */
private var internalProfileId: Int = -1
/** [profileId] needs to be set before any of the live data members can be accessed. */
private var profileId: ProfileId = ProfileId.newBuilder().setLoggedOut(true).build()

private val completedStoryListResultLiveData: LiveData<AsyncResult<CompletedStoryList>> by lazy {
topicController.getCompletedStoryList(
ProfileId.newBuilder().setInternalId(internalProfileId).build()
).toLiveData()
topicController.getCompletedStoryList(profileId).toLiveData()
}

private val completedStoryLiveData: LiveData<CompletedStoryList> by lazy {
Expand All @@ -44,9 +42,9 @@ class CompletedStoryListViewModel @Inject constructor(
Transformations.map(completedStoryLiveData, ::processCompletedStoryList)
}

/** Sets internalProfileId to this ViewModel. */
fun setProfileId(internalProfileId: Int) {
this.internalProfileId = internalProfileId
/** Sets profileId to this ViewModel. */
fun setProfileId(profileId: ProfileId) {
this.profileId = profileId
}

private fun processCompletedStoryListResult(
Expand Down Expand Up @@ -74,7 +72,7 @@ class CompletedStoryListViewModel @Inject constructor(
completedStoryList.completedStoryList.map { completedStory ->
CompletedStoryItemViewModel(
activity,
internalProfileId,
profileId.loggedInInternalProfileId, // Use the loggedInInternalProfileId
completedStory,
entityType,
intentFactoryShim,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,37 @@ class DeveloperOptionsActivity :
@Inject
lateinit var resourceHandler: AppLanguageResourceHandler

private var internalProfileId = -1
private lateinit var profileId: ProfileId

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
(activityComponent as ActivityComponentImpl).inject(this)
internalProfileId = intent.extractCurrentUserProfileId().internalId
profileId = intent.extractCurrentUserProfileId()
developerOptionsActivityPresenter.handleOnCreate()
title = resourceHandler.getStringInLocale(R.string.developer_options_activity_title)
}

override fun routeToMarkChaptersCompleted() {
startActivity(
MarkChaptersCompletedActivity.createMarkChaptersCompletedIntent(
context = this, internalProfileId, showConfirmationNotice = false
if (!profileId.loggedOut) {
startActivity(
MarkChaptersCompletedActivity.createMarkChaptersCompletedIntent(
context = this, profileId.loggedInInternalProfileId, showConfirmationNotice = false
)
)
)
}
}

override fun routeToMarkStoriesCompleted() {
startActivity(
MarkStoriesCompletedActivity
.createMarkStoriesCompletedIntent(this, internalProfileId)
.createMarkStoriesCompletedIntent(this, profileId.loggedInInternalProfileId)
)
}

override fun routeToMarkTopicsCompleted() {
startActivity(
MarkTopicsCompletedActivity
.createMarkTopicsCompletedIntent(this, internalProfileId)
.createMarkTopicsCompletedIntent(this, profileId.loggedInInternalProfileId)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class MarkChaptersCompletedFragmentPresenter @Inject constructor(
this.selectedExplorationIds += selectedExplorationIds
this.selectedExplorationTitles += selectedExplorationTitles

profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build()
profileId = ProfileId.newBuilder().setLoggedInInternalProfileId(internalProfileId).build()
viewModel.setProfileId(profileId)

linearLayoutManager = LinearLayoutManager(activity.applicationContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ class MarkStoriesCompletedActivity : InjectableAutoLocalizedAppCompatActivity()
@Inject
lateinit var resourceHandler: AppLanguageResourceHandler

private var internalProfileId = -1
private var profileId: ProfileId = ProfileId.newBuilder().setLoggedOut(true).build()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
(activityComponent as ActivityComponentImpl).inject(this)

val profileId = intent?.extractCurrentUserProfileId()
internalProfileId = profileId?.internalId ?: -1
markStoriesCompletedActivityPresenter.handleOnCreate(internalProfileId)
val currentProfileId = intent?.extractCurrentUserProfileId()
profileId = currentProfileId ?: ProfileId.newBuilder().setLoggedOut(true).build()
markStoriesCompletedActivityPresenter.handleOnCreate(
profileId.loggedInInternalProfileId
)
title = resourceHandler.getStringInLocale(R.string.mark_stories_completed_activity_title)
}

Expand All @@ -48,7 +50,7 @@ class MarkStoriesCompletedActivity : InjectableAutoLocalizedAppCompatActivity()

/** Returns an [Intent] to start this activity. */
fun createMarkStoriesCompletedIntent(context: Context, internalProfileId: Int): Intent {
val profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build()
val profileId = ProfileId.newBuilder().setLoggedInInternalProfileId(internalProfileId).build()
return Intent(context, MarkStoriesCompletedActivity::class.java).apply {
decorateWithUserProfileId(profileId)
decorateWithScreenName(MARK_STORIES_COMPLETED_ACTIVITY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class MarkStoriesCompletedFragment : InjectableFragment() {

/** Returns a new [MarkStoriesCompletedFragment]. */
fun newInstance(internalProfileId: Int): MarkStoriesCompletedFragment {
val profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build()
val profileId = ProfileId.newBuilder().setLoggedInInternalProfileId(internalProfileId).build()
return MarkStoriesCompletedFragment().apply {
arguments = Bundle().apply {
decorateWithUserProfileId(profileId)
Expand All @@ -51,7 +51,7 @@ class MarkStoriesCompletedFragment : InjectableFragment() {
checkNotNull(arguments) { "Expected arguments to be passed to MarkStoriesCompletedFragment" }

val profileId = arguments.extractCurrentUserProfileId()
val internalProfileId = profileId.internalId
val internalProfileId = profileId.loggedInInternalProfileId

var selectedStoryIdList = ArrayList<String>()
if (savedInstanceState != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class MarkStoriesCompletedFragmentPresenter @Inject constructor(

this.selectedStoryIdList = selectedStoryIdList

profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build()
profileId = ProfileId.newBuilder().setLoggedInInternalProfileId(internalProfileId).build()
viewModel.setProfileId(profileId)

linearLayoutManager = LinearLayoutManager(activity.applicationContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MarkStoriesCompletedTestActivity : InjectableAutoLocalizedAppCompatActivit
setContentView(R.layout.mark_stories_completed_activity)

val profileId = intent?.extractCurrentUserProfileId()
internalProfileId = profileId?.internalId ?: -1
internalProfileId = profileId?.loggedInInternalProfileId ?: -1

if (getMarkStoriesCompletedFragment() == null) {
val markStoriesCompletedFragment = MarkStoriesCompletedFragment.newInstance(internalProfileId)
Expand All @@ -44,7 +44,7 @@ class MarkStoriesCompletedTestActivity : InjectableAutoLocalizedAppCompatActivit

/** Returns an [Intent] for [MarkStoriesCompletedTestActivity]. */
fun createMarkStoriesCompletedTestIntent(context: Context, internalProfileId: Int): Intent {
val profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build()
val profileId = ProfileId.newBuilder().setLoggedInInternalProfileId(internalProfileId).build()
val intent = Intent(context, MarkStoriesCompletedTestActivity::class.java)
intent.decorateWithUserProfileId(profileId)
return intent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ class MarkTopicsCompletedActivity : InjectableAutoLocalizedAppCompatActivity() {
@Inject
lateinit var resourceHandler: AppLanguageResourceHandler

private var internalProfileId = -1
private lateinit var profileId: ProfileId

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
(activityComponent as ActivityComponentImpl).inject(this)
val profileId = intent?.extractCurrentUserProfileId()
internalProfileId = profileId?.internalId ?: -1
markTopicsCompletedActivityPresenter.handleOnCreate(internalProfileId)
profileId =
intent?.extractCurrentUserProfileId() ?: ProfileId.newBuilder().setLoggedOut(true).build()
if (!profileId.loggedOut) {
markTopicsCompletedActivityPresenter.handleOnCreate(profileId.loggedInInternalProfileId)
}
title = resourceHandler.getStringInLocale(R.string.mark_topics_completed_activity_title)
}

Expand All @@ -47,7 +49,7 @@ class MarkTopicsCompletedActivity : InjectableAutoLocalizedAppCompatActivity() {
companion object {
/** Returns an [Intent] for [MarkStoriesCompletedTestActivity]. */
fun createMarkTopicsCompletedIntent(context: Context, internalProfileId: Int): Intent {
val profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build()
val profileId = ProfileId.newBuilder().setLoggedInInternalProfileId(internalProfileId).build()
return Intent(context, MarkTopicsCompletedActivity::class.java).apply {
decorateWithUserProfileId(profileId)
decorateWithScreenName(MARK_TOPICS_COMPLETED_ACTIVITY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class MarkTopicsCompletedFragment : InjectableFragment() {

/** Returns a new [MarkTopicsCompletedFragment]. */
fun newInstance(internalProfileId: Int): MarkTopicsCompletedFragment {
val profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build()
val profileId = ProfileId.newBuilder().setLoggedInInternalProfileId(internalProfileId).build()
return MarkTopicsCompletedFragment().apply {
arguments = Bundle().apply {
decorateWithUserProfileId(profileId)
Expand All @@ -50,7 +50,7 @@ class MarkTopicsCompletedFragment : InjectableFragment() {
val arguments =
checkNotNull(arguments) { "Expected arguments to be passed to MarkTopicsCompletedFragment" }

val internalProfileId = arguments.extractCurrentUserProfileId().internalId
val internalProfileId = arguments.extractCurrentUserProfileId().loggedInInternalProfileId

var selectedTopicIdList = ArrayList<String>()
if (savedInstanceState != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class MarkTopicsCompletedFragmentPresenter @Inject constructor(

this.selectedTopicIdList = selectedTopicIdList

this.profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build()
this.profileId = ProfileId.newBuilder().setLoggedInInternalProfileId(internalProfileId).build()
viewModel.setProfileId(profileId)

linearLayoutManager = LinearLayoutManager(activity.applicationContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@ import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extrac
/** The activity for testing [MarkTopicsCompletedFragment]. */
class MarkTopicsCompletedTestActivity : InjectableAutoLocalizedAppCompatActivity() {

private var internalProfileId = -1
private var profileId: ProfileId = ProfileId.newBuilder().setLoggedOut(true).build()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
(activityComponent as ActivityComponentImpl).inject(this)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_arrow_back_white_24dp)
setContentView(R.layout.mark_topics_completed_activity)
val profileId = intent?.extractCurrentUserProfileId()
internalProfileId = profileId?.internalId ?: -1
val currentProfileId = intent?.extractCurrentUserProfileId()
profileId = currentProfileId ?: ProfileId.newBuilder().setLoggedOut(true).build()
if (getMarkTopicsCompletedFragment() == null) {
val markTopicsCompletedFragment = MarkTopicsCompletedFragment.newInstance(internalProfileId)
val markTopicsCompletedFragment = MarkTopicsCompletedFragment.newInstance(
profileId.loggedInInternalProfileId
)
supportFragmentManager.beginTransaction().add(
R.id.mark_topics_completed_container,
markTopicsCompletedFragment
Expand All @@ -41,7 +43,7 @@ class MarkTopicsCompletedTestActivity : InjectableAutoLocalizedAppCompatActivity
companion object {
/** Returns an [Intent] for [MarkTopicsCompletedTestActivity]. */
fun createMarkTopicsCompletedTestIntent(context: Context, internalProfileId: Int): Intent {
val profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build()
val profileId = ProfileId.newBuilder().setLoggedInInternalProfileId(internalProfileId).build()
val intent = Intent(context, MarkTopicsCompletedTestActivity::class.java).apply {
decorateWithUserProfileId(profileId)
}
Expand Down
Loading
Loading