mirror of
https://github.com/nextcloud/android.git
synced 2024-11-22 21:25:35 +03:00
Adapt OperationsService for NextcloudClient
Signed-off-by: ZetaTom <70907959+ZetaTom@users.noreply.github.com>
This commit is contained in:
parent
2c3b42445b
commit
d6c3eb0196
1 changed files with 21 additions and 19 deletions
|
@ -29,6 +29,8 @@ import android.util.Pair;
|
||||||
|
|
||||||
import com.nextcloud.client.account.User;
|
import com.nextcloud.client.account.User;
|
||||||
import com.nextcloud.client.account.UserAccountManager;
|
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.nextcloud.utils.extensions.IntentExtensionsKt;
|
||||||
import com.owncloud.android.MainApp;
|
import com.owncloud.android.MainApp;
|
||||||
import com.owncloud.android.datamodel.ArbitraryDataProvider;
|
import com.owncloud.android.datamodel.ArbitraryDataProvider;
|
||||||
|
@ -260,7 +262,7 @@ public class OperationsService extends Service {
|
||||||
*/
|
*/
|
||||||
private final ConcurrentMap<OnRemoteOperationListener, Handler> mBoundListeners = new ConcurrentHashMap<>();
|
private final ConcurrentMap<OnRemoteOperationListener, Handler> mBoundListeners = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private ServiceHandler mServiceHandler;
|
private final ServiceHandler mServiceHandler;
|
||||||
|
|
||||||
public OperationsServiceBinder(ServiceHandler serviceHandler) {
|
public OperationsServiceBinder(ServiceHandler serviceHandler) {
|
||||||
mServiceHandler = serviceHandler;
|
mServiceHandler = serviceHandler;
|
||||||
|
@ -380,7 +382,7 @@ public class OperationsService extends Service {
|
||||||
OperationsService mService;
|
OperationsService mService;
|
||||||
|
|
||||||
|
|
||||||
private ConcurrentLinkedQueue<Pair<Target, RemoteOperation>> mPendingOperations =
|
private final ConcurrentLinkedQueue<Pair<Target, RemoteOperation>> mPendingOperations =
|
||||||
new ConcurrentLinkedQueue<>();
|
new ConcurrentLinkedQueue<>();
|
||||||
private RemoteOperation mCurrentOperation;
|
private RemoteOperation mCurrentOperation;
|
||||||
private Target mLastTarget;
|
private Target mLastTarget;
|
||||||
|
@ -416,11 +418,12 @@ public class OperationsService extends Service {
|
||||||
if (next != null) {
|
if (next != null) {
|
||||||
mCurrentOperation = next.second;
|
mCurrentOperation = next.second;
|
||||||
RemoteOperationResult result;
|
RemoteOperationResult result;
|
||||||
|
OwnCloudAccount ocAccount = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
/// prepare client object to send the request to the ownCloud server
|
/// prepare client object to send the request to the ownCloud server
|
||||||
if (mLastTarget == null || !mLastTarget.equals(next.first)) {
|
if (mLastTarget == null || !mLastTarget.equals(next.first)) {
|
||||||
mLastTarget = next.first;
|
mLastTarget = next.first;
|
||||||
OwnCloudAccount ocAccount;
|
|
||||||
if (mLastTarget.mAccount != null) {
|
if (mLastTarget.mAccount != null) {
|
||||||
ocAccount = new OwnCloudAccount(mLastTarget.mAccount, mService);
|
ocAccount = new OwnCloudAccount(mLastTarget.mAccount, mService);
|
||||||
} else {
|
} else {
|
||||||
|
@ -430,9 +433,21 @@ public class OperationsService extends Service {
|
||||||
getClientFor(ocAccount, mService);
|
getClientFor(ocAccount, mService);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// perform the operation
|
// perform the operation
|
||||||
result = mCurrentOperation.execute(mOwnCloudClient);
|
try {
|
||||||
} catch (AccountsException e) {
|
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) {
|
if (mLastTarget.mAccount == null) {
|
||||||
Log_OC.e(TAG, "Error while trying to get authorization for a NULL account",
|
Log_OC.e(TAG, "Error while trying to get authorization for a NULL account",
|
||||||
e);
|
e);
|
||||||
|
@ -442,15 +457,6 @@ public class OperationsService extends Service {
|
||||||
}
|
}
|
||||||
result = new RemoteOperationResult(e);
|
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) {
|
} catch (Exception e) {
|
||||||
if (mLastTarget.mAccount == null) {
|
if (mLastTarget.mAccount == null) {
|
||||||
Log_OC.e(TAG, "Unexpected error for a NULL account", e);
|
Log_OC.e(TAG, "Unexpected error for a NULL account", e);
|
||||||
|
@ -537,10 +543,6 @@ public class OperationsService extends Service {
|
||||||
false);
|
false);
|
||||||
updateLinkOperation.setHideFileDownload(hideFileDownload);
|
updateLinkOperation.setHideFileDownload(hideFileDownload);
|
||||||
|
|
||||||
// if (operationIntent.hasExtra(EXTRA_SHARE_PUBLIC_UPLOAD)) {
|
|
||||||
// updateLinkOperation.setPublicUpload(true);
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (operationIntent.hasExtra(EXTRA_SHARE_PUBLIC_LABEL)) {
|
if (operationIntent.hasExtra(EXTRA_SHARE_PUBLIC_LABEL)) {
|
||||||
updateLinkOperation.setLabel(operationIntent.getStringExtra(EXTRA_SHARE_PUBLIC_LABEL));
|
updateLinkOperation.setLabel(operationIntent.getStringExtra(EXTRA_SHARE_PUBLIC_LABEL));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue