@@ -2218,6 +2218,38 @@ public void setFabEnabled(final boolean enabled) {
22182218 }
22192219 }
22202220
2221+ /**
2222+ * Returns the navigation drawer menu item corresponding to this fragment.
2223+ *
2224+ * <p>
2225+ * OCFileListFragment is the parent for GalleryFragment, SharedListFragment,
2226+ * and GroupfolderListFragment. It also internally handles listing favorites,
2227+ * shared files, or recently modified items via search events. This method
2228+ * checks the current fragment type and search state to give correct drawer menu ID.
2229+ * </p>
2230+ *
2231+ * @return the menu item ID to highlight in the navigation drawer
2232+ */
2233+ public int getMenuItemId () {
2234+ // getMenuItemId will be called from onResume of FileDisplayActivity before checking menu item id
2235+ // search argument needs to be set if exists
2236+ setSearchArgs (getArguments ());
2237+
2238+ if (getClass () == GalleryFragment .class ) {
2239+ return R .id .nav_gallery ;
2240+ } else if (getClass () == SharedListFragment .class || isSearchEventShared () || currentSearchType == SHARED_FILTER ) {
2241+ return R .id .nav_shared ;
2242+ } else if (getClass () == GroupfolderListFragment .class || currentSearchType == SearchType .GROUPFOLDER ) {
2243+ return R .id .nav_groupfolders ;
2244+ } else if (isSearchEventFavorite () || currentSearchType == FAVORITE_SEARCH ) {
2245+ return R .id .nav_favorites ;
2246+ } else if (currentSearchType == RECENTLY_MODIFIED_SEARCH ) {
2247+ return R .id .nav_recently_modified ;
2248+ } else {
2249+ return R .id .nav_all_files ;
2250+ }
2251+ }
2252+
22212253 public boolean isEmpty () {
22222254 return mAdapter == null || mAdapter .isEmpty ();
22232255 }
@@ -2244,7 +2276,6 @@ private boolean isSearchEvent(SearchRemoteOperation.SearchType givenEvent) {
22442276 public boolean shouldNavigateBackToAllFiles () {
22452277 return this instanceof GalleryFragment ||
22462278 isSearchEventFavorite () ||
2247- isSearchEventShared () ||
2248- DrawerActivity .menuItemId == R .id .nav_favorites ;
2279+ isSearchEventShared ();
22492280 }
22502281}
0 commit comments