Browse Source

Remove parent path, no need to check

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 10 months ago
parent
commit
51380469a1

+ 1 - 7
app/schemas/com.nextcloud.client.database.NextcloudDatabase/84.json

@@ -1237,7 +1237,7 @@
       },
       {
         "tableName": "offline_operations",
-        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT, `offline_operations_parent_oc_file_id` INTEGER, `offline_operations_parent_path` TEXT, `offline_operations_type` TEXT, `offline_operations_path` TEXT, `offline_operations_file_name` TEXT, `offline_operations_created_at` INTEGER)",
+        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT, `offline_operations_parent_oc_file_id` INTEGER, `offline_operations_type` TEXT, `offline_operations_path` TEXT, `offline_operations_file_name` TEXT, `offline_operations_created_at` INTEGER)",
         "fields": [
           {
             "fieldPath": "id",
@@ -1251,12 +1251,6 @@
             "affinity": "INTEGER",
             "notNull": false
           },
-          {
-            "fieldPath": "parentPath",
-            "columnName": "offline_operations_parent_path",
-            "affinity": "TEXT",
-            "notNull": false
-          },
           {
             "fieldPath": "type",
             "columnName": "offline_operations_type",

+ 3 - 9
app/schemas/com.nextcloud.client.database.NextcloudDatabase/85.json

@@ -2,7 +2,7 @@
   "formatVersion": 1,
   "database": {
     "version": 85,
-    "identityHash": "70f2e2adb603afda7f87dbfb3b902e02",
+    "identityHash": "d1710bd13728e71a6b2c530bd1954fda",
     "entities": [
       {
         "tableName": "arbitrary_data",
@@ -1237,7 +1237,7 @@
       },
       {
         "tableName": "offline_operations",
-        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT, `offline_operations_parent_oc_file_id` INTEGER, `offline_operations_parent_path` TEXT, `offline_operations_path` TEXT, `offline_operations_type` TEXT, `offline_operations_file_name` TEXT, `offline_operations_created_at` INTEGER)",
+        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT, `offline_operations_parent_oc_file_id` INTEGER, `offline_operations_path` TEXT, `offline_operations_type` TEXT, `offline_operations_file_name` TEXT, `offline_operations_created_at` INTEGER)",
         "fields": [
           {
             "fieldPath": "id",
@@ -1251,12 +1251,6 @@
             "affinity": "INTEGER",
             "notNull": false
           },
-          {
-            "fieldPath": "parentPath",
-            "columnName": "offline_operations_parent_path",
-            "affinity": "TEXT",
-            "notNull": false
-          },
           {
             "fieldPath": "path",
             "columnName": "offline_operations_path",
@@ -1295,7 +1289,7 @@
     "views": [],
     "setupQueries": [
       "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
-      "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '70f2e2adb603afda7f87dbfb3b902e02')"
+      "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'd1710bd13728e71a6b2c530bd1954fda')"
     ]
   }
 }

+ 0 - 3
app/src/main/java/com/nextcloud/client/database/entity/OfflineOperationEntity.kt

@@ -22,9 +22,6 @@ data class OfflineOperationEntity(
     @ColumnInfo(name = ProviderTableMeta.OFFLINE_OPERATION_PARENT_OC_FILE_ID)
     var parentOCFileId: Long? = null,
 
-    @ColumnInfo(name = ProviderTableMeta.OFFLINE_OPERATION_PARENT_PATH)
-    var parentPath: String? = null,
-
     @ColumnInfo(name = ProviderTableMeta.OFFLINE_OPERATION_PATH)
     var path: String? = null,
 

+ 2 - 4
app/src/main/java/com/nextcloud/client/jobs/offlineOperations/repository/OfflineOperationsRepository.kt

@@ -74,10 +74,9 @@ class OfflineOperationsRepository(
                 nextOperation.parentOCFileId?.let { parentId ->
                     fileDataStorageManager.getFileById(parentId)?.let { ocFile ->
                         ocFile.decryptedRemotePath?.let { updatedPath ->
-                            val newParentPath = ocFile.parentRemotePath
                             val newPath = updatedPath + nextOperation.filename + pathSeparator
 
-                            if (newParentPath != nextOperation.parentPath || newPath != nextOperation.path) {
+                            if (newPath != nextOperation.path) {
                                 nextOperation.apply {
                                     type = when (type) {
                                         is OfflineOperationType.CreateFile -> (type as OfflineOperationType.CreateFile).copy(
@@ -90,7 +89,6 @@ class OfflineOperationsRepository(
 
                                         else -> type
                                     }
-                                    parentPath = newParentPath
                                     path = newPath
                                 }
                             } else {
@@ -104,7 +102,7 @@ class OfflineOperationsRepository(
     }
 
     override fun convertToOCFiles(fileId: Long): List<OCFile> =
-        getAllSubEntities(fileId).map { entity ->
+        dao.getSubEntitiesByParentOCFileId(fileId).map { entity ->
             OCFile(entity.path).apply {
                 mimeType = if (entity.type is OfflineOperationType.CreateFolder) {
                     MimeType.DIRECTORY

+ 1 - 5
app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java

@@ -163,9 +163,6 @@ public class FileDataStorageManager {
 
             if (parentFile != null) {
                 entity.setParentOCFileId(parentFile.getFileId());
-                if (!parentFile.isOfflineOperation()) {
-                    entity.setParentPath(parentPath);
-                }
             }
 
             offlineOperationDao.insert(entity);
@@ -173,7 +170,7 @@ public class FileDataStorageManager {
         }
     }
 
-    public OfflineOperationEntity addCreateFolderOfflineOperation(String path, String filename, String parentPath, Long parentOCFileId) {
+    public OfflineOperationEntity addCreateFolderOfflineOperation(String path, String filename, Long parentOCFileId) {
         OfflineOperationEntity entity = new OfflineOperationEntity();
 
         entity.setFilename(filename);
@@ -182,7 +179,6 @@ public class FileDataStorageManager {
         OfflineOperationType.CreateFolder operationType = new OfflineOperationType.CreateFolder(OfflineOperationRawType.CreateFolder.name(), path);
         entity.setType(operationType);
         entity.setPath(path);
-        entity.setParentPath(parentPath);
         entity.setCreatedAt(System.currentTimeMillis() / 1000L);
 
         offlineOperationDao.insert(entity);

+ 0 - 12
app/src/main/java/com/owncloud/android/datamodel/OCFile.java

@@ -788,18 +788,6 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
         return getRemoteId() == null;
     }
 
-    public String getOfflineOperationParentPath() {
-        if (isOfflineOperation()) {
-            if (Objects.equals(remotePath, OCFile.PATH_SEPARATOR)) {
-                return OCFile.PATH_SEPARATOR;
-            } else {
-                return null;
-            }
-        } else {
-            return getDecryptedRemotePath();
-        }
-    }
-
     public String getEtagInConflict() {
         return this.etagInConflict;
     }

+ 0 - 1
app/src/main/java/com/owncloud/android/db/ProviderMeta.java

@@ -289,7 +289,6 @@ public class ProviderMeta {
 
         // Columns of offline operation table
         public static final String OFFLINE_OPERATION_PARENT_OC_FILE_ID = "offline_operations_parent_oc_file_id";
-        public static final String OFFLINE_OPERATION_PARENT_PATH = "offline_operations_parent_path";
         public static final String OFFLINE_OPERATION_TYPE = "offline_operations_type";
         public static final String OFFLINE_OPERATION_PATH = "offline_operations_path";
         public static final String OFFLINE_OPERATION_CREATED_AT = "offline_operations_created_at";

+ 19 - 21
app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java

@@ -19,6 +19,7 @@ import android.content.res.Resources;
 import android.graphics.Color;
 import android.graphics.PorterDuff;
 import android.graphics.drawable.Drawable;
+import android.os.Build;
 import android.os.Handler;
 import android.os.Looper;
 import android.text.TextUtils;
@@ -80,12 +81,14 @@ import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 import java.util.Objects;
 import java.util.Set;
 import java.util.UUID;
+import java.util.stream.Collectors;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
@@ -738,6 +741,8 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
         return !TextUtils.isEmpty(currentDirectory.getRichWorkspace().trim());
     }
 
+    private final int eTag = 0;
+
     /**
      * Change the adapted directory for a new one
      *
@@ -784,10 +789,10 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
             mFiles = sortOrder.sortCloudFiles(mFiles);
             prepareListOfHiddenFiles();
             mergeOCFilesForLivePhoto();
+            mFilesAll.clear();
 
             // TODO check necessity of it
-            // addOfflineOperations(directory.getFileId());
-            mFilesAll.clear();
+            addOfflineOperations(directory.getFileId());
             mFilesAll.addAll(mFiles);
             currentDirectory = directory;
         } else {
@@ -802,28 +807,21 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
 
     private void addOfflineOperations(long fileId) {
         List<OCFile> offlineOperations = mStorageManager.offlineOperationsRepository.convertToOCFiles(fileId);
-        List<OCFile> filesToAdd = new ArrayList<>();
-
-        for (OCFile offlineFile : offlineOperations) {
-            boolean shouldAdd = true;
-            Iterator<OCFile> iterator = mFiles.iterator();
-
-            if (iterator.hasNext()) {
-                do {
-                    OCFile file = iterator.next();
-                    if (Objects.equals(file.getDecryptedRemotePath(), offlineFile.getDecryptedRemotePath())) {
-                        shouldAdd = false;
-                        break;
-                    }
-                } while (iterator.hasNext());
-            }
+        List<OCFile> newFiles;
 
-            if (shouldAdd) {
-                filesToAdd.add(offlineFile);
-            }
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
+            newFiles = offlineOperations.stream()
+                .filter(offlineFile -> mFilesAll.stream()
+                    .noneMatch(file -> Objects.equals(file.getDecryptedRemotePath(), offlineFile.getDecryptedRemotePath())))
+                .toList();
+        } else {
+            newFiles = offlineOperations.stream()
+                .filter(offlineFile -> mFilesAll.stream()
+                    .noneMatch(file -> Objects.equals(file.getDecryptedRemotePath(), offlineFile.getDecryptedRemotePath())))
+                .collect(Collectors.toList());
         }
 
-        mFiles.addAll(filesToAdd);
+        mFilesAll.addAll(newFiles);
     }
 
     public void setData(List<Object> objects,

+ 0 - 1
app/src/main/java/com/owncloud/android/ui/dialog/CreateFolderDialogFragment.kt

@@ -189,7 +189,6 @@ class CreateFolderDialogFragment : DialogFragment(), DialogInterface.OnClickList
                     fileDataStorageManager.addCreateFolderOfflineOperation(
                         path,
                         newFolderName,
-                        parentFolder?.offlineOperationParentPath,
                         parentFolder?.fileId
                     )