package eu.alefzero.owncloud.syncadapter;\r
\r
import java.io.IOException;\r
-import java.io.ObjectInputStream.GetField;\r
import java.util.List;\r
import java.util.Vector;\r
\r
*/\r
\r
private long mCurrentSyncTime;\r
+ private boolean mCancellation;\r
+ private Account mAccount;\r
\r
public FileSyncAdapter(Context context, boolean autoInitialize) {\r
super(context, autoInitialize);\r
String authority, ContentProviderClient provider,\r
SyncResult syncResult) {\r
\r
- this.setAccount(account);\r
+ mCancellation = false;\r
+ mAccount = account;\r
+ \r
+ this.setAccount(mAccount);\r
this.setContentProvider(provider);\r
- this.setStorageManager(new FileDataStorageManager(account,\r
+ this.setStorageManager(new FileDataStorageManager(mAccount,\r
getContentProvider()));\r
\r
/* Commented code for ugly performance tests\r
*/\r
\r
\r
- Log.d(TAG, "syncing owncloud account " + account.name);\r
+ Log.d(TAG, "syncing owncloud account " + mAccount.name);\r
\r
sendStickyBroadcast(true, null); // message to signal the start to the UI\r
\r
OCFile file = fillOCFile(we);\r
file.setParentId(0);\r
getStorageManager().saveFile(file);\r
- fetchData(getUri().toString(), syncResult, file.getFileId(), account);\r
+ if (!mCancellation) {\r
+ fetchData(getUri().toString(), syncResult, file.getFileId());\r
+ }\r
}\r
} catch (OperationCanceledException e) {\r
e.printStackTrace();\r
sendStickyBroadcast(false, null); \r
}\r
\r
- private void fetchData(String uri, SyncResult syncResult, long parentId, Account account) {\r
+ private void fetchData(String uri, SyncResult syncResult, long parentId) {\r
try {\r
//Log.v(TAG, "syncing: fetching " + uri);\r
\r
sendStickyBroadcast(true, getStorageManager().getFileById(parentId).getRemotePath());\r
\r
// recursive fetch\r
- for (OCFile newFile : files) {\r
+ for (int i=0; i < files.size() && !mCancellation; i++) {\r
+ OCFile newFile = files.get(i);\r
if (newFile.getMimetype().equals("DIR")) {\r
- fetchData(getUri().toString() + newFile.getRemotePath(), syncResult, newFile.getFileId(), account);\r
+ fetchData(getUri().toString() + newFile.getRemotePath(), syncResult, newFile.getFileId());\r
}\r
}\r
- \r
+ if (mCancellation) Log.d(TAG, "Leaving " + uri + " because cancellation request");\r
+ \r
/* Commented code for ugly performance tests\r
mResponseDelays[mDelaysIndex] = responseDelay;\r
mSaveDelays[mDelaysIndex] = saveDelay;\r
e.printStackTrace();\r
} catch (Throwable t) {\r
// TODO update syncResult\r
- Log.e(TAG, "problem while synchronizing owncloud account " + account.name, t);\r
+ Log.e(TAG, "problem while synchronizing owncloud account " + mAccount.name, t);\r
t.printStackTrace();\r
}\r
}\r
getContext().sendStickyBroadcast(i);\r
}\r
\r
+ /**\r
+ * Called by system SyncManager when a synchronization is required to be cancelled.\r
+ * \r
+ * Sets the mCancellation flag to 'true'. THe synchronization will be stopped when before a new folder is fetched. Data of the last folder\r
+ * fetched will be still saved in the database. See onPerformSync implementation.\r
+ */\r
@Override\r
public void onSyncCanceled() {\r
- Log.d(TAG, "sync is being cancelled !! ************************************************");\r
+ Log.d(TAG, "Synchronization of " + mAccount.name + " has been requested to cancell");\r
+ mCancellation = true;\r
super.onSyncCanceled();\r
}\r
\r