From d6c3eb0196f248c33253868fa44d5d066dc6598c Mon Sep 17 00:00:00 2001 From: ZetaTom <70907959+ZetaTom@users.noreply.github.com> Date: Mon, 8 Jan 2024 12:57:15 +0100 Subject: [PATCH] Adapt OperationsService for NextcloudClient Signed-off-by: ZetaTom <70907959+ZetaTom@users.noreply.github.com> --- .../android/services/OperationsService.java | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/services/OperationsService.java b/app/src/main/java/com/owncloud/android/services/OperationsService.java index 6ea23a8662..f7fa577966 100644 --- a/app/src/main/java/com/owncloud/android/services/OperationsService.java +++ b/app/src/main/java/com/owncloud/android/services/OperationsService.java @@ -29,6 +29,8 @@ import android.util.Pair; import com.nextcloud.client.account.User; import com.nextcloud.client.account.UserAccountManager; +import com.nextcloud.common.NextcloudClient; +import com.nextcloud.java.util.Optional; import com.nextcloud.utils.extensions.IntentExtensionsKt; import com.owncloud.android.MainApp; import com.owncloud.android.datamodel.ArbitraryDataProvider; @@ -260,7 +262,7 @@ public class OperationsService extends Service { */ private final ConcurrentMap mBoundListeners = new ConcurrentHashMap<>(); - private ServiceHandler mServiceHandler; + private final ServiceHandler mServiceHandler; public OperationsServiceBinder(ServiceHandler serviceHandler) { mServiceHandler = serviceHandler; @@ -380,7 +382,7 @@ public class OperationsService extends Service { OperationsService mService; - private ConcurrentLinkedQueue> mPendingOperations = + private final ConcurrentLinkedQueue> mPendingOperations = new ConcurrentLinkedQueue<>(); private RemoteOperation mCurrentOperation; private Target mLastTarget; @@ -416,11 +418,12 @@ public class OperationsService extends Service { if (next != null) { mCurrentOperation = next.second; RemoteOperationResult result; + OwnCloudAccount ocAccount = null; + try { /// prepare client object to send the request to the ownCloud server if (mLastTarget == null || !mLastTarget.equals(next.first)) { mLastTarget = next.first; - OwnCloudAccount ocAccount; if (mLastTarget.mAccount != null) { ocAccount = new OwnCloudAccount(mLastTarget.mAccount, mService); } else { @@ -430,9 +433,21 @@ public class OperationsService extends Service { getClientFor(ocAccount, mService); } - /// perform the operation - result = mCurrentOperation.execute(mOwnCloudClient); - } catch (AccountsException e) { + // perform the operation + try { + result = mCurrentOperation.execute(mOwnCloudClient); + } catch (UnsupportedOperationException e) { + // TODO remove - added to aid in transition to NextcloudClient + + if (ocAccount == null) { + throw e; + } + + NextcloudClient nextcloudClient = OwnCloudClientManagerFactory.getDefaultSingleton() + .getNextcloudClientFor(ocAccount, mService.getBaseContext()); + result = mCurrentOperation.run(nextcloudClient); + } + } catch (AccountsException | IOException e) { if (mLastTarget.mAccount == null) { Log_OC.e(TAG, "Error while trying to get authorization for a NULL account", e); @@ -442,15 +457,6 @@ public class OperationsService extends Service { } result = new RemoteOperationResult(e); - } catch (IOException e) { - if (mLastTarget.mAccount == null) { - Log_OC.e(TAG, "Error while trying to get authorization for a NULL account", - e); - } else { - Log_OC.e(TAG, "Error while trying to get authorization for " + - mLastTarget.mAccount.name, e); - } - result = new RemoteOperationResult(e); } catch (Exception e) { if (mLastTarget.mAccount == null) { Log_OC.e(TAG, "Unexpected error for a NULL account", e); @@ -537,10 +543,6 @@ public class OperationsService extends Service { false); updateLinkOperation.setHideFileDownload(hideFileDownload); -// if (operationIntent.hasExtra(EXTRA_SHARE_PUBLIC_UPLOAD)) { -// updateLinkOperation.setPublicUpload(true); -// } - if (operationIntent.hasExtra(EXTRA_SHARE_PUBLIC_LABEL)) { updateLinkOperation.setLabel(operationIntent.getStringExtra(EXTRA_SHARE_PUBLIC_LABEL)); }