mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Merge pull request #85 from owncloud/update_share_link_for_OC_8.2
Update share link for oc 8.2
This commit is contained in:
commit
5985ba9a9f
@ -37,6 +37,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||
|
||||
/**
|
||||
* Provide a list shares for a specific file.
|
||||
@ -65,12 +66,14 @@ public class GetRemoteSharesForFileOperation extends RemoteOperation {
|
||||
* Constructor
|
||||
*
|
||||
* @param remoteFilePath Path to file or folder
|
||||
* @param reshares If set to false (default), only shares from the current user are returned
|
||||
* @param reshares If set to false (default), only shares from the current user are
|
||||
* returned
|
||||
* If set to true, all shares from the given file are returned
|
||||
* @param subfiles If set to false (default), lists only the folder being shared
|
||||
* If set to true, all shared files within the folder are returned.
|
||||
*/
|
||||
public GetRemoteSharesForFileOperation(String remoteFilePath, boolean reshares, boolean subfiles) {
|
||||
public GetRemoteSharesForFileOperation(String remoteFilePath, boolean reshares,
|
||||
boolean subfiles) {
|
||||
mRemoteFilePath = remoteFilePath;
|
||||
mReshares = reshares;
|
||||
mSubfiles = subfiles;
|
||||
@ -88,11 +91,11 @@ public class GetRemoteSharesForFileOperation extends RemoteOperation {
|
||||
get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH);
|
||||
|
||||
// Add Parameters to Get Method
|
||||
get.setQueryString(new NameValuePair[] {
|
||||
new NameValuePair(PARAM_PATH, mRemoteFilePath),
|
||||
new NameValuePair(PARAM_RESHARES, String.valueOf(mReshares)),
|
||||
new NameValuePair(PARAM_SUBFILES, String.valueOf(mSubfiles))
|
||||
});
|
||||
get.setQueryString(new NameValuePair[]{
|
||||
new NameValuePair(PARAM_PATH, mRemoteFilePath),
|
||||
new NameValuePair(PARAM_RESHARES, String.valueOf(mReshares)),
|
||||
new NameValuePair(PARAM_SUBFILES, String.valueOf(mSubfiles))
|
||||
});
|
||||
|
||||
get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
|
||||
|
||||
@ -114,8 +117,12 @@ public class GetRemoteSharesForFileOperation extends RemoteOperation {
|
||||
ArrayList<Object> sharesObjects = new ArrayList<Object>();
|
||||
for (OCShare share: mShares) {
|
||||
// Build the link
|
||||
if (share.getToken().length() > 0) {
|
||||
share.setShareLink(client.getBaseUri() + ShareUtils.SHARING_LINK_TOKEN + share.getToken());
|
||||
if (( share.getShareLink() == null) &&
|
||||
(share.getToken().length() > 0)) {
|
||||
String linkToken = ShareUtils.getSharingToken(
|
||||
client.getOwnCloudVersion());
|
||||
share.setShareLink(client.getBaseUri() + linkToken +
|
||||
share.getToken());
|
||||
}
|
||||
sharesObjects.add(share);
|
||||
}
|
||||
|
@ -24,6 +24,8 @@
|
||||
|
||||
package com.owncloud.android.lib.resources.shares;
|
||||
|
||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||
|
||||
/**
|
||||
* Contains Constants for Share Operation
|
||||
*
|
||||
@ -36,7 +38,18 @@ public class ShareUtils {
|
||||
// OCS Route
|
||||
public static final String SHARING_API_PATH ="/ocs/v1.php/apps/files_sharing/api/v1/shares";
|
||||
|
||||
// String to build the link with the token of a share: server address + "/public.php?service=files&t=" + token
|
||||
public static final String SHARING_LINK_TOKEN = "/public.php?service=files&t=";
|
||||
// String to build the link with the token of a share:
|
||||
// server address + "/public.php?service=files&t=" + token
|
||||
public static final String SHARING_LINK_TOKEN_BEFORE_VERSION_8 = "/public.php?service=files&t=";
|
||||
public static final String SHARING_LINK_TOKEN_AFTER_VERSION_8= "/index.php/s/";
|
||||
|
||||
public static String getSharingToken(OwnCloudVersion version){
|
||||
if (version!= null && version.isAfter8Version()){
|
||||
return SHARING_LINK_TOKEN_AFTER_VERSION_8;
|
||||
} else {
|
||||
return SHARING_LINK_TOKEN_BEFORE_VERSION_8;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -126,7 +126,8 @@ public class ShareXMLParser {
|
||||
* @throws XmlPullParserException
|
||||
* @throws IOException
|
||||
*/
|
||||
public ArrayList<OCShare> parseXMLResponse(InputStream is) throws XmlPullParserException, IOException {
|
||||
public ArrayList<OCShare> parseXMLResponse(InputStream is) throws XmlPullParserException,
|
||||
IOException {
|
||||
|
||||
try {
|
||||
// XMLPullParser
|
||||
@ -151,7 +152,8 @@ public class ShareXMLParser {
|
||||
* @throws XmlPullParserException
|
||||
* @throws IOException
|
||||
*/
|
||||
private ArrayList<OCShare> readOCS (XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||
private ArrayList<OCShare> readOCS (XmlPullParser parser) throws XmlPullParserException,
|
||||
IOException {
|
||||
ArrayList<OCShare> shares = new ArrayList<OCShare>();
|
||||
parser.require(XmlPullParser.START_TAG, ns , NODE_OCS);
|
||||
while (parser.next() != XmlPullParser.END_TAG) {
|
||||
@ -209,7 +211,8 @@ public class ShareXMLParser {
|
||||
* @throws XmlPullParserException
|
||||
* @throws IOException
|
||||
*/
|
||||
private ArrayList<OCShare> readData(XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||
private ArrayList<OCShare> readData(XmlPullParser parser) throws XmlPullParserException,
|
||||
IOException {
|
||||
ArrayList<OCShare> shares = new ArrayList<OCShare>();
|
||||
OCShare share = null;
|
||||
|
||||
@ -259,7 +262,8 @@ public class ShareXMLParser {
|
||||
* @throws XmlPullParserException
|
||||
* @throws IOException
|
||||
*/
|
||||
private void readElement(XmlPullParser parser, ArrayList<OCShare> shares) throws XmlPullParserException, IOException {
|
||||
private void readElement(XmlPullParser parser, ArrayList<OCShare> shares)
|
||||
throws XmlPullParserException, IOException {
|
||||
parser.require(XmlPullParser.START_TAG, ns, NODE_ELEMENT);
|
||||
|
||||
OCShare share = new OCShare();
|
||||
@ -273,7 +277,8 @@ public class ShareXMLParser {
|
||||
String name = parser.getName();
|
||||
|
||||
if (name.equalsIgnoreCase(NODE_ELEMENT)) {
|
||||
// patch to work around servers responding with extra <element> surrounding all the shares on the same file before
|
||||
// patch to work around servers responding with extra <element> surrounding all
|
||||
// the shares on the same file before
|
||||
// https://github.com/owncloud/core/issues/6992 was fixed
|
||||
readElement(parser, shares);
|
||||
|
||||
@ -327,6 +332,11 @@ public class ShareXMLParser {
|
||||
} else if (name.equalsIgnoreCase(NODE_SHARE_WITH_DISPLAY_NAME)) {
|
||||
share.setSharedWithDisplayName(readNode(parser, NODE_SHARE_WITH_DISPLAY_NAME));
|
||||
|
||||
} else if (name.equalsIgnoreCase(NODE_URL)) {
|
||||
share.setShareType(ShareType.PUBLIC_LINK);
|
||||
String value = readNode(parser, NODE_URL);
|
||||
share.setShareLink(value);
|
||||
|
||||
} else {
|
||||
skip(parser);
|
||||
}
|
||||
@ -344,7 +354,8 @@ public class ShareXMLParser {
|
||||
}
|
||||
|
||||
private void fixPathForFolder(OCShare share) {
|
||||
if (share.isFolder() && share.getPath() != null && share.getPath().length() > 0 && !share.getPath().endsWith(FileUtils.PATH_SEPARATOR)) {
|
||||
if (share.isFolder() && share.getPath() != null && share.getPath().length() > 0 &&
|
||||
!share.getPath().endsWith(FileUtils.PATH_SEPARATOR)) {
|
||||
share.setPath(share.getPath() + FileUtils.PATH_SEPARATOR);
|
||||
}
|
||||
}
|
||||
@ -357,7 +368,8 @@ public class ShareXMLParser {
|
||||
* @throws XmlPullParserException
|
||||
* @throws IOException
|
||||
*/
|
||||
private String readNode (XmlPullParser parser, String node) throws XmlPullParserException, IOException{
|
||||
private String readNode (XmlPullParser parser, String node) throws XmlPullParserException,
|
||||
IOException{
|
||||
parser.require(XmlPullParser.START_TAG, ns, node);
|
||||
String value = readText(parser);
|
||||
//Log_OC.d(TAG, "node= " + node + ", value= " + value);
|
||||
|
@ -43,6 +43,8 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> {
|
||||
|
||||
public static final int MINIMUM_SERVER_VERSION_FOR_REMOTE_THUMBNAILS = 0x07080000; // 7.8.0
|
||||
|
||||
public static final int VERSION_8 = 0x08000000; // 8.0
|
||||
|
||||
private static final int MAX_DOTS = 3;
|
||||
|
||||
// format is in version
|
||||
@ -129,7 +131,13 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> {
|
||||
return (mVersion >= MINIMUM_VERSION_WITH_FORBIDDEN_CHARS);
|
||||
}
|
||||
|
||||
public boolean supportsRemoteThumbnails() { return (mVersion >= MINIMUM_SERVER_VERSION_FOR_REMOTE_THUMBNAILS); }
|
||||
public boolean supportsRemoteThumbnails() {
|
||||
return (mVersion >= MINIMUM_SERVER_VERSION_FOR_REMOTE_THUMBNAILS);
|
||||
}
|
||||
|
||||
public boolean isAfter8Version(){
|
||||
return (mVersion >= VERSION_8);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user