Fix filterAssistantMenuItem

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-04-16 11:48:51 +02:00 committed by Alper Öztürk
parent 7e97a02c44
commit 3d03ea09b0
2 changed files with 27 additions and 17 deletions

View file

@ -29,7 +29,6 @@ import android.graphics.drawable.LayerDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
import android.text.TextUtils;
import android.view.Menu;
@ -285,14 +284,12 @@ public abstract class DrawerActivity extends ToolbarActivity
viewThemeUtils.material.colorProgressBar(mQuotaProgressBar);
}
private boolean showTopBanner = false;
public void updateHeader() {
int primaryColor = themeColorUtils.unchangedPrimaryColor(getAccount(), this);
boolean isClientBranded = getResources().getBoolean(R.bool.is_branded_client);
if (getAccount() != null &&
getCapabilities().getServerBackground() != null &&
!getResources().getBoolean(R.bool.is_branded_client)) {
getCapabilities().getServerBackground() != null && !isClientBranded) {
OCCapability capability = getCapabilities();
String logo = capability.getServerLogo();
@ -342,19 +339,29 @@ public abstract class DrawerActivity extends ToolbarActivity
}
// hide ecosystem apps according to user preference or in branded client
LinearLayout ecosystemApps = mNavigationViewHeader.findViewById(R.id.drawer_ecosystem_apps);
showTopBanner = !getResources().getBoolean(R.bool.is_branded_client) && preferences.isShowEcosystemApps();
LinearLayout banner = mNavigationViewHeader.findViewById(R.id.drawer_ecosystem_apps);
boolean shouldHideTopBanner = isClientBranded || !preferences.isShowEcosystemApps();
if (showTopBanner) {
showBanner(ecosystemApps, primaryColor);
if (shouldHideTopBanner) {
hideTopBanner(banner);
} else {
MenuItem assistanMenuItem = findViewById(R.id.nav_assistant);
assistanMenuItem.setVisible(false);
ecosystemApps.setVisibility(View.GONE);
showTopBanner(banner, primaryColor);
}
}
private void showBanner(LinearLayout banner, int primaryColor) {
private void hideTopBanner(LinearLayout banner) {
banner.setVisibility(View.GONE);
}
private void hideAssistantMenuItem() {
MenuItem assistantMenuItem = findViewById(R.id.nav_assistant);
if (assistantMenuItem != null) {
assistantMenuItem.setVisible(false);
}
}
private void showTopBanner(LinearLayout banner, int primaryColor) {
LinearLayout notesView = banner.findViewById(R.id.drawer_ecosystem_notes);
LinearLayout talkView = banner.findViewById(R.id.drawer_ecosystem_talk);
LinearLayout moreView = banner.findViewById(R.id.drawer_ecosystem_more);
@ -472,7 +479,7 @@ public abstract class DrawerActivity extends ToolbarActivity
DrawerMenuUtil.filterTrashbinMenuItem(menu, capability);
DrawerMenuUtil.filterActivityMenuItem(menu, capability);
DrawerMenuUtil.filterGroupfoldersMenuItem(menu, capability);
DrawerMenuUtil.filterAssistantMenuItem(menu, capability, getResources(), showTopBanner);
DrawerMenuUtil.filterAssistantMenuItem(menu, capability, getResources());
DrawerMenuUtil.setupHomeMenuItem(menu, getResources());
DrawerMenuUtil.removeMenuItem(menu, R.id.nav_community, !getResources().getBoolean(R.bool.participate_enabled));
DrawerMenuUtil.removeMenuItem(menu, R.id.nav_shared, !getResources().getBoolean(R.bool.shared_enabled));

View file

@ -48,9 +48,12 @@ public final class DrawerMenuUtil {
}
}
public static void filterAssistantMenuItem(Menu menu, @Nullable OCCapability capability, Resources resources, boolean showTopBanner) {
boolean showCondition = (capability != null && capability.getAssistant().isTrue() && !resources.getBoolean(R.bool.is_branded_client));
if (!showCondition || showTopBanner) {
public static void filterAssistantMenuItem(Menu menu, @Nullable OCCapability capability, Resources resources) {
if (resources.getBoolean(R.bool.is_branded_client)) {
if (capability != null && capability.getAssistant().isFalse()) {
removeMenuItem(menu, R.id.nav_assistant);
}
} else {
removeMenuItem(menu, R.id.nav_assistant);
}
}