X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/cfe4273de5fd5d54f3933a9cb8b53cdd35e1b11d..9b9b02c384b4453b3debd703c52e24b6136540f8:/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 85f9cbb3..14237e47 100644 --- a/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java +++ b/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java @@ -19,7 +19,11 @@ package eu.alefzero.owncloud.syncadapter; import java.io.IOException; -import java.net.URLDecoder; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; import java.util.Vector; import org.apache.jackrabbit.webdav.DavException; @@ -35,6 +39,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; @@ -64,13 +69,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); // message to signal the start to the UI PropFindMethod query; try { @@ -98,33 +100,67 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { } catch (DavException e) { syncResult.stats.numIoExceptions++; e.printStackTrace(); + } catch (RuntimeException r) { + //TODO count ; any type of exception should be treated, and the progress indicator finished; + // reporting the user about bad synchronizations should be discussed + r.printStackTrace(); + throw r; } - i.putExtra(FileSyncService.IN_PROGRESS, false); - getContext().sendStickyBroadcast(i); + sendStickyBroadcast(false, -1); } private void fetchData(String uri, SyncResult syncResult, long parentId) { try { + Log.v(TAG, "syncing: fetching " + uri); + + boolean logmore = (uri.contains("many-files")); + + // remote request + if (logmore) Log.v(TAG, "syncing: fetching many-files, TO REQUEST"); PropFindMethod query = new PropFindMethod(uri); getClient().executeMethod(query); MultiStatus resp = null; + + if (logmore) Log.v(TAG, "syncing: fetching many-files, TO PREPARE THE RESPONSE"); resp = query.getResponseBodyAsMultiStatus(); + + // insertion of updated files + if (logmore) Log.v(TAG, "syncing: fetching many-files, TO PARSE REPONSES"); for (int i = 1; i < resp.getResponses().length; ++i) { + if (logmore) Log.v(TAG, "syncing: fetching many-files, PARSING REPONSE " + i + "-esima"); WebdavEntry we = new WebdavEntry(resp.getResponses()[i], getUri().getPath()); OCFile file = fillOCFile(we); file.setParentId(parentId); getStorageManager().saveFile(file); if (parentId == 0) parentId = file.getFileId(); - if (we.contentType().equals("DIR")) - fetchData(getUri().toString() + we.path(), syncResult, file.getFileId()); } + + // removal of old files + // TODO - getDirectoryContent is crashing the app by lack of memory when a lot of files are in the same directory!!!! + // tested with the path / + if (logmore) Log.v(TAG, "syncing: fetching many-files, RETRIEVING VECTOR OF FILES"); 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 + if (logmore) Log.v(TAG, "syncing: fetching many-files, NOTIFYING THE UI"); + sendStickyBroadcast(true, parentId); + + // recursive fetch + if (logmore) Log.v(TAG, "syncing: fetching many-files, TRYING TO RECURSE"); + files = getStorageManager().getDirectoryContent(getStorageManager().getFileById(parentId)); + for (OCFile file : files) { + if (file.getMimetype().equals("DIR")) { + fetchData(getUri().toString() + file.getRemotePath(), syncResult, file.getFileId()); + } + } + + } catch (OperationCanceledException e) { e.printStackTrace(); } catch (AuthenticatorException e) { @@ -140,7 +176,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { } private OCFile fillOCFile(WebdavEntry we) { - OCFile file = new OCFile(URLDecoder.decode(we.path())); + OCFile file = new OCFile(we.path()); file.setCreationTimestamp(we.createTimestamp()); file.setFileLength(we.contentLength()); file.setMimetype(we.contentType()); @@ -148,5 +184,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); + } }