From 5265782e16845ac3ad3da7dd63449815a693913f Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 26 Sep 2024 12:22:32 +0200 Subject: [PATCH] Fix creation and modification date Signed-off-by: alperozturk --- .../OfflineOperationsWorker.kt | 7 +++- .../datamodel/FileDataStorageManager.java | 36 ++++++++++++------- .../android/ui/adapter/OCFileListAdapter.java | 15 ++++---- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/com/nextcloud/client/jobs/offlineOperations/OfflineOperationsWorker.kt b/app/src/main/java/com/nextcloud/client/jobs/offlineOperations/OfflineOperationsWorker.kt index 41d46396e2..93e6c7ae91 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/offlineOperations/OfflineOperationsWorker.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/offlineOperations/OfflineOperationsWorker.kt @@ -130,11 +130,16 @@ class OfflineOperationsWorker( is OfflineOperationType.CreateFile -> { val createFileOperation = withContext(NonCancellable) { val operationType = (operation.type as OfflineOperationType.CreateFile) + val lastModificationDate = System.currentTimeMillis() / 1000 + UploadFileRemoteOperation( operationType.localPath, operationType.remotePath, operationType.mimeType, - System.currentTimeMillis() + "", + lastModificationDate, + operation.createdAt ?: System.currentTimeMillis(), + true ) } diff --git a/app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java b/app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java index bf087910eb..7cb4917e94 100644 --- a/app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -155,7 +155,11 @@ public class FileDataStorageManager { OfflineOperationEntity entity = new OfflineOperationEntity(); entity.setPath(remotePath); entity.setType(new OfflineOperationType.CreateFile(OfflineOperationRawType.CreateFile.name(), localPath, remotePath, mimeType)); - entity.setCreatedAt(System.currentTimeMillis() / 1000L); + + long createdAt = System.currentTimeMillis(); + long modificationTimestamp = System.currentTimeMillis(); + + entity.setCreatedAt(createdAt); entity.setFilename(new File(remotePath).getName()); String parentPath = new File(remotePath).getParent() + OCFile.PATH_SEPARATOR; @@ -166,7 +170,7 @@ public class FileDataStorageManager { } offlineOperationDao.insert(entity); - createPendingFile(remotePath, mimeType); + createPendingFile(remotePath, mimeType, createdAt, modificationTimestamp); } } @@ -179,24 +183,32 @@ public class FileDataStorageManager { OfflineOperationType.CreateFolder operationType = new OfflineOperationType.CreateFolder(OfflineOperationRawType.CreateFolder.name(), path); entity.setType(operationType); entity.setPath(path); - entity.setCreatedAt(System.currentTimeMillis() / 1000L); + + long createdAt = System.currentTimeMillis(); + long modificationTimestamp = System.currentTimeMillis(); + + entity.setCreatedAt(createdAt); offlineOperationDao.insert(entity); - createPendingDirectory(path); + createPendingDirectory(path, createdAt, modificationTimestamp); return entity; } - public void createPendingFile(String path, String mimeType) { - OCFile ocFile = new OCFile(path); - ocFile.setMimeType(mimeType); - saveFileWithParent(ocFile, MainApp.getAppContext()); + public void createPendingFile(String path, String mimeType, long createdAt, long modificationTimestamp) { + OCFile file = new OCFile(path); + file.setMimeType(mimeType); + file.setCreationTimestamp(createdAt); + file.setModificationTimestamp(modificationTimestamp); + saveFileWithParent(file, MainApp.getAppContext()); } - public void createPendingDirectory(String path) { - OCFile file = new OCFile(path); - file.setMimeType(MimeType.DIRECTORY); - saveFileWithParent(file, MainApp.getAppContext()); + public void createPendingDirectory(String path, long createdAt, long modificationTimestamp) { + OCFile directory = new OCFile(path); + directory.setMimeType(MimeType.DIRECTORY); + directory.setCreationTimestamp(createdAt); + directory.setModificationTimestamp(modificationTimestamp); + saveFileWithParent(directory, MainApp.getAppContext()); } public void deleteOfflineOperation(OCFile file) { diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java b/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java index 7f386c9abd..cd5eb4067b 100644 --- a/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java +++ b/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java @@ -32,7 +32,6 @@ import android.widget.LinearLayout; import com.elyeproj.loaderviewlibrary.LoaderImageView; import com.nextcloud.android.common.ui.theme.utils.ColorRole; import com.nextcloud.client.account.User; -import com.nextcloud.client.database.entity.OfflineOperationEntity; import com.nextcloud.client.jobs.upload.FileUploadHelper; import com.nextcloud.client.preferences.AppPreferences; import com.nextcloud.model.OCFileFilterType; @@ -48,7 +47,6 @@ import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.datamodel.SyncedFolderProvider; import com.owncloud.android.datamodel.ThumbnailsCacheManager; -import com.owncloud.android.datamodel.UploadsStorageManager; import com.owncloud.android.datamodel.VirtualFolderType; import com.owncloud.android.datamodel.e2e.v1.decrypted.DecryptedFolderMetadataFileV1; import com.owncloud.android.datamodel.e2e.v2.decrypted.DecryptedFolderMetadataFile; @@ -82,8 +80,6 @@ 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; @@ -603,13 +599,14 @@ public class OCFileListAdapter extends RecyclerView.Adapter= 0) { @@ -617,11 +614,11 @@ public class OCFileListAdapter extends RecyclerView.Adapter - * These function also need to be used: {@link FileDataStorageManager#createPendingDirectory(String)}, {@link FileDataStorageManager#createPendingFile(String, String)}. + * These function also need to be used: {@link FileDataStorageManager#createPendingDirectory(String, long, long)}, {@link FileDataStorageManager#createPendingFile(String, String, long, long)}. */ private void addOfflineOperations(long fileId) { List offlineOperations = mStorageManager.offlineOperationsRepository.convertToOCFiles(fileId);