Browse Source

Merge pull request #3455 from nextcloud/DocumentProviderRefreshNew

Document provider: refresh
Andy Scherzinger 6 years ago
parent
commit
bea1560dd9

+ 29 - 2
src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java

@@ -114,6 +114,11 @@ public class RefreshFolderOperation extends RemoteOperation {
     /** 'True' means that Etag will be ignored */
     private boolean mIgnoreETag;
 
+    /**
+     * 'True' means that no share and no capabilities will be updated
+     */
+    private boolean mOnlyFileMetadata;
+
     private List<SynchronizeFileOperation> mFilesToSyncContents;
     // this will be used for every file when 'folder synchronization' replaces 'folder download'
 
@@ -148,6 +153,28 @@ public class RefreshFolderOperation extends RemoteOperation {
         mForgottenLocalFiles = new HashMap<>();
         mRemoteFolderChanged = false;
         mIgnoreETag = ignoreETag;
+        mOnlyFileMetadata = false;
+        mFilesToSyncContents = new Vector<>();
+    }
+
+    public RefreshFolderOperation(OCFile folder,
+                                  long currentSyncTime,
+                                  boolean syncFullAccount,
+                                  boolean ignoreETag,
+                                  boolean onlyFileMetadata,
+                                  FileDataStorageManager dataStorageManager,
+                                  Account account,
+                                  Context context) {
+        mLocalFolder = folder;
+        mCurrentSyncTime = currentSyncTime;
+        mSyncFullAccount = syncFullAccount;
+        mStorageManager = dataStorageManager;
+        mAccount = account;
+        mContext = context;
+        mForgottenLocalFiles = new HashMap<>();
+        mRemoteFolderChanged = false;
+        mIgnoreETag = ignoreETag;
+        mOnlyFileMetadata = onlyFileMetadata;
         mFilesToSyncContents = new Vector<>();
     }
 
@@ -185,7 +212,7 @@ public class RefreshFolderOperation extends RemoteOperation {
         mConflictsFound = 0;
         mForgottenLocalFiles.clear();
 
-        if (OCFile.ROOT_PATH.equals(mLocalFolder.getRemotePath()) && !mSyncFullAccount) {
+        if (OCFile.ROOT_PATH.equals(mLocalFolder.getRemotePath()) && !mSyncFullAccount && !mOnlyFileMetadata) {
             updateOCVersion(client);
             updateUserProfile();
         }
@@ -214,7 +241,7 @@ public class RefreshFolderOperation extends RemoteOperation {
             );
         }
 
-        if (result.isSuccess() && !mSyncFullAccount) {
+        if (result.isSuccess() && !mSyncFullAccount && !mOnlyFileMetadata) {
             refreshSharesForFolder(client); // share result is ignored
         }
 

+ 23 - 5
src/main/java/com/owncloud/android/providers/DocumentsStorageProvider.java

@@ -42,6 +42,8 @@ import android.provider.DocumentsProvider;
 import android.util.Log;
 import android.widget.Toast;
 
+import com.evernote.android.job.JobRequest;
+import com.evernote.android.job.util.Device;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.authentication.AccountUtils;
@@ -54,6 +56,7 @@ import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.operations.CreateFolderOperation;
+import com.owncloud.android.operations.RefreshFolderOperation;
 import com.owncloud.android.operations.RemoveFileOperation;
 import com.owncloud.android.operations.SynchronizeFileOperation;
 import com.owncloud.android.ui.activity.ConflictsResolveActivity;
@@ -128,20 +131,35 @@ public class DocumentsStorageProvider extends DocumentsProvider {
         return result;
     }
 
+    @SuppressLint("LongLogTag")
     @Override
-    public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder) {
+    public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder)
+        throws FileNotFoundException {
 
         final long folderId = Long.parseLong(parentDocumentId);
         updateCurrentStorageManagerIfNeeded(folderId);
 
-        final FileCursor result = new FileCursor(projection);
-
         final OCFile browsedDir = currentStorageManager.getFileById(folderId);
+
+        Account account = currentStorageManager.getAccount();
+
+        if (Device.getNetworkType(getContext()).equals(JobRequest.NetworkType.UNMETERED)) {
+            RemoteOperationResult result = new RefreshFolderOperation(browsedDir, System.currentTimeMillis(), false,
+                                                                      false, true, currentStorageManager, account,
+                                                                      getContext()).execute(client);
+
+            if (!result.isSuccess()) {
+                throw new FileNotFoundException("Failed to update document " + parentDocumentId);
+            }
+        }
+
+        final FileCursor resultCursor = new FileCursor(projection);
+        
         for (OCFile file : currentStorageManager.getFolderContent(browsedDir, false)) {
-            result.addFile(file);
+            resultCursor.addFile(file);
         }
 
-        return result;
+        return resultCursor;
     }
 
     @SuppressLint("LongLogTag")