X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/b6a9e6d6a7c3330dda436af878e3644cd8dc7ed1..b599f945e691230a280c26c109483c3cc03c60cf:/src/com/owncloud/android/services/OperationsService.java diff --git a/src/com/owncloud/android/services/OperationsService.java b/src/com/owncloud/android/services/OperationsService.java index 316657c4..40e65002 100644 --- a/src/com/owncloud/android/services/OperationsService.java +++ b/src/com/owncloud/android/services/OperationsService.java @@ -24,10 +24,13 @@ import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.lib.network.OwnCloudClientFactory; import com.owncloud.android.lib.network.OwnCloudClient; +import com.owncloud.android.operations.CreateShareOperation; import com.owncloud.android.operations.GetSharesOperation; +import com.owncloud.android.operations.UnshareLinkOperation; import com.owncloud.android.operations.common.SyncOperation; import com.owncloud.android.lib.operations.common.RemoteOperation; import com.owncloud.android.lib.operations.common.RemoteOperationResult; +import com.owncloud.android.lib.operations.common.ShareType; import com.owncloud.android.utils.Log_OC; import android.accounts.Account; @@ -42,7 +45,7 @@ import android.os.IBinder; import android.os.Looper; import android.os.Message; import android.os.Process; -import android.support.v4.content.LocalBroadcastManager; +//import android.support.v4.content.LocalBroadcastManager; import android.util.Pair; public class OperationsService extends Service { @@ -51,7 +54,12 @@ public class OperationsService extends Service { public static final String EXTRA_ACCOUNT = "ACCOUNT"; public static final String EXTRA_SERVER_URL = "SERVER_URL"; - public static final String EXTRA_RESULT = "RESULT"; + public static final String EXTRA_REMOTE_PATH = "REMOTE_PATH"; + public static final String EXTRA_SEND_INTENT = "SEND_INTENT"; + public static final String EXTRA_RESULT = "RESULT"; + + public static final String ACTION_CREATE_SHARE = "CREATE_SHARE"; + public static final String ACTION_UNSHARE = "UNSHARE"; public static final String ACTION_OPERATION_ADDED = OperationsService.class.getName() + ".OPERATION_ADDED"; public static final String ACTION_OPERATION_FINISHED = OperationsService.class.getName() + ".OPERATION_FINISHED"; @@ -107,8 +115,27 @@ public class OperationsService extends Service { try { Account account = intent.getParcelableExtra(EXTRA_ACCOUNT); String serverUrl = intent.getStringExtra(EXTRA_SERVER_URL); + Target target = new Target(account, (serverUrl == null) ? null : Uri.parse(serverUrl)); - GetSharesOperation operation = new GetSharesOperation(); + RemoteOperation operation = null; + + String action = intent.getAction(); + if (action == ACTION_CREATE_SHARE) { // Create Share + String remotePath = intent.getStringExtra(EXTRA_REMOTE_PATH); + Intent sendIntent = intent.getParcelableExtra(EXTRA_SEND_INTENT); + if (remotePath.length() > 0) { + operation = new CreateShareOperation(remotePath, ShareType.PUBLIC_LINK, + "", false, "", 1, sendIntent); + } + } else if (action == ACTION_UNSHARE) { // Unshare file + String remotePath = intent.getStringExtra(EXTRA_REMOTE_PATH); + if (remotePath.length() > 0) { + operation = new UnshareLinkOperation(remotePath, this.getApplicationContext()); + } + } else { + operation = new GetSharesOperation(); + } + mPendingOperations.add(new Pair(target, operation)); sendBroadcastNewOperation(target, operation); @@ -228,7 +255,14 @@ public class OperationsService extends Service { Log_OC.e(TAG, "Error while trying to get autorization 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); + } else { + Log_OC.e(TAG, "Unexpected error for " + mLastTarget.mAccount.name, e); + } + result = new RemoteOperationResult(e); + } finally { synchronized(mPendingOperations) { mPendingOperations.poll(); @@ -255,8 +289,9 @@ public class OperationsService extends Service { } else { intent.putExtra(EXTRA_SERVER_URL, target.mServerUrl); } - LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this); - lbm.sendBroadcast(intent); + //LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this); + //lbm.sendBroadcast(intent); + sendStickyBroadcast(intent); } @@ -279,8 +314,9 @@ public class OperationsService extends Service { } else { intent.putExtra(EXTRA_SERVER_URL, target.mServerUrl); } - LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this); - lbm.sendBroadcast(intent); + //LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this); + //lbm.sendBroadcast(intent); + sendStickyBroadcast(intent); }