DrawerMenuUtil.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Nextcloud Android client application
  3. *
  4. * @author Andy Scherzinger
  5. * @author Chris Narkiewicz <hello@ezaquarii.com>
  6. *
  7. * Copyright (C) 2018 Andy Scherzinger
  8. * Copyright (C) 2020 Chris Narkiewicz <hello@ezaquarii.com>
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  12. * License as published by the Free Software Foundation; either
  13. * version 3 of the License, or any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public
  21. * License along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. package com.owncloud.android.utils;
  24. import android.content.res.Resources;
  25. import android.view.Menu;
  26. import com.nextcloud.client.account.User;
  27. import com.owncloud.android.R;
  28. import com.owncloud.android.lib.resources.status.OCCapability;
  29. import androidx.annotation.Nullable;
  30. /**
  31. * A helper class for drawer menu related operations.
  32. */
  33. public final class DrawerMenuUtil {
  34. private DrawerMenuUtil() {
  35. }
  36. public static void filterSearchMenuItems(Menu menu,
  37. User user,
  38. Resources resources) {
  39. if (user.isAnonymous()) {
  40. filterMenuItems(menu, R.id.nav_gallery, R.id.nav_favorites);
  41. }
  42. if (!resources.getBoolean(R.bool.recently_modified_enabled)) {
  43. menu.removeItem(R.id.nav_recently_modified);
  44. }
  45. }
  46. public static void filterTrashbinMenuItem(Menu menu, @Nullable OCCapability capability) {
  47. if (capability != null && capability.getFilesUndelete().isFalse() ||
  48. capability != null && capability.getFilesUndelete().isUnknown()) {
  49. filterMenuItems(menu, R.id.nav_trashbin);
  50. }
  51. }
  52. public static void filterActivityMenuItem(Menu menu, @Nullable OCCapability capability) {
  53. if (capability != null && capability.getActivity().isFalse()) {
  54. filterMenuItems(menu, R.id.nav_activity);
  55. }
  56. }
  57. public static void filterAssistantMenuItem(Menu menu, @Nullable OCCapability capability, Resources resources) {
  58. if (capability != null && !capability.getAssistant().isTrue() && resources.getBoolean(R.bool.is_branded_client)) {
  59. filterMenuItems(menu, R.id.nav_assistant);
  60. }
  61. }
  62. public static void filterGroupfoldersMenuItem(Menu menu, @Nullable OCCapability capability) {
  63. if (capability != null && !capability.getGroupfolders().isTrue()) {
  64. filterMenuItems(menu, R.id.nav_groupfolders);
  65. }
  66. }
  67. public static void removeMenuItem(Menu menu, int id, boolean remove) {
  68. if (remove) {
  69. menu.removeItem(id);
  70. }
  71. }
  72. public static void setupHomeMenuItem(Menu menu, Resources resources) {
  73. if (resources.getBoolean(R.bool.use_home) && menu.findItem(R.id.nav_all_files) != null) {
  74. menu.findItem(R.id.nav_all_files).setTitle(resources.getString(R.string.drawer_item_home));
  75. menu.findItem(R.id.nav_all_files).setIcon(R.drawable.ic_home);
  76. }
  77. }
  78. private static void filterMenuItems(Menu menu, int... menuIds) {
  79. if (menuIds != null) {
  80. for (int menuId : menuIds) {
  81. menu.removeItem(menuId);
  82. }
  83. }
  84. }
  85. }