Browse Source

Remove workaround

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 10 months ago
parent
commit
45d363a417

+ 0 - 43
app/src/main/java/com/nextcloud/utils/extensions/DrawerActivityExtensions.kt

@@ -1,43 +0,0 @@
-/*
- * Nextcloud - Android Client
- *
- * SPDX-FileCopyrightText: 2024 Alper Ozturk <alper.ozturk@nextcloud.com>
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-
-package com.nextcloud.utils.extensions
-
-import com.owncloud.android.R
-import com.owncloud.android.ui.activity.DrawerActivity
-
-/**
- * Determines the appropriate menu item ID based on the current ActionBar title.
- *
- * This function serves as a workaround solution because not all drawer menu item
- * navigations extend from DrawerActivity. As a result, the content and highlighted
- * menu item may not always match. This function helps maintain consistency between
- * the displayed content and the highlighted menu item.
- *
- * @return The menu item ID corresponding to the current ActionBar title, or null if
- *         the ActionBar is not available.
- */
-fun DrawerActivity.getMenuItemIdFromTitle(): Int? {
-    val actionBar = supportActionBar ?: return null
-
-    return when (actionBar.title) {
-        getString(R.string.drawer_item_all_files) -> R.id.nav_all_files
-        getString(R.string.drawer_item_personal_files) -> R.id.nav_personal_files
-        getString(R.string.drawer_item_activities) -> R.id.nav_activity
-        getString(R.string.drawer_item_favorites) -> R.id.nav_favorites
-        getString(R.string.drawer_item_gallery) -> R.id.nav_gallery
-        getString(R.string.drawer_item_shared) -> R.id.nav_shared
-        getString(R.string.drawer_item_groupfolders) -> R.id.nav_groupfolders
-        getString(R.string.drawer_item_on_device) -> R.id.nav_on_device
-        getString(R.string.drawer_item_recently_modified) -> R.id.nav_recently_modified
-        getString(R.string.drawer_item_notifications) -> R.id.nav_notifications
-        getString(R.string.drawer_item_assistant) -> R.id.nav_assistant
-        getString(R.string.drawer_item_uploads_list) -> R.id.nav_uploads
-        getString(R.string.drawer_item_trashbin) -> R.id.nav_trashbin
-        else -> DrawerActivity.menuItemId
-    }
-}

+ 4 - 10
app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java

@@ -15,10 +15,8 @@ package com.owncloud.android.ui.activity;
 import android.accounts.AuthenticatorException;
 import android.accounts.OperationCanceledException;
 import android.app.Activity;
-import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
-import android.content.IntentFilter;
 import android.content.res.ColorStateList;
 import android.content.res.Configuration;
 import android.graphics.Bitmap;
@@ -124,11 +122,8 @@ import androidx.core.content.res.ResourcesCompat;
 import androidx.core.view.GravityCompat;
 import androidx.drawerlayout.widget.DrawerLayout;
 import androidx.fragment.app.Fragment;
-import androidx.localbroadcastmanager.content.LocalBroadcastManager;
 import hct.Hct;
 
-import static com.nextcloud.utils.extensions.DrawerActivityExtensionsKt.getMenuItemIdFromTitle;
-
 /**
  * Base class to handle setup of the drawer implementation including user switching and avatar fetching and fallback
  * generation.
@@ -234,16 +229,14 @@ public abstract class DrawerActivity extends ToolbarActivity
      */
     private void setupDrawerToggle() {
         mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) {
+            private boolean isMenuItemChecked = false;
 
             @Override
             public void onDrawerSlide(View drawerView, float slideOffset) {
                 super.onDrawerSlide(drawerView, slideOffset);
-                if (slideOffset > 0) {
-                    Integer menuItemIdFromTitle = getMenuItemIdFromTitle(DrawerActivity.this);
-                    if (menuItemIdFromTitle != null && menuItemIdFromTitle != menuItemId) {
-                        menuItemId = menuItemIdFromTitle;
-                    }
+                if (slideOffset > 0 && !isMenuItemChecked) {
                     setDrawerMenuItemChecked();
+                    isMenuItemChecked = true;
                 }
             }
 
@@ -258,6 +251,7 @@ public abstract class DrawerActivity extends ToolbarActivity
                     pendingRunnable = null;
                 }
 
+                isMenuItemChecked = false;
                 closeDrawer();
             }