X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/b22ad95e2fe78bc03a43c83dfef6232a187d8fdd..7c2174d09e376ecc5ebd9a510a66dc7582b173f9:/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java diff --git a/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java b/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java index d5512a18..230d3a75 100644 --- a/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java +++ b/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java @@ -19,6 +19,9 @@ package eu.alefzero.owncloud.syncadapter; import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; import java.util.Vector; import org.apache.jackrabbit.webdav.DavException; @@ -34,6 +37,7 @@ import android.content.Intent; import android.content.SyncResult; import android.os.Bundle; import android.util.Log; +import android.webkit.MimeTypeMap; import eu.alefzero.owncloud.datamodel.FileDataStorageManager; import eu.alefzero.owncloud.datamodel.OCFile; import eu.alefzero.webdav.WebdavEntry; @@ -63,13 +67,10 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { this.setContentProvider(provider); this.setStorageManager(new FileDataStorageManager(account, getContentProvider())); - + Log.d(TAG, "syncing owncloud account " + account.name); - Intent i = new Intent(FileSyncService.SYNC_MESSAGE); - i.putExtra(FileSyncService.IN_PROGRESS, true); - i.putExtra(FileSyncService.ACCOUNT_NAME, account.name); - getContext().sendStickyBroadcast(i); + sendStickyBroadcast(true, -1); // starting message to UI PropFindMethod query; try { @@ -98,8 +99,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { syncResult.stats.numIoExceptions++; e.printStackTrace(); } - i.putExtra(FileSyncService.IN_PROGRESS, false); - getContext().sendStickyBroadcast(i); + sendStickyBroadcast(false, -1); } private void fetchData(String uri, SyncResult syncResult, long parentId) { @@ -108,6 +108,8 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { getClient().executeMethod(query); MultiStatus resp = null; resp = query.getResponseBodyAsMultiStatus(); + List paths = new ArrayList(); + List fileIds = new ArrayList(); for (int i = 1; i < resp.getResponses().length; ++i) { WebdavEntry we = new WebdavEntry(resp.getResponses()[i], getUri().getPath()); OCFile file = fillOCFile(we); @@ -115,15 +117,31 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { getStorageManager().saveFile(file); if (parentId == 0) parentId = file.getFileId(); - if (we.contentType().equals("DIR")) - fetchData(getUri().toString() + we.path(), syncResult, file.getFileId()); + if (we.contentType().equals("DIR")) { + // for recursive fetch later + paths.add(we.path()); + fileIds.add(file.getFileId()); + } } + Vector files = getStorageManager().getDirectoryContent( getStorageManager().getFileById(parentId)); for (OCFile file : files) { if (file.getLastSyncDate() != mCurrentSyncTime && file.getLastSyncDate() != 0) getStorageManager().removeFile(file); } + + // synched folder -> notice to IU + sendStickyBroadcast(true, parentId); + + // recursive fetch + Iterator pathsIt = paths.iterator(); + Iterator fileIdsIt = fileIds.iterator(); + while (pathsIt.hasNext()) { + fetchData(getUri().toString() + pathsIt.next(), syncResult, fileIdsIt.next()); + } + + } catch (OperationCanceledException e) { e.printStackTrace(); } catch (AuthenticatorException e) { @@ -147,5 +165,16 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { file.setLastSyncDate(mCurrentSyncTime); return file; } + + + private void sendStickyBroadcast(boolean inProgress, long OCDirId) { + Intent i = new Intent(FileSyncService.SYNC_MESSAGE); + i.putExtra(FileSyncService.IN_PROGRESS, inProgress); + i.putExtra(FileSyncService.ACCOUNT_NAME, getAccount().name); + if (OCDirId > 0) { + i.putExtra(FileSyncService.SYNC_FOLDER, OCDirId); + } + getContext().sendStickyBroadcast(i); + } }