Skip to content

Commit

Permalink
Hide step count for additional learners onboarding
Browse files Browse the repository at this point in the history
  • Loading branch information
adhiamboperes committed Sep 3, 2024
1 parent 2de3784 commit 34e8da5
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ class CreateProfileFragmentPresenter @Inject constructor(

val params = IntroActivityParams.newBuilder()
.setProfileNickname(profileName)
.setParentScreen(IntroActivityParams.ParentScreen.CREATE_PROFILE_SCREEN)
.build()

val intent =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ class IntroActivity : InjectableAutoLocalizedAppCompatActivity() {
super.onCreate(savedInstanceState)
(activityComponent as ActivityComponentImpl).inject(this)

val profileNickname =
intent.getProtoExtra(PARAMS_KEY, IntroActivityParams.getDefaultInstance()).profileNickname
val activityParams = intent.getProtoExtra(PARAMS_KEY, IntroActivityParams.getDefaultInstance())
val profileNickname = activityParams.profileNickname

val profileId = intent.extractCurrentUserProfileId()

onboardingLearnerIntroActivityPresenter.handleOnCreate(profileNickname, profileId)
val parentScreen = activityParams.parentScreen

onboardingLearnerIntroActivityPresenter.handleOnCreate(profileNickname, profileId, parentScreen)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import org.oppia.android.R
import org.oppia.android.app.activity.ActivityScope
import org.oppia.android.app.model.IntroActivityParams
import org.oppia.android.app.model.IntroFragmentArguments
import org.oppia.android.app.model.ProfileId
import org.oppia.android.databinding.IntroActivityBinding
Expand All @@ -15,7 +16,7 @@ import javax.inject.Inject
private const val TAG_LEARNER_INTRO_FRAGMENT = "TAG_INTRO_FRAGMENT"

/** Argument key for bundling the profile nickname. */
const val PROFILE_NICKNAME_ARGUMENT_KEY = "IntroFragment.Arguments"
const val INTRO_FRAGMENT_ARGUMENT_KEY = "IntroFragment.Arguments"

/** The Presenter for [IntroActivity]. */
@ActivityScope
Expand All @@ -25,19 +26,26 @@ class IntroActivityPresenter @Inject constructor(
private lateinit var binding: IntroActivityBinding

/** Handle creation and binding of the [IntroActivity] layout. */
fun handleOnCreate(profileNickname: String, profileId: ProfileId) {
fun handleOnCreate(
profileNickname: String,
profileId: ProfileId,
parentScreen: IntroActivityParams.ParentScreen
) {
binding = DataBindingUtil.setContentView(activity, R.layout.intro_activity)
binding.lifecycleOwner = activity

if (getIntroFragment() == null) {
val introFragment = IntroFragment()

val argumentsProto =
IntroFragmentArguments.newBuilder().setProfileNickname(profileNickname).build()
IntroFragmentArguments.newBuilder()
.setProfileNickname(profileNickname)
.setParentScreen(parentScreen)
.build()

val args = Bundle().apply {
decorateWithUserProfileId(profileId)
putProto(PROFILE_NICKNAME_ARGUMENT_KEY, argumentsProto)
putProto(INTRO_FRAGMENT_ARGUMENT_KEY, argumentsProto)
}

introFragment.arguments = args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@ class IntroFragment : InjectableFragment() {
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val profileNickname =
val args =
checkNotNull(
arguments?.getProto(
PROFILE_NICKNAME_ARGUMENT_KEY,
INTRO_FRAGMENT_ARGUMENT_KEY,
IntroFragmentArguments.getDefaultInstance()
)
) {
"Expected profileNickname to be included in the arguments for IntroFragment."
}.profileNickname
"Expected IntroFragment to have arguments."
}

val profileNickname = args.profileNickname

val parentScreen = args.parentScreen

val profileId =
checkNotNull(arguments?.extractCurrentUserProfileId()) {
Expand All @@ -46,7 +50,8 @@ class IntroFragment : InjectableFragment() {
inflater,
container,
profileNickname,
profileId
profileId,
parentScreen
)
}
}
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 org.oppia.android.R
import org.oppia.android.app.model.AudioLanguage
import org.oppia.android.app.model.IntroActivityParams
import org.oppia.android.app.model.ProfileId
import org.oppia.android.app.options.AudioLanguageActivity
import org.oppia.android.app.translation.AppLanguageResourceHandler
Expand All @@ -33,7 +34,8 @@ class IntroFragmentPresenter @Inject constructor(
inflater: LayoutInflater,
container: ViewGroup?,
profileNickname: String,
profileId: ProfileId
profileId: ProfileId,
parentScreen: IntroActivityParams.ParentScreen
): View {
binding = LearnerIntroFragmentBinding.inflate(
inflater,
Expand All @@ -47,6 +49,10 @@ class IntroFragmentPresenter @Inject constructor(

markProfileOnboardingStarted(profileId)

if (parentScreen == IntroActivityParams.ParentScreen.PROFILE_CHOOSER_SCREEN) {
binding.onboardingStepsCount?.visibility = View.GONE
}

binding.onboardingNavigationBack.setOnClickListener {
activity.finish()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ class ProfileChooserFragmentPresenter @Inject constructor(
private fun launchOnboardingScreen(profileId: ProfileId, profileName: String) {
val introActivityParams = IntroActivityParams.newBuilder()
.setProfileNickname(profileName)
.setParentScreen(IntroActivityParams.ParentScreen.PROFILE_CHOOSER_SCREEN)
.build()

val intent = IntroActivity.createIntroActivity(activity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,12 @@ class CreateProfileFragmentTest {
.perform(click())
testCoroutineDispatchers.runCurrent()

val expectedParams =
IntroActivityParams.newBuilder().setProfileNickname("John").setProfileId(0).build()
val expectedParams = IntroActivityParams.newBuilder()
.setProfileNickname("John")
.setProfileId(0)
.setParentScreen(IntroActivityParams.ParentScreen.CREATE_PROFILE_SCREEN)
.build()

intended(
allOf(
hasComponent(IntroActivity::class.java.name),
Expand Down Expand Up @@ -273,7 +277,12 @@ class CreateProfileFragmentTest {
testCoroutineDispatchers.runCurrent()

val expectedParams =
IntroActivityParams.newBuilder().setProfileNickname("John").setProfileId(0).build()
IntroActivityParams.newBuilder()
.setProfileNickname("John")
.setProfileId(0)
.setParentScreen(IntroActivityParams.ParentScreen.CREATE_PROFILE_SCREEN)
.build()

intended(
allOf(
hasComponent(IntroActivity::class.java.name),
Expand Down Expand Up @@ -320,8 +329,11 @@ class CreateProfileFragmentTest {
.perform(click())
testCoroutineDispatchers.runCurrent()

val expectedParams =
IntroActivityParams.newBuilder().setProfileNickname("John").setProfileId(0).build()
val expectedParams = IntroActivityParams.newBuilder()
.setProfileNickname("John")
.setProfileId(0)
.setParentScreen(IntroActivityParams.ParentScreen.CREATE_PROFILE_SCREEN)
.build()
intended(
allOf(
hasComponent(IntroActivity::class.java.name),
Expand Down Expand Up @@ -383,8 +395,12 @@ class CreateProfileFragmentTest {
.perform(click())
testCoroutineDispatchers.runCurrent()

val expectedParams =
IntroActivityParams.newBuilder().setProfileNickname("John").setProfileId(0).build()
val expectedParams = IntroActivityParams.newBuilder()
.setProfileNickname("John")
.setProfileId(0)
.setParentScreen(IntroActivityParams.ParentScreen.CREATE_PROFILE_SCREEN)
.build()

intended(
allOf(
hasComponent(IntroActivity::class.java.name),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ class IntroFragmentTest {
ActivityScenario<IntroActivity>? {
val params = IntroActivityParams.newBuilder()
.setProfileNickname(testProfileNickname)
.setParentScreen(IntroActivityParams.ParentScreen.CREATE_PROFILE_SCREEN)
.build()

val scenario = ActivityScenario.launch<IntroActivity>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ import androidx.test.core.app.ActivityScenario.launch
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.doesNotExist
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.RecyclerViewActions.scrollToPosition
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.Intents.intended
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
import androidx.test.espresso.intent.matcher.IntentMatchers.hasExtraWithKey
import androidx.test.espresso.matcher.ViewMatchers.Visibility
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
Expand Down Expand Up @@ -45,6 +48,8 @@ import org.oppia.android.app.classroom.ClassroomListActivity
import org.oppia.android.app.devoptions.DeveloperOptionsModule
import org.oppia.android.app.devoptions.DeveloperOptionsStarterModule
import org.oppia.android.app.home.HomeActivity
import org.oppia.android.app.model.ProfileId
import org.oppia.android.app.model.ProfileType
import org.oppia.android.app.onboarding.IntroActivity
import org.oppia.android.app.player.state.itemviewmodel.SplitScreenInteractionModule
import org.oppia.android.app.profile.AdminAuthActivity.Companion.ADMIN_AUTH_ACTIVITY_PARAMS_KEY
Expand Down Expand Up @@ -85,7 +90,6 @@ import org.oppia.android.domain.platformparameter.PlatformParameterSingletonModu
import org.oppia.android.domain.profile.ProfileManagementController
import org.oppia.android.domain.question.QuestionModule
import org.oppia.android.domain.workmanager.WorkManagerConfigurationModule
import org.oppia.android.testing.OppiaTestRule
import org.oppia.android.testing.TestLogReportingModule
import org.oppia.android.testing.firebase.TestAuthenticationModule
import org.oppia.android.testing.junit.InitializeDefaultLocaleRule
Expand Down Expand Up @@ -127,8 +131,8 @@ class ProfileChooserFragmentTest {
@get:Rule
val initializeDefaultLocaleRule = InitializeDefaultLocaleRule()

@get:Rule
val oppiaTestRule = OppiaTestRule()
// @get:Rule
// val oppiaTestRule = OppiaTestRule()

private val activityTestRule: ActivityTestRule<ProfileChooserActivity> = ActivityTestRule(
ProfileChooserActivity::class.java, /* initialTouchMode= */ true, /* launchActivity= */ false
Expand All @@ -146,6 +150,8 @@ class ProfileChooserFragmentTest {
@Inject
lateinit var testCoroutineDispatchers: TestCoroutineDispatchers

private val testProfileId = ProfileId.newBuilder().setInternalId(0).build()

@Before
fun setUp() {
Intents.init()
Expand Down Expand Up @@ -363,8 +369,9 @@ class ProfileChooserFragmentTest {

@Test
fun testMigrateProfiles_onboardingV2_clickAdminProfile_checkOpensPinPasswordActivity() {
profileTestHelper.initializeProfiles(autoLogIn = true)
TestPlatformParameterModule.forceEnableOnboardingFlowV2(true)
profileTestHelper.initializeProfiles(autoLogIn = true)
profileTestHelper.updateProfileType(testProfileId, ProfileType.SUPERVISOR)

launch(ProfileChooserActivity::class.java).use {
testCoroutineDispatchers.runCurrent()
Expand Down Expand Up @@ -437,6 +444,34 @@ class ProfileChooserFragmentTest {
}
}

@Test
fun testMigrateProfiles_onboardingV2_clickLearnerWithoutPin_checkIntroActivityHasNoStepCount() {
TestPlatformParameterModule.forceEnableOnboardingFlowV2(true)
profileTestHelper.addOnlyAdminProfile()
profileManagementController.addProfile(
name = "Learner",
pin = "",
avatarImagePath = null,
allowDownloadAccess = true,
colorRgb = -10710042,
isAdmin = false
)

launch(ProfileChooserActivity::class.java).use {
testCoroutineDispatchers.runCurrent()
onView(
atPosition(
recyclerViewId = R.id.profiles_list,
position = 1
)
).perform(click())

testCoroutineDispatchers.runCurrent()

onView(withText(R.string.onboarding_step_count_four)).check(doesNotExist())
}
}

@Test
fun testProfileChooserFragment_clickAdminProfileWithNoPin_checkOpensAdminPinActivity() {
TestPlatformParameterModule.forceEnableOnboardingFlowV2(false)
Expand Down Expand Up @@ -581,6 +616,7 @@ class ProfileChooserFragmentTest {

@Test
fun testProfileChooserFragment_clickProfile_opensHomeActivity() {
TestPlatformParameterModule.forceEnableMultipleClassrooms(false)
TestPlatformParameterModule.forceEnableOnboardingFlowV2(false)
profileTestHelper.addOnlyAdminProfileWithoutPin()
launch<ProfileChooserActivity>(createProfileChooserActivityIntent()).use {
Expand Down Expand Up @@ -643,7 +679,7 @@ class ProfileChooserFragmentTest {
}

@Test
fun testFragment_enableOnboardingV2_landscape_checkAScrollArrowsAreDisplayed() {
fun testFragment_enableOnboardingV2_landscapeMode_checkScrollArrowsAreDisplayed() {
TestPlatformParameterModule.forceEnableOnboardingFlowV2(true)
profileTestHelper.addOnlyAdminProfile()
profileTestHelper.addMoreProfiles(8)
Expand All @@ -665,8 +701,16 @@ class ProfileChooserFragmentTest {
testCoroutineDispatchers.runCurrent()
orientationLandscape()
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.profile_list_scroll_left)).check(matches(not(isDisplayed())))
onView(withId(R.id.profile_list_scroll_right)).check(matches(not(isDisplayed())))
onView(withId(R.id.profile_list_scroll_left)).check(
matches(withEffectiveVisibility(Visibility.GONE))
)
onView(withId(R.id.profile_list_scroll_right)).check(
matches(
withEffectiveVisibility(
Visibility.GONE
)
)
)
}
}

Expand Down Expand Up @@ -748,8 +792,9 @@ class ProfileChooserFragmentTest {
// that a profile was previously logged in).
profileTestHelper.initializeProfiles(autoLogIn = true)
launch<ProfileChooserActivity>(createProfileChooserActivityIntent()).use {
testCoroutineDispatchers.runCurrent()

onView(isRoot()).perform(orientationLandscape())
testCoroutineDispatchers.runCurrent()
onView(
atPositionOnView(
recyclerViewId = R.id.profiles_list_landscape,
Expand Down Expand Up @@ -840,6 +885,7 @@ class ProfileChooserFragmentTest {
fun testFragment_enableOnboardingV2_clickProfileWithPin_checkOpensPinPasswordActivity() {
TestPlatformParameterModule.forceEnableOnboardingFlowV2(true)
profileTestHelper.addOnlyAdminProfile()
profileTestHelper.updateProfileType(testProfileId, ProfileType.SUPERVISOR)
launch(ProfileChooserActivity::class.java).use {
testCoroutineDispatchers.runCurrent()
onView(
Expand Down
18 changes: 18 additions & 0 deletions model/src/main/proto/arguments.proto
Original file line number Diff line number Diff line change
Expand Up @@ -900,12 +900,30 @@ message IntroActivityParams {

// The internal Id associated with the newly created profile.
int32 profile_id = 2;

// The screen from which the introduction activity was opened.
ParentScreen parent_screen = 3;

// Different parent screens that can open a new onboarding introduction activity instance.
enum ParentScreen {
// Indicates that the originating screen isn't actually known.
PARENT_SCREEN_UNSPECIFIED = 0;

// Corresponds to the Create Profile Screen in the onboarding flow.
CREATE_PROFILE_SCREEN = 1;

// Corresponds to the profile list screen.
PROFILE_CHOOSER_SCREEN = 2;
}
}

// Arguments required when creating a new IntroFragment.
message IntroFragmentArguments {
// The nickname associated with a newly created profile.
string profile_nickname = 1;

// The screen from which the introduction fragment was opened.
IntroActivityParams.ParentScreen parent_screen = 2;
}

// Params required when creating a new CreateProfileActivity.
Expand Down

0 comments on commit 34e8da5

Please sign in to comment.