Small improvements to the refresh of the files list and memory handling while synchro...
authorDavid A. Velasco <dvelasco@solidgear.es>
Wed, 4 Jul 2012 13:44:59 +0000 (15:44 +0200)
committerDavid A. Velasco <dvelasco@solidgear.es>
Wed, 4 Jul 2012 13:44:59 +0000 (15:44 +0200)
AndroidManifest.xml
src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java
src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java

index d2d03e6..4f334df 100644 (file)
@@ -18,7 +18,7 @@
  -->\r
 <manifest package="eu.alefzero.owncloud"\r
     android:versionCode="1"\r
-    android:versionName="0.1.143B" xmlns:android="http://schemas.android.com/apk/res/android">\r
+    android:versionName="0.1.144B" 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
index 230d3a7..0bd2ec2 100644 (file)
@@ -21,7 +21,9 @@ package eu.alefzero.owncloud.syncadapter;
 import java.io.IOException;\r
 import java.util.ArrayList;\r
 import java.util.Iterator;\r
+import java.util.LinkedList;\r
 import java.util.List;\r
+import java.util.Queue;\r
 import java.util.Vector;\r
 \r
 import org.apache.jackrabbit.webdav.DavException;\r
@@ -70,7 +72,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
         \r
         Log.d(TAG, "syncing owncloud account " + account.name);\r
 \r
-        sendStickyBroadcast(true, -1);  // starting message to UI\r
+        sendStickyBroadcast(true, -1);  // message to signal the start to the UI\r
 \r
         PropFindMethod query;\r
         try {\r
@@ -108,8 +110,8 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
             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
+            Queue<String> paths = new LinkedList<String>();\r
+            Queue<Long> fileIds = new LinkedList<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
@@ -135,11 +137,11 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
             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
+            while(!paths.isEmpty()) {\r
+                fetchData(getUri().toString() + paths.remove(), syncResult, fileIds.remove());\r
             }\r
+            paths = null;\r
+            fileIds = null;\r
 \r
 \r
         } catch (OperationCanceledException e) {\r
index 2c4ae38..74c2ee5 100644 (file)
@@ -610,32 +610,34 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
                     FileSyncService.IN_PROGRESS, false);\r
             String account_name = intent\r
                     .getStringExtra(FileSyncService.ACCOUNT_NAME);\r
+\r
             Log.d("FileDisplay", "sync of account " + account_name\r
                     + " is in_progress: " + inProgress);\r
-            setSupportProgressBarIndeterminateVisibility(inProgress);\r
+\r
+            //if (account_name.equals(AccountUtils.getCurrentOwnCloudAccount(context).name)) {  // TODO - probably this check should be added, but won't push it until really tests are done; no time now\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
+                /// try to refresh the view with every message received from the FileSyncAdapter; brute, but more user friendly when there are a lot of files in the server\r
+                OCFile currentDir;\r
+                if (mCurrentDir == null)\r
+                    currentDir = mStorageManager.getFileByPath("/");\r
+                else\r
+                    currentDir = mStorageManager.getFileByPath(mCurrentDir.getRemotePath());\r
+                \r
+                if (currentDir != null) {\r
+                    mCurrentDir = currentDir;\r
+                    FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager()\r
+                            .findFragmentById(R.id.fileList);\r
+                    if (fileListFragment != null) {\r
+                        if (!mCurrentDir.equals(fileListFragment.getCurrentFile())) {\r
+                            fileListFragment.listDirectory(mCurrentDir);    // only set the directory in the fragment first time\r
+                        } else\r
+                            fileListFragment.listDirectory();   // enough to show new files in the current directory if they are added after \r
                     }\r
                 }\r
-            }\r
-            \r
-            if (!inProgress) {\r
-                FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager()\r
-                        .findFragmentById(R.id.fileList);\r
-                if (fileListFragment != null)\r
-                    fileListFragment.listDirectory();\r
-            }\r
+                \r
+                setSupportProgressBarIndeterminateVisibility(inProgress);\r
+            //}\r
         }\r
-\r
     }\r
     \r
 \r