From: David A. Velasco Date: Mon, 12 May 2014 11:34:02 +0000 (+0200) Subject: Optimized binding to OperationsService to grant no result is lost X-Git-Tag: oc-android-1.7.0_signed~309^2~30 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/e0dc1e2b92bbdea32129ad9f62c242509fcb67cf?ds=inline;hp=--cc Optimized binding to OperationsService to grant no result is lost --- e0dc1e2b92bbdea32129ad9f62c242509fcb67cf diff --git a/src/com/owncloud/android/authentication/AuthenticatorActivity.java b/src/com/owncloud/android/authentication/AuthenticatorActivity.java index 1247f3f5..32bbcdcc 100644 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -114,7 +114,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { private static final String KEY_AUTH_STATUS_TEXT = "AUTH_STATUS_TEXT"; private static final String KEY_AUTH_STATUS_ICON = "AUTH_STATUS_ICON"; private static final String KEY_SERVER_AUTH_METHOD = "SERVER_AUTH_METHOD"; - private static final String KEY_WAITING_FOR_OP_ID = "DETECT_AUTH_OP_ID"; + private static final String KEY_WAITING_FOR_OP_ID = "WAITING_FOR_OP_ID"; private static final String KEY_AUTH_TOKEN = "AUTH_TOKEN"; private static final String AUTH_ON = "on"; diff --git a/src/com/owncloud/android/files/FileOperationsHelper.java b/src/com/owncloud/android/files/FileOperationsHelper.java index 022cbec1..73d598cf 100644 --- a/src/com/owncloud/android/files/FileOperationsHelper.java +++ b/src/com/owncloud/android/files/FileOperationsHelper.java @@ -49,6 +49,9 @@ public class FileOperationsHelper { private static final String FTAG_CHOOSER_DIALOG = "CHOOSER_DIALOG"; protected FileActivity mFileActivity = null; + + /// Identifier of operation in progress which result shouldn't be lost + private long mWaitingForOpId = Long.MAX_VALUE; public FileOperationsHelper(FileActivity fileActivity) { mFileActivity = fileActivity; @@ -121,7 +124,7 @@ public class FileOperationsHelper { service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount()); service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath()); service.putExtra(OperationsService.EXTRA_SEND_INTENT, sendIntent); - mFileActivity.getOperationsServiceBinder().newOperation(service); + mWaitingForOpId = mFileActivity.getOperationsServiceBinder().newOperation(service); } else { Log_OC.wtf(TAG, "Trying to open a NULL OCFile"); @@ -159,7 +162,7 @@ public class FileOperationsHelper { service.setAction(OperationsService.ACTION_UNSHARE); service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount()); service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath()); - mFileActivity.getOperationsServiceBinder().newOperation(service); + mWaitingForOpId = mFileActivity.getOperationsServiceBinder().newOperation(service); mFileActivity.showLoadingDialog(); @@ -197,7 +200,7 @@ public class FileOperationsHelper { service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount()); service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath()); service.putExtra(OperationsService.EXTRA_SYNC_FILE_CONTENTS, true); - mFileActivity.getOperationsServiceBinder().newOperation(service); + mWaitingForOpId = mFileActivity.getOperationsServiceBinder().newOperation(service); mFileActivity.showLoadingDialog(); } @@ -210,7 +213,7 @@ public class FileOperationsHelper { service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount()); service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath()); service.putExtra(OperationsService.EXTRA_NEWNAME, newFilename); - mFileActivity.getOperationsServiceBinder().newOperation(service); + mWaitingForOpId = mFileActivity.getOperationsServiceBinder().newOperation(service); mFileActivity.showLoadingDialog(); } @@ -223,7 +226,7 @@ public class FileOperationsHelper { service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount()); service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath()); service.putExtra(OperationsService.EXTRA_REMOVE_ONLY_LOCAL, onlyLocalCopy); - mFileActivity.getOperationsServiceBinder().newOperation(service); + mWaitingForOpId = mFileActivity.getOperationsServiceBinder().newOperation(service); mFileActivity.showLoadingDialog(); } @@ -236,8 +239,18 @@ public class FileOperationsHelper { service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount()); service.putExtra(OperationsService.EXTRA_REMOTE_PATH, remotePath); service.putExtra(OperationsService.EXTRA_CREATE_FULL_PATH, createFullPath); - mFileActivity.getOperationsServiceBinder().newOperation(service); + mWaitingForOpId = mFileActivity.getOperationsServiceBinder().newOperation(service); mFileActivity.showLoadingDialog(); } + + + public long getOpIdWaitingFor() { + return mWaitingForOpId; + } + + + public void setOpIdWaitingFor(long waitingForOpId) { + mWaitingForOpId = waitingForOpId; + } } diff --git a/src/com/owncloud/android/ui/activity/FileActivity.java b/src/com/owncloud/android/ui/activity/FileActivity.java index 55fbe5f4..895e7764 100644 --- a/src/com/owncloud/android/ui/activity/FileActivity.java +++ b/src/com/owncloud/android/ui/activity/FileActivity.java @@ -75,6 +75,7 @@ implements OnRemoteOperationListener, ComponentsGetter { public static final String TAG = FileActivity.class.getSimpleName(); private static final String DIALOG_WAIT_TAG = "DIALOG_WAIT"; + private static final String KEY_WAITING_FOR_OP_ID = "WAITING_FOR_OP_ID";; /** OwnCloud {@link Account} where the main {@link OCFile} handled by the activity is located. */ @@ -129,6 +130,9 @@ implements OnRemoteOperationListener, ComponentsGetter { account = savedInstanceState.getParcelable(FileActivity.EXTRA_ACCOUNT); mFile = savedInstanceState.getParcelable(FileActivity.EXTRA_FILE); mFromNotification = savedInstanceState.getBoolean(FileActivity.EXTRA_FROM_NOTIFICATION); + mFileOperationsHelper.setOpIdWaitingFor( + savedInstanceState.getLong(KEY_WAITING_FOR_OP_ID, Long.MAX_VALUE) + ); } else { account = getIntent().getParcelableExtra(FileActivity.EXTRA_ACCOUNT); mFile = getIntent().getParcelableExtra(FileActivity.EXTRA_FILE); @@ -179,6 +183,24 @@ implements OnRemoteOperationListener, ComponentsGetter { } } + @Override + protected void onResume() { + super.onResume(); + + if (mOperationsServiceBinder != null) { + doOnResumeAndBound(); + } + + } + + @Override + protected void onPause() { + if (mOperationsServiceBinder != null) { + mOperationsServiceBinder.removeOperationListener(this); + } + + super.onPause(); + } @Override protected void onStop() { @@ -285,6 +307,7 @@ implements OnRemoteOperationListener, ComponentsGetter { outState.putParcelable(FileActivity.EXTRA_FILE, mFile); outState.putParcelable(FileActivity.EXTRA_ACCOUNT, mAccount); outState.putBoolean(FileActivity.EXTRA_FROM_NOTIFICATION, mFromNotification); + outState.putLong(KEY_WAITING_FOR_OP_ID, mFileOperationsHelper.getOpIdWaitingFor()); } @@ -424,6 +447,9 @@ implements OnRemoteOperationListener, ComponentsGetter { @Override public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) { Log_OC.d(TAG, "Received result of operation in FileActivity - common behaviour for all the FileActivities "); + + mFileOperationsHelper.setOpIdWaitingFor(Long.MAX_VALUE); + if (operation instanceof CreateShareOperation) { onCreateShareOperationFinish((CreateShareOperation) operation, result); @@ -502,6 +528,15 @@ implements OnRemoteOperationListener, ComponentsGetter { } + private void doOnResumeAndBound() { + mOperationsServiceBinder.addOperationListener(FileActivity.this, mHandler); + long waitingForOpId = mFileOperationsHelper.getOpIdWaitingFor(); + if (waitingForOpId <= Integer.MAX_VALUE) { + mOperationsServiceBinder.dispatchResultIfFinished((int)waitingForOpId, this); + } + } + + /** * Implements callback methods for service binding. Passed as a parameter to { */ @@ -512,10 +547,10 @@ implements OnRemoteOperationListener, ComponentsGetter { if (component.equals(new ComponentName(FileActivity.this, OperationsService.class))) { Log_OC.d(TAG, "Operations service connected"); mOperationsServiceBinder = (OperationsServiceBinder) service; - mOperationsServiceBinder.addOperationListener(FileActivity.this, mHandler); - if (!mOperationsServiceBinder.isPerformingBlockingOperation()) { + /*if (!mOperationsServiceBinder.isPerformingBlockingOperation()) { dismissLoadingDialog(); - } + }*/ + doOnResumeAndBound(); } else { return;