Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix #590: Full UI Switch Profile Option #651

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.drawerlayout.widget.DrawerLayout
Expand All @@ -23,6 +24,7 @@ import org.oppia.app.home.HomeActivity
import org.oppia.app.home.KEY_HOME_PROFILE_ID
import org.oppia.app.model.Profile
import org.oppia.app.model.ProfileId
import org.oppia.app.profile.ProfileActivity
import org.oppia.domain.profile.ProfileManagementController
import org.oppia.util.data.AsyncResult
import org.oppia.util.logging.Logger
Expand Down Expand Up @@ -84,16 +86,30 @@ class NavigationDrawerFragmentPresenter @Inject constructor(

private fun openActivityByMenuItemId(menuItemId: Int) {
if (previousMenuItemId != menuItemId && menuItemId != 0) {
val intent = when (NavigationDrawerItem.valueFromNavId(menuItemId)) {
when (NavigationDrawerItem.valueFromNavId(menuItemId)) {
NavigationDrawerItem.HOME -> {
Intent(fragment.activity, HomeActivity::class.java)
val intent = Intent(fragment.activity, HomeActivity::class.java)
fragment.activity!!.startActivity(intent)
fragment.activity!!.finish()
}
NavigationDrawerItem.HELP -> {
Intent(fragment.activity, HelpActivity::class.java)
val intent = Intent(fragment.activity, HelpActivity::class.java)
fragment.activity!!.startActivity(intent)
fragment.activity!!.finish()
}
NavigationDrawerItem.SWITCH_PROFILE -> {
AlertDialog.Builder(fragment.context!!, R.style.AlertDialogTheme)
.setMessage(R.string.home_activity_back_dialog_message)
.setNegativeButton(R.string.home_activity_back_dialog_cancel) { dialog, _ ->
dialog.dismiss()
}
.setPositiveButton(R.string.home_activity_back_dialog_exit) { _, _ ->
// TODO(#322): Need to start intent for ProfileActivity to get update. Change to finish when live data bug is fixed.
val intent = ProfileActivity.createProfileActivity(fragment.context!!)
fragment.activity!!.startActivity(intent)
PrarabdhGarg marked this conversation as resolved.
Show resolved Hide resolved
}.create().show()
}
}
fragment.activity!!.startActivity(intent)
fragment.activity!!.finish()
} else {
drawerLayout.closeDrawers()
}
Expand All @@ -111,6 +127,9 @@ class NavigationDrawerFragmentPresenter @Inject constructor(
NavigationDrawerItem.HELP -> {
binding.fragmentDrawerNavView.menu.getItem(NavigationDrawerItem.HELP.ordinal).isChecked = true
}
NavigationDrawerItem.SWITCH_PROFILE -> {
binding.fragmentDrawerNavView.menu.getItem(NavigationDrawerItem.SWITCH_PROFILE.ordinal).isChecked = true
}
}
this.drawerLayout = drawerLayout
previousMenuItemId = menuItemId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.oppia.app.R

/** Represents different destinations that can be selected by the user from the navigation drawer. */
enum class NavigationDrawerItem(val value: Int) {
HOME(R.id.nav_home), HELP(R.id.nav_help);
HOME(R.id.nav_home), HELP(R.id.nav_help), SWITCH_PROFILE(R.id.nav_switch_profile);

companion object {
fun valueFromNavId(id: Int): NavigationDrawerItem {
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/org/oppia/app/profile/ProfileActivity.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.oppia.app.profile

import android.content.Context
import android.content.Intent
import android.os.Bundle
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.oppia.app.activity.InjectableAppCompatActivity
Expand All @@ -9,6 +11,14 @@ import javax.inject.Inject
class ProfileActivity : InjectableAppCompatActivity() {
@Inject lateinit var profileActivityPresenter: ProfileActivityPresenter

companion object {
fun createProfileActivity(context: Context): Intent {
val intent = Intent(context, ProfileActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
return intent
}
}

@ExperimentalCoroutinesApi
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/ic_profile_exit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="200dp"
android:height="197.23dp"
android:viewportWidth="200"
android:viewportHeight="197.23">
<path
android:fillColor="#FF000000"
android:pathData="M200,6.07c-2,-5 -3.56,-6 -9.15,-6q-60.27,0 -120.54,-0.05c-5.56,0 -8.49,3.26 -8.43,8.3 0.2,17.62 0.07,35.24 0.07,52.87v2.52L75.56,63.71L75.56,14.16h89.92a18.64,18.64 0,0 1,-1.59 1.18c-11,6.21 -21.92,12.47 -32.95,18.59a8.63,8.63 0,0 0,-4.87 8.37q0.09,51.87 0,103.73v3.25L75.71,149.28L75.71,111.07L61.95,111.07v2.3q0,21.24 0,42.47c0,4.71 2.59,7.37 7.32,7.38q27,0 54,0h2.87v24.48c0,6 1.06,7.55 6.63,9.52h0.88c1.52,-0.68 3.1,-1.25 4.54,-2.06 18.48,-10.45 36.92,-21 55.44,-31.36 2.82,-1.58 5.46,-3.07 6.39,-6.4Z"/>
<path
android:fillColor="#FF000000"
android:pathData="M46.89,97.16h2.84q16.92,0 33.84,0c5.27,0 9,-2.27 10.29,-6.65 2.21,-7.35 -3.1,-12.81 -8.91,-12.76 -11.87,0.09 -23.74,0 -35.61,0.07 -1.94,0 -2.54,-0.53 -2.49,-2.49 0.13,-5.23 0,-10.47 0.06,-15.7 0,-1.75 -0.27,-3.21 -2,-4a4.58,4.58 0,0 0,-4.94 0.64q-9.89,7.21 -19.77,14.4 -8.65,6.27 -17.32,12.53c-3.78,2.73 -3.83,5.49 -0.11,8.2q18.54,13.49 37.07,26.95c1.62,1.18 3.25,1.7 5.1,0.76s2,-2.47 2,-4.3C46.85,109.04 46.89,103.29 46.89,97.16Z"/>
</vector>
4 changes: 4 additions & 0 deletions app/src/main/res/menu/navigation_drawer_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@
android:id="@+id/nav_help"
android:icon="@drawable/ic_help_grey_icon_24dp"
android:title="@string/menu_help" />
<item
android:id="@+id/nav_switch_profile"
android:icon="@drawable/ic_profile_exit"
android:title="@string/menu_switch_profile" />
</group>
</menu>
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<string name="nav_header_desc">Navigation header</string>
<string name="menu_home">Home</string>
<string name="menu_help">Help</string>
<string name="menu_switch_profile">Switch Profile</string>
<string name="admin_settings">Admin Settings</string>
<string name="drawer_open_content_description">Navigation Menu Open</string>
<string name="drawer_close_content_description">>Navigation Menu Close</string>
Expand Down Expand Up @@ -176,7 +177,7 @@
<string name="tab_downloads">Downloads</string>
<string name="tab_updates">Updates (2)</string>
<!-- HomeActivityBackDialog -->
<string name="home_activity_back_dialog_message">Exit your profile and go to the Profile Chooser?</string>
<string name="home_activity_back_dialog_message">Would you like to exit your profile?</string>
<string name="home_activity_back_dialog_cancel">Cancel</string>
<string name="home_activity_back_dialog_exit">Exit</string>
<!-- ProfileListActivity. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import androidx.test.espresso.contrib.DrawerActions.open
import androidx.test.espresso.contrib.DrawerMatchers.isClosed
import androidx.test.espresso.contrib.DrawerMatchers.isOpen
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.matcher.ViewMatchers.isCompletelyDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withId
Expand All @@ -35,6 +38,7 @@ import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.oppia.app.R
import org.oppia.app.profile.ProfileActivity
import org.oppia.app.recyclerview.RecyclerViewMatcher
import org.oppia.app.utility.OrientationChangeAction.Companion.orientationLandscape
import org.oppia.domain.profile.ProfileTestHelper
Expand Down Expand Up @@ -147,6 +151,26 @@ class NavigationDrawerTestActivityTest {
}
}

@Test
fun testNavigationDrawerTestActivity_openNavigationDrawer_selectSwitchProfileMenu_showsExitToProfileChooserDialog() {
launch(NavigationDrawerTestActivity::class.java).use {
onView(withId(R.id.home_activity_drawer_layout)).perform(open())
onView(withText(R.string.menu_switch_profile)).perform(click())
onView(withText(R.string.home_activity_back_dialog_message)).check(matches(isDisplayed()))
}
}

@Test
fun testNavigationDrawerTestActivity_openNavigationDrawer_selectSwitchProfileMenu_showsExitToProfileChooserDialog_clickExit_checkOpensProfileActivity() {
launch(NavigationDrawerTestActivity::class.java).use {
onView(withId(R.id.home_activity_drawer_layout)).perform(open())
onView(withText(R.string.menu_switch_profile)).perform(click())
onView(withText(R.string.home_activity_back_dialog_message)).check(matches(isDisplayed()))
onView(withText(R.string.home_activity_back_dialog_exit)).perform(click())
intended(hasComponent(ProfileActivity::class.java.name))
}
}

@Test
fun testNavigationDrawerTestActivity_openNavigationDrawer_selectHelpMenuInNavigationDrawer_clickNavigationDrawerHamburger_navigationDrawerIsOpenedAndVerifiedSuccessfully() {
launch(NavigationDrawerTestActivity::class.java).use {
Expand Down