From 15bc754ea7603a21fd6bfeaf7f1fb834e857513e Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Wed, 17 Oct 2018 10:20:42 +0200 Subject: [PATCH] move client to thread Signed-off-by: tobiasKaminsky --- .../ui/activity/NotificationsActivity.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.java b/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.java index 9c358b871e..0a5a3f434e 100644 --- a/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.java +++ b/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);