Migrate drawer menu utilities to new user model

Signed-off-by: Chris Narkiewicz <hello@ezaquarii.com>
This commit is contained in:
Chris Narkiewicz 2020-02-09 01:22:03 +00:00
parent f415cd966f
commit b5fb9c1374
No known key found for this signature in database
GPG key ID: 30D28CA4CCC665C6
2 changed files with 11 additions and 14 deletions

View file

@ -374,8 +374,8 @@ public abstract class DrawerActivity extends ToolbarActivity
getContentResolver()); getContentResolver());
OCCapability capability = storageManager.getCapability(user.getAccountName()); OCCapability capability = storageManager.getCapability(user.getAccountName());
DrawerMenuUtil.filterSearchMenuItems(menu, user.toPlatformAccount(), getResources(), true); DrawerMenuUtil.filterSearchMenuItems(menu, user, getResources(), true);
DrawerMenuUtil.filterTrashbinMenuItem(menu, user.toPlatformAccount(), capability, accountManager); DrawerMenuUtil.filterTrashbinMenuItem(menu, user, capability);
DrawerMenuUtil.filterActivityMenuItem(menu, capability); DrawerMenuUtil.filterActivityMenuItem(menu, capability);
DrawerMenuUtil.setupHomeMenuItem(menu, getResources()); DrawerMenuUtil.setupHomeMenuItem(menu, getResources());

View file

@ -20,11 +20,10 @@
package com.owncloud.android.utils; package com.owncloud.android.utils;
import android.accounts.Account;
import android.content.res.Resources; import android.content.res.Resources;
import android.view.Menu; import android.view.Menu;
import com.nextcloud.client.account.UserAccountManager; import com.nextcloud.client.account.User;
import com.owncloud.android.R; import com.owncloud.android.R;
import com.owncloud.android.lib.resources.status.OCCapability; import com.owncloud.android.lib.resources.status.OCCapability;
import com.owncloud.android.lib.resources.status.OwnCloudVersion; import com.owncloud.android.lib.resources.status.OwnCloudVersion;
@ -39,10 +38,10 @@ public final class DrawerMenuUtil {
} }
public static void filterSearchMenuItems(Menu menu, public static void filterSearchMenuItems(Menu menu,
Account account, User user,
Resources resources, Resources resources,
boolean hasSearchSupport) { boolean hasSearchSupport) {
if (account != null && !hasSearchSupport) { if (!user.isAnonymous() && !hasSearchSupport) {
filterMenuItems(menu, R.id.nav_photos, R.id.nav_favorites, R.id.nav_videos); filterMenuItems(menu, R.id.nav_photos, R.id.nav_favorites, R.id.nav_videos);
} }
@ -58,18 +57,16 @@ public final class DrawerMenuUtil {
if (!resources.getBoolean(R.bool.videos_enabled)) { if (!resources.getBoolean(R.bool.videos_enabled)) {
menu.removeItem(R.id.nav_videos); menu.removeItem(R.id.nav_videos);
} }
} else if (account != null) { } else if (!user.isAnonymous()) {
filterMenuItems(menu, R.id.nav_recently_added, R.id.nav_recently_modified, R.id.nav_videos); filterMenuItems(menu, R.id.nav_recently_added, R.id.nav_recently_modified, R.id.nav_videos);
} }
} }
public static void filterTrashbinMenuItem(Menu menu, public static void filterTrashbinMenuItem(Menu menu, User user, @Nullable OCCapability capability) {
@Nullable Account account, if (!user.isAnonymous() &&
@Nullable OCCapability capability, user.getServer().getVersion().compareTo(OwnCloudVersion.nextcloud_14) < 0 ||
UserAccountManager accountManager) { capability != null && capability.getFilesUndelete().isFalse() ||
if (account != null && capability != null && capability != null && capability.getFilesUndelete().isUnknown()) {
(accountManager.getServerVersion(account).compareTo(OwnCloudVersion.nextcloud_14) < 0 ||
capability.getFilesUndelete().isFalse() || capability.getFilesUndelete().isUnknown())) {
filterMenuItems(menu, R.id.nav_trashbin); filterMenuItems(menu, R.id.nav_trashbin);
} }
} }