mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Add support for optional name in public shares (WIP)
This commit is contained in:
parent
0dce40b160
commit
188ce07155
@ -1,5 +1,5 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/* ownCloud Android Library is available under MIT license
|
||||||
* Copyright (C) 2016 ownCloud GmbH.
|
* Copyright (C) 2017 ownCloud GmbH.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
package com.owncloud.android.lib.resources.shares;
|
package com.owncloud.android.lib.resources.shares;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
@ -35,9 +36,9 @@ import com.owncloud.android.lib.resources.files.FileUtils;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains the data of a Share from the Share API
|
* Contains the data of a Share from the Share API
|
||||||
*
|
|
||||||
* @author masensio
|
|
||||||
*
|
*
|
||||||
|
* @author masensio
|
||||||
|
* @author David A. Velasco
|
||||||
*/
|
*/
|
||||||
public class OCShare implements Parcelable, Serializable {
|
public class OCShare implements Parcelable, Serializable {
|
||||||
|
|
||||||
@ -56,33 +57,27 @@ public class OCShare implements Parcelable, Serializable {
|
|||||||
public static final int SHARE_PERMISSION_FLAG = 16;
|
public static final int SHARE_PERMISSION_FLAG = 16;
|
||||||
public static final int MAXIMUM_PERMISSIONS_FOR_FILE =
|
public static final int MAXIMUM_PERMISSIONS_FOR_FILE =
|
||||||
READ_PERMISSION_FLAG +
|
READ_PERMISSION_FLAG +
|
||||||
UPDATE_PERMISSION_FLAG +
|
UPDATE_PERMISSION_FLAG +
|
||||||
SHARE_PERMISSION_FLAG
|
SHARE_PERMISSION_FLAG;
|
||||||
;
|
|
||||||
public static final int MAXIMUM_PERMISSIONS_FOR_FOLDER =
|
public static final int MAXIMUM_PERMISSIONS_FOR_FOLDER =
|
||||||
MAXIMUM_PERMISSIONS_FOR_FILE +
|
MAXIMUM_PERMISSIONS_FOR_FILE +
|
||||||
CREATE_PERMISSION_FLAG +
|
CREATE_PERMISSION_FLAG +
|
||||||
DELETE_PERMISSION_FLAG
|
DELETE_PERMISSION_FLAG;
|
||||||
;
|
|
||||||
public static final int FEDERATED_PERMISSIONS_FOR_FILE_UP_TO_OC9 =
|
public static final int FEDERATED_PERMISSIONS_FOR_FILE_UP_TO_OC9 =
|
||||||
READ_PERMISSION_FLAG +
|
READ_PERMISSION_FLAG +
|
||||||
UPDATE_PERMISSION_FLAG
|
UPDATE_PERMISSION_FLAG;
|
||||||
;
|
|
||||||
public static final int FEDERATED_PERMISSIONS_FOR_FILE_AFTER_OC9 =
|
public static final int FEDERATED_PERMISSIONS_FOR_FILE_AFTER_OC9 =
|
||||||
READ_PERMISSION_FLAG +
|
READ_PERMISSION_FLAG +
|
||||||
UPDATE_PERMISSION_FLAG +
|
UPDATE_PERMISSION_FLAG +
|
||||||
SHARE_PERMISSION_FLAG
|
SHARE_PERMISSION_FLAG;
|
||||||
;
|
|
||||||
public static final int FEDERATED_PERMISSIONS_FOR_FOLDER_UP_TO_OC9 =
|
public static final int FEDERATED_PERMISSIONS_FOR_FOLDER_UP_TO_OC9 =
|
||||||
READ_PERMISSION_FLAG +
|
READ_PERMISSION_FLAG +
|
||||||
UPDATE_PERMISSION_FLAG +
|
UPDATE_PERMISSION_FLAG +
|
||||||
CREATE_PERMISSION_FLAG +
|
CREATE_PERMISSION_FLAG +
|
||||||
DELETE_PERMISSION_FLAG
|
DELETE_PERMISSION_FLAG;
|
||||||
;
|
|
||||||
public static final int FEDERATED_PERMISSIONS_FOR_FOLDER_AFTER_OC9 =
|
public static final int FEDERATED_PERMISSIONS_FOR_FOLDER_AFTER_OC9 =
|
||||||
FEDERATED_PERMISSIONS_FOR_FOLDER_UP_TO_OC9 +
|
FEDERATED_PERMISSIONS_FOR_FOLDER_UP_TO_OC9 +
|
||||||
SHARE_PERMISSION_FLAG
|
SHARE_PERMISSION_FLAG;
|
||||||
;
|
|
||||||
|
|
||||||
private long mId;
|
private long mId;
|
||||||
private long mFileSource;
|
private long mFileSource;
|
||||||
@ -95,33 +90,34 @@ public class OCShare implements Parcelable, Serializable {
|
|||||||
private long mExpirationDate;
|
private long mExpirationDate;
|
||||||
private String mToken;
|
private String mToken;
|
||||||
private String mSharedWithDisplayName;
|
private String mSharedWithDisplayName;
|
||||||
|
private String mName;
|
||||||
private boolean mIsFolder;
|
private boolean mIsFolder;
|
||||||
private long mUserId;
|
private long mUserId;
|
||||||
private long mRemoteId;
|
private long mRemoteId;
|
||||||
private String mShareLink;
|
private String mShareLink;
|
||||||
|
|
||||||
public OCShare() {
|
public OCShare() {
|
||||||
super();
|
super();
|
||||||
resetData();
|
resetData();
|
||||||
}
|
}
|
||||||
|
|
||||||
public OCShare(String path) {
|
public OCShare(String path) {
|
||||||
resetData();
|
resetData();
|
||||||
if (path == null || path.length() <= 0 || !path.startsWith(FileUtils.PATH_SEPARATOR)) {
|
if (path == null || path.length() <= 0 || !path.startsWith(FileUtils.PATH_SEPARATOR)) {
|
||||||
Log_OC.e(TAG, "Trying to create a OCShare with a non valid path");
|
Log_OC.e(TAG, "Trying to create a OCShare with a non valid path");
|
||||||
throw new IllegalArgumentException("Trying to create a OCShare with a non valid path: " + path);
|
throw new IllegalArgumentException("Trying to create a OCShare with a non valid path: " + path);
|
||||||
}
|
}
|
||||||
mPath = path;
|
mPath = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used internally. Reset all file properties
|
* Used internally. Reset all file properties
|
||||||
*/
|
*/
|
||||||
private void resetData() {
|
private void resetData() {
|
||||||
mId = -1;
|
mId = -1;
|
||||||
mFileSource = 0;
|
mFileSource = 0;
|
||||||
mItemSource = 0;
|
mItemSource = 0;
|
||||||
mShareType = ShareType.NO_SHARED;
|
mShareType = ShareType.NO_SHARED;
|
||||||
mShareWith = "";
|
mShareWith = "";
|
||||||
mPath = "";
|
mPath = "";
|
||||||
mPermissions = -1;
|
mPermissions = -1;
|
||||||
@ -133,18 +129,19 @@ public class OCShare implements Parcelable, Serializable {
|
|||||||
mUserId = -1;
|
mUserId = -1;
|
||||||
mRemoteId = -1;
|
mRemoteId = -1;
|
||||||
mShareLink = "";
|
mShareLink = "";
|
||||||
}
|
mName = "";
|
||||||
|
}
|
||||||
|
|
||||||
/// Getters and Setters
|
/// Getters and Setters
|
||||||
|
|
||||||
public long getId() {
|
public long getId() {
|
||||||
return mId;
|
return mId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(long id){
|
public void setId(long id) {
|
||||||
mId = id;
|
mId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getFileSource() {
|
public long getFileSource() {
|
||||||
return mFileSource;
|
return mFileSource;
|
||||||
}
|
}
|
||||||
@ -225,6 +222,20 @@ public class OCShare implements Parcelable, Serializable {
|
|||||||
this.mSharedWithDisplayName = (sharedWithDisplayName != null) ? sharedWithDisplayName : "";
|
this.mSharedWithDisplayName = (sharedWithDisplayName != null) ? sharedWithDisplayName : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
if (mName.length() > 0) {
|
||||||
|
return mName;
|
||||||
|
}
|
||||||
|
if (mPath.length() > 0) {
|
||||||
|
return (new File(mPath)).getName();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
mName = (name != null) ? name : "";
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isFolder() {
|
public boolean isFolder() {
|
||||||
return mIsFolder;
|
return mIsFolder;
|
||||||
}
|
}
|
||||||
@ -248,11 +259,11 @@ public class OCShare implements Parcelable, Serializable {
|
|||||||
public void setIdRemoteShared(long remoteId) {
|
public void setIdRemoteShared(long remoteId) {
|
||||||
this.mRemoteId = remoteId;
|
this.mRemoteId = remoteId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getShareLink() {
|
public String getShareLink() {
|
||||||
return this.mShareLink;
|
return this.mShareLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setShareLink(String shareLink) {
|
public void setShareLink(String shareLink) {
|
||||||
this.mShareLink = (shareLink != null) ? shareLink : "";
|
this.mShareLink = (shareLink != null) ? shareLink : "";
|
||||||
}
|
}
|
||||||
@ -260,8 +271,8 @@ public class OCShare implements Parcelable, Serializable {
|
|||||||
public boolean isPasswordProtected() {
|
public boolean isPasswordProtected() {
|
||||||
return ShareType.PUBLIC_LINK.equals(mShareType) && mShareWith.length() > 0;
|
return ShareType.PUBLIC_LINK.equals(mShareType) && mShareWith.length() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parcelable Methods
|
* Parcelable Methods
|
||||||
*/
|
*/
|
||||||
public static final Parcelable.Creator<OCShare> CREATOR = new Parcelable.Creator<OCShare>() {
|
public static final Parcelable.Creator<OCShare> CREATOR = new Parcelable.Creator<OCShare>() {
|
||||||
@ -275,19 +286,19 @@ public class OCShare implements Parcelable, Serializable {
|
|||||||
return new OCShare[size];
|
return new OCShare[size];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reconstruct from parcel
|
* Reconstruct from parcel
|
||||||
*
|
*
|
||||||
* @param source The source parcel
|
* @param source The source parcel
|
||||||
*/
|
*/
|
||||||
protected OCShare(Parcel source) {
|
protected OCShare(Parcel source) {
|
||||||
readFromParcel(source);
|
readFromParcel(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readFromParcel(Parcel source) {
|
public void readFromParcel(Parcel source) {
|
||||||
mId = source.readLong();
|
mId = source.readLong();
|
||||||
|
|
||||||
mFileSource = source.readLong();
|
mFileSource = source.readLong();
|
||||||
mItemSource = source.readLong();
|
mItemSource = source.readLong();
|
||||||
try {
|
try {
|
||||||
@ -306,18 +317,19 @@ public class OCShare implements Parcelable, Serializable {
|
|||||||
mUserId = source.readLong();
|
mUserId = source.readLong();
|
||||||
mRemoteId = source.readLong();
|
mRemoteId = source.readLong();
|
||||||
mShareLink = source.readString();
|
mShareLink = source.readString();
|
||||||
|
mName = source.readString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return this.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int describeContents() {
|
|
||||||
return this.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
dest.writeLong(mId);
|
dest.writeLong(mId);
|
||||||
dest.writeLong(mFileSource);
|
dest.writeLong(mFileSource);
|
||||||
dest.writeLong(mItemSource);
|
dest.writeLong(mItemSource);
|
||||||
dest.writeString((mShareType == null) ? "" : mShareType.name());
|
dest.writeString((mShareType == null) ? "" : mShareType.name());
|
||||||
@ -332,6 +344,7 @@ public class OCShare implements Parcelable, Serializable {
|
|||||||
dest.writeLong(mUserId);
|
dest.writeLong(mUserId);
|
||||||
dest.writeLong(mRemoteId);
|
dest.writeLong(mRemoteId);
|
||||||
dest.writeString(mShareLink);
|
dest.writeString(mShareLink);
|
||||||
|
dest.writeString(mName);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -94,6 +94,7 @@ public class ShareToRemoteOperationResultParser {
|
|||||||
share.getShareLink().length() <= 0) &&
|
share.getShareLink().length() <= 0) &&
|
||||||
share.getToken().length() > 0
|
share.getToken().length() > 0
|
||||||
) {
|
) {
|
||||||
|
// TODO - deal with https://github.com/owncloud/android/issues/1811
|
||||||
if (mServerBaseUri != null) {
|
if (mServerBaseUri != null) {
|
||||||
String sharingLinkPath = ShareUtils.getSharingLinkPath(mOwnCloudVersion);
|
String sharingLinkPath = ShareUtils.getSharingLinkPath(mOwnCloudVersion);
|
||||||
share.setShareLink(mServerBaseUri + sharingLinkPath + share.getToken());
|
share.setShareLink(mServerBaseUri + sharingLinkPath + share.getToken());
|
||||||
|
@ -76,6 +76,7 @@ public class ShareXMLParser {
|
|||||||
private static final String NODE_STORAGE = "storage";
|
private static final String NODE_STORAGE = "storage";
|
||||||
private static final String NODE_MAIL_SEND = "mail_send";
|
private static final String NODE_MAIL_SEND = "mail_send";
|
||||||
private static final String NODE_SHARE_WITH_DISPLAY_NAME = "share_with_displayname";
|
private static final String NODE_SHARE_WITH_DISPLAY_NAME = "share_with_displayname";
|
||||||
|
private static final String NODE_NAME = "name";
|
||||||
|
|
||||||
private static final String NODE_URL = "url";
|
private static final String NODE_URL = "url";
|
||||||
|
|
||||||
@ -356,7 +357,10 @@ public class ShareXMLParser {
|
|||||||
String value = readNode(parser, NODE_URL);
|
String value = readNode(parser, NODE_URL);
|
||||||
share.setShareLink(value);
|
share.setShareLink(value);
|
||||||
|
|
||||||
} else {
|
} else if (name.equalsIgnoreCase(NODE_NAME)) {
|
||||||
|
share.setName(readNode(parser, NODE_NAME));
|
||||||
|
|
||||||
|
} else {
|
||||||
skip(parser);
|
skip(parser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,6 +55,7 @@ public class UpdateRemoteShareOperation extends RemoteOperation {
|
|||||||
|
|
||||||
private static final String TAG = GetRemoteShareOperation.class.getSimpleName();
|
private static final String TAG = GetRemoteShareOperation.class.getSimpleName();
|
||||||
|
|
||||||
|
private static final String PARAM_NAME = "name";
|
||||||
private static final String PARAM_PASSWORD = "password";
|
private static final String PARAM_PASSWORD = "password";
|
||||||
private static final String PARAM_EXPIRATION_DATE = "expireDate";
|
private static final String PARAM_EXPIRATION_DATE = "expireDate";
|
||||||
private static final String PARAM_PERMISSIONS = "permissions";
|
private static final String PARAM_PERMISSIONS = "permissions";
|
||||||
@ -87,6 +89,7 @@ public class UpdateRemoteShareOperation extends RemoteOperation {
|
|||||||
* Upload permissions for the public link (only folders)
|
* Upload permissions for the public link (only folders)
|
||||||
*/
|
*/
|
||||||
private Boolean mPublicUpload;
|
private Boolean mPublicUpload;
|
||||||
|
private String mName;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -102,6 +105,17 @@ public class UpdateRemoteShareOperation extends RemoteOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set name to update in Share resource. Ignored by servers previous to version 10.0.0
|
||||||
|
*
|
||||||
|
* @param name Name to set to the target share.
|
||||||
|
* Empty string clears the current name.
|
||||||
|
* Null results in no update applied to the name.
|
||||||
|
*/
|
||||||
|
public void setName(String name) {
|
||||||
|
this.mName = name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set password to update in Share resource.
|
* Set password to update in Share resource.
|
||||||
*
|
*
|
||||||
@ -150,38 +164,41 @@ public class UpdateRemoteShareOperation extends RemoteOperation {
|
|||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||||
RemoteOperationResult result = null;
|
RemoteOperationResult result = null;
|
||||||
int status = -1;
|
int status;
|
||||||
|
|
||||||
/// prepare array of parameters to update
|
/// prepare array of parameters to update
|
||||||
List<Pair<String, String>> parametersToUpdate = new ArrayList<Pair<String, String>>();
|
List<Pair<String, String>> parametersToUpdate = new ArrayList<>();
|
||||||
|
if (mName != null) {
|
||||||
|
parametersToUpdate.add(new Pair<>(PARAM_NAME, mName));
|
||||||
|
}
|
||||||
if (mPassword != null) {
|
if (mPassword != null) {
|
||||||
parametersToUpdate.add(new Pair<String, String>(PARAM_PASSWORD, mPassword));
|
parametersToUpdate.add(new Pair<>(PARAM_PASSWORD, mPassword));
|
||||||
}
|
}
|
||||||
if (mExpirationDateInMillis < 0) {
|
if (mExpirationDateInMillis < 0) {
|
||||||
// clear expiration date
|
// clear expiration date
|
||||||
parametersToUpdate.add(new Pair(PARAM_EXPIRATION_DATE, ""));
|
parametersToUpdate.add(new Pair<>(PARAM_EXPIRATION_DATE, ""));
|
||||||
|
|
||||||
} else if (mExpirationDateInMillis > 0) {
|
} else if (mExpirationDateInMillis > 0) {
|
||||||
// set expiration date
|
// set expiration date
|
||||||
DateFormat dateFormat = new SimpleDateFormat(FORMAT_EXPIRATION_DATE);
|
DateFormat dateFormat = new SimpleDateFormat(FORMAT_EXPIRATION_DATE, Locale.GERMAN);
|
||||||
Calendar expirationDate = Calendar.getInstance();
|
Calendar expirationDate = Calendar.getInstance();
|
||||||
expirationDate.setTimeInMillis(mExpirationDateInMillis);
|
expirationDate.setTimeInMillis(mExpirationDateInMillis);
|
||||||
String formattedExpirationDate = dateFormat.format(expirationDate.getTime());
|
String formattedExpirationDate = dateFormat.format(expirationDate.getTime());
|
||||||
parametersToUpdate.add(new Pair(PARAM_EXPIRATION_DATE, formattedExpirationDate));
|
parametersToUpdate.add(new Pair<>(PARAM_EXPIRATION_DATE, formattedExpirationDate));
|
||||||
|
|
||||||
} // else, ignore - no update
|
} // else, ignore - no update
|
||||||
if (mPermissions > 0) {
|
if (mPermissions > 0) {
|
||||||
// set permissions
|
// set permissions
|
||||||
parametersToUpdate.add(new Pair(PARAM_PERMISSIONS, Integer.toString(mPermissions)));
|
parametersToUpdate.add(new Pair<>(PARAM_PERMISSIONS, Integer.toString(mPermissions)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mPublicUpload != null) {
|
if (mPublicUpload != null) {
|
||||||
parametersToUpdate.add(new Pair(PARAM_PUBLIC_UPLOAD, Boolean.toString(mPublicUpload)));
|
parametersToUpdate.add(new Pair<>(PARAM_PUBLIC_UPLOAD, Boolean.toString(mPublicUpload)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// perform required PUT requests
|
/// perform required PUT requests
|
||||||
PutMethod put = null;
|
PutMethod put = null;
|
||||||
String uriString = null;
|
String uriString;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Uri requestUri = client.getBaseUri();
|
Uri requestUri = client.getBaseUri();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user