Browse Source

Bug #811 was Fixed
External Links are marked grey in the Drawer

alejandro 8 years ago
parent
commit
cf3fbc79c6

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

@@ -70,6 +70,7 @@ import com.owncloud.android.ui.events.DummyDrawerEvent;
 import com.owncloud.android.ui.events.MenuItemClickEvent;
 import com.owncloud.android.ui.events.SearchEvent;
 import com.owncloud.android.utils.DisplayUtils;
+import com.owncloud.android.utils.svg.MenuSimpleTarget;
 
 import org.greenrobot.eventbus.EventBus;
 import org.greenrobot.eventbus.Subscribe;
@@ -919,21 +920,23 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
             final int size = Math.round(24 * density);
 
             for (final ExternalLink link : externalLinksProvider.getExternalLink(ExternalLinkType.LINK)) {
-                SimpleTarget target = new SimpleTarget<Drawable>() {
+
+                int id=mNavigationView.getMenu().add(R.id.drawer_menu_external_links, MENU_ITEM_EXTERNAL_LINK,
+                        MENU_ORDER_EXTERNAL_LINKS, link.name).setCheckable(true).getItemId();
+
+                MenuSimpleTarget target = new MenuSimpleTarget<Drawable>(id) {
                     @Override
                     public void onResourceReady(Drawable resource, GlideAnimation glideAnimation) {
-                        mNavigationView.getMenu().add(R.id.drawer_menu_external_links, MENU_ITEM_EXTERNAL_LINK,
-                                MENU_ORDER_EXTERNAL_LINKS, link.name)
-                                .setIcon(resource.getCurrent());
+                        mNavigationView.getMenu().findItem(getIdMenuItem()).setIcon(resource);
                     }
 
                     @Override
                     public void onLoadFailed(Exception e, Drawable errorDrawable) {
                         super.onLoadFailed(e, errorDrawable);
-                        mNavigationView.getMenu().add(R.id.drawer_menu_external_links, MENU_ITEM_EXTERNAL_LINK,
-                                MENU_ORDER_EXTERNAL_LINKS, link.name)
-                                .setIcon(errorDrawable.getCurrent());
+                        mNavigationView.getMenu().findItem(getIdMenuItem()).setIcon(errorDrawable.getCurrent());
                     }
+
+
                 };
 
                 externalLinksProvider.downloadIcon(this, link.iconUrl, target, R.drawable.ic_link_grey, size, size);

+ 9 - 1
src/main/java/com/owncloud/android/ui/activity/ExternalSiteWebView.java

@@ -51,6 +51,7 @@ public class ExternalSiteWebView extends FileActivity {
     private static final String TAG = ExternalSiteWebView.class.getSimpleName();
 
     private boolean showSidebar = false;
+    private int menuItemId;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -59,7 +60,7 @@ public class ExternalSiteWebView extends FileActivity {
         Bundle extras = getIntent().getExtras();
         String title = extras.getString(EXTRA_TITLE);
         String url = extras.getString(EXTRA_URL);
-        int menuItemId = extras.getInt(EXTRA_MENU_ITEM_ID);
+        menuItemId = extras.getInt(EXTRA_MENU_ITEM_ID);
         showSidebar = extras.getBoolean(EXTRA_SHOW_SIDEBAR);
 
         // show progress
@@ -159,4 +160,11 @@ public class ExternalSiteWebView extends FileActivity {
         fileDisplayActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
         startActivity(fileDisplayActivity);
     }
+
+    @Override
+    protected void onPostCreate(Bundle savedInstanceState) {
+        super.onPostCreate(savedInstanceState);
+        setDrawerMenuItemChecked(menuItemId);
+
+    }
 }

+ 44 - 0
src/main/java/com/owncloud/android/utils/svg/MenuSimpleTarget.java

@@ -0,0 +1,44 @@
+/**
+ * Nextcloud Android client application
+ *
+ * @author Alejandro Bautista
+ * Copyright (C) 2017 Andy Scherzinger
+ * Copyright (C) 2017 Mario Danic
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.owncloud.android.utils.svg;
+
+
+import com.bumptech.glide.request.target.SimpleTarget;
+
+/**
+ * SimpleTarget for MenuItems
+ */
+
+public abstract class MenuSimpleTarget<Z> extends SimpleTarget<Z>{
+
+    private final int mIdMenuItem;
+
+    public MenuSimpleTarget(int idMenuItem){
+        super();
+        this.mIdMenuItem=idMenuItem;
+    }
+
+
+    public int getIdMenuItem() {
+        return mIdMenuItem;
+    }
+}