Added dynamic update of files list while full synchronization is performed
authorDavid A. Velasco <dvelasco@solidgear.es>
Fri, 29 Jun 2012 13:16:19 +0000 (15:16 +0200)
committerDavid A. Velasco <dvelasco@solidgear.es>
Fri, 29 Jun 2012 13:16:19 +0000 (15:16 +0200)
AndroidManifest.xml
src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java
src/eu/alefzero/owncloud/syncadapter/FileSyncService.java
src/eu/alefzero/owncloud/ui/activity/AuthenticatorActivity.java
src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java
src/eu/alefzero/owncloud/ui/fragment/FileListFragment.java

index 99c9925..4e9ca6f 100644 (file)
@@ -18,7 +18,7 @@
  -->\r
 <manifest package="eu.alefzero.owncloud"\r
     android:versionCode="1"\r
  -->\r
 <manifest package="eu.alefzero.owncloud"\r
     android:versionCode="1"\r
-    android:versionName="0.1.139B" xmlns:android="http://schemas.android.com/apk/res/android">\r
+    android:versionName="0.1.140B" xmlns:android="http://schemas.android.com/apk/res/android">\r
 \r
     <uses-permission android:name="android.permission.GET_ACCOUNTS" />\r
     <uses-permission android:name="android.permission.USE_CREDENTIALS" />\r
 \r
     <uses-permission android:name="android.permission.GET_ACCOUNTS" />\r
     <uses-permission android:name="android.permission.USE_CREDENTIALS" />\r
index 7255e5d..39a8831 100644 (file)
@@ -19,6 +19,9 @@
 package eu.alefzero.owncloud.syncadapter;\r
 \r
 import java.io.IOException;\r
 package eu.alefzero.owncloud.syncadapter;\r
 \r
 import java.io.IOException;\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+import java.util.List;\r
 import java.util.Vector;\r
 \r
 import org.apache.jackrabbit.webdav.DavException;\r
 import java.util.Vector;\r
 \r
 import org.apache.jackrabbit.webdav.DavException;\r
@@ -64,13 +67,10 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
         this.setContentProvider(provider);\r
         this.setStorageManager(new FileDataStorageManager(account,\r
                 getContentProvider()));\r
         this.setContentProvider(provider);\r
         this.setStorageManager(new FileDataStorageManager(account,\r
                 getContentProvider()));\r
-\r
+        \r
         Log.d(TAG, "syncing owncloud account " + account.name);\r
 \r
         Log.d(TAG, "syncing owncloud account " + account.name);\r
 \r
-        Intent i = new Intent(FileSyncService.SYNC_MESSAGE);\r
-        i.putExtra(FileSyncService.IN_PROGRESS, true);\r
-        i.putExtra(FileSyncService.ACCOUNT_NAME, account.name);\r
-        getContext().sendStickyBroadcast(i);\r
+        sendStickyBroadcast(true, -1);  // starting message to the main IU\r
 \r
         PropFindMethod query;\r
         try {\r
 \r
         PropFindMethod query;\r
         try {\r
@@ -99,8 +99,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
             syncResult.stats.numIoExceptions++;\r
             e.printStackTrace();\r
         }\r
             syncResult.stats.numIoExceptions++;\r
             e.printStackTrace();\r
         }\r
-        i.putExtra(FileSyncService.IN_PROGRESS, false);\r
-        getContext().sendStickyBroadcast(i);\r
+        sendStickyBroadcast(false, -1);        \r
     }\r
 \r
     private void fetchData(String uri, SyncResult syncResult, long parentId) {\r
     }\r
 \r
     private void fetchData(String uri, SyncResult syncResult, long parentId) {\r
@@ -109,6 +108,8 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
             getClient().executeMethod(query);\r
             MultiStatus resp = null;\r
             resp = query.getResponseBodyAsMultiStatus();\r
             getClient().executeMethod(query);\r
             MultiStatus resp = null;\r
             resp = query.getResponseBodyAsMultiStatus();\r
+            List<String> paths = new ArrayList<String>();\r
+            List<Long> fileIds = new ArrayList<Long>(); \r
             for (int i = 1; i < resp.getResponses().length; ++i) {\r
                 WebdavEntry we = new WebdavEntry(resp.getResponses()[i], getUri().getPath());\r
                 OCFile file = fillOCFile(we);\r
             for (int i = 1; i < resp.getResponses().length; ++i) {\r
                 WebdavEntry we = new WebdavEntry(resp.getResponses()[i], getUri().getPath());\r
                 OCFile file = fillOCFile(we);\r
@@ -116,15 +117,31 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
                 getStorageManager().saveFile(file);\r
                 if (parentId == 0)\r
                     parentId = file.getFileId();\r
                 getStorageManager().saveFile(file);\r
                 if (parentId == 0)\r
                     parentId = file.getFileId();\r
-                if (we.contentType().equals("DIR"))\r
-                    fetchData(getUri().toString() + we.path(), syncResult, file.getFileId());\r
+                if (we.contentType().equals("DIR")) {\r
+                    // for recursive fetch later\r
+                    paths.add(we.path());\r
+                    fileIds.add(file.getFileId());\r
+                }\r
             }\r
             }\r
+            \r
             Vector<OCFile> files = getStorageManager().getDirectoryContent(\r
                     getStorageManager().getFileById(parentId));\r
             for (OCFile file : files) {\r
                 if (file.getLastSyncDate() != mCurrentSyncTime && file.getLastSyncDate() != 0)\r
                     getStorageManager().removeFile(file);\r
             }\r
             Vector<OCFile> files = getStorageManager().getDirectoryContent(\r
                     getStorageManager().getFileById(parentId));\r
             for (OCFile file : files) {\r
                 if (file.getLastSyncDate() != mCurrentSyncTime && file.getLastSyncDate() != 0)\r
                     getStorageManager().removeFile(file);\r
             }\r
+            \r
+            // synched folder -> notice to main thread\r
+            sendStickyBroadcast(true, parentId);\r
+\r
+            // recursive fetch\r
+            Iterator<String> pathsIt = paths.iterator();\r
+            Iterator<Long> fileIdsIt = fileIds.iterator();\r
+            while (pathsIt.hasNext()) {\r
+                fetchData(getUri().toString() + pathsIt.next(), syncResult, fileIdsIt.next());\r
+            }\r
+\r
+\r
         } catch (OperationCanceledException e) {\r
             e.printStackTrace();\r
         } catch (AuthenticatorException e) {\r
         } catch (OperationCanceledException e) {\r
             e.printStackTrace();\r
         } catch (AuthenticatorException e) {\r
@@ -148,5 +165,16 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
         file.setLastSyncDate(mCurrentSyncTime);\r
         return file;\r
     }\r
         file.setLastSyncDate(mCurrentSyncTime);\r
         return file;\r
     }\r
+    \r
+    \r
+    private void sendStickyBroadcast(boolean inProgress, long OCDirId) {\r
+        Intent i = new Intent(FileSyncService.SYNC_MESSAGE);\r
+        i.putExtra(FileSyncService.IN_PROGRESS, inProgress);\r
+        i.putExtra(FileSyncService.ACCOUNT_NAME, getAccount().name);\r
+        if (OCDirId > 0) {\r
+            i.putExtra(FileSyncService.SYNC_FOLDER, OCDirId);\r
+        }\r
+        getContext().sendStickyBroadcast(i);\r
+    }\r
 \r
 }\r
 \r
 }\r
index 6ab23db..6c1ed0f 100644 (file)
@@ -31,6 +31,7 @@ public class FileSyncService extends Service {
     public static final String SYNC_MESSAGE = "eu.alefzero.owncloud.files.ACCOUNT_SYNC";\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_MESSAGE = "eu.alefzero.owncloud.files.ACCOUNT_SYNC";\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_FOLDER = "eu.alefzero.owncloud.files.SYNC_FOLDER";\r
 \r
     /*\r
      * {@inheritDoc}\r
 \r
     /*\r
      * {@inheritDoc}\r
index bd0ddb0..b944240 100644 (file)
@@ -204,8 +204,9 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             setResult(RESULT_OK, intent);\r
             Bundle bundle = new Bundle();\r
             bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);\r
             setResult(RESULT_OK, intent);\r
             Bundle bundle = new Bundle();\r
             bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);\r
-            getContentResolver().startSync(ProviderTableMeta.CONTENT_URI,\r
-                    bundle);\r
+            //getContentResolver().startSync(ProviderTableMeta.CONTENT_URI,\r
+            //        bundle);\r
+            ContentResolver.requestSync(account, "org.ownlcoud", bundle);\r
 \r
             /*\r
              * if\r
 \r
             /*\r
              * if\r
index 7de1e28..657d6df 100644 (file)
@@ -147,6 +147,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
             case R.id.startSync: {\r
                 Bundle bundle = new Bundle();\r
                 bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);\r
             case R.id.startSync: {\r
                 Bundle bundle = new Bundle();\r
                 bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);\r
+                bundle.putString("PROBANDO", "PARAMETRO PASADO AL SYNC");\r
                 ContentResolver.requestSync(\r
                         AccountUtils.getCurrentOwnCloudAccount(this),\r
                         "org.owncloud", bundle);\r
                 ContentResolver.requestSync(\r
                         AccountUtils.getCurrentOwnCloudAccount(this),\r
                         "org.owncloud", bundle);\r
@@ -614,6 +615,21 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
             Log.d("FileDisplay", "sync of account " + account_name\r
                     + " is in_progress: " + inProgress);\r
             setSupportProgressBarIndeterminateVisibility(inProgress);\r
             Log.d("FileDisplay", "sync of account " + account_name\r
                     + " is in_progress: " + inProgress);\r
             setSupportProgressBarIndeterminateVisibility(inProgress);\r
+            \r
+            long OCDirId = intent.getLongExtra(FileSyncService.SYNC_FOLDER, -1);\r
+            if (OCDirId > 0) {\r
+                OCFile syncDir = mStorageManager.getFileById(OCDirId);\r
+                if (syncDir != null && (\r
+                        (mCurrentDir == null && syncDir.getFileName().equals("/")) ||\r
+                         syncDir.equals(mCurrentDir))\r
+                    ) {\r
+                    FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);\r
+                    if (fileListFragment != null) { \r
+                        fileListFragment.listDirectory();\r
+                    }\r
+                }\r
+            }\r
+            \r
             if (!inProgress) {\r
                 FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager()\r
                         .findFragmentById(R.id.fileList);\r
             if (!inProgress) {\r
                 FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager()\r
                         .findFragmentById(R.id.fileList);\r
index 3cfead5..895b3a2 100644 (file)
@@ -210,9 +210,9 @@ public class FileListFragment extends FragmentListView {
         mFile = directory;\r
         \r
         mFiles = storageManager.getDirectoryContent(directory);\r
         mFile = directory;\r
         \r
         mFiles = storageManager.getDirectoryContent(directory);\r
-        if (mFiles == null || mFiles.size() == 0) {\r
+        /*if (mFiles == null || mFiles.size() == 0) {\r
             Toast.makeText(getActivity(), "There are no files here", Toast.LENGTH_LONG).show();\r
             Toast.makeText(getActivity(), "There are no files here", Toast.LENGTH_LONG).show();\r
-        }\r
+        }*/\r
         setListAdapter(new FileListListAdapter(directory, storageManager, getActivity()));\r
     }\r
 \r
         setListAdapter(new FileListListAdapter(directory, storageManager, getActivity()));\r
     }\r
 \r