Sfoglia il codice sorgente

move client to thread

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 6 anni fa
parent
commit
15bc754ea7

+ 16 - 14
src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.java

@@ -233,20 +233,6 @@ public class NotificationsActivity extends FileActivity {
                 PorterDuff.Mode.SRC_IN);
         setLoadingMessage();
 
-        try {
-            OwnCloudAccount ocAccount = new OwnCloudAccount(currentAccount, this);
-            client = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, this);
-            client.setOwnCloudVersion(AccountUtils.getServerVersion(currentAccount));
-
-            hideRefreshLayoutLoader();
-        } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException |
-                IOException | OperationCanceledException | AuthenticatorException e) {
-            Log_OC.e(TAG, "Error initializing client", e);
-        }
-
-        adapter = new NotificationListAdapter(client, this);
-        recyclerView.setAdapter(adapter);
-
         LinearLayoutManager layoutManager = new LinearLayoutManager(this);
 
         recyclerView.setLayoutManager(layoutManager);
@@ -267,6 +253,22 @@ public class NotificationsActivity extends FileActivity {
 
     private void fetchAndSetData() {
         Thread t = new Thread(() -> {
+            if (client == null) {
+                try {
+                    OwnCloudAccount ocAccount = new OwnCloudAccount(currentAccount, this);
+                    client = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, this);
+                    client.setOwnCloudVersion(AccountUtils.getServerVersion(currentAccount));
+                } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException |
+                    IOException | OperationCanceledException | AuthenticatorException e) {
+                    Log_OC.e(TAG, "Error initializing client", e);
+                }
+            }
+
+            if (adapter == null) {
+                adapter = new NotificationListAdapter(client, this);
+                recyclerView.setAdapter(adapter);
+            }
+
             RemoteOperation getRemoteNotificationOperation = new GetRemoteNotificationsOperation();
             final RemoteOperationResult result = getRemoteNotificationOperation.execute(client);