8787import com .owncloud .android .ui .activities .ActivitiesActivity ;
8888import com .owncloud .android .ui .events .AccountRemovedEvent ;
8989import com .owncloud .android .ui .events .ChangeMenuEvent ;
90- import com .owncloud .android .ui .events .DummyDrawerEvent ;
9190import com .owncloud .android .ui .events .SearchEvent ;
9291import com .owncloud .android .ui .fragment .FileDetailsSharingProcessFragment ;
9392import com .owncloud .android .ui .fragment .GalleryFragment ;
@@ -177,6 +176,8 @@ public abstract class DrawerActivity extends ToolbarActivity
177176 */
178177 public static int menuItemId = Menu .NONE ;
179178
179+ private static int previousMenuItemId = Menu .NONE ;
180+
180181 /**
181182 * container layout of the quota view.
182183 */
@@ -263,39 +264,17 @@ private void checkAssistantBottomNavigationMenu() {
263264 .setVisible (isAssistantAvailable );
264265 }
265266
266- @ SuppressFBWarnings ("RV" )
267- private void handleBottomNavigationViewClicks () {
268- bottomNavigationView .setOnItemSelectedListener (menuItem -> {
269- menuItemId = menuItem .getItemId ();
270-
271- exitSelectionMode ();
272- resetOnlyPersonalAndOnDevice ();
273-
274- if (menuItemId == R .id .nav_all_files ) {
275- showFiles (false ,false );
276- if (this instanceof FileDisplayActivity fda ) {
277- fda .browseToRoot ();
278- }
279- EventBus .getDefault ().post (new ChangeMenuEvent ());
280- } else if (menuItemId == R .id .nav_favorites ) {
281- setupToolbar ();
282- handleSearchEvents (new SearchEvent ("" , SearchRemoteOperation .SearchType .FAVORITE_SEARCH ), menuItemId );
283- } else if (menuItemId == R .id .nav_assistant && !(this instanceof ComposeActivity )) {
284- startComposeActivity (new ComposeDestination .AssistantScreen (null ), R .string .assistant_screen_top_bar_title );
285- } else if (menuItemId == R .id .nav_gallery ) {
286- setupToolbar ();
287- startPhotoSearch (menuItem .getItemId ());
288- }
289-
290- // Remove extra icon from the action bar
291- if (getSupportActionBar () != null ) {
292- getSupportActionBar ().setIcon (null );
293- }
294-
295- setNavigationViewItemChecked ();
267+ private void openFavoritesTab () {
268+ resetOnlyPersonalAndOnDevice ();
269+ setupToolbar ();
270+ SearchEvent searchEvent = new SearchEvent ("" , SearchRemoteOperation .SearchType .FAVORITE_SEARCH );
271+ launchActivityForSearch (searchEvent , R .id .nav_favorites );
272+ }
296273
297- return false ;
298- });
274+ private void openMediaTab (int menuItemId ) {
275+ resetOnlyPersonalAndOnDevice ();
276+ setupToolbar ();
277+ startPhotoSearch (menuItemId );
299278 }
300279
301280 @ Nullable
@@ -320,16 +299,10 @@ private void exitSelectionMode() {
320299 }
321300 }
322301
323- /**
324- * initializes and sets up the drawer toggle.
325- */
326302 private void setupDrawerToggle () {
327303 mDrawerToggle = new ActionBarDrawerToggle (this , mDrawerLayout , R .string .drawer_open , R .string .drawer_close ) {
328- /** Called when a drawer has settled in a completely closed state. */
329304 public void onDrawerClosed (View view ) {
330305 super .onDrawerClosed (view );
331- supportInvalidateOptionsMenu ();
332- mDrawerToggle .setDrawerIndicatorEnabled (isDrawerIndicatorAvailable ());
333306
334307 if (pendingRunnable != null ) {
335308 new Handler ().post (pendingRunnable );
@@ -338,23 +311,12 @@ public void onDrawerClosed(View view) {
338311
339312 closeDrawer ();
340313 }
341-
342- /** Called when a drawer has settled in a completely open state. */
343- public void onDrawerOpened (View drawerView ) {
344- super .onDrawerOpened (drawerView );
345- mDrawerToggle .setDrawerIndicatorEnabled (true );
346- supportInvalidateOptionsMenu ();
347- }
348314 };
349315
350- // Set the drawer toggle as the DrawerListener
351316 mDrawerLayout .addDrawerListener (mDrawerToggle );
352317 mDrawerToggle .setDrawerIndicatorEnabled (true );
353318 mDrawerToggle .setDrawerSlideAnimationEnabled (true );
354- Drawable backArrow = ResourcesCompat .getDrawable (getResources (),
355- R .drawable .ic_arrow_back ,
356- null );
357-
319+ final Drawable backArrow = ResourcesCompat .getDrawable (getResources (), R .drawable .ic_arrow_back , null );
358320 if (backArrow != null ) {
359321 viewThemeUtils .platform .tintToolbarArrowDrawable (this , mDrawerToggle , backArrow );
360322 }
@@ -552,12 +514,9 @@ private void filterDrawerMenu(final Menu menu, @NonNull final User user) {
552514 DrawerMenuUtil .removeMenuItem (menu , R .id .nav_logout , !getResources ().getBoolean (R .bool .show_drawer_logout ));
553515 }
554516
555- @ Subscribe (threadMode = ThreadMode .MAIN )
556- public void onMessageEvent (DummyDrawerEvent event ) {
557- unsetAllDrawerMenuItems ();
558- }
559-
517+ // region navigation item click
560518 private void onNavigationItemClicked (final MenuItem menuItem ) {
519+ setPreviousMenuItemId (menuItemId );
561520 int itemId = menuItem .getItemId ();
562521
563522 // Settings screen cannot display drawer menu thus no need to highlight
@@ -587,16 +546,11 @@ private void onNavigationItemClicked(final MenuItem menuItem) {
587546
588547 closeDrawer ();
589548 } else if (itemId == R .id .nav_favorites ) {
590- resetOnlyPersonalAndOnDevice ();
591- setupToolbar ();
592- handleSearchEvents (new SearchEvent ("" , SearchRemoteOperation .SearchType .FAVORITE_SEARCH ), menuItem .getItemId ());
549+ openFavoritesTab ();
593550 } else if (itemId == R .id .nav_gallery ) {
594- resetOnlyPersonalAndOnDevice ();
595- setupToolbar ();
596- startPhotoSearch (menuItem .getItemId ());
551+ openMediaTab (menuItem .getItemId ());
597552 } else if (itemId == R .id .nav_on_device ) {
598- EventBus .getDefault ().post (new ChangeMenuEvent ());
599- showFiles (true , false );
553+ showOnDeviceFiles ();
600554 } else if (itemId == R .id .nav_uploads ) {
601555 resetOnlyPersonalAndOnDevice ();
602556 startActivity (UploadListActivity .class , Intent .FLAG_ACTIVITY_CLEAR_TOP );
@@ -645,6 +599,53 @@ private void onNavigationItemClicked(final MenuItem menuItem) {
645599 Log_OC .w (TAG , "Unknown drawer menu item clicked: " + menuItem .getTitle ());
646600 }
647601 }
602+
603+ resetFileDepthAndConfigureMenuItem ();
604+ }
605+
606+ @ SuppressFBWarnings ("RV" )
607+ private void handleBottomNavigationViewClicks () {
608+ bottomNavigationView .setOnItemSelectedListener (menuItem -> {
609+ setPreviousMenuItemId (menuItemId );
610+ menuItemId = menuItem .getItemId ();
611+
612+ exitSelectionMode ();
613+ resetOnlyPersonalAndOnDevice ();
614+
615+ if (menuItemId == R .id .nav_all_files ) {
616+ showFiles (false ,false );
617+ if (this instanceof FileDisplayActivity fda ) {
618+ fda .browseToRoot ();
619+ }
620+ EventBus .getDefault ().post (new ChangeMenuEvent ());
621+ } else if (menuItemId == R .id .nav_favorites ) {
622+ openFavoritesTab ();
623+ } else if (menuItemId == R .id .nav_assistant && !(this instanceof ComposeActivity )) {
624+ startComposeActivity (new ComposeDestination .AssistantScreen (null ), R .string .assistant_screen_top_bar_title );
625+ } else if (menuItemId == R .id .nav_gallery ) {
626+ openMediaTab (menuItem .getItemId ());
627+ }
628+
629+ // Remove extra icon from the action bar
630+ if (getSupportActionBar () != null ) {
631+ getSupportActionBar ().setIcon (null );
632+ }
633+
634+ setNavigationViewItemChecked ();
635+ resetFileDepthAndConfigureMenuItem ();
636+
637+ return false ;
638+ });
639+ }
640+ // endregion
641+
642+ private void resetFileDepthAndConfigureMenuItem () {
643+ // from navigation user always sees root level
644+ resetFileDepth ();
645+
646+ if (this instanceof FileDisplayActivity fda ) {
647+ fda .configureMenuItem ();
648+ }
648649 }
649650
650651 private void startComposeActivity (ComposeDestination destination , int titleId ) {
@@ -684,11 +685,15 @@ public void openAddAccount() {
684685 }
685686 }
686687
687- protected void openSharedTab () {
688+ private void resetFileDepth () {
688689 final var ocFileListFragment = getOCFileListFragment ();
689690 if (ocFileListFragment != null ) {
690691 ocFileListFragment .resetFileDepth ();
691692 }
693+ }
694+
695+ protected void openSharedTab () {
696+ resetFileDepth ();
692697 resetOnlyPersonalAndOnDevice ();
693698 SearchEvent searchEvent = new SearchEvent ("" , SearchRemoteOperation .SearchType .SHARED_FILTER );
694699 launchActivityForSearch (searchEvent , R .id .nav_shared );
@@ -708,19 +713,6 @@ public void startPhotoSearch(int id) {
708713 launchActivityForSearch (searchEvent , id );
709714 }
710715
711- private void handleSearchEvents (SearchEvent searchEvent , int menuItemId ) {
712- if (this instanceof FileDisplayActivity ) {
713- final Fragment leftFragment = ((FileDisplayActivity ) this ).getLeftFragment ();
714- if (leftFragment instanceof GalleryFragment || leftFragment instanceof SharedListFragment ) {
715- launchActivityForSearch (searchEvent , menuItemId );
716- } else {
717- EventBus .getDefault ().post (searchEvent );
718- }
719- } else {
720- launchActivityForSearch (searchEvent , menuItemId );
721- }
722- }
723-
724716 private void launchActivityForSearch (SearchEvent searchEvent , int menuItemId ) {
725717 DrawerActivity .menuItemId = menuItemId ;
726718 Intent intent = new Intent (getApplicationContext (), FileDisplayActivity .class );
@@ -880,14 +872,18 @@ private void setQuotaInformation(long usedSpace, long totalSpace, int relative,
880872
881873 private void unsetAllDrawerMenuItems () {
882874 if (drawerNavigationView != null ) {
883- drawerNavigationView .getMenu ();
884875 Menu menu = drawerNavigationView .getMenu ();
885876 for (int i = 0 ; i < menu .size (); i ++) {
886877 menu .getItem (i ).setChecked (false );
887878 }
888879 }
889880
890- menuItemId = Menu .NONE ;
881+ if (bottomNavigationView != null ) {
882+ Menu menu = bottomNavigationView .getMenu ();
883+ for (int i = 0 ; i < menu .size (); i ++) {
884+ menu .getItem (i ).setChecked (false );
885+ }
886+ }
891887 }
892888
893889 private void updateQuotaLink () {
@@ -963,12 +959,19 @@ public void onLoadFailed(@Nullable Drawable errorDrawable) {
963959 */
964960 @ SuppressFBWarnings ("RV" )
965961 public void setNavigationViewItemChecked () {
962+ unsetAllDrawerMenuItems ();
963+
964+ // Don't check any items
965+ if (menuItemId == Menu .NONE ) {
966+ return ;
967+ }
968+
966969 if (drawerNavigationView != null ) {
967970 MenuItem menuItem = drawerNavigationView .getMenu ().findItem (menuItemId );
968971
969972 if (menuItem != null && !menuItem .isChecked ()) {
970- viewThemeUtils .platform .colorNavigationView (drawerNavigationView );
971973 menuItem .setChecked (true );
974+ viewThemeUtils .platform .colorNavigationView (drawerNavigationView );
972975 }
973976 }
974977
@@ -1260,6 +1263,16 @@ public void showFiles(boolean onDeviceOnly, boolean onlyPersonalFiles) {
12601263 startActivity (intent );
12611264 }
12621265
1266+ private void showOnDeviceFiles () {
1267+ MainApp .showOnlyFilesOnDevice (true );
1268+ MainApp .showOnlyPersonalFiles (false );
1269+
1270+ Intent intent = new Intent (getApplicationContext (), FileDisplayActivity .class );
1271+ intent .addFlags (Intent .FLAG_ACTIVITY_CLEAR_TOP );
1272+ intent .setAction (FileDisplayActivity .ON_DEVICE );
1273+ startActivity (intent );
1274+ }
1275+
12631276 @ Override
12641277 public void avatarGenerated (Drawable avatarDrawable , Object callContext ) {
12651278 if (callContext instanceof MenuItem menuItem ) {
@@ -1444,4 +1457,26 @@ private void checkStoragePermissionWarningBannerVisibility() {
14441457 uploadFilesActivity .setupStoragePermissionWarningBanner ();
14451458 }
14461459 }
1460+
1461+ public static boolean isToolbarStyleSearch () {
1462+ return menuItemId == Menu .NONE ||
1463+ menuItemId == R .id .nav_all_files ||
1464+ menuItemId == R .id .nav_personal_files ;
1465+ }
1466+
1467+ public static boolean isMenuItemIdBelongsToSearchType () {
1468+ return menuItemId == R .id .nav_favorites ||
1469+ menuItemId == R .id .nav_shared ||
1470+ menuItemId == R .id .nav_on_device ||
1471+ menuItemId == R .id .nav_recently_modified ||
1472+ menuItemId == R .id .nav_gallery ;
1473+ }
1474+
1475+ public static int getPreviousMenuItemId () {
1476+ return previousMenuItemId ;
1477+ }
1478+
1479+ public static void setPreviousMenuItemId (int menuItemId ) {
1480+ previousMenuItemId = menuItemId ;
1481+ }
14471482}
0 commit comments