Avoid use of queues to delay recursion
[pub/Android/ownCloud.git] / src / eu / alefzero / owncloud / ui / activity / FileDisplayActivity.java
index 2c4ae38..188d1f0 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
@@ -717,17 +719,11 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
         \r
         // If we are on a large device -> update fragment\r
         if (mDualPane) {\r
-            FileDetailFragment fileDetails = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);\r
-            if (fileDetails == null) {\r
-                // first selected file since the current directory was listed\r
-                FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();\r
-                transaction.replace(R.id.file_details_container, new FileDetailFragment(file, AccountUtils.getCurrentOwnCloudAccount(this)), FileDetailFragment.FTAG);\r
-                transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);\r
-                transaction.commit();\r
-            } else {\r
-                // another select file\r
-                fileDetails.updateFileDetails(file, AccountUtils.getCurrentOwnCloudAccount(this));\r
-            }   \r
+            // buttons in the details view are problematic when trying to reuse an existing fragment; create always a new one solves some of them, BUT no all; downloads are 'dangerous'\r
+            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();\r
+            transaction.replace(R.id.file_details_container, new FileDetailFragment(file, AccountUtils.getCurrentOwnCloudAccount(this)), FileDetailFragment.FTAG);\r
+            transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);\r
+            transaction.commit();\r
             \r
         } else {    // small or medium screen device -> new Activity\r
             Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);\r