Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ dependencies {
// dependencies for app building
implementation 'com.android.support:multidex:1.0.3'
// implementation project('nextcloud-android-library')
genericImplementation "com.github.nextcloud:android-library:master-SNAPSHOT"
gplayImplementation "com.github.nextcloud:android-library:master-SNAPSHOT"
versionDevImplementation "com.github.nextcloud:android-library:master-SNAPSHOT"
genericImplementation 'com.github.nextcloud:android-library:master-SNAPSHOT'
gplayImplementation 'com.github.nextcloud:android-library:master-SNAPSHOT'
versionDevImplementation 'com.github.nextcloud:android-library:master-SNAPSHOT'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation "com.android.support:support-v4:${supportLibraryVersion}"
implementation "com.android.support:design:${supportLibraryVersion}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
import com.owncloud.android.lib.common.network.WebdavEntry;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.files.ReadRemoteFileOperation;
import com.owncloud.android.lib.resources.files.RemoteFile;
import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation;
import com.owncloud.android.lib.resources.files.model.RemoteFile;
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.resources.status.CapabilityBooleanType;
Expand Down Expand Up @@ -209,12 +209,10 @@ public boolean saveFile(OCFile file) {
if (sameRemotePath ||
fileExists(file.getFileId())) { // for renamed files; no more delete and create

OCFile oldFile;

if (sameRemotePath) {
oldFile = getFileByPath(file.getRemotePath());
OCFile oldFile = getFileByPath(file.getRemotePath());
file.setFileId(oldFile.getFileId());
} else {
oldFile = getFileById(file.getFileId());
}

overridden = true;
Expand Down Expand Up @@ -269,7 +267,7 @@ public OCFile saveFileWithParent(OCFile file, Context context) {
OCFile returnFile;
if (parentFile == null) {
// remote request
ReadRemoteFileOperation operation = new ReadRemoteFileOperation(parentPath);
ReadFileRemoteOperation operation = new ReadFileRemoteOperation(parentPath);
RemoteOperationResult result = operation.execute(getAccount(), context);
if (result.isSuccess()) {
OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));
Expand Down Expand Up @@ -400,7 +398,7 @@ public void saveFolder(OCFile folder, Collection<OCFile> updatedFiles, Collectio
if (results != null) {
long newId;
Iterator<OCFile> filesIt = updatedFiles.iterator();
OCFile file = null;
OCFile file;
for (ContentProviderResult result : results) {
if (filesIt.hasNext()) {
file = filesIt.next();
Expand Down Expand Up @@ -653,8 +651,8 @@ public void moveLocalFile(OCFile file, String targetPath, String targetParentPat
/// 2. prepare a batch of update operations to change all the descendants
ArrayList<ContentProviderOperation> operations = new ArrayList<>(c.getCount());
String defaultSavePath = FileStorageUtils.getSavePath(account.name);
List<String> originalPathsToTriggerMediaScan = new ArrayList<String>();
List<String> newPathsToTriggerMediaScan = new ArrayList<String>();
List<String> originalPathsToTriggerMediaScan = new ArrayList<>();
List<String> newPathsToTriggerMediaScan = new ArrayList<>();
if (c.moveToFirst()) {
int lengthOfOldPath = file.getRemotePath().length();
int lengthOfOldStoragePath = defaultSavePath.length() + lengthOfOldPath;
Expand Down Expand Up @@ -891,7 +889,7 @@ private boolean fileExists(String cmp_key, String value) {
}

private Cursor getFileCursorForValue(String key, String value) {
Cursor c = null;
Cursor c;
if (getContentResolver() != null) {
c = getContentResolver()
.query(ProviderTableMeta.CONTENT_URI,
Expand Down Expand Up @@ -1125,7 +1123,7 @@ private Cursor getShareCursorForValue(String key, String value) {
* @return First {@link OCShare} instance found in DB bound to the file in 'path'
*/
public OCShare getFirstShareByPathAndType(String path, ShareType type, String shareWith) {
Cursor cursor = null;
Cursor cursor;
if (shareWith == null) {
shareWith = "";
}
Expand Down Expand Up @@ -1511,7 +1509,7 @@ public void saveSharesDB(List<OCShare> shares) {

public void removeSharesForFile(String remotePath) {
resetShareFlagInAFile(remotePath);
ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
operations = prepareRemoveSharesInFile(remotePath, operations);
// apply operations in batch
if (operations.size() > 0) {
Expand All @@ -1533,7 +1531,7 @@ public void removeSharesForFile(String remotePath) {

public void saveSharesInFolder(ArrayList<OCShare> shares, OCFile folder) {
resetShareFlagsInFolder(folder);
ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
operations = prepareRemoveSharesInFolder(folder, operations);

if (shares != null) {
Expand Down Expand Up @@ -1667,8 +1665,8 @@ public List<OCShare> getSharesWithForAFile(String filePath, String accountName)
cursor = null;
}
}
ArrayList<OCShare> shares = new ArrayList<OCShare>();
OCShare share = null;
ArrayList<OCShare> shares = new ArrayList<>();
OCShare share;
if (cursor != null) {
if (cursor.moveToFirst()) {
do {
Expand Down Expand Up @@ -2009,7 +2007,7 @@ private Cursor getCapabilityCursorForAccount(String accountName) {
}

public OCCapability getCapability(String accountName) {
OCCapability capability = null;
OCCapability capability;
Cursor c = getCapabilityCursorForAccount(accountName);

if (c.moveToFirst()) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/owncloud/android/datamodel/OCFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import com.owncloud.android.lib.common.network.WebdavEntry;
import com.owncloud.android.lib.common.network.WebdavUtils;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.files.ServerFileInterface;
import com.owncloud.android.lib.resources.files.model.ServerFileInterface;
import com.owncloud.android.utils.MimeType;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.files.ServerFileInterface;
import com.owncloud.android.lib.resources.files.TrashbinFile;
import com.owncloud.android.lib.resources.files.model.ServerFileInterface;
import com.owncloud.android.lib.resources.trashbin.model.TrashbinFile;
import com.owncloud.android.ui.TextDrawable;
import com.owncloud.android.ui.adapter.DiskLruImageCache;
import com.owncloud.android.ui.fragment.FileFragment;
Expand Down Expand Up @@ -397,7 +397,7 @@ public ThumbnailGenerationTask(ImageView imageView, FileDataStorageManager stora
Account account, List<ThumbnailGenerationTask> asyncTasks)
throws IllegalArgumentException {
// Use a WeakReference to ensure the ImageView can be garbage collected
mImageViewReference = new WeakReference<ImageView>(imageView);
mImageViewReference = new WeakReference<>(imageView);
if (storageManager == null) {
throw new IllegalArgumentException("storageManager must not be NULL");
}
Expand All @@ -421,7 +421,7 @@ public ThumbnailGenerationTask(FileDataStorageManager storageManager, Account ac

public ThumbnailGenerationTask(ImageView imageView) {
// Use a WeakReference to ensure the ImageView can be garbage collected
mImageViewReference = new WeakReference<ImageView>(imageView);
mImageViewReference = new WeakReference<>(imageView);
}

@SuppressFBWarnings("Dm")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,18 @@

package com.owncloud.android.operations;

import android.util.Log;

import com.google.gson.GsonBuilder;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.comments.CommentFileRemoteOperation;
import com.owncloud.android.operations.common.SyncOperation;

import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;


/**
* Restore a {@link com.owncloud.android.lib.resources.files.FileVersion}.
* Comment file
*/
public class CommentFileOperation extends SyncOperation {

private static final String TAG = CommentFileOperation.class.getSimpleName();
private static final int POST_READ_TIMEOUT = 30000;
private static final int POST_CONNECTION_TIMEOUT = 5000;

private static final String ACTOR_ID = "actorId";
private static final String ACTOR_TYPE = "actorType";
private static final String ACTOR_TYPE_VALUE = "users";
private static final String VERB = "verb";
private static final String VERB_VALUE = "comment";
private static final String MESSAGE = "message";

private String message;
private String fileId;
private String userId;
Expand All @@ -76,37 +56,12 @@ public CommentFileOperation(String message, String fileId, String userId) {
*/
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = new CommentFileRemoteOperation(message, fileId, userId).execute(client, true);

RemoteOperationResult result;
try {
String url = client.getNewWebdavUri() + "/comments/files/" + fileId;
PostMethod postMethod = new PostMethod(url);
postMethod.addRequestHeader("Content-type", "application/json");

Map<String, String> values = new HashMap<>();
values.put(ACTOR_ID, userId);
values.put(ACTOR_TYPE, ACTOR_TYPE_VALUE);
values.put(VERB, VERB_VALUE);
values.put(MESSAGE, message);

String json = new GsonBuilder().create().toJson(values, Map.class);

postMethod.setRequestEntity(new StringRequestEntity(json));

int status = client.executeMethod(postMethod, POST_READ_TIMEOUT, POST_CONNECTION_TIMEOUT);

result = new RemoteOperationResult(isSuccess(status), postMethod);

client.exhaustResponse(postMethod.getResponseBodyAsStream());
} catch (IOException e) {
result = new RemoteOperationResult(e);
Log.e(TAG, "Post comment to file with id " + fileId + " failed: " + result.getLogMessage(), e);
if (!result.isSuccess()) {
Log_OC.e(this, "File with Id " + fileId + " could not be commented");
}

return result;
}

private boolean isSuccess(int status) {
return status == HttpStatus.SC_CREATED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.resources.files.CopyRemoteFileOperation;
import com.owncloud.android.lib.resources.files.CopyFileRemoteOperation;
import com.owncloud.android.operations.common.SyncOperation;


Expand Down Expand Up @@ -74,13 +74,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {
if (mFile.isFolder()) {
targetPath += OCFile.PATH_SEPARATOR;
}
CopyRemoteFileOperation operation = new CopyRemoteFileOperation(
mSrcPath,
targetPath,
false
);

RemoteOperationResult result = operation.execute(client);
RemoteOperationResult result = new CopyFileRemoteOperation(mSrcPath, targetPath, false).execute(client);

/// 3. local copy
if (result.isSuccess()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.files.CreateRemoteFolderOperation;
import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation;
import com.owncloud.android.lib.resources.files.RemoteFile;
import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation;
import com.owncloud.android.lib.resources.files.ReadFolderRemoteOperation;
import com.owncloud.android.lib.resources.files.model.RemoteFile;
import com.owncloud.android.operations.common.SyncOperation;
import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.MimeType;
Expand Down Expand Up @@ -61,12 +61,11 @@ public CreateFolderOperation(String remotePath, boolean createFullPath) {

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
CreateRemoteFolderOperation operation = new CreateRemoteFolderOperation(mRemotePath, mCreateFullPath);
RemoteOperationResult result = operation.execute(client, true);
RemoteOperationResult result = new CreateFolderRemoteOperation(mRemotePath, mCreateFullPath).execute(client);

if (result.isSuccess()) {
ReadRemoteFolderOperation remoteFolderOperation = new ReadRemoteFolderOperation(mRemotePath);
RemoteOperationResult remoteFolderOperationResult = remoteFolderOperation.execute(client, true);
RemoteOperationResult remoteFolderOperationResult = new ReadFolderRemoteOperation(mRemotePath)
.execute(client, true);

createdRemoteFolder = (RemoteFile) remoteFolderOperationResult.getData().get(0);
saveFolderInDB();
Expand All @@ -79,7 +78,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {

@Override
public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
if (operation instanceof CreateRemoteFolderOperation) {
if (operation instanceof CreateFolderRemoteOperation) {
onCreateRemoteFolderOperationFinish(result);
}
}
Expand Down
Loading