Browse Source

Merge pull request #1985 from nextcloud/drawerLoad

Fix NPE in external link icon loading
Andy Scherzinger 7 years ago
parent
commit
e21429a557
1 changed files with 15 additions and 7 deletions
  1. 15 7
      src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java

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

@@ -1027,17 +1027,14 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
                 MenuSimpleTarget target = new MenuSimpleTarget<Drawable>(id) {
                     @Override
                     public void onResourceReady(Drawable resource, GlideAnimation glideAnimation) {
-                        mNavigationView.getMenu().findItem(getIdMenuItem()).setIcon(
-                                ThemeUtils.tintDrawable(resource, greyColor));
+                        setExternalLinkIcon(getIdMenuItem(), resource, greyColor);
                     }
 
                     @Override
                     public void onLoadFailed(Exception e, Drawable errorDrawable) {
                         super.onLoadFailed(e, errorDrawable);
-                        mNavigationView.getMenu().findItem(getIdMenuItem()).setIcon(errorDrawable.getCurrent());
+                        setExternalLinkIcon(getIdMenuItem(), errorDrawable, greyColor);
                     }
-
-
                 };
 
                 DisplayUtils.downloadIcon(this, link.iconUrl, target, R.drawable.ic_link_grey, size, size);
@@ -1045,6 +1042,18 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
         }
     }
 
+    private void setExternalLinkIcon(int id, Drawable drawable, int greyColor) {
+        MenuItem menuItem = mNavigationView.getMenu().findItem(id);
+
+        if (menuItem != null) {
+            if (drawable != null) {
+                menuItem.setIcon(ThemeUtils.tintDrawable(drawable, greyColor));
+            } else {
+                menuItem.setIcon(R.drawable.ic_link_grey);
+            }
+        }
+    }
+
     public void updateHeaderBackground() {
         if (getAccount() != null &&
                 getStorageManager().getCapability(getAccount().name).getServerBackground() != null) {
@@ -1366,8 +1375,6 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
 
                 Account account = AccountUtils.getCurrentOwnCloudAccount(DrawerActivity.this);
 
-                externalLinksProvider.deleteAllExternalLinks();
-
                 if (account != null && getStorageManager() != null &&
                         getStorageManager().getCapability(account.name) != null &&
                         getStorageManager().getCapability(account.name).getExternalLinks().isTrue()) {
@@ -1401,6 +1408,7 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
                                 FileActivity.APP_OPENED_COUNT, String.valueOf(count + 1));
                     }
                 } else {
+                    externalLinksProvider.deleteAllExternalLinks();
                     Log_OC.d("ExternalLinks", "links disabled");
                 }
                 runOnUiThread(() -> updateExternalLinksInDrawer());