Browse Source

Merge pull request #1831 from nextcloud/externalLinksProperHandling

Better handling when switching to an account with disabled external links
Andy Scherzinger 7 years ago
parent
commit
f58edc5a0e
1 changed files with 30 additions and 33 deletions
  1. 30 33
      src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java

+ 30 - 33
src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java

@@ -1335,53 +1335,50 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
      */
     public void fetchExternalLinks(final boolean force) {
         if (getBaseContext().getResources().getBoolean(R.bool.show_external_links)) {
-            Thread t = new Thread(new Runnable() {
-                public void run() {
-                    // fetch capabilities as early as possible
-                    if ((getCapabilities() == null || getCapabilities().getAccountName().isEmpty())
-                            && getStorageManager() != null) {
-                        GetCapabilitiesOperarion getCapabilities = new GetCapabilitiesOperarion();
-                        getCapabilities.execute(getStorageManager(), getBaseContext());
-                    }
-
-                    Account account = AccountUtils.getCurrentOwnCloudAccount(DrawerActivity.this);
+            Thread t = new Thread(() -> {
+                // fetch capabilities as early as possible
+                if ((getCapabilities() == null || getCapabilities().getAccountName().isEmpty())
+                        && getStorageManager() != null) {
+                    GetCapabilitiesOperarion getCapabilities = new GetCapabilitiesOperarion();
+                    getCapabilities.execute(getStorageManager(), getBaseContext());
+                }
 
-                    if (account != null && getStorageManager() != null &&
-                            getStorageManager().getCapability(account.name) != null &&
-                            getStorageManager().getCapability(account.name).getExternalLinks().isTrue()) {
+                Account account = AccountUtils.getCurrentOwnCloudAccount(DrawerActivity.this);
 
-                        int count = sharedPreferences.getInt(EXTERNAL_LINKS_COUNT, -1);
-                        if (count > 10 || count == -1 || force) {
-                            if (force) {
-                                Log_OC.d("ExternalLinks", "force update");
-                            }
+                externalLinksProvider.deleteAllExternalLinks();
 
-                            sharedPreferences.edit().putInt(EXTERNAL_LINKS_COUNT, 0).apply();
+                if (account != null && getStorageManager() != null &&
+                        getStorageManager().getCapability(account.name) != null &&
+                        getStorageManager().getCapability(account.name).getExternalLinks().isTrue()) {
 
-                            Log_OC.d("ExternalLinks", "update via api");
-                            ExternalLinksProvider externalLinksProvider = new ExternalLinksProvider(getContentResolver());
+                    int count = sharedPreferences.getInt(EXTERNAL_LINKS_COUNT, -1);
+                    if (count > 10 || count == -1 || force) {
+                        if (force) {
+                            Log_OC.d("ExternalLinks", "force update");
+                        }
 
-                            RemoteOperation getExternalLinksOperation = new ExternalLinksOperation();
-                            RemoteOperationResult result = getExternalLinksOperation.execute(account, DrawerActivity.this);
+                        sharedPreferences.edit().putInt(EXTERNAL_LINKS_COUNT, 0).apply();
 
-                            if (result.isSuccess() && result.getData() != null) {
-                                externalLinksProvider.deleteAllExternalLinks();
+                        Log_OC.d("ExternalLinks", "update via api");
+                        RemoteOperation getExternalLinksOperation = new ExternalLinksOperation();
+                        RemoteOperationResult result = getExternalLinksOperation.execute(account, DrawerActivity.this);
 
-                                ArrayList<ExternalLink> externalLinks = (ArrayList<ExternalLink>) (Object) result.getData();
+                        if (result.isSuccess() && result.getData() != null) {
+                            externalLinksProvider.deleteAllExternalLinks();
 
-                                for (ExternalLink link : externalLinks) {
-                                    externalLinksProvider.storeExternalLink(link);
-                                }
+                            ArrayList<ExternalLink> externalLinks = (ArrayList<ExternalLink>) (Object) result.getData();
 
-                                runOnUiThread(() -> updateExternalLinksInDrawer());
+                            for (ExternalLink link : externalLinks) {
+                                externalLinksProvider.storeExternalLink(link);
                             }
-                        } else {
-                            sharedPreferences.edit().putInt(EXTERNAL_LINKS_COUNT, count + 1).apply();
                         }
                     } else {
-                        Log_OC.d("ExternalLinks", "links disabled");
+                        sharedPreferences.edit().putInt(EXTERNAL_LINKS_COUNT, count + 1).apply();
                     }
+                } else {
+                    Log_OC.d("ExternalLinks", "links disabled");
                 }
+                runOnUiThread(() -> updateExternalLinksInDrawer());
             });
 
             t.start();