import android.accounts.Account;
import android.content.Context;
import android.content.Intent;
+import android.support.v4.content.LocalBroadcastManager;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.operations.remote.ReadRemoteFileOperation;
import com.owncloud.android.lib.operations.remote.ReadRemoteFolderOperation;
import com.owncloud.android.lib.operations.common.RemoteFile;
-import com.owncloud.android.syncadapter.FileSyncService;
+import com.owncloud.android.syncadapter.FileSyncAdapter;
import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.Log_OC;
private static final String TAG = SynchronizeFolderOperation.class.getSimpleName();
+ public static final String EVENT_SINGLE_FOLDER_SYNCED = SynchronizeFolderOperation.class.getName() + ".EVENT_SINGLE_FOLDER_SYNCED";
/** Time stamp for the synchronization process in progress */
private long mCurrentSyncTime;
}
if (!mSyncFullAccount) {
- sendStickyBroadcast(false, mLocalFolder.getRemotePath(), result);
+ sendLocalBroadcast(mLocalFolder.getRemotePath(), result);
}
return result;
* @param inProgress 'True' when the synchronization progress is not finished.
* @param dirRemotePath Remote path of a folder that was just synchronized (with or without success)
*/
- private void sendStickyBroadcast(boolean inProgress, String dirRemotePath, RemoteOperationResult result) {
- Intent i = new Intent(FileSyncService.getSyncMessage());
- i.putExtra(FileSyncService.IN_PROGRESS, inProgress);
- i.putExtra(FileSyncService.ACCOUNT_NAME, mAccount.name);
+ private void sendLocalBroadcast(String dirRemotePath, RemoteOperationResult result) {
+ Intent intent = new Intent(EVENT_SINGLE_FOLDER_SYNCED);
+ intent.putExtra(FileSyncAdapter.EXTRA_ACCOUNT_NAME, mAccount.name);
if (dirRemotePath != null) {
- i.putExtra(FileSyncService.SYNC_FOLDER_REMOTE_PATH, dirRemotePath);
+ intent.putExtra(FileSyncAdapter.EXTRA_FOLDER_PATH, dirRemotePath);
}
- if (result != null) {
- i.putExtra(FileSyncService.SYNC_RESULT, result);
- }
- mContext.sendStickyBroadcast(i);
+ intent.putExtra(FileSyncAdapter.EXTRA_RESULT, result);
+ //mContext.sendStickyBroadcast(intent);
+ LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent);
}
import android.content.Intent;
import android.content.SyncResult;
import android.os.Bundle;
+import android.support.v4.content.LocalBroadcastManager;
/**
* Implementation of {@link AbstractThreadedSyncAdapter} responsible for synchronizing
private static final int MAX_FAILED_RESULTS = 3;
+ public static final String EVENT_FULL_SYNC_START = FileSyncAdapter.class.getName() + ".EVENT_FULL_SYNC_START";
+ public static final String EVENT_FULL_SYNC_END = FileSyncAdapter.class.getName() + ".EVENT_FULL_SYNC_END";
+ public static final String EVENT_FOLDER_CONTENTS_SYNCED = FileSyncAdapter.class.getName() + ".EVENT_FOLDER_CONTENTS_SYNCED";
+ public static final String EVENT_FOLDER_SIZE_SYNCED = FileSyncAdapter.class.getName() + ".EVENT_FOLDER_SIZE_SYNCED";
+
+ public static final String EXTRA_ACCOUNT_NAME = FileSyncAdapter.class.getName() + ".EXTRA_ACCOUNT_NAME";
+ public static final String EXTRA_FOLDER_PATH = FileSyncAdapter.class.getName() + ".EXTRA_FOLDER_PATH";
+ public static final String EXTRA_RESULT = FileSyncAdapter.class.getName() + ".EXTRA_RESULT";
+
+
/** Time stamp for the current synchronization process, used to distinguish fresh data */
private long mCurrentSyncTime;
}
Log_OC.d(TAG, "Synchronization of ownCloud account " + account.name + " starting");
- sendStickyBroadcast(true, null, null); // message to signal the start of the synchronization to the UI
+ sendLocalBroadcast(EVENT_FULL_SYNC_START, null, null); // message to signal the start of the synchronization to the UI
try {
updateOCVersion();
if (mForgottenLocalFiles.size() > 0) {
notifyForgottenLocalFiles();
}
- sendStickyBroadcast(false, null, mLastFailedResult); // message to signal the end to the UI
+ sendLocalBroadcast(EVENT_FULL_SYNC_END, null, mLastFailedResult); // message to signal the end to the UI
}
}
// synchronized folder -> notice to UI - ALWAYS, although !result.isSuccess
- sendStickyBroadcast(true, folder.getRemotePath(), null);
+ sendLocalBroadcast(EVENT_FOLDER_CONTENTS_SYNCED, folder.getRemotePath(), result);
// check the result of synchronizing the folder
if (result.isSuccess() || result.getCode() == ResultCode.SYNC_CONFLICT) {
syncDown = (parentEtagChanged || etag == null || etag.length() == 0);
if(syncDown) { */
synchronizeFolder(newFile);
- // update the size of the parent folder again after recursive synchronization
- //getStorageManager().updateFolderSize(parent.getFileId());
- sendStickyBroadcast(true, parent.getRemotePath(), null); // notify again to refresh size in UI
+ sendLocalBroadcast(EVENT_FOLDER_SIZE_SYNCED, parent.getRemotePath(), null);
//}
}
}
/**
* Sends a message to any application component interested in the progress of the synchronization.
*
- * @param inProgress 'True' when the synchronization progress is not finished.
- * @param dirRemotePath Remote path of a folder that was just synchronized (with or without success)
+ * @param event Event in the process of synchronization to be notified.
+ * @param dirRemotePath Remote path of the folder target of the event occurred.
+ * @param result Result of an individual {@ SynchronizeFolderOperation}, if completed; may be null.
*/
- private void sendStickyBroadcast(boolean inProgress, String dirRemotePath, RemoteOperationResult result) {
- Intent i = new Intent(FileSyncService.getSyncMessage());
- i.putExtra(FileSyncService.IN_PROGRESS, inProgress);
- i.putExtra(FileSyncService.ACCOUNT_NAME, getAccount().name);
+ private void sendLocalBroadcast(String event, String dirRemotePath, RemoteOperationResult result) {
+ Intent intent = new Intent(event);
+ intent.putExtra(FileSyncAdapter.EXTRA_ACCOUNT_NAME, getAccount().name);
if (dirRemotePath != null) {
- i.putExtra(FileSyncService.SYNC_FOLDER_REMOTE_PATH, dirRemotePath);
+ intent.putExtra(FileSyncAdapter.EXTRA_FOLDER_PATH, dirRemotePath);
}
if (result != null) {
- i.putExtra(FileSyncService.SYNC_RESULT, result);
+ intent.putExtra(FileSyncAdapter.EXTRA_RESULT, result);
}
- getContext().sendStickyBroadcast(i);
+ //getContext().sendStickyBroadcast(i);
+ LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
}
*/\r
public class FileSyncService extends Service {\r
\r
- private static final String SYNC_MESSAGE = "ACCOUNT_SYNC";\r
- public static final String SYNC_FOLDER_REMOTE_PATH = "SYNC_FOLDER_REMOTE_PATH";\r
- public static final String IN_PROGRESS = "SYNC_IN_PROGRESS";\r
- public static final String ACCOUNT_NAME = "ACCOUNT_NAME";\r
- public static final String SYNC_RESULT = "SYNC_RESULT";\r
-\r
// Storage for an instance of the sync adapter\r
private static FileSyncAdapter sSyncAdapter = null;\r
// Object to use as a thread-safe lock\r
private static final Object sSyncAdapterLock = new Object();\r
\r
- public static String getSyncMessage(){\r
- return FileSyncService.class.getName().toString() + SYNC_MESSAGE;\r
- }\r
/*\r
* {@inheritDoc}\r
*/\r
import com.owncloud.android.operations.SynchronizeFileOperation;
import com.owncloud.android.operations.SynchronizeFolderOperation;
import com.owncloud.android.services.OperationsService;
-import com.owncloud.android.syncadapter.FileSyncService;
+import com.owncloud.android.syncadapter.FileSyncAdapter;
import com.owncloud.android.ui.dialog.EditNameDialog;
import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener;
import com.owncloud.android.ui.dialog.LoadingDialog;
Log_OC.e(TAG, "onResume() start");
// Listen for sync messages
- IntentFilter syncIntentFilter = new IntentFilter(FileSyncService.getSyncMessage());
+ IntentFilter syncIntentFilter = new IntentFilter(FileSyncAdapter.EVENT_FULL_SYNC_START);
+ syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_END);
+ syncIntentFilter.addAction(FileSyncAdapter.EVENT_FOLDER_SIZE_SYNCED);
+ syncIntentFilter.addAction(FileSyncAdapter.EVENT_FOLDER_CONTENTS_SYNCED);
+ syncIntentFilter.addAction(SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_SYNCED);
mSyncBroadcastReceiver = new SyncBroadcastReceiver();
- registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
+ //registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
+ LocalBroadcastManager.getInstance(this).registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
// Listen for upload messages
IntentFilter uploadIntentFilter = new IntentFilter(FileUploader.getUploadFinishMessage());
super.onPause();
Log_OC.e(TAG, "onPause() start");
if (mSyncBroadcastReceiver != null) {
- unregisterReceiver(mSyncBroadcastReceiver);
+ //unregisterReceiver(mSyncBroadcastReceiver);
+ LocalBroadcastManager.getInstance(this).unregisterReceiver(mSyncBroadcastReceiver);
mSyncBroadcastReceiver = null;
}
if (mUploadFinishReceiver != null) {
*/
@Override
public void onReceive(Context context, Intent intent) {
- boolean inProgress = intent.getBooleanExtra(FileSyncService.IN_PROGRESS, false);
- String accountName = intent.getStringExtra(FileSyncService.ACCOUNT_NAME);
- RemoteOperationResult synchResult = (RemoteOperationResult)intent.getSerializableExtra(FileSyncService.SYNC_RESULT);
+ String event = intent.getAction();
+ String accountName = intent.getStringExtra(FileSyncAdapter.EXTRA_ACCOUNT_NAME);
+ String synchFolderRemotePath = intent.getStringExtra(FileSyncAdapter.EXTRA_FOLDER_PATH);
+ RemoteOperationResult synchResult = (RemoteOperationResult)intent.getSerializableExtra(FileSyncAdapter.EXTRA_RESULT);
+ boolean sameAccount = (getAccount() != null && accountName.equals(getAccount().name) && mStorageManager != null);
- if (getAccount() != null && accountName.equals(getAccount().name)
- && mStorageManager != null) {
+ if (sameAccount) {
- String synchFolderRemotePath = intent.getStringExtra(FileSyncService.SYNC_FOLDER_REMOTE_PATH);
-
- OCFile currentFile = (getFile() == null) ? null : mStorageManager.getFileByPath(getFile().getRemotePath());
- OCFile currentDir = (getCurrentDir() == null) ? null : mStorageManager.getFileByPath(getCurrentDir().getRemotePath());
-
- if (currentDir == null) {
- // current folder was removed from the server
- Toast.makeText( FileDisplayActivity.this,
- String.format(getString(R.string.sync_current_folder_was_removed), mDirectories.getItem(0)),
- Toast.LENGTH_LONG)
- .show();
- browseToRoot();
+ if (!FileSyncAdapter.EVENT_FULL_SYNC_START.equals(event)) {
- } else {
- if (currentFile == null && !getFile().isFolder()) {
- // currently selected file was removed in the server, and now we know it
- cleanSecondFragment();
- currentFile = currentDir;
- }
-
- if (synchFolderRemotePath != null && currentDir.getRemotePath().equals(synchFolderRemotePath)) {
- OCFileListFragment fileListFragment = getListOfFilesFragment();
- if (fileListFragment != null) {
- fileListFragment.listDirectory(currentDir);
+ OCFile currentFile = (getFile() == null) ? null : mStorageManager.getFileByPath(getFile().getRemotePath());
+ OCFile currentDir = (getCurrentDir() == null) ? null : mStorageManager.getFileByPath(getCurrentDir().getRemotePath());
+
+ if (currentDir == null) {
+ // current folder was removed from the server
+ Toast.makeText( FileDisplayActivity.this,
+ String.format(getString(R.string.sync_current_folder_was_removed), mDirectories.getItem(0)),
+ Toast.LENGTH_LONG)
+ .show();
+ browseToRoot();
+
+ } else {
+ if (currentFile == null && !getFile().isFolder()) {
+ // currently selected file was removed in the server, and now we know it
+ cleanSecondFragment();
+ currentFile = currentDir;
}
+
+ if (synchFolderRemotePath != null && currentDir.getRemotePath().equals(synchFolderRemotePath)) {
+ OCFileListFragment fileListFragment = getListOfFilesFragment();
+ if (fileListFragment != null) {
+ fileListFragment.listDirectory(currentDir);
+ }
+ }
+ setFile(currentFile);
}
- setFile(currentFile);
- }
-
- if (synchResult != null && synchResult.isSuccess() && isSharedSupported()) {
- startGetShares();
+
+ mSyncInProgress = (!FileSyncAdapter.EVENT_FULL_SYNC_END.equals(event) && !SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_SYNCED.equals(event));
+
+ if (synchResult != null &&
+ synchResult.isSuccess() &&
+ (SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_SYNCED.equals(event) ||
+ FileSyncAdapter.EVENT_FOLDER_CONTENTS_SYNCED.equals(event)
+ )
+ ) {
+ startGetShares();
+ }
+
}
-
- removeStickyBroadcast(intent);
- mSyncInProgress = inProgress;
+ //removeStickyBroadcast(intent);
setSupportProgressBarIndeterminateVisibility(mSyncInProgress || mRefreshSharesInProgress);
}