From: David A. Velasco Date: Fri, 29 Jun 2012 13:16:19 +0000 (+0200) Subject: Added dynamic update of files list while full synchronization is performed X-Git-Tag: oc-android-1.4.3~325 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/d6205749eb5a9ef1991c2313ab2b3bffbc2753d5?ds=inline Added dynamic update of files list while full synchronization is performed --- diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 99c9925e..4e9ca6f2 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -18,7 +18,7 @@ --> + android:versionName="0.1.140B" xmlns:android="http://schemas.android.com/apk/res/android"> diff --git a/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java b/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java index 7255e5d1..39a88317 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; @@ -64,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 the main IU PropFindMethod query; try { @@ -99,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) { @@ -109,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); @@ -116,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 main thread + 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) { @@ -148,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); + } } diff --git a/src/eu/alefzero/owncloud/syncadapter/FileSyncService.java b/src/eu/alefzero/owncloud/syncadapter/FileSyncService.java index 6ab23db1..6c1ed0fc 100644 --- a/src/eu/alefzero/owncloud/syncadapter/FileSyncService.java +++ b/src/eu/alefzero/owncloud/syncadapter/FileSyncService.java @@ -31,6 +31,7 @@ public class FileSyncService extends Service { public static final String SYNC_MESSAGE = "eu.alefzero.owncloud.files.ACCOUNT_SYNC"; public static final String IN_PROGRESS = "sync_in_progress"; public static final String ACCOUNT_NAME = "account_name"; + public static final String SYNC_FOLDER = "eu.alefzero.owncloud.files.SYNC_FOLDER"; /* * {@inheritDoc} diff --git a/src/eu/alefzero/owncloud/ui/activity/AuthenticatorActivity.java b/src/eu/alefzero/owncloud/ui/activity/AuthenticatorActivity.java index bd0ddb0b..b944240a 100644 --- a/src/eu/alefzero/owncloud/ui/activity/AuthenticatorActivity.java +++ b/src/eu/alefzero/owncloud/ui/activity/AuthenticatorActivity.java @@ -204,8 +204,9 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity setResult(RESULT_OK, intent); Bundle bundle = new Bundle(); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); - getContentResolver().startSync(ProviderTableMeta.CONTENT_URI, - bundle); + //getContentResolver().startSync(ProviderTableMeta.CONTENT_URI, + // bundle); + ContentResolver.requestSync(account, "org.ownlcoud", bundle); /* * if diff --git a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java index 7de1e286..657d6df9 100644 --- a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java +++ b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java @@ -147,6 +147,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements case R.id.startSync: { Bundle bundle = new Bundle(); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); + bundle.putString("PROBANDO", "PARAMETRO PASADO AL SYNC"); ContentResolver.requestSync( AccountUtils.getCurrentOwnCloudAccount(this), "org.owncloud", bundle); @@ -614,6 +615,21 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements Log.d("FileDisplay", "sync of account " + account_name + " is in_progress: " + inProgress); setSupportProgressBarIndeterminateVisibility(inProgress); + + long OCDirId = intent.getLongExtra(FileSyncService.SYNC_FOLDER, -1); + if (OCDirId > 0) { + OCFile syncDir = mStorageManager.getFileById(OCDirId); + if (syncDir != null && ( + (mCurrentDir == null && syncDir.getFileName().equals("/")) || + syncDir.equals(mCurrentDir)) + ) { + FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList); + if (fileListFragment != null) { + fileListFragment.listDirectory(); + } + } + } + if (!inProgress) { FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager() .findFragmentById(R.id.fileList); diff --git a/src/eu/alefzero/owncloud/ui/fragment/FileListFragment.java b/src/eu/alefzero/owncloud/ui/fragment/FileListFragment.java index 3cfead57..895b3a28 100644 --- a/src/eu/alefzero/owncloud/ui/fragment/FileListFragment.java +++ b/src/eu/alefzero/owncloud/ui/fragment/FileListFragment.java @@ -210,9 +210,9 @@ public class FileListFragment extends FragmentListView { mFile = directory; mFiles = storageManager.getDirectoryContent(directory); - if (mFiles == null || mFiles.size() == 0) { + /*if (mFiles == null || mFiles.size() == 0) { Toast.makeText(getActivity(), "There are no files here", Toast.LENGTH_LONG).show(); - } + }*/ setListAdapter(new FileListListAdapter(directory, storageManager, getActivity())); }