Auto rename oc upload

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-09-24 10:37:43 +02:00 committed by Alper Öztürk
parent c10c97bf22
commit b0082d26f9

View file

@ -27,6 +27,7 @@ import com.nextcloud.client.account.CurrentAccountProvider;
import com.nextcloud.client.account.User; import com.nextcloud.client.account.User;
import com.nextcloud.client.jobs.upload.FileUploadHelper; import com.nextcloud.client.jobs.upload.FileUploadHelper;
import com.nextcloud.client.jobs.upload.FileUploadWorker; import com.nextcloud.client.jobs.upload.FileUploadWorker;
import com.nextcloud.utils.autoRename.AutoRename;
import com.owncloud.android.MainApp; import com.owncloud.android.MainApp;
import com.owncloud.android.db.OCUpload; import com.owncloud.android.db.OCUpload;
import com.owncloud.android.db.ProviderMeta.ProviderTableMeta; import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
@ -34,7 +35,9 @@ import com.owncloud.android.db.UploadResult;
import com.owncloud.android.files.services.NameCollisionPolicy; import com.owncloud.android.files.services.NameCollisionPolicy;
import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.status.OCCapability;
import com.owncloud.android.operations.UploadFileOperation; import com.owncloud.android.operations.UploadFileOperation;
import com.owncloud.android.utils.theme.CapabilityUtils;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -65,6 +68,7 @@ public class UploadsStorageManager extends Observable {
private final ContentResolver contentResolver; private final ContentResolver contentResolver;
private final CurrentAccountProvider currentAccountProvider; private final CurrentAccountProvider currentAccountProvider;
private OCCapability capability;
public UploadsStorageManager( public UploadsStorageManager(
CurrentAccountProvider currentAccountProvider, CurrentAccountProvider currentAccountProvider,
@ -77,6 +81,14 @@ public class UploadsStorageManager extends Observable {
this.currentAccountProvider = currentAccountProvider; this.currentAccountProvider = currentAccountProvider;
} }
private void initOCCapability() {
try {
this.capability = CapabilityUtils.getCapability(MainApp.getAppContext());
} catch (RuntimeException e) {
Log_OC.e(TAG,"Failed to set OCCapability: Dependencies are not yet ready.");
}
}
/** /**
* Stores an upload object in DB. * Stores an upload object in DB.
* *
@ -570,10 +582,17 @@ public class UploadsStorageManager extends Observable {
} }
private OCUpload createOCUploadFromCursor(Cursor c) { private OCUpload createOCUploadFromCursor(Cursor c) {
initOCCapability();
OCUpload upload = null; OCUpload upload = null;
if (c != null) { if (c != null) {
String localPath = c.getString(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_LOCAL_PATH)); String localPath = c.getString(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_LOCAL_PATH));
String remotePath = c.getString(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_REMOTE_PATH)); String remotePath = c.getString(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_REMOTE_PATH));
if (capability != null) {
remotePath = AutoRename.INSTANCE.rename(remotePath, capability,true);
}
String accountName = c.getString(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_ACCOUNT_NAME)); String accountName = c.getString(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_ACCOUNT_NAME));
upload = new OCUpload(localPath, remotePath, accountName); upload = new OCUpload(localPath, remotePath, accountName);