Fix creation and modification date

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-09-26 12:22:32 +02:00
parent 0a250857bf
commit 5265782e16
No known key found for this signature in database
GPG key ID: 4E577DC593B59BDF
3 changed files with 36 additions and 22 deletions

View file

@ -130,11 +130,16 @@ class OfflineOperationsWorker(
is OfflineOperationType.CreateFile -> { is OfflineOperationType.CreateFile -> {
val createFileOperation = withContext(NonCancellable) { val createFileOperation = withContext(NonCancellable) {
val operationType = (operation.type as OfflineOperationType.CreateFile) val operationType = (operation.type as OfflineOperationType.CreateFile)
val lastModificationDate = System.currentTimeMillis() / 1000
UploadFileRemoteOperation( UploadFileRemoteOperation(
operationType.localPath, operationType.localPath,
operationType.remotePath, operationType.remotePath,
operationType.mimeType, operationType.mimeType,
System.currentTimeMillis() "",
lastModificationDate,
operation.createdAt ?: System.currentTimeMillis(),
true
) )
} }

View file

@ -155,7 +155,11 @@ public class FileDataStorageManager {
OfflineOperationEntity entity = new OfflineOperationEntity(); OfflineOperationEntity entity = new OfflineOperationEntity();
entity.setPath(remotePath); entity.setPath(remotePath);
entity.setType(new OfflineOperationType.CreateFile(OfflineOperationRawType.CreateFile.name(), localPath, remotePath, mimeType)); 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()); entity.setFilename(new File(remotePath).getName());
String parentPath = new File(remotePath).getParent() + OCFile.PATH_SEPARATOR; String parentPath = new File(remotePath).getParent() + OCFile.PATH_SEPARATOR;
@ -166,7 +170,7 @@ public class FileDataStorageManager {
} }
offlineOperationDao.insert(entity); 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); OfflineOperationType.CreateFolder operationType = new OfflineOperationType.CreateFolder(OfflineOperationRawType.CreateFolder.name(), path);
entity.setType(operationType); entity.setType(operationType);
entity.setPath(path); entity.setPath(path);
entity.setCreatedAt(System.currentTimeMillis() / 1000L);
long createdAt = System.currentTimeMillis();
long modificationTimestamp = System.currentTimeMillis();
entity.setCreatedAt(createdAt);
offlineOperationDao.insert(entity); offlineOperationDao.insert(entity);
createPendingDirectory(path); createPendingDirectory(path, createdAt, modificationTimestamp);
return entity; return entity;
} }
public void createPendingFile(String path, String mimeType) { public void createPendingFile(String path, String mimeType, long createdAt, long modificationTimestamp) {
OCFile ocFile = new OCFile(path); OCFile file = new OCFile(path);
ocFile.setMimeType(mimeType); file.setMimeType(mimeType);
saveFileWithParent(ocFile, MainApp.getAppContext()); file.setCreationTimestamp(createdAt);
file.setModificationTimestamp(modificationTimestamp);
saveFileWithParent(file, MainApp.getAppContext());
} }
public void createPendingDirectory(String path) { public void createPendingDirectory(String path, long createdAt, long modificationTimestamp) {
OCFile file = new OCFile(path); OCFile directory = new OCFile(path);
file.setMimeType(MimeType.DIRECTORY); directory.setMimeType(MimeType.DIRECTORY);
saveFileWithParent(file, MainApp.getAppContext()); directory.setCreationTimestamp(createdAt);
directory.setModificationTimestamp(modificationTimestamp);
saveFileWithParent(directory, MainApp.getAppContext());
} }
public void deleteOfflineOperation(OCFile file) { public void deleteOfflineOperation(OCFile file) {

View file

@ -32,7 +32,6 @@ import android.widget.LinearLayout;
import com.elyeproj.loaderviewlibrary.LoaderImageView; import com.elyeproj.loaderviewlibrary.LoaderImageView;
import com.nextcloud.android.common.ui.theme.utils.ColorRole; import com.nextcloud.android.common.ui.theme.utils.ColorRole;
import com.nextcloud.client.account.User; import com.nextcloud.client.account.User;
import com.nextcloud.client.database.entity.OfflineOperationEntity;
import com.nextcloud.client.jobs.upload.FileUploadHelper; import com.nextcloud.client.jobs.upload.FileUploadHelper;
import com.nextcloud.client.preferences.AppPreferences; import com.nextcloud.client.preferences.AppPreferences;
import com.nextcloud.model.OCFileFilterType; 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.OCFile;
import com.owncloud.android.datamodel.SyncedFolderProvider; import com.owncloud.android.datamodel.SyncedFolderProvider;
import com.owncloud.android.datamodel.ThumbnailsCacheManager; import com.owncloud.android.datamodel.ThumbnailsCacheManager;
import com.owncloud.android.datamodel.UploadsStorageManager;
import com.owncloud.android.datamodel.VirtualFolderType; import com.owncloud.android.datamodel.VirtualFolderType;
import com.owncloud.android.datamodel.e2e.v1.decrypted.DecryptedFolderMetadataFileV1; import com.owncloud.android.datamodel.e2e.v1.decrypted.DecryptedFolderMetadataFileV1;
import com.owncloud.android.datamodel.e2e.v2.decrypted.DecryptedFolderMetadataFile; import com.owncloud.android.datamodel.e2e.v2.decrypted.DecryptedFolderMetadataFile;
@ -82,8 +80,6 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Objects; import java.util.Objects;
@ -603,13 +599,14 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
holder.getFileSize().setVisibility(View.VISIBLE); holder.getFileSize().setVisibility(View.VISIBLE);
if (file.isOfflineOperation()) { if (file.isOfflineOperation()) {
holder.getFileSize().setText(MainApp.string(R.string.oc_file_list_adapter_offline_operation_description_text)); holder.getFileSize().setText(MainApp.string(R.string.oc_file_list_adapter_offline_operation_description_text));
holder.getFileSizeSeparator().setVisibility(View.GONE);
} else { } else {
holder.getFileSize().setText(DisplayUtils.bytesToHumanReadable(localSize)); holder.getFileSize().setText(DisplayUtils.bytesToHumanReadable(localSize));
holder.getFileSizeSeparator().setVisibility(View.VISIBLE);
} }
holder.getFileSizeSeparator().setVisibility(View.VISIBLE);
} else { } else {
final long fileLength = file.getFileLength(); final long fileLength = file.getFileLength();
if (fileLength >= 0) { if (fileLength >= 0) {
@ -617,11 +614,11 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
if (file.isOfflineOperation()) { if (file.isOfflineOperation()) {
holder.getFileSize().setText(MainApp.string(R.string.oc_file_list_adapter_offline_operation_description_text)); holder.getFileSize().setText(MainApp.string(R.string.oc_file_list_adapter_offline_operation_description_text));
holder.getFileSizeSeparator().setVisibility(View.GONE);
} else { } else {
holder.getFileSize().setText(DisplayUtils.bytesToHumanReadable(fileLength)); holder.getFileSize().setText(DisplayUtils.bytesToHumanReadable(fileLength));
holder.getFileSizeSeparator().setVisibility(View.VISIBLE);
} }
holder.getFileSizeSeparator().setVisibility(View.VISIBLE);
} else { } else {
holder.getFileSize().setVisibility(View.GONE); holder.getFileSize().setVisibility(View.GONE);
holder.getFileSizeSeparator().setVisibility(View.GONE); holder.getFileSizeSeparator().setVisibility(View.GONE);
@ -807,7 +804,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
* The issue arises when {@link RefreshFolderOperation} deletes pending Offline Operations, while some may still exist in the table. * The issue arises when {@link RefreshFolderOperation} deletes pending Offline Operations, while some may still exist in the table.
* If only this function is used, it cause crash in {@link FileDisplayActivity mSyncBroadcastReceiver.onReceive}. * If only this function is used, it cause crash in {@link FileDisplayActivity mSyncBroadcastReceiver.onReceive}.
* <p> * <p>
* 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) { private void addOfflineOperations(long fileId) {
List<OCFile> offlineOperations = mStorageManager.offlineOperationsRepository.convertToOCFiles(fileId); List<OCFile> offlineOperations = mStorageManager.offlineOperationsRepository.convertToOCFiles(fileId);