From c867ad0ca1600cad48b133865bbaa1fab57526c6 Mon Sep 17 00:00:00 2001 From: prayutsu Date: Tue, 9 Feb 2021 19:31:47 +0530 Subject: [PATCH 01/25] Refactor the function markHomeMenuCloseDrawer() to restoreLastCheckedMenuItem() --- .../app/drawer/ExitProfileDialogFragment.kt | 24 +- .../app/drawer/ExitProfileDialogInterface.kt | 2 +- .../app/drawer/NavigationDrawerFragment.kt | 2 +- .../NavigationDrawerFragmentPresenter.kt | 38 ++- .../oppia/android/app/home/HomeActivity.kt | 2 +- .../testing/NavigationDrawerActivityTest.kt | 229 ++++++++++++++++-- 6 files changed, 257 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt b/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt index 66b005b4622..035f476a3c8 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt @@ -15,18 +15,18 @@ class ExitProfileDialogFragment : DialogFragment() { companion object { // TODO(#1655): Re-restrict access to fields in tests post-Gradle. - const val BOOL_IS_FROM_NAVIGATION_DRAWER_EXTRA_KEY = - "BOOL_IS_FROM_NAVIGATION_DRAWER_EXTRA_KEY" + const val BOOL_RESTORE_LAST_CHECKED_MENU_ITEM_KEY = + "BOOL_RESTORE_LAST_CHECKED_MENU_ITEM_KEY" /** * This function is responsible for displaying content in DialogFragment. * * @return [ExitProfileDialogFragment]: DialogFragment */ - fun newInstance(isFromNavigationDrawer: Boolean): ExitProfileDialogFragment { + fun newInstance(restoreLastCheckedMenuItem: Boolean): ExitProfileDialogFragment { val exitProfileDialogFragment = ExitProfileDialogFragment() val args = Bundle() - args.putBoolean(BOOL_IS_FROM_NAVIGATION_DRAWER_EXTRA_KEY, isFromNavigationDrawer) + args.putBoolean(BOOL_RESTORE_LAST_CHECKED_MENU_ITEM_KEY, restoreLastCheckedMenuItem) exitProfileDialogFragment.arguments = args return exitProfileDialogFragment } @@ -38,33 +38,35 @@ class ExitProfileDialogFragment : DialogFragment() { val args = checkNotNull(arguments) { "Expected arguments to be pass to ExitProfileDialogFragment" } - val isFromNavigationDrawer = args.getBoolean( - BOOL_IS_FROM_NAVIGATION_DRAWER_EXTRA_KEY, + val restoreLastCheckedMenuItem = args.getBoolean( + BOOL_RESTORE_LAST_CHECKED_MENU_ITEM_KEY, false ) - if (isFromNavigationDrawer) { + if (restoreLastCheckedMenuItem) { exitProfileDialogInterface = parentFragment as ExitProfileDialogInterface } - return AlertDialog + val alertDialog = AlertDialog .Builder(ContextThemeWrapper(activity as Context, R.style.AlertDialogTheme)) .setMessage(R.string.home_activity_back_dialog_message) .setNegativeButton(R.string.home_activity_back_dialog_cancel) { dialog, _ -> - if (isFromNavigationDrawer) { - exitProfileDialogInterface.markHomeMenuCloseDrawer() + if (restoreLastCheckedMenuItem) { + exitProfileDialogInterface.restoreLastCheckedMenuItem() } dialog.dismiss() } .setPositiveButton(R.string.home_activity_back_dialog_exit) { _, _ -> // TODO(#322): Need to start intent for ProfileChooserActivity to get update. Change to finish when live data bug is fixed. val intent = ProfileChooserActivity.createProfileChooserActivity(activity!!) - if (!isFromNavigationDrawer) { + if (!restoreLastCheckedMenuItem) { intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) } activity!!.startActivity(intent) } .create() + alertDialog.setCanceledOnTouchOutside(false) + return alertDialog } } diff --git a/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogInterface.kt b/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogInterface.kt index 3fbbcc4daab..37d78c1bdd0 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogInterface.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogInterface.kt @@ -2,5 +2,5 @@ package org.oppia.android.app.drawer /** Interface to handle option selection in [ExitProfileDialogFragment]. */ interface ExitProfileDialogInterface { - fun markHomeMenuCloseDrawer() + fun restoreLastCheckedMenuItem() } diff --git a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragment.kt b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragment.kt index cad40d9d4a2..5b4d5dcd7da 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragment.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragment.kt @@ -40,7 +40,7 @@ class NavigationDrawerFragment : navigationDrawerFragmentPresenter.openProfileProgress(profileId) } - override fun markHomeMenuCloseDrawer() { + override fun restoreLastCheckedMenuItem() { navigationDrawerFragmentPresenter.markHomeMenuCloseDrawer() } } diff --git a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt index 7032676f0e8..3ebd245b5fd 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt @@ -105,9 +105,7 @@ class NavigationDrawerFragmentPresenter @Inject constructor( return@setOnClickListener } - binding.fragmentDrawerNavView.menu.forEach { menuItem -> - menuItem.isCheckable = false - } + uncheckAllMenuItemsWhenAdministratorControlsIsSelected() drawerLayout.closeDrawers() getFooterViewModel().isAdministratorControlsSelected.set(true) @@ -244,8 +242,13 @@ class NavigationDrawerFragmentPresenter @Inject constructor( if (previousFragment != null) { fragment.childFragmentManager.beginTransaction().remove(previousFragment).commitNow() } + getFooterViewModel().isAdministratorControlsSelected.set(false) + binding.fragmentDrawerNavView.menu.getItem( + NavigationDrawerItem.SWITCH_PROFILE.ordinal + ).isChecked = + true val dialogFragment = ExitProfileDialogFragment - .newInstance(isFromNavigationDrawer = true) + .newInstance(restoreLastCheckedMenuItem = true) dialogFragment.showNow(fragment.childFragmentManager, TAG_SWITCH_PROFILE_DIALOG) } } @@ -264,13 +267,31 @@ class NavigationDrawerFragmentPresenter @Inject constructor( } fun markHomeMenuCloseDrawer() { - binding.fragmentDrawerNavView.menu.getItem( - NavigationDrawerItem.HOME.ordinal - ).isChecked = - true + if (previousMenuItemId != null) { + val lastCheckedMenuItemValue: Int = previousMenuItemId!! + if (lastCheckedMenuItemValue == 0) { + getFooterViewModel().isAdministratorControlsSelected.set(true) + uncheckAllMenuItemsWhenAdministratorControlsIsSelected() + binding.fragmentDrawerNavView.menu.getItem(NavigationDrawerItem.SWITCH_PROFILE.ordinal).isChecked = + false + } else { + binding.fragmentDrawerNavView.menu.getItem( + NavigationDrawerItem.valueFromNavId( + lastCheckedMenuItemValue + ).ordinal + ).isChecked = + true + } + } drawerLayout.closeDrawers() } + private fun uncheckAllMenuItemsWhenAdministratorControlsIsSelected() { + binding.fragmentDrawerNavView.menu.forEach { + it.isCheckable = false; + } + } + /** * Initializes the navigation drawer for the specified [DrawerLayout] and [Toolbar], which the host activity is * expected to provide. The [menuItemId] corresponds to the menu ID of the current activity, for navigation purposes. @@ -345,6 +366,7 @@ class NavigationDrawerFragmentPresenter @Inject constructor( } else { // For showing navigation drawer in AdministratorControlsActivity getFooterViewModel().isAdministratorControlsSelected.set(true) + uncheckAllMenuItemsWhenAdministratorControlsIsSelected() this.drawerLayout = drawerLayout drawerToggle = object : ActionBarDrawerToggle( fragment.activity, diff --git a/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt b/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt index 164af1622e7..ec14714e390 100644 --- a/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt +++ b/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt @@ -49,7 +49,7 @@ class HomeActivity : supportFragmentManager.beginTransaction().remove(previousFragment).commitNow() } val dialogFragment = ExitProfileDialogFragment - .newInstance(isFromNavigationDrawer = false) + .newInstance(restoreLastCheckedMenuItem = false) dialogFragment.showNow(supportFragmentManager, TAG_SWITCH_PROFILE_DIALOG) } diff --git a/app/src/sharedTest/java/org/oppia/android/app/testing/NavigationDrawerActivityTest.kt b/app/src/sharedTest/java/org/oppia/android/app/testing/NavigationDrawerActivityTest.kt index ac38474ccdc..f0472b12c3e 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/testing/NavigationDrawerActivityTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/testing/NavigationDrawerActivityTest.kt @@ -27,6 +27,7 @@ import androidx.test.espresso.intent.Intents.intended import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent import androidx.test.espresso.intent.matcher.IntentMatchers.hasExtra import androidx.test.espresso.matcher.RootMatchers.isDialog +import androidx.test.espresso.matcher.ViewMatchers import androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA @@ -37,9 +38,12 @@ import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.espresso.util.HumanReadables import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.google.android.material.navigation.NavigationView import dagger.Component +import org.hamcrest.Description import org.hamcrest.Matchers.allOf import org.hamcrest.Matchers.not +import org.hamcrest.TypeSafeMatcher import org.junit.After import org.junit.Before import org.junit.Ignore @@ -55,6 +59,7 @@ import org.oppia.android.app.application.ApplicationInjector import org.oppia.android.app.application.ApplicationInjectorProvider import org.oppia.android.app.application.ApplicationModule import org.oppia.android.app.application.ApplicationStartupListenerModule +import org.oppia.android.app.drawer.NavigationDrawerItem import org.oppia.android.app.help.HelpActivity import org.oppia.android.app.model.ProfileId import org.oppia.android.app.mydownloads.MyDownloadsActivity @@ -161,7 +166,7 @@ class NavigationDrawerActivityTest { } @Test - fun testNavigationDrawerTestActivity_openNavDrawer_navDrawerIsOpened() { + fun testNavDrawer_openNavDrawer_navDrawerIsOpened() { launch(NavigationDrawerTestActivity::class.java).use { it.openNavigationDrawer() onView(withId(R.id.home_fragment_placeholder)).check(matches(isCompletelyDisplayed())) @@ -170,7 +175,7 @@ class NavigationDrawerActivityTest { } @Test - fun testNavigationDrawerTestActivity_openNavDrawer_changeConfig_navDrawerIsDisplayed() { + fun testNavDrawer_openNavDrawer_configChange_navDrawerIsDisplayed() { launch(NavigationDrawerTestActivity::class.java).use { it.openNavigationDrawer() onView(isRoot()).perform(orientationLandscape()) @@ -179,7 +184,7 @@ class NavigationDrawerActivityTest { } @Test - fun testNavigationDrawerTestActivity_withAdminProfile_openNavDrawer_profileNameIsDisplayed() { + fun testNavDrawer_withAdminProfile_openNavDrawer_profileNameIsDisplayed() { launch( createNavigationDrawerActivityIntent( internalProfileId @@ -197,7 +202,7 @@ class NavigationDrawerActivityTest { } @Test - fun testNavigationDrawerTestActivity_withAdminProfile_changeConfig_profileNameIsDisplayed() { + fun testNavDrawer_withAdminProfile_configChange_profileNameIsDisplayed() { launch( createNavigationDrawerActivityIntent( internalProfileId @@ -216,7 +221,7 @@ class NavigationDrawerActivityTest { } @Test - fun testNavigationDrawerTestActivity_openNavDrawer_profileProgressIsDisplayed() { + fun testNavDrawer_openNavDrawer_profileProgressIsDisplayed() { launch( createNavigationDrawerActivityIntent( internalProfileId @@ -234,7 +239,7 @@ class NavigationDrawerActivityTest { } @Test - fun testNavigationDrawerTestActivity_withUserProfile_openNavDrawer_profileNameIsDisplayed() { + fun testNavDrawer_withUserProfile_openNavDrawer_profileNameIsDisplayed() { launch( createNavigationDrawerActivityIntent( internalProfileId1 @@ -252,7 +257,7 @@ class NavigationDrawerActivityTest { } @Test - fun testNavigationDrawerTestActivity_clickOnHeader_opensProfileProgressActivity() { + fun testNavDrawer_clickOnHeader_opensProfileProgressActivity() { launch( createNavigationDrawerActivityIntent( internalProfileId @@ -272,8 +277,185 @@ class NavigationDrawerActivityTest { } } + // TODO(#2535): Unable to open NavigationDrawer multiple times on Robolectric + @RunOn(TestPlatform.ESPRESSO) + @Test + fun testNavDrawer_openNavDrawer_switchProfile_cancel_homeItemIsSelected() { + launch( + createNavigationDrawerActivityIntent(internalProfileId) + ).use { + it.openNavigationDrawer() + onView(withText(R.string.menu_switch_profile)).perform(click()) + onView(withText(R.string.home_activity_back_dialog_cancel)) + .inRoot(isDialog()) + .perform(click()) + it.openNavigationDrawer() + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.fragment_drawer_nav_view)) + .check(matches(checkNavigationViewItemStatus(NavigationDrawerItem.HOME))) + } + } + + // TODO(#2535): Unable to open NavigationDrawer multiple times on Robolectric + @RunOn(TestPlatform.ESPRESSO) + @Test + fun testNavDrawer_openNavDrawer_options_switchProfile_cancel_optionsIsSelected() { + launch( + createNavigationDrawerActivityIntent(internalProfileId) + ).use { + it.openNavigationDrawer() + onView(withText(R.string.menu_options)).perform(click()) + it.openNavigationDrawer() + onView(withText(R.string.menu_switch_profile)).perform(click()) + onView(withText(R.string.home_activity_back_dialog_cancel)) + .inRoot(isDialog()) + .perform(click()) + it.openNavigationDrawer() + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.fragment_drawer_nav_view)) + .check(matches(checkNavigationViewItemStatus(NavigationDrawerItem.OPTIONS))) + } + } + + // TODO(#2535): Unable to open NavigationDrawer multiple times on Robolectric + @RunOn(TestPlatform.ESPRESSO) + @Test + fun testNavDrawer_openNavDrawer_help_switchProfile_cancel_helpIsSelected() { + launch( + createNavigationDrawerActivityIntent(internalProfileId) + ).use { + it.openNavigationDrawer() + onView(withText(R.string.menu_help)).perform(click()) + it.openNavigationDrawer() + onView(withText(R.string.menu_switch_profile)).perform(click()) + onView(withText(R.string.home_activity_back_dialog_cancel)) + .inRoot(isDialog()) + .perform(click()) + it.openNavigationDrawer() + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.fragment_drawer_nav_view)) + .check(matches(checkNavigationViewItemStatus(NavigationDrawerItem.HELP))) + } + } + + // TODO(#2535): Unable to open NavigationDrawer multiple times on Robolectric + @RunOn(TestPlatform.ESPRESSO) + @Test + fun testNavDrawer_openNavDrawer_admin_switchProfile_cancel_adminIsSelected() { + launch( + createNavigationDrawerActivityIntent(internalProfileId) + ).use { + it.openNavigationDrawer() + onView(withText(R.string.administrator_controls)).perform(click()) + it.openNavigationDrawer() + onView(withText(R.string.menu_switch_profile)).perform(click()) + onView(withText(R.string.home_activity_back_dialog_cancel)) + .inRoot(isDialog()) + .perform(click()) + it.openNavigationDrawer() + testCoroutineDispatchers.runCurrent() + onView( + allOf( + withText(R.string.administrator_controls), + isDescendantOfA(withId(R.id.administrator_controls_linear_layout)) + ) + ).check(matches(ViewMatchers.hasTextColor(R.color.highlightedNavMenuItem))) + } + } + + // TODO(#2535): Unable to open NavigationDrawer multiple times on Robolectric + @RunOn(TestPlatform.ESPRESSO) + @Test + fun testNavDrawer_openNavDrawer_switchProfile_cancel_configChange_homeIsSelected() { + launch( + createNavigationDrawerActivityIntent(internalProfileId) + ).use { + it.openNavigationDrawer() + onView(withText(R.string.menu_switch_profile)).perform(click()) + onView(withText(R.string.home_activity_back_dialog_cancel)) + .inRoot(isDialog()) + .perform(click()) + it.openNavigationDrawer() + onView(isRoot()).perform(orientationLandscape()) + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.fragment_drawer_nav_view)) + .check(matches(checkNavigationViewItemStatus(NavigationDrawerItem.HOME))) + } + } + + // TODO(#2535): Unable to open NavigationDrawer multiple times on Robolectric + @RunOn(TestPlatform.ESPRESSO) + @Test + fun testNavDrawer_openNavDrawer_options_switchProfile_cancel_configChange_optionsIsSelected() { + launch( + createNavigationDrawerActivityIntent(internalProfileId) + ).use { + it.openNavigationDrawer() + onView(withText(R.string.menu_options)).perform(click()) + it.openNavigationDrawer() + onView(withText(R.string.menu_switch_profile)).perform(click()) + onView(withText(R.string.home_activity_back_dialog_cancel)) + .inRoot(isDialog()) + .perform(click()) + it.openNavigationDrawer() + onView(isRoot()).perform(orientationLandscape()) + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.fragment_drawer_nav_view)) + .check(matches(checkNavigationViewItemStatus(NavigationDrawerItem.OPTIONS))) + } + } + + // TODO(#2535): Unable to open NavigationDrawer multiple times on Robolectric + @RunOn(TestPlatform.ESPRESSO) + @Test + fun testNavDrawer_openNavDrawer_help_switchProfile_cancel_configChange_helpIsSelected() { + launch( + createNavigationDrawerActivityIntent(internalProfileId) + ).use { + it.openNavigationDrawer() + onView(withText(R.string.menu_help)).perform(click()) + it.openNavigationDrawer() + onView(withText(R.string.menu_switch_profile)).perform(click()) + onView(withText(R.string.home_activity_back_dialog_cancel)) + .inRoot(isDialog()) + .perform(click()) + it.openNavigationDrawer() + onView(isRoot()).perform(orientationLandscape()) + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.fragment_drawer_nav_view)) + .check(matches(checkNavigationViewItemStatus(NavigationDrawerItem.HELP))) + } + } + + // TODO(#2535): Unable to open NavigationDrawer multiple times on Robolectric + @RunOn(TestPlatform.ESPRESSO) + @Test + fun testNavDrawer_openNavDrawer_admin_switchProfile_cancel_configChange_adminIsSelected() { + launch( + createNavigationDrawerActivityIntent(internalProfileId) + ).use { + it.openNavigationDrawer() + onView(withText(R.string.administrator_controls)).perform(click()) + it.openNavigationDrawer() + onView(withText(R.string.menu_switch_profile)).perform(click()) + onView(withText(R.string.home_activity_back_dialog_cancel)) + .inRoot(isDialog()) + .perform(click()) + it.openNavigationDrawer() + testCoroutineDispatchers.runCurrent() + onView(isRoot()).perform(orientationLandscape()) + testCoroutineDispatchers.runCurrent() + onView( + allOf( + withText(R.string.administrator_controls), + isDescendantOfA(withId(R.id.administrator_controls_linear_layout)) + ) + ).check(matches(ViewMatchers.hasTextColor(R.color.highlightedNavMenuItem))) + } + } + @Test - fun testNavigationDrawerTestActivity_withAdminProfile_openNavDrawer_adminControlsIsDisplayed() { + fun testNavDrawer_withAdminProfile_openNavDrawer_adminControlsIsDisplayed() { launch( createNavigationDrawerActivityIntent(internalProfileId) ).use { @@ -283,7 +465,7 @@ class NavigationDrawerActivityTest { } @Test - fun testNavigationDrawerTestActivity_withAdminProfile_changeConfig_adminControlsIsDisplayed() { + fun testNavDrawer_withAdminProfile_configChange_adminControlsIsDisplayed() { launch( createNavigationDrawerActivityIntent(internalProfileId) ).use { @@ -295,7 +477,7 @@ class NavigationDrawerActivityTest { } @Test - fun testNavigationDrawerTestActivity_withAdminProfile_adminMenu_opensAdminControlsActivity() { + fun testNavDrawer_withAdminProfile_adminMenu_opensAdminControlsActivity() { launch( createNavigationDrawerActivityIntent( internalProfileId @@ -310,7 +492,7 @@ class NavigationDrawerActivityTest { } @Test - fun testNavigationDrawerTestActivity_withUserProfile_adminControlsAreNotDisplayed() { + fun testNavDrawer_withUserProfile_adminControlsAreNotDisplayed() { launch( createNavigationDrawerActivityIntent( internalProfileId1 @@ -325,7 +507,7 @@ class NavigationDrawerActivityTest { // TODO(#1806): Enable this once lowfi implementation is done. @Test @Ignore("My Downloads is removed until we have full download support.") - fun testNavigationDrawerTestActivity_myDownloadsMenu_myDownloadsFragmentIsDisplayed() { + fun testNavDrawer_myDownloadsMenu_myDownloadsFragmentIsDisplayed() { launch(NavigationDrawerTestActivity::class.java).use { it.openNavigationDrawer() onView(withText(R.string.menu_my_downloads)).perform(click()) @@ -334,7 +516,7 @@ class NavigationDrawerActivityTest { } @Test - fun testNavigationDrawerTestActivity_switchProfileMenu_showsExitToProfileChooserDialog() { + fun testNavDrawer_switchProfileMenu_exitToProfileChooserDialogIsDisplayed() { launch(NavigationDrawerTestActivity::class.java).use { it.openNavigationDrawer() onView(withText(R.string.menu_switch_profile)).perform(click()) @@ -345,7 +527,7 @@ class NavigationDrawerActivityTest { } @Test - fun testNavigationDrawerTestActivity_switchProfileMenu_clickExit_opensProfileChooserActivity() { + fun testNavDrawer_switchProfileMenu_clickExit_opensProfileChooserActivity() { launch(NavigationDrawerTestActivity::class.java).use { it.openNavigationDrawer() onView(withText(R.string.menu_switch_profile)).perform(click()) @@ -361,7 +543,7 @@ class NavigationDrawerActivityTest { @RunOn(TestPlatform.ESPRESSO) @Test - fun testNavigationDrawerTestActivity_openNavDrawerAndClose_navDrawerIsClosed() { + fun testNavDrawer_openNavDrawerAndClose_navDrawerIsClosed() { launch(NavigationDrawerTestActivity::class.java).use { testCoroutineDispatchers.runCurrent() it.openNavigationDrawer() @@ -372,7 +554,7 @@ class NavigationDrawerActivityTest { @RunOn(TestPlatform.ESPRESSO) @Test - fun testNavigationDrawerTestActivity_selectSwitchProfileMenu_clickCancel_navDrawerIsClosed() { + fun testNavDrawer_selectSwitchProfileMenu_clickCancel_navDrawerIsClosed() { launch(NavigationDrawerTestActivity::class.java).use { it.openNavigationDrawer() onView(withText(R.string.menu_switch_profile)).perform(click()) @@ -388,7 +570,7 @@ class NavigationDrawerActivityTest { } @Test - fun testNavigationDrawerTestActivity_selectSwitchProfile_changeConfig_dialogIsVisible() { + fun testNavDrawer_selectSwitchProfile_configChange_dialogIsVisible() { launch(NavigationDrawerTestActivity::class.java).use { it.openNavigationDrawer() onView(withText(R.string.menu_switch_profile)).perform(click()) @@ -401,7 +583,7 @@ class NavigationDrawerActivityTest { } @Test - fun testNavigationDrawerTestActivity_openNavDrawer_selectHelpMenu_opensHelpActivity() { + fun testNavDrawer_openNavDrawer_selectHelpMenu_opensHelpActivity() { launch(NavigationDrawerTestActivity::class.java).use { it.openNavigationDrawer() onView(withText(R.string.menu_help)).perform(click()) @@ -490,6 +672,17 @@ class NavigationDrawerActivityTest { return view.getParent() } + private fun checkNavigationViewItemStatus(item: NavigationDrawerItem) = + object : TypeSafeMatcher() { + override fun describeTo(description: Description) { + description.appendText("NavigationViewItem is checked") + } + + override fun matchesSafely(view: View): Boolean { + return (view as NavigationView).menu.getItem(item.ordinal).isChecked + } + } + // TODO(#59): Figure out a way to reuse modules instead of needing to re-declare them. // TODO(#1675): Add NetworkModule once data module is migrated off of Moshi. @Singleton From b99ce309f61b05a6ef21515b244966e9655d42b2 Mon Sep 17 00:00:00 2001 From: prayutsu Date: Tue, 9 Feb 2021 19:33:20 +0530 Subject: [PATCH 02/25] Fix lint errors. --- .../android/app/drawer/NavigationDrawerFragmentPresenter.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt index 3ebd245b5fd..5333486a180 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt @@ -272,7 +272,9 @@ class NavigationDrawerFragmentPresenter @Inject constructor( if (lastCheckedMenuItemValue == 0) { getFooterViewModel().isAdministratorControlsSelected.set(true) uncheckAllMenuItemsWhenAdministratorControlsIsSelected() - binding.fragmentDrawerNavView.menu.getItem(NavigationDrawerItem.SWITCH_PROFILE.ordinal).isChecked = + binding.fragmentDrawerNavView.menu.getItem( + NavigationDrawerItem.SWITCH_PROFILE.ordinal + ).isChecked = false } else { binding.fragmentDrawerNavView.menu.getItem( @@ -288,7 +290,7 @@ class NavigationDrawerFragmentPresenter @Inject constructor( private fun uncheckAllMenuItemsWhenAdministratorControlsIsSelected() { binding.fragmentDrawerNavView.menu.forEach { - it.isCheckable = false; + it.isCheckable = false } } From 25ca17aa458464cee7223813c7c4d703fdb7218d Mon Sep 17 00:00:00 2001 From: prayutsu Date: Tue, 9 Feb 2021 22:26:36 +0530 Subject: [PATCH 03/25] Make naming consistent. --- .../org/oppia/android/app/drawer/NavigationDrawerFragment.kt | 2 +- .../android/app/drawer/NavigationDrawerFragmentPresenter.kt | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragment.kt b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragment.kt index 5b4d5dcd7da..f050655b106 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragment.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragment.kt @@ -41,6 +41,6 @@ class NavigationDrawerFragment : } override fun restoreLastCheckedMenuItem() { - navigationDrawerFragmentPresenter.markHomeMenuCloseDrawer() + navigationDrawerFragmentPresenter.restoreLastCheckedMenuItem() } } diff --git a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt index 5333486a180..4dcec2ed822 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt @@ -21,6 +21,7 @@ import org.oppia.android.app.help.HelpActivity import org.oppia.android.app.home.HomeActivity import org.oppia.android.app.model.CompletedStoryList import org.oppia.android.app.model.OngoingTopicList +import org.oppia.android.app.model.OppiaLogger import org.oppia.android.app.model.Profile import org.oppia.android.app.model.ProfileId import org.oppia.android.app.mydownloads.MyDownloadsActivity @@ -266,7 +267,7 @@ class NavigationDrawerFragmentPresenter @Inject constructor( ) } - fun markHomeMenuCloseDrawer() { + fun restoreLastCheckedMenuItem() { if (previousMenuItemId != null) { val lastCheckedMenuItemValue: Int = previousMenuItemId!! if (lastCheckedMenuItemValue == 0) { From a0eb27eb16ad0549e5c3959729ab630807949c9c Mon Sep 17 00:00:00 2001 From: prayutsu Date: Tue, 9 Feb 2021 22:33:13 +0530 Subject: [PATCH 04/25] Fix lint. --- .../android/app/drawer/NavigationDrawerFragmentPresenter.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt index 4dcec2ed822..5161cb7dcf3 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt @@ -21,7 +21,6 @@ import org.oppia.android.app.help.HelpActivity import org.oppia.android.app.home.HomeActivity import org.oppia.android.app.model.CompletedStoryList import org.oppia.android.app.model.OngoingTopicList -import org.oppia.android.app.model.OppiaLogger import org.oppia.android.app.model.Profile import org.oppia.android.app.model.ProfileId import org.oppia.android.app.mydownloads.MyDownloadsActivity From 7507d0d211a01278e345bfa107b20e95a331aa93 Mon Sep 17 00:00:00 2001 From: prayutsu Date: Wed, 10 Feb 2021 17:15:07 +0530 Subject: [PATCH 05/25] Handle highlighting Administrator Controls separately. --- .../app/drawer/ExitProfileDialogFragment.kt | 37 +++++++++++++------ .../app/drawer/ExitProfileDialogInterface.kt | 3 +- .../app/drawer/NavigationDrawerFragment.kt | 8 +++- .../NavigationDrawerFragmentPresenter.kt | 31 ++++++++++++---- .../oppia/android/app/home/HomeActivity.kt | 5 ++- model/src/main/proto/arguments.proto | 22 +++++++++++ 6 files changed, 84 insertions(+), 22 deletions(-) create mode 100644 model/src/main/proto/arguments.proto diff --git a/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt b/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt index 035f476a3c8..5a740140188 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt @@ -8,25 +8,29 @@ import androidx.appcompat.app.AlertDialog import androidx.appcompat.view.ContextThemeWrapper import androidx.fragment.app.DialogFragment import org.oppia.android.R +import org.oppia.android.app.model.ExitProfileDialogArguments import org.oppia.android.app.profile.ProfileChooserActivity +import org.oppia.android.util.extensions.getProto +import org.oppia.android.util.extensions.putProto /** [DialogFragment] that gives option to either cancel or exit current profile. */ class ExitProfileDialogFragment : DialogFragment() { companion object { // TODO(#1655): Re-restrict access to fields in tests post-Gradle. - const val BOOL_RESTORE_LAST_CHECKED_MENU_ITEM_KEY = - "BOOL_RESTORE_LAST_CHECKED_MENU_ITEM_KEY" + const val EXIT_PROFILE_DIALOG_ARGUMENTS_PROTO = "EXIT_PROFILE_DIALOG_ARGUMENT_PROTO" /** * This function is responsible for displaying content in DialogFragment. * * @return [ExitProfileDialogFragment]: DialogFragment */ - fun newInstance(restoreLastCheckedMenuItem: Boolean): ExitProfileDialogFragment { + fun newInstance( + exitProfileDialogArguments: ExitProfileDialogArguments + ): ExitProfileDialogFragment { val exitProfileDialogFragment = ExitProfileDialogFragment() val args = Bundle() - args.putBoolean(BOOL_RESTORE_LAST_CHECKED_MENU_ITEM_KEY, restoreLastCheckedMenuItem) + args.putProto(EXIT_PROFILE_DIALOG_ARGUMENTS_PROTO, exitProfileDialogArguments) exitProfileDialogFragment.arguments = args return exitProfileDialogFragment } @@ -38,12 +42,17 @@ class ExitProfileDialogFragment : DialogFragment() { val args = checkNotNull(arguments) { "Expected arguments to be pass to ExitProfileDialogFragment" } - val restoreLastCheckedMenuItem = args.getBoolean( - BOOL_RESTORE_LAST_CHECKED_MENU_ITEM_KEY, - false + val exitProfileDialogArguments = args.getProto( + EXIT_PROFILE_DIALOG_ARGUMENTS_PROTO, + ExitProfileDialogArguments.getDefaultInstance() ) - if (restoreLastCheckedMenuItem) { + val restoreLastCheckedItem = when (exitProfileDialogArguments.highlightItemCase) { + ExitProfileDialogArguments.HighlightItemCase.HIGHLIGHTITEM_NOT_SET -> false + else -> true + } + + if (restoreLastCheckedItem) { exitProfileDialogInterface = parentFragment as ExitProfileDialogInterface } @@ -52,15 +61,21 @@ class ExitProfileDialogFragment : DialogFragment() { .Builder(ContextThemeWrapper(activity as Context, R.style.AlertDialogTheme)) .setMessage(R.string.home_activity_back_dialog_message) .setNegativeButton(R.string.home_activity_back_dialog_cancel) { dialog, _ -> - if (restoreLastCheckedMenuItem) { - exitProfileDialogInterface.restoreLastCheckedMenuItem() + if (restoreLastCheckedItem) { + if (exitProfileDialogArguments.highlightItemCase == + ExitProfileDialogArguments.HighlightItemCase.HIGHLIGHT_LAST_CHECKED_MENU_ITEM + ) { + exitProfileDialogInterface.highlightLastCheckedMenuItem() + } else { + exitProfileDialogInterface.highlightAdministratorControlsItem() + } } dialog.dismiss() } .setPositiveButton(R.string.home_activity_back_dialog_exit) { _, _ -> // TODO(#322): Need to start intent for ProfileChooserActivity to get update. Change to finish when live data bug is fixed. val intent = ProfileChooserActivity.createProfileChooserActivity(activity!!) - if (!restoreLastCheckedMenuItem) { + if (!restoreLastCheckedItem) { intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) } activity!!.startActivity(intent) diff --git a/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogInterface.kt b/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogInterface.kt index 37d78c1bdd0..23c77eb902e 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogInterface.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogInterface.kt @@ -2,5 +2,6 @@ package org.oppia.android.app.drawer /** Interface to handle option selection in [ExitProfileDialogFragment]. */ interface ExitProfileDialogInterface { - fun restoreLastCheckedMenuItem() + fun highlightLastCheckedMenuItem() + fun highlightAdministratorControlsItem() } diff --git a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragment.kt b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragment.kt index f050655b106..fad10f0e08a 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragment.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragment.kt @@ -40,7 +40,11 @@ class NavigationDrawerFragment : navigationDrawerFragmentPresenter.openProfileProgress(profileId) } - override fun restoreLastCheckedMenuItem() { - navigationDrawerFragmentPresenter.restoreLastCheckedMenuItem() + override fun highlightLastCheckedMenuItem() { + navigationDrawerFragmentPresenter.highlightLastCheckedMenuItem() + } + + override fun highlightAdministratorControlsItem() { + navigationDrawerFragmentPresenter.highlightAdministratorControlsItem() } } diff --git a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt index 5161cb7dcf3..968971c3d38 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt @@ -20,6 +20,7 @@ import org.oppia.android.app.fragment.FragmentScope import org.oppia.android.app.help.HelpActivity import org.oppia.android.app.home.HomeActivity import org.oppia.android.app.model.CompletedStoryList +import org.oppia.android.app.model.ExitProfileDialogArguments import org.oppia.android.app.model.OngoingTopicList import org.oppia.android.app.model.Profile import org.oppia.android.app.model.ProfileId @@ -197,7 +198,6 @@ class NavigationDrawerFragmentPresenter @Inject constructor( } private fun openActivityByMenuItemId(menuItemId: Int) { - getFooterViewModel().isAdministratorControlsSelected.set(false) if (previousMenuItemId != menuItemId) { when (NavigationDrawerItem.valueFromNavId(menuItemId)) { NavigationDrawerItem.HOME -> { @@ -242,13 +242,25 @@ class NavigationDrawerFragmentPresenter @Inject constructor( if (previousFragment != null) { fragment.childFragmentManager.beginTransaction().remove(previousFragment).commitNow() } + val exitProfileDialogArguments = + if (getFooterViewModel().isAdministratorControlsSelected.get() == true) { + ExitProfileDialogArguments + .newBuilder() + .setHighlightAdministratorControlsItem(true) + .build() + } else { + ExitProfileDialogArguments + .newBuilder() + .setHighlightLastCheckedMenuItem(true) + .build() + } getFooterViewModel().isAdministratorControlsSelected.set(false) binding.fragmentDrawerNavView.menu.getItem( NavigationDrawerItem.SWITCH_PROFILE.ordinal ).isChecked = true val dialogFragment = ExitProfileDialogFragment - .newInstance(restoreLastCheckedMenuItem = true) + .newInstance(exitProfileDialogArguments = exitProfileDialogArguments) dialogFragment.showNow(fragment.childFragmentManager, TAG_SWITCH_PROFILE_DIALOG) } } @@ -266,17 +278,14 @@ class NavigationDrawerFragmentPresenter @Inject constructor( ) } - fun restoreLastCheckedMenuItem() { + fun highlightLastCheckedMenuItem() { if (previousMenuItemId != null) { val lastCheckedMenuItemValue: Int = previousMenuItemId!! - if (lastCheckedMenuItemValue == 0) { - getFooterViewModel().isAdministratorControlsSelected.set(true) - uncheckAllMenuItemsWhenAdministratorControlsIsSelected() + if (lastCheckedMenuItemValue != 0) { binding.fragmentDrawerNavView.menu.getItem( NavigationDrawerItem.SWITCH_PROFILE.ordinal ).isChecked = false - } else { binding.fragmentDrawerNavView.menu.getItem( NavigationDrawerItem.valueFromNavId( lastCheckedMenuItemValue @@ -284,7 +293,15 @@ class NavigationDrawerFragmentPresenter @Inject constructor( ).isChecked = true } + drawerLayout.closeDrawers() } + } + + fun highlightAdministratorControlsItem() { + binding.fragmentDrawerNavView.menu.getItem(NavigationDrawerItem.SWITCH_PROFILE.ordinal).isChecked = + false + getFooterViewModel().isAdministratorControlsSelected.set(true) + uncheckAllMenuItemsWhenAdministratorControlsIsSelected() drawerLayout.closeDrawers() } diff --git a/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt b/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt index ec14714e390..46725dbee7f 100644 --- a/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt +++ b/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt @@ -9,6 +9,7 @@ import org.oppia.android.app.drawer.ExitProfileDialogFragment import org.oppia.android.app.drawer.KEY_NAVIGATION_PROFILE_ID import org.oppia.android.app.drawer.TAG_SWITCH_PROFILE_DIALOG import org.oppia.android.app.home.recentlyplayed.RecentlyPlayedActivity +import org.oppia.android.app.model.ExitProfileDialogArguments import org.oppia.android.app.topic.TopicActivity import javax.inject.Inject @@ -48,8 +49,10 @@ class HomeActivity : if (previousFragment != null) { supportFragmentManager.beginTransaction().remove(previousFragment).commitNow() } + val exitProfileDialogArguments = + ExitProfileDialogArguments.newBuilder().setHighlightNone(true).build() val dialogFragment = ExitProfileDialogFragment - .newInstance(restoreLastCheckedMenuItem = false) + .newInstance(exitProfileDialogArguments = exitProfileDialogArguments) dialogFragment.showNow(supportFragmentManager, TAG_SWITCH_PROFILE_DIALOG) } diff --git a/model/src/main/proto/arguments.proto b/model/src/main/proto/arguments.proto new file mode 100644 index 00000000000..7a688e57541 --- /dev/null +++ b/model/src/main/proto/arguments.proto @@ -0,0 +1,22 @@ +syntax = "proto3"; + +package model; + +option java_package = "org.oppia.android.app.model"; +option java_multiple_files = true; + +// The fragment arguments passed to instances of ExitProfileDialogFragment. +message ExitProfileDialogArguments { + // Decides the correct menu item to be highlighted after canceling the ExitProfile dialog. + oneof highlightItem { + // Whether any menu item needs to be highlighted or not. + bool highlight_none = 1; + + // Whether some menuItem from the Navigation Drawer menu needs to be highlighted or not. + bool highlight_last_checked_menu_item = 2; + + // Whether Administrator Controls item from the Navigation Drawer footer needs to be + // highlighted or not. + bool highlight_administrator_controls_item = 3; + } +} From 6cea308000dd56b1add2287406a6ed6ae1c3730b Mon Sep 17 00:00:00 2001 From: prayutsu Date: Wed, 10 Feb 2021 17:16:24 +0530 Subject: [PATCH 06/25] Fix lint errors. --- .../android/app/drawer/NavigationDrawerFragmentPresenter.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt index 968971c3d38..90abe2a84d9 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt @@ -298,7 +298,9 @@ class NavigationDrawerFragmentPresenter @Inject constructor( } fun highlightAdministratorControlsItem() { - binding.fragmentDrawerNavView.menu.getItem(NavigationDrawerItem.SWITCH_PROFILE.ordinal).isChecked = + binding.fragmentDrawerNavView.menu.getItem( + NavigationDrawerItem.SWITCH_PROFILE.ordinal + ).isChecked = false getFooterViewModel().isAdministratorControlsSelected.set(true) uncheckAllMenuItemsWhenAdministratorControlsIsSelected() From 251b2c69ca94acef6e3415932c98a6b57c4bd980 Mon Sep 17 00:00:00 2001 From: prayutsu Date: Wed, 10 Feb 2021 17:19:20 +0530 Subject: [PATCH 07/25] Use let for null check. --- .../app/drawer/NavigationDrawerFragmentPresenter.kt | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt index 90abe2a84d9..11baa495c00 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt @@ -279,16 +279,11 @@ class NavigationDrawerFragmentPresenter @Inject constructor( } fun highlightLastCheckedMenuItem() { - if (previousMenuItemId != null) { - val lastCheckedMenuItemValue: Int = previousMenuItemId!! - if (lastCheckedMenuItemValue != 0) { - binding.fragmentDrawerNavView.menu.getItem( - NavigationDrawerItem.SWITCH_PROFILE.ordinal - ).isChecked = - false + previousMenuItemId?.let { itemId -> + if (itemId != 0) { binding.fragmentDrawerNavView.menu.getItem( NavigationDrawerItem.valueFromNavId( - lastCheckedMenuItemValue + itemId ).ordinal ).isChecked = true From 72c52aef6960c4f55d60c6876a6ffb6cb5e31b7d Mon Sep 17 00:00:00 2001 From: prayutsu Date: Wed, 10 Feb 2021 17:21:48 +0530 Subject: [PATCH 08/25] Fix proto lint errors. --- model/src/main/proto/arguments.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/src/main/proto/arguments.proto b/model/src/main/proto/arguments.proto index 7a688e57541..d8496171587 100644 --- a/model/src/main/proto/arguments.proto +++ b/model/src/main/proto/arguments.proto @@ -8,7 +8,7 @@ option java_multiple_files = true; // The fragment arguments passed to instances of ExitProfileDialogFragment. message ExitProfileDialogArguments { // Decides the correct menu item to be highlighted after canceling the ExitProfile dialog. - oneof highlightItem { + oneof highlight_item { // Whether any menu item needs to be highlighted or not. bool highlight_none = 1; From 2b387bd819c009f840adaf4277312a3c6dddf683 Mon Sep 17 00:00:00 2001 From: prayutsu Date: Wed, 10 Feb 2021 17:38:55 +0530 Subject: [PATCH 09/25] Make separate method to unhighlight Switch Profile. --- .../android/app/drawer/ExitProfileDialogFragment.kt | 1 + .../android/app/drawer/ExitProfileDialogInterface.kt | 1 + .../oppia/android/app/drawer/NavigationDrawerFragment.kt | 4 ++++ .../app/drawer/NavigationDrawerFragmentPresenter.kt | 9 ++++++--- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt b/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt index 5a740140188..5c9d11f1715 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt @@ -62,6 +62,7 @@ class ExitProfileDialogFragment : DialogFragment() { .setMessage(R.string.home_activity_back_dialog_message) .setNegativeButton(R.string.home_activity_back_dialog_cancel) { dialog, _ -> if (restoreLastCheckedItem) { + exitProfileDialogInterface.unhighlightSwitchProfileMenuItem() if (exitProfileDialogArguments.highlightItemCase == ExitProfileDialogArguments.HighlightItemCase.HIGHLIGHT_LAST_CHECKED_MENU_ITEM ) { diff --git a/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogInterface.kt b/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogInterface.kt index 23c77eb902e..75754b72cf9 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogInterface.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogInterface.kt @@ -4,4 +4,5 @@ package org.oppia.android.app.drawer interface ExitProfileDialogInterface { fun highlightLastCheckedMenuItem() fun highlightAdministratorControlsItem() + fun unhighlightSwitchProfileMenuItem() } diff --git a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragment.kt b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragment.kt index fad10f0e08a..24cdcae5a3c 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragment.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragment.kt @@ -47,4 +47,8 @@ class NavigationDrawerFragment : override fun highlightAdministratorControlsItem() { navigationDrawerFragmentPresenter.highlightAdministratorControlsItem() } + + override fun unhighlightSwitchProfileMenuItem() { + navigationDrawerFragmentPresenter.unhighlightSwitchProfileMenuItem() + } } diff --git a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt index 11baa495c00..bedc1fd355a 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt @@ -293,13 +293,16 @@ class NavigationDrawerFragmentPresenter @Inject constructor( } fun highlightAdministratorControlsItem() { + getFooterViewModel().isAdministratorControlsSelected.set(true) + uncheckAllMenuItemsWhenAdministratorControlsIsSelected() + drawerLayout.closeDrawers() + } + + fun unhighlightSwitchProfileMenuItem() { binding.fragmentDrawerNavView.menu.getItem( NavigationDrawerItem.SWITCH_PROFILE.ordinal ).isChecked = false - getFooterViewModel().isAdministratorControlsSelected.set(true) - uncheckAllMenuItemsWhenAdministratorControlsIsSelected() - drawerLayout.closeDrawers() } private fun uncheckAllMenuItemsWhenAdministratorControlsIsSelected() { From 8888659c8a6f311b4a85a0b45628180b0f319409 Mon Sep 17 00:00:00 2001 From: prayutsu Date: Wed, 10 Feb 2021 18:40:22 +0530 Subject: [PATCH 10/25] Rectify cases to set restoreLastCheckedItem --- .../org/oppia/android/app/drawer/ExitProfileDialogFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt b/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt index 5c9d11f1715..771f5c4ead0 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt @@ -48,7 +48,7 @@ class ExitProfileDialogFragment : DialogFragment() { ) val restoreLastCheckedItem = when (exitProfileDialogArguments.highlightItemCase) { - ExitProfileDialogArguments.HighlightItemCase.HIGHLIGHTITEM_NOT_SET -> false + ExitProfileDialogArguments.HighlightItemCase.HIGHLIGHT_NONE -> false else -> true } From af0a91c04e8f422f6d292aa93150879c9585ad0f Mon Sep 17 00:00:00 2001 From: prayutsu Date: Wed, 10 Feb 2021 19:12:16 +0530 Subject: [PATCH 11/25] Fix BUILD.bazel error. --- model/BUILD.bazel | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/model/BUILD.bazel b/model/BUILD.bazel index 397f5bbcd50..0cf7ef878bc 100644 --- a/model/BUILD.bazel +++ b/model/BUILD.bazel @@ -38,6 +38,15 @@ load("@rules_java//java:defs.bzl", "java_lite_proto_library") # ], # ... # ) +proto_library( + name = "arguments_proto", + srcs = ["src/main/proto/arguments.proto"], +) + +java_lite_proto_library( + name = "arguments_java_proto_lite", + deps = [":arguments_proto"], +) proto_library( name = "event_logger_proto", From f27526f201f463c0d51a3c6f7174429838f8e095 Mon Sep 17 00:00:00 2001 From: prayutsu Date: Thu, 11 Feb 2021 10:48:21 +0530 Subject: [PATCH 12/25] Fix Build Binary with bazel failing Github Check. --- .../org/oppia/android/app/drawer/ExitProfileDialogFragment.kt | 3 ++- model/BUILD.bazel | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt b/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt index 771f5c4ead0..f703d01bbd3 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt @@ -48,7 +48,8 @@ class ExitProfileDialogFragment : DialogFragment() { ) val restoreLastCheckedItem = when (exitProfileDialogArguments.highlightItemCase) { - ExitProfileDialogArguments.HighlightItemCase.HIGHLIGHT_NONE -> false + ExitProfileDialogArguments.HighlightItemCase.HIGHLIGHT_ADMINISTRATOR_CONTROLS_ITEM, + ExitProfileDialogArguments.HighlightItemCase.HIGHLIGHT_LAST_CHECKED_MENU_ITEM -> true else -> true } diff --git a/model/BUILD.bazel b/model/BUILD.bazel index 0cf7ef878bc..eaa8eee45de 100644 --- a/model/BUILD.bazel +++ b/model/BUILD.bazel @@ -201,6 +201,7 @@ android_library( name = "model", visibility = ["//visibility:public"], exports = [ + ":arguments_java_proto_lite", ":event_logger_java_proto_lite", ":exploration_java_proto_lite", ":interaction_object_java_proto_lite", From a58aca5aa27202f3fb9226904c127e0602e8dc6b Mon Sep 17 00:00:00 2001 From: prayutsu Date: Thu, 11 Feb 2021 11:21:09 +0530 Subject: [PATCH 13/25] Correct when statement to set `restoreLastCheckedItem`. --- .../org/oppia/android/app/drawer/ExitProfileDialogFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt b/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt index f703d01bbd3..437576d3cd8 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt @@ -50,7 +50,7 @@ class ExitProfileDialogFragment : DialogFragment() { val restoreLastCheckedItem = when (exitProfileDialogArguments.highlightItemCase) { ExitProfileDialogArguments.HighlightItemCase.HIGHLIGHT_ADMINISTRATOR_CONTROLS_ITEM, ExitProfileDialogArguments.HighlightItemCase.HIGHLIGHT_LAST_CHECKED_MENU_ITEM -> true - else -> true + else -> false } if (restoreLastCheckedItem) { From 50c21a8756ef452adf89850c39ef9abc0521c332 Mon Sep 17 00:00:00 2001 From: prayutsu Date: Fri, 12 Feb 2021 11:30:47 +0530 Subject: [PATCH 14/25] Replace oneOf with enum and fiz nit in BUILD file. --- .../app/drawer/ExitProfileDialogFragment.kt | 11 +++++------ .../drawer/NavigationDrawerFragmentPresenter.kt | 5 +++-- .../org/oppia/android/app/home/HomeActivity.kt | 6 +++++- model/BUILD.bazel | 1 + model/src/main/proto/arguments.proto | 16 ++++++---------- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt b/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt index 437576d3cd8..2a0129d5a7a 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt @@ -9,6 +9,7 @@ import androidx.appcompat.view.ContextThemeWrapper import androidx.fragment.app.DialogFragment import org.oppia.android.R import org.oppia.android.app.model.ExitProfileDialogArguments +import org.oppia.android.app.model.HighlightItem import org.oppia.android.app.profile.ProfileChooserActivity import org.oppia.android.util.extensions.getProto import org.oppia.android.util.extensions.putProto @@ -47,9 +48,9 @@ class ExitProfileDialogFragment : DialogFragment() { ExitProfileDialogArguments.getDefaultInstance() ) - val restoreLastCheckedItem = when (exitProfileDialogArguments.highlightItemCase) { - ExitProfileDialogArguments.HighlightItemCase.HIGHLIGHT_ADMINISTRATOR_CONTROLS_ITEM, - ExitProfileDialogArguments.HighlightItemCase.HIGHLIGHT_LAST_CHECKED_MENU_ITEM -> true + val restoreLastCheckedItem = when (exitProfileDialogArguments.highlightItem) { + HighlightItem.ADMINISTRATOR_CONTROLS_ITEM, + HighlightItem.LAST_CHECKED_MENU_ITEM -> true else -> false } @@ -64,9 +65,7 @@ class ExitProfileDialogFragment : DialogFragment() { .setNegativeButton(R.string.home_activity_back_dialog_cancel) { dialog, _ -> if (restoreLastCheckedItem) { exitProfileDialogInterface.unhighlightSwitchProfileMenuItem() - if (exitProfileDialogArguments.highlightItemCase == - ExitProfileDialogArguments.HighlightItemCase.HIGHLIGHT_LAST_CHECKED_MENU_ITEM - ) { + if (exitProfileDialogArguments.highlightItem == HighlightItem.LAST_CHECKED_MENU_ITEM) { exitProfileDialogInterface.highlightLastCheckedMenuItem() } else { exitProfileDialogInterface.highlightAdministratorControlsItem() diff --git a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt index bedc1fd355a..d2abacfe43e 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt @@ -21,6 +21,7 @@ import org.oppia.android.app.help.HelpActivity import org.oppia.android.app.home.HomeActivity import org.oppia.android.app.model.CompletedStoryList import org.oppia.android.app.model.ExitProfileDialogArguments +import org.oppia.android.app.model.HighlightItem import org.oppia.android.app.model.OngoingTopicList import org.oppia.android.app.model.Profile import org.oppia.android.app.model.ProfileId @@ -246,12 +247,12 @@ class NavigationDrawerFragmentPresenter @Inject constructor( if (getFooterViewModel().isAdministratorControlsSelected.get() == true) { ExitProfileDialogArguments .newBuilder() - .setHighlightAdministratorControlsItem(true) + .setHighlightItem(HighlightItem.ADMINISTRATOR_CONTROLS_ITEM) .build() } else { ExitProfileDialogArguments .newBuilder() - .setHighlightLastCheckedMenuItem(true) + .setHighlightItem(HighlightItem.LAST_CHECKED_MENU_ITEM) .build() } getFooterViewModel().isAdministratorControlsSelected.set(false) diff --git a/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt b/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt index 46725dbee7f..758ee7bcad4 100644 --- a/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt +++ b/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt @@ -10,6 +10,7 @@ import org.oppia.android.app.drawer.KEY_NAVIGATION_PROFILE_ID import org.oppia.android.app.drawer.TAG_SWITCH_PROFILE_DIALOG import org.oppia.android.app.home.recentlyplayed.RecentlyPlayedActivity import org.oppia.android.app.model.ExitProfileDialogArguments +import org.oppia.android.app.model.HighlightItem import org.oppia.android.app.topic.TopicActivity import javax.inject.Inject @@ -50,7 +51,10 @@ class HomeActivity : supportFragmentManager.beginTransaction().remove(previousFragment).commitNow() } val exitProfileDialogArguments = - ExitProfileDialogArguments.newBuilder().setHighlightNone(true).build() + ExitProfileDialogArguments + .newBuilder() + .setHighlightItem(HighlightItem.NONE_UNSPECIFIED) + .build() val dialogFragment = ExitProfileDialogFragment .newInstance(exitProfileDialogArguments = exitProfileDialogArguments) dialogFragment.showNow(supportFragmentManager, TAG_SWITCH_PROFILE_DIALOG) diff --git a/model/BUILD.bazel b/model/BUILD.bazel index eaa8eee45de..63227df3877 100644 --- a/model/BUILD.bazel +++ b/model/BUILD.bazel @@ -38,6 +38,7 @@ load("@rules_java//java:defs.bzl", "java_lite_proto_library") # ], # ... # ) + proto_library( name = "arguments_proto", srcs = ["src/main/proto/arguments.proto"], diff --git a/model/src/main/proto/arguments.proto b/model/src/main/proto/arguments.proto index d8496171587..6e5774b4978 100644 --- a/model/src/main/proto/arguments.proto +++ b/model/src/main/proto/arguments.proto @@ -8,15 +8,11 @@ option java_multiple_files = true; // The fragment arguments passed to instances of ExitProfileDialogFragment. message ExitProfileDialogArguments { // Decides the correct menu item to be highlighted after canceling the ExitProfile dialog. - oneof highlight_item { - // Whether any menu item needs to be highlighted or not. - bool highlight_none = 1; - - // Whether some menuItem from the Navigation Drawer menu needs to be highlighted or not. - bool highlight_last_checked_menu_item = 2; + HighlightItem highlight_item = 1; +} - // Whether Administrator Controls item from the Navigation Drawer footer needs to be - // highlighted or not. - bool highlight_administrator_controls_item = 3; - } +enum HighlightItem { + NONE_UNSPECIFIED = 0; + LAST_CHECKED_MENU_ITEM = 1; + ADMINISTRATOR_CONTROLS_ITEM = 2; } From 99df13f0f2fef9254eec218b84c0247b930f1432 Mon Sep 17 00:00:00 2001 From: prayutsu Date: Fri, 12 Feb 2021 22:54:52 +0530 Subject: [PATCH 15/25] Fix Highlighting Correct Item after pressing back button. --- .../app/drawer/ExitProfileDialogFragment.kt | 54 +++++++++++---- .../oppia/android/app/home/HomeActivity.kt | 6 ++ .../android/app/home/HomeActivityPresenter.kt | 6 +- .../testing/NavigationDrawerActivityTest.kt | 65 +++++++++++++++++++ 4 files changed, 117 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt b/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt index 2a0129d5a7a..017c0fe5abe 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt @@ -2,8 +2,10 @@ package org.oppia.android.app.drawer import android.app.Dialog import android.content.Context +import android.content.DialogInterface import android.content.Intent import android.os.Bundle +import android.util.Log import androidx.appcompat.app.AlertDialog import androidx.appcompat.view.ContextThemeWrapper import androidx.fragment.app.DialogFragment @@ -54,23 +56,10 @@ class ExitProfileDialogFragment : DialogFragment() { else -> false } - if (restoreLastCheckedItem) { - exitProfileDialogInterface = - parentFragment as ExitProfileDialogInterface - } - val alertDialog = AlertDialog .Builder(ContextThemeWrapper(activity as Context, R.style.AlertDialogTheme)) .setMessage(R.string.home_activity_back_dialog_message) .setNegativeButton(R.string.home_activity_back_dialog_cancel) { dialog, _ -> - if (restoreLastCheckedItem) { - exitProfileDialogInterface.unhighlightSwitchProfileMenuItem() - if (exitProfileDialogArguments.highlightItem == HighlightItem.LAST_CHECKED_MENU_ITEM) { - exitProfileDialogInterface.highlightLastCheckedMenuItem() - } else { - exitProfileDialogInterface.highlightAdministratorControlsItem() - } - } dialog.dismiss() } .setPositiveButton(R.string.home_activity_back_dialog_exit) { _, _ -> @@ -85,4 +74,43 @@ class ExitProfileDialogFragment : DialogFragment() { alertDialog.setCanceledOnTouchOutside(false) return alertDialog } + + override fun onDestroy() { + super.onDestroy() + Log.d("Home", "onDestroy: called1") + } + + override fun onDestroyView() { + super.onDestroyView() + Log.d("Home", "onDestroyView: called1") + } + + override fun onDismiss(dialog: DialogInterface) { + super.onDismiss(dialog) + Log.d("Home", "onDismiss: called1") + val args = + checkNotNull(arguments) { "Expected arguments to be pass to ExitProfileDialogFragment" } + + val exitProfileDialogArguments = args.getProto( + EXIT_PROFILE_DIALOG_ARGUMENTS_PROTO, + ExitProfileDialogArguments.getDefaultInstance() + ) + + val restoreLastCheckedItem = when (exitProfileDialogArguments.highlightItem) { + HighlightItem.ADMINISTRATOR_CONTROLS_ITEM, + HighlightItem.LAST_CHECKED_MENU_ITEM -> true + else -> false + } + + if (restoreLastCheckedItem) { + exitProfileDialogInterface = + parentFragment as ExitProfileDialogInterface + exitProfileDialogInterface.unhighlightSwitchProfileMenuItem() + if (exitProfileDialogArguments.highlightItem == HighlightItem.LAST_CHECKED_MENU_ITEM) { + exitProfileDialogInterface.highlightLastCheckedMenuItem() + } else { + exitProfileDialogInterface.highlightAdministratorControlsItem() + } + } + } } diff --git a/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt b/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt index 758ee7bcad4..7327a5cb8a8 100644 --- a/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt +++ b/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt @@ -3,6 +3,7 @@ package org.oppia.android.app.home import android.content.Context import android.content.Intent import android.os.Bundle +import android.util.Log import org.oppia.android.R import org.oppia.android.app.activity.InjectableAppCompatActivity import org.oppia.android.app.drawer.ExitProfileDialogFragment @@ -32,6 +33,11 @@ class HomeActivity : } } + override fun onStart() { + super.onStart() + homeActivityPresenter.handleOnStart() + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) activityComponent.inject(this) diff --git a/app/src/main/java/org/oppia/android/app/home/HomeActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/home/HomeActivityPresenter.kt index 91614a2cd81..2a25addd793 100644 --- a/app/src/main/java/org/oppia/android/app/home/HomeActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/home/HomeActivityPresenter.kt @@ -1,5 +1,6 @@ package org.oppia.android.app.home +import android.util.Log import android.view.View import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.Toolbar @@ -18,7 +19,6 @@ class HomeActivityPresenter @Inject constructor(private val activity: AppCompatA fun handleOnCreate() { activity.setContentView(R.layout.home_activity) - setUpNavigationDrawer() if (getHomeFragment() == null) { activity.supportFragmentManager.beginTransaction().add( R.id.home_fragment_placeholder, @@ -28,6 +28,10 @@ class HomeActivityPresenter @Inject constructor(private val activity: AppCompatA } } + fun handleOnStart() { + setUpNavigationDrawer() + } + private fun setUpNavigationDrawer() { val toolbar = activity.findViewById(R.id.home_activity_toolbar) as Toolbar activity.setSupportActionBar(toolbar) diff --git a/app/src/sharedTest/java/org/oppia/android/app/testing/NavigationDrawerActivityTest.kt b/app/src/sharedTest/java/org/oppia/android/app/testing/NavigationDrawerActivityTest.kt index 002d3be942c..6d4b05610d5 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/testing/NavigationDrawerActivityTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/testing/NavigationDrawerActivityTest.kt @@ -17,6 +17,7 @@ import androidx.test.espresso.PerformException import androidx.test.espresso.UiController import androidx.test.espresso.ViewAction import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.action.ViewActions.pressBack import androidx.test.espresso.action.ViewActions.swipeUp import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.contrib.DrawerActions.close @@ -460,6 +461,70 @@ class NavigationDrawerActivityTest { } } + // TODO(#2535): Unable to open NavigationDrawer multiple times on Robolectric + @RunOn(TestPlatform.ESPRESSO) + @Test + fun testNavDrawer_openNavDrawer_options_pressBack_homeIsSelected() { + launch( + createNavigationDrawerActivityIntent(internalProfileId) + ).use { + it.openNavigationDrawer() + onView(withText(R.string.menu_options)).perform(click()) + pressBack() + it.openNavigationDrawer() + onView(withId(R.id.fragment_drawer_nav_view)) + .check(matches(checkNavigationViewItemStatus(NavigationDrawerItem.HOME))) + } + } + + // TODO(#2535): Unable to open NavigationDrawer multiple times on Robolectric + @RunOn(TestPlatform.ESPRESSO) + @Test + fun testNavDrawer_openNavDrawer_help_pressBack_homeIsSelected() { + launch( + createNavigationDrawerActivityIntent(internalProfileId) + ).use { + it.openNavigationDrawer() + onView(withText(R.string.menu_help)).perform(click()) + pressBack() + it.openNavigationDrawer() + onView(withId(R.id.fragment_drawer_nav_view)) + .check(matches(checkNavigationViewItemStatus(NavigationDrawerItem.HOME))) + } + } + + // TODO(#2535): Unable to open NavigationDrawer multiple times on Robolectric + @RunOn(TestPlatform.ESPRESSO) + @Test + fun testNavDrawer_openNavDrawer_switchProfile_pressBack_homeIsSelected() { + launch( + createNavigationDrawerActivityIntent(internalProfileId) + ).use { + it.openNavigationDrawer() + onView(withText(R.string.menu_switch_profile)).perform(click()) + pressBack() + it.openNavigationDrawer() + onView(withId(R.id.fragment_drawer_nav_view)) + .check(matches(checkNavigationViewItemStatus(NavigationDrawerItem.HOME))) + } + } + + // TODO(#2535): Unable to open NavigationDrawer multiple times on Robolectric + @RunOn(TestPlatform.ESPRESSO) + @Test + fun testNavDrawer_openNavDrawer_admin_pressBack_homeIsSelected() { + launch( + createNavigationDrawerActivityIntent(internalProfileId) + ).use { + it.openNavigationDrawer() + onView(withText(R.string.administrator_controls)).perform(click()) + pressBack() + it.openNavigationDrawer() + onView(withId(R.id.fragment_drawer_nav_view)) + .check(matches(checkNavigationViewItemStatus(NavigationDrawerItem.HOME))) + } + } + @Test fun testNavDrawer_withAdminProfile_openNavDrawer_adminControlsIsDisplayed() { launch( From c67d36be1e18cbcfb7714175bd026c95c3173179 Mon Sep 17 00:00:00 2001 From: prayutsu Date: Sat, 13 Feb 2021 00:33:36 +0530 Subject: [PATCH 16/25] Fix test cases. --- .../main/java/org/oppia/android/app/home/HomeActivity.kt | 6 +++--- .../org/oppia/android/app/home/HomeActivityPresenter.kt | 2 +- .../android/app/testing/NavigationDrawerTestActivity.kt | 5 +++++ .../android/app/testing/NavigationDrawerActivityTest.kt | 8 ++++---- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt b/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt index 7327a5cb8a8..1206ef20231 100644 --- a/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt +++ b/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt @@ -33,9 +33,9 @@ class HomeActivity : } } - override fun onStart() { - super.onStart() - homeActivityPresenter.handleOnStart() + override fun onResume() { + super.onResume() + homeActivityPresenter.handleOnResume() } override fun onCreate(savedInstanceState: Bundle?) { diff --git a/app/src/main/java/org/oppia/android/app/home/HomeActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/home/HomeActivityPresenter.kt index 2a25addd793..58c1e9cbece 100644 --- a/app/src/main/java/org/oppia/android/app/home/HomeActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/home/HomeActivityPresenter.kt @@ -28,7 +28,7 @@ class HomeActivityPresenter @Inject constructor(private val activity: AppCompatA } } - fun handleOnStart() { + fun handleOnResume() { setUpNavigationDrawer() } diff --git a/app/src/main/java/org/oppia/android/app/testing/NavigationDrawerTestActivity.kt b/app/src/main/java/org/oppia/android/app/testing/NavigationDrawerTestActivity.kt index 2149dba653e..bb8a47607ec 100644 --- a/app/src/main/java/org/oppia/android/app/testing/NavigationDrawerTestActivity.kt +++ b/app/src/main/java/org/oppia/android/app/testing/NavigationDrawerTestActivity.kt @@ -32,6 +32,11 @@ class NavigationDrawerTestActivity : InjectableAppCompatActivity(), RouteToTopic title = getString(R.string.menu_home) } + override fun onResume() { + super.onResume() + homeActivityPresenter.handleOnResume() + } + override fun routeToTopic(internalProfileId: Int, topicId: String) { startActivity(TopicActivity.createTopicActivityIntent(this, internalProfileId, topicId)) } diff --git a/app/src/sharedTest/java/org/oppia/android/app/testing/NavigationDrawerActivityTest.kt b/app/src/sharedTest/java/org/oppia/android/app/testing/NavigationDrawerActivityTest.kt index 6d4b05610d5..20e69ece521 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/testing/NavigationDrawerActivityTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/testing/NavigationDrawerActivityTest.kt @@ -470,7 +470,7 @@ class NavigationDrawerActivityTest { ).use { it.openNavigationDrawer() onView(withText(R.string.menu_options)).perform(click()) - pressBack() + onView(isRoot()).perform(pressBack()) it.openNavigationDrawer() onView(withId(R.id.fragment_drawer_nav_view)) .check(matches(checkNavigationViewItemStatus(NavigationDrawerItem.HOME))) @@ -486,7 +486,7 @@ class NavigationDrawerActivityTest { ).use { it.openNavigationDrawer() onView(withText(R.string.menu_help)).perform(click()) - pressBack() + onView(isRoot()).perform(pressBack()) it.openNavigationDrawer() onView(withId(R.id.fragment_drawer_nav_view)) .check(matches(checkNavigationViewItemStatus(NavigationDrawerItem.HOME))) @@ -502,7 +502,7 @@ class NavigationDrawerActivityTest { ).use { it.openNavigationDrawer() onView(withText(R.string.menu_switch_profile)).perform(click()) - pressBack() + onView(isRoot()).perform(pressBack()) it.openNavigationDrawer() onView(withId(R.id.fragment_drawer_nav_view)) .check(matches(checkNavigationViewItemStatus(NavigationDrawerItem.HOME))) @@ -518,7 +518,7 @@ class NavigationDrawerActivityTest { ).use { it.openNavigationDrawer() onView(withText(R.string.administrator_controls)).perform(click()) - pressBack() + onView(isRoot()).perform(pressBack()) it.openNavigationDrawer() onView(withId(R.id.fragment_drawer_nav_view)) .check(matches(checkNavigationViewItemStatus(NavigationDrawerItem.HOME))) From aa9a1d45f5a2026b2d96cb1d6e193252d5d3fed4 Mon Sep 17 00:00:00 2001 From: prayutsu Date: Sat, 13 Feb 2021 00:42:43 +0530 Subject: [PATCH 17/25] Fix lint errors. --- app/src/main/java/org/oppia/android/app/home/HomeActivity.kt | 3 +-- .../java/org/oppia/android/app/home/HomeActivityPresenter.kt | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt b/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt index 1206ef20231..f4424b340ba 100644 --- a/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt +++ b/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt @@ -3,7 +3,6 @@ package org.oppia.android.app.home import android.content.Context import android.content.Intent import android.os.Bundle -import android.util.Log import org.oppia.android.R import org.oppia.android.app.activity.InjectableAppCompatActivity import org.oppia.android.app.drawer.ExitProfileDialogFragment @@ -35,7 +34,7 @@ class HomeActivity : override fun onResume() { super.onResume() - homeActivityPresenter.handleOnResume() + homeActivityPresenter.handleOnResume() } override fun onCreate(savedInstanceState: Bundle?) { diff --git a/app/src/main/java/org/oppia/android/app/home/HomeActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/home/HomeActivityPresenter.kt index 58c1e9cbece..1cc8078b012 100644 --- a/app/src/main/java/org/oppia/android/app/home/HomeActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/home/HomeActivityPresenter.kt @@ -1,6 +1,5 @@ package org.oppia.android.app.home -import android.util.Log import android.view.View import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.Toolbar From ae251f2aa6094db190249af5b81b4f7568152a3a Mon Sep 17 00:00:00 2001 From: prayutsu Date: Sat, 13 Feb 2021 00:58:31 +0530 Subject: [PATCH 18/25] Add explanation comment for enum HighlightItem. --- model/src/main/proto/arguments.proto | 2 ++ 1 file changed, 2 insertions(+) diff --git a/model/src/main/proto/arguments.proto b/model/src/main/proto/arguments.proto index 6e5774b4978..be6ff925176 100644 --- a/model/src/main/proto/arguments.proto +++ b/model/src/main/proto/arguments.proto @@ -11,6 +11,8 @@ message ExitProfileDialogArguments { HighlightItem highlight_item = 1; } +// Represents the type of item/menuItem that should be highlighted after canceling the +// ExitProfile dialog. enum HighlightItem { NONE_UNSPECIFIED = 0; LAST_CHECKED_MENU_ITEM = 1; From 9d86ea53b14e39a97d46f157afc870ddb1b013d2 Mon Sep 17 00:00:00 2001 From: prayutsu Date: Sat, 13 Feb 2021 01:08:44 +0530 Subject: [PATCH 19/25] Refactor enum HighlightItem. --- .../main/java/org/oppia/android/app/home/HomeActivity.kt | 2 +- model/src/main/proto/arguments.proto | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt b/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt index f4424b340ba..c0c2a8c0de0 100644 --- a/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt +++ b/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt @@ -58,7 +58,7 @@ class HomeActivity : val exitProfileDialogArguments = ExitProfileDialogArguments .newBuilder() - .setHighlightItem(HighlightItem.NONE_UNSPECIFIED) + .setHighlightItem(HighlightItem.ITEM_UNSPECIFIED) .build() val dialogFragment = ExitProfileDialogFragment .newInstance(exitProfileDialogArguments = exitProfileDialogArguments) diff --git a/model/src/main/proto/arguments.proto b/model/src/main/proto/arguments.proto index be6ff925176..8bc85de5792 100644 --- a/model/src/main/proto/arguments.proto +++ b/model/src/main/proto/arguments.proto @@ -14,7 +14,12 @@ message ExitProfileDialogArguments { // Represents the type of item/menuItem that should be highlighted after canceling the // ExitProfile dialog. enum HighlightItem { - NONE_UNSPECIFIED = 0; + // Indicates that none of the items needs to be highlighted. + ITEM_UNSPECIFIED = 0; + + // Indicates that one of the NavigationDrawerItem needs to be highlighted. LAST_CHECKED_MENU_ITEM = 1; + + // Indicates that the Administrator Controls item needs to be highlighted. ADMINISTRATOR_CONTROLS_ITEM = 2; } From b3960af5c8645692d56443d01b960fcf82893cb4 Mon Sep 17 00:00:00 2001 From: prayutsu Date: Sat, 13 Feb 2021 01:15:59 +0530 Subject: [PATCH 20/25] Remove Logs from ExitProfileDialogFragment.kt. --- .../android/app/drawer/ExitProfileDialogFragment.kt | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt b/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt index 017c0fe5abe..97713b1f67d 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/ExitProfileDialogFragment.kt @@ -5,7 +5,6 @@ import android.content.Context import android.content.DialogInterface import android.content.Intent import android.os.Bundle -import android.util.Log import androidx.appcompat.app.AlertDialog import androidx.appcompat.view.ContextThemeWrapper import androidx.fragment.app.DialogFragment @@ -75,19 +74,8 @@ class ExitProfileDialogFragment : DialogFragment() { return alertDialog } - override fun onDestroy() { - super.onDestroy() - Log.d("Home", "onDestroy: called1") - } - - override fun onDestroyView() { - super.onDestroyView() - Log.d("Home", "onDestroyView: called1") - } - override fun onDismiss(dialog: DialogInterface) { super.onDismiss(dialog) - Log.d("Home", "onDismiss: called1") val args = checkNotNull(arguments) { "Expected arguments to be pass to ExitProfileDialogFragment" } From 9201a6f330871583b5143b345f799901c6720b5b Mon Sep 17 00:00:00 2001 From: prayutsu Date: Sat, 13 Feb 2021 15:13:38 +0530 Subject: [PATCH 21/25] Add test cases for Landscape mode and MY_DOWNLOADS menuItem. --- .../testing/NavigationDrawerActivityTest.kt | 151 ++++++++++++++++++ 1 file changed, 151 insertions(+) diff --git a/app/src/sharedTest/java/org/oppia/android/app/testing/NavigationDrawerActivityTest.kt b/app/src/sharedTest/java/org/oppia/android/app/testing/NavigationDrawerActivityTest.kt index 20e69ece521..23d8e5d83c4 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/testing/NavigationDrawerActivityTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/testing/NavigationDrawerActivityTest.kt @@ -345,6 +345,29 @@ class NavigationDrawerActivityTest { } } + // TODO(#1806): Enable this once lowfi implementation is done. + // TODO(#2535): Unable to open NavigationDrawer multiple times on Robolectric + @RunOn(TestPlatform.ESPRESSO) + @Test + @Ignore("My Downloads is removed until we have full download support.") + fun testNavDrawer_openNavDrawer_download_switchProfile_cancel_downloadIsSelected() { + launch( + createNavigationDrawerActivityIntent(internalProfileId) + ).use { + it.openNavigationDrawer() + onView(withText(R.string.menu_my_downloads)).perform(click()) + it.openNavigationDrawer() + onView(withText(R.string.menu_switch_profile)).perform(click()) + onView(withText(R.string.home_activity_back_dialog_cancel)) + .inRoot(isDialog()) + .perform(click()) + it.openNavigationDrawer() + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.fragment_drawer_nav_view)) + .check(matches(checkNavigationViewItemStatus(NavigationDrawerItem.DOWNLOADS))) + } + } + // TODO(#2535): Unable to open NavigationDrawer multiple times on Robolectric @RunOn(TestPlatform.ESPRESSO) @Test @@ -434,6 +457,29 @@ class NavigationDrawerActivityTest { } } + // TODO(#1806): Enable this once lowfi implementation is done. + // TODO(#2535): Unable to open NavigationDrawer multiple times on Robolectric + @RunOn(TestPlatform.ESPRESSO) + @Test + @Ignore("My Downloads is removed until we have full download support.") + fun testNavDrawer_openNavDrawer_download_switchProfile_cancel_configChange_downloadIsSelected() { + launch( + createNavigationDrawerActivityIntent(internalProfileId) + ).use { + it.openNavigationDrawer() + onView(withText(R.string.menu_my_downloads)).perform(click()) + it.openNavigationDrawer() + onView(withText(R.string.menu_switch_profile)).perform(click()) + onView(withText(R.string.home_activity_back_dialog_cancel)) + .inRoot(isDialog()) + .perform(click()) + it.openNavigationDrawer() + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.fragment_drawer_nav_view)) + .check(matches(checkNavigationViewItemStatus(NavigationDrawerItem.DOWNLOADS))) + } + } + // TODO(#2535): Unable to open NavigationDrawer multiple times on Robolectric @RunOn(TestPlatform.ESPRESSO) @Test @@ -493,6 +539,24 @@ class NavigationDrawerActivityTest { } } + // TODO(#1806): Enable this once lowfi implementation is done. + // TODO(#2535): Unable to open NavigationDrawer multiple times on Robolectric + @RunOn(TestPlatform.ESPRESSO) + @Test + @Ignore("My Downloads is removed until we have full download support.") + fun testNavDrawer_openNavDrawer_download_pressBack_homeIsSelected() { + launch( + createNavigationDrawerActivityIntent(internalProfileId) + ).use { + it.openNavigationDrawer() + onView(withText(R.string.menu_my_downloads)).perform(click()) + onView(isRoot()).perform(pressBack()) + it.openNavigationDrawer() + onView(withId(R.id.fragment_drawer_nav_view)) + .check(matches(checkNavigationViewItemStatus(NavigationDrawerItem.HOME))) + } + } + // TODO(#2535): Unable to open NavigationDrawer multiple times on Robolectric @RunOn(TestPlatform.ESPRESSO) @Test @@ -525,6 +589,93 @@ class NavigationDrawerActivityTest { } } + // TODO(#2535): Unable to open NavigationDrawer multiple times on Robolectric + @RunOn(TestPlatform.ESPRESSO) + @Test + fun testNavDrawer_openNavDrawer_options_pressBack_configChange_homeIsSelected() { + launch( + createNavigationDrawerActivityIntent(internalProfileId) + ).use { + it.openNavigationDrawer() + onView(withText(R.string.menu_options)).perform(click()) + onView(isRoot()).perform(pressBack()) + it.openNavigationDrawer() + onView(isRoot()).perform(orientationLandscape()) + onView(withId(R.id.fragment_drawer_nav_view)) + .check(matches(checkNavigationViewItemStatus(NavigationDrawerItem.HOME))) + } + } + + // TODO(#2535): Unable to open NavigationDrawer multiple times on Robolectric + @RunOn(TestPlatform.ESPRESSO) + @Test + fun testNavDrawer_openNavDrawer_help_pressBack_configChange_homeIsSelected() { + launch( + createNavigationDrawerActivityIntent(internalProfileId) + ).use { + it.openNavigationDrawer() + onView(withText(R.string.menu_help)).perform(click()) + onView(isRoot()).perform(pressBack()) + it.openNavigationDrawer() + onView(isRoot()).perform(orientationLandscape()) + onView(withId(R.id.fragment_drawer_nav_view)) + .check(matches(checkNavigationViewItemStatus(NavigationDrawerItem.HOME))) + } + } + + // TODO(#1806): Enable this once lowfi implementation is done. + // TODO(#2535): Unable to open NavigationDrawer multiple times on Robolectric + @RunOn(TestPlatform.ESPRESSO) + @Test + @Ignore("My Downloads is removed until we have full download support.") + fun testNavDrawer_openNavDrawer_download_pressBack_configChange_homeIsSelected() { + launch( + createNavigationDrawerActivityIntent(internalProfileId) + ).use { + it.openNavigationDrawer() + onView(withText(R.string.menu_my_downloads)).perform(click()) + onView(isRoot()).perform(pressBack()) + it.openNavigationDrawer() + onView(isRoot()).perform(orientationLandscape()) + onView(withId(R.id.fragment_drawer_nav_view)) + .check(matches(checkNavigationViewItemStatus(NavigationDrawerItem.HOME))) + } + } + + // TODO(#2535): Unable to open NavigationDrawer multiple times on Robolectric + @RunOn(TestPlatform.ESPRESSO) + @Test + fun testNavDrawer_openNavDrawer_switchProfile_pressBack_configChange_homeIsSelected() { + launch( + createNavigationDrawerActivityIntent(internalProfileId) + ).use { + it.openNavigationDrawer() + onView(withText(R.string.menu_switch_profile)).perform(click()) + onView(isRoot()).perform(pressBack()) + it.openNavigationDrawer() + onView(isRoot()).perform(orientationLandscape()) + onView(withId(R.id.fragment_drawer_nav_view)) + .check(matches(checkNavigationViewItemStatus(NavigationDrawerItem.HOME))) + } + } + + // TODO(#2535): Unable to open NavigationDrawer multiple times on Robolectric + @RunOn(TestPlatform.ESPRESSO) + @Test + fun testNavDrawer_openNavDrawer_admin_pressBack_configChange_homeIsSelected() { + launch( + createNavigationDrawerActivityIntent(internalProfileId) + ).use { + it.openNavigationDrawer() + onView(withText(R.string.administrator_controls)).perform(click()) + onView(isRoot()).perform(pressBack()) + it.openNavigationDrawer() + onView(isRoot()).perform(orientationLandscape()) + onView(withId(R.id.fragment_drawer_nav_view)) + .check(matches(checkNavigationViewItemStatus(NavigationDrawerItem.HOME))) + } + } + @Test fun testNavDrawer_withAdminProfile_openNavDrawer_adminControlsIsDisplayed() { launch( From f96a35d4f7fde3e841806b11fc511a765649b06d Mon Sep 17 00:00:00 2001 From: prayutsu Date: Sat, 13 Feb 2021 21:41:20 +0530 Subject: [PATCH 22/25] Remove `item` from the testcase. --- .../oppia/android/app/testing/NavigationDrawerActivityTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/sharedTest/java/org/oppia/android/app/testing/NavigationDrawerActivityTest.kt b/app/src/sharedTest/java/org/oppia/android/app/testing/NavigationDrawerActivityTest.kt index 23d8e5d83c4..1f629be29ba 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/testing/NavigationDrawerActivityTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/testing/NavigationDrawerActivityTest.kt @@ -287,7 +287,7 @@ class NavigationDrawerActivityTest { // TODO(#2535): Unable to open NavigationDrawer multiple times on Robolectric @RunOn(TestPlatform.ESPRESSO) @Test - fun testNavDrawer_openNavDrawer_switchProfile_cancel_homeItemIsSelected() { + fun testNavDrawer_openNavDrawer_switchProfile_cancel_homeIsSelected() { launch( createNavigationDrawerActivityIntent(internalProfileId) ).use { From 9515093ead679be114dcfaa89dedceba492d4e42 Mon Sep 17 00:00:00 2001 From: prayutsu Date: Sun, 14 Feb 2021 11:01:25 +0530 Subject: [PATCH 23/25] Restructure HighlightItem enum. --- .../main/java/org/oppia/android/app/home/HomeActivity.kt | 2 +- model/src/main/proto/arguments.proto | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt b/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt index c0c2a8c0de0..1999793fd20 100644 --- a/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt +++ b/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt @@ -58,7 +58,7 @@ class HomeActivity : val exitProfileDialogArguments = ExitProfileDialogArguments .newBuilder() - .setHighlightItem(HighlightItem.ITEM_UNSPECIFIED) + .setHighlightItem(HighlightItem.NONE) .build() val dialogFragment = ExitProfileDialogFragment .newInstance(exitProfileDialogArguments = exitProfileDialogArguments) diff --git a/model/src/main/proto/arguments.proto b/model/src/main/proto/arguments.proto index 8bc85de5792..bc8dedb5d3e 100644 --- a/model/src/main/proto/arguments.proto +++ b/model/src/main/proto/arguments.proto @@ -14,12 +14,15 @@ message ExitProfileDialogArguments { // Represents the type of item/menuItem that should be highlighted after canceling the // ExitProfile dialog. enum HighlightItem { - // Indicates that none of the items needs to be highlighted. + // Indicates that the highlight item was not set ITEM_UNSPECIFIED = 0; + // Indicates that none of the items needs to be highlighted. + NONE = 1; + // Indicates that one of the NavigationDrawerItem needs to be highlighted. - LAST_CHECKED_MENU_ITEM = 1; + LAST_CHECKED_MENU_ITEM = 2; // Indicates that the Administrator Controls item needs to be highlighted. - ADMINISTRATOR_CONTROLS_ITEM = 2; + ADMINISTRATOR_CONTROLS_ITEM = 3; } From 4121e211368a1e0c78381320b4f5395404f51eec Mon Sep 17 00:00:00 2001 From: prayutsu Date: Mon, 15 Feb 2021 10:45:39 +0530 Subject: [PATCH 24/25] Replace onResume() with onRestart() method. --- .../java/org/oppia/android/app/home/HomeActivity.kt | 10 +++++----- .../oppia/android/app/home/HomeActivityPresenter.kt | 3 ++- .../app/testing/NavigationDrawerTestActivity.kt | 6 +++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt b/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt index 1999793fd20..8dd1103d694 100644 --- a/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt +++ b/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt @@ -32,11 +32,6 @@ class HomeActivity : } } - override fun onResume() { - super.onResume() - homeActivityPresenter.handleOnResume() - } - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) activityComponent.inject(this) @@ -45,6 +40,11 @@ class HomeActivity : title = getString(R.string.menu_home) } + override fun onRestart() { + super.onRestart() + homeActivityPresenter.handleOnReStart() + } + override fun routeToTopic(internalProfileId: Int, topicId: String) { startActivity(TopicActivity.createTopicActivityIntent(this, internalProfileId, topicId)) } diff --git a/app/src/main/java/org/oppia/android/app/home/HomeActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/home/HomeActivityPresenter.kt index 1cc8078b012..b7a237f60fc 100644 --- a/app/src/main/java/org/oppia/android/app/home/HomeActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/home/HomeActivityPresenter.kt @@ -18,6 +18,7 @@ class HomeActivityPresenter @Inject constructor(private val activity: AppCompatA fun handleOnCreate() { activity.setContentView(R.layout.home_activity) + setUpNavigationDrawer() if (getHomeFragment() == null) { activity.supportFragmentManager.beginTransaction().add( R.id.home_fragment_placeholder, @@ -27,7 +28,7 @@ class HomeActivityPresenter @Inject constructor(private val activity: AppCompatA } } - fun handleOnResume() { + fun handleOnReStart() { setUpNavigationDrawer() } diff --git a/app/src/main/java/org/oppia/android/app/testing/NavigationDrawerTestActivity.kt b/app/src/main/java/org/oppia/android/app/testing/NavigationDrawerTestActivity.kt index bb8a47607ec..1081c6b14f7 100644 --- a/app/src/main/java/org/oppia/android/app/testing/NavigationDrawerTestActivity.kt +++ b/app/src/main/java/org/oppia/android/app/testing/NavigationDrawerTestActivity.kt @@ -32,9 +32,9 @@ class NavigationDrawerTestActivity : InjectableAppCompatActivity(), RouteToTopic title = getString(R.string.menu_home) } - override fun onResume() { - super.onResume() - homeActivityPresenter.handleOnResume() + override fun onRestart() { + super.onRestart() + homeActivityPresenter.handleOnReStart() } override fun routeToTopic(internalProfileId: Int, topicId: String) { From 83e99d1ecd1002f49937564e7d455a6c9041ee34 Mon Sep 17 00:00:00 2001 From: prayutsu Date: Mon, 15 Feb 2021 18:43:40 +0530 Subject: [PATCH 25/25] Fix nits. --- app/src/main/java/org/oppia/android/app/home/HomeActivity.kt | 2 +- .../java/org/oppia/android/app/home/HomeActivityPresenter.kt | 2 +- .../oppia/android/app/testing/NavigationDrawerTestActivity.kt | 2 +- model/src/main/proto/arguments.proto | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt b/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt index 8dd1103d694..fe423af43b0 100644 --- a/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt +++ b/app/src/main/java/org/oppia/android/app/home/HomeActivity.kt @@ -42,7 +42,7 @@ class HomeActivity : override fun onRestart() { super.onRestart() - homeActivityPresenter.handleOnReStart() + homeActivityPresenter.handleOnRestart() } override fun routeToTopic(internalProfileId: Int, topicId: String) { diff --git a/app/src/main/java/org/oppia/android/app/home/HomeActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/home/HomeActivityPresenter.kt index b7a237f60fc..5f32ea6c547 100644 --- a/app/src/main/java/org/oppia/android/app/home/HomeActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/home/HomeActivityPresenter.kt @@ -28,7 +28,7 @@ class HomeActivityPresenter @Inject constructor(private val activity: AppCompatA } } - fun handleOnReStart() { + fun handleOnRestart() { setUpNavigationDrawer() } diff --git a/app/src/main/java/org/oppia/android/app/testing/NavigationDrawerTestActivity.kt b/app/src/main/java/org/oppia/android/app/testing/NavigationDrawerTestActivity.kt index 1081c6b14f7..6c2fab253f9 100644 --- a/app/src/main/java/org/oppia/android/app/testing/NavigationDrawerTestActivity.kt +++ b/app/src/main/java/org/oppia/android/app/testing/NavigationDrawerTestActivity.kt @@ -34,7 +34,7 @@ class NavigationDrawerTestActivity : InjectableAppCompatActivity(), RouteToTopic override fun onRestart() { super.onRestart() - homeActivityPresenter.handleOnReStart() + homeActivityPresenter.handleOnRestart() } override fun routeToTopic(internalProfileId: Int, topicId: String) { diff --git a/model/src/main/proto/arguments.proto b/model/src/main/proto/arguments.proto index bc8dedb5d3e..9806d80e16e 100644 --- a/model/src/main/proto/arguments.proto +++ b/model/src/main/proto/arguments.proto @@ -7,12 +7,12 @@ option java_multiple_files = true; // The fragment arguments passed to instances of ExitProfileDialogFragment. message ExitProfileDialogArguments { - // Decides the correct menu item to be highlighted after canceling the ExitProfile dialog. + // Decides the correct menu item to be highlighted after canceling the ExitProfileDialogFragment. HighlightItem highlight_item = 1; } // Represents the type of item/menuItem that should be highlighted after canceling the -// ExitProfile dialog. +// ExitProfileDialogFragment. enum HighlightItem { // Indicates that the highlight item was not set ITEM_UNSPECIFIED = 0;