Skip to content

Commit

Permalink
Auto rename oc upload
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Sep 24, 2024
1 parent 494d9da commit 4c98afd
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@
import com.nextcloud.client.account.User;
import com.nextcloud.client.jobs.upload.FileUploadHelper;
import com.nextcloud.client.jobs.upload.FileUploadWorker;
import com.nextcloud.utils.autoRename.AutoRename;
import com.owncloud.android.MainApp;
import com.owncloud.android.db.OCUpload;
import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
import com.owncloud.android.db.UploadResult;
import com.owncloud.android.files.services.NameCollisionPolicy;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
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.utils.theme.CapabilityUtils;

import java.io.File;
import java.util.ArrayList;
Expand Down Expand Up @@ -65,6 +68,7 @@ public class UploadsStorageManager extends Observable {

private final ContentResolver contentResolver;
private final CurrentAccountProvider currentAccountProvider;
private OCCapability capability;

public UploadsStorageManager(
CurrentAccountProvider currentAccountProvider,
Expand All @@ -77,6 +81,14 @@ public UploadsStorageManager(
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.
*
Expand Down Expand Up @@ -570,10 +582,17 @@ private List<OCUpload> getUploadPage(long limit, final long afterId, final boole
}

private OCUpload createOCUploadFromCursor(Cursor c) {
initOCCapability();

OCUpload upload = null;
if (c != null) {
String localPath = c.getString(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_LOCAL_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));
upload = new OCUpload(localPath, remotePath, accountName);

Expand Down

0 comments on commit 4c98afd

Please sign in to comment.