mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Include and parse shareWithAdditionalInfo to be used in shares autocompletion and list
This commit is contained in:
parent
249e25768b
commit
59ed7e42ec
@ -36,6 +36,7 @@ import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod;
|
||||
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 org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@ -46,13 +47,13 @@ import static com.owncloud.android.lib.common.operations.RemoteOperationResult.R
|
||||
|
||||
/**
|
||||
* Created by masensio on 08/10/2015.
|
||||
* <p>
|
||||
*
|
||||
* Retrieves a list of sharees (possible targets of a share) from the ownCloud server.
|
||||
* <p>
|
||||
*
|
||||
* Currently only handles users and groups. Users in other OC servers (federation) should be added later.
|
||||
* <p>
|
||||
*
|
||||
* Depends on SHAREE API. {@See https://github.com/owncloud/documentation/issues/1626}
|
||||
* <p>
|
||||
*
|
||||
* Syntax:
|
||||
* Entry point: ocs/v2.php/apps/files_sharing/api/v1/sharees
|
||||
* HTTP method: GET
|
||||
@ -61,7 +62,7 @@ import static com.owncloud.android.lib.common.operations.RemoteOperationResult.R
|
||||
* url argument: search - string, optional
|
||||
* url arguments: perPage - int, optional
|
||||
* url arguments: page - int, optional
|
||||
* <p>
|
||||
*
|
||||
* Status codes:
|
||||
* 100 - successful
|
||||
*
|
||||
@ -71,22 +72,22 @@ import static com.owncloud.android.lib.common.operations.RemoteOperationResult.R
|
||||
*/
|
||||
public class GetRemoteShareesOperation extends RemoteOperation<ArrayList<JSONObject>> {
|
||||
|
||||
public static final String NODE_VALUE = "value";
|
||||
public static final String PROPERTY_LABEL = "label";
|
||||
public static final String PROPERTY_SHARE_TYPE = "shareType";
|
||||
public static final String PROPERTY_SHARE_WITH = "shareWith";
|
||||
private static final String TAG = GetRemoteShareesOperation.class.getSimpleName();
|
||||
|
||||
// OCS Routes
|
||||
private static final String OCS_ROUTE = "ocs/v2.php/apps/files_sharing/api/v1/sharees"; // from OC 8.2
|
||||
|
||||
// Arguments - names
|
||||
private static final String PARAM_FORMAT = "format";
|
||||
private static final String PARAM_ITEM_TYPE = "itemType";
|
||||
private static final String PARAM_SEARCH = "search";
|
||||
private static final String PARAM_PAGE = "page"; // default = 1
|
||||
private static final String PARAM_PER_PAGE = "perPage"; // default = 200
|
||||
|
||||
// Arguments - constant values
|
||||
private static final String VALUE_FORMAT = "json";
|
||||
private static final String VALUE_ITEM_TYPE = "file"; // to get the server search for users / groups
|
||||
|
||||
// JSON Node names
|
||||
private static final String NODE_OCS = "ocs";
|
||||
private static final String NODE_DATA = "data";
|
||||
@ -94,6 +95,12 @@ public class GetRemoteShareesOperation extends RemoteOperation<ArrayList<JSONObj
|
||||
private static final String NODE_USERS = "users";
|
||||
private static final String NODE_GROUPS = "groups";
|
||||
private static final String NODE_REMOTES = "remotes";
|
||||
public static final String NODE_VALUE = "value";
|
||||
public static final String PROPERTY_LABEL = "label";
|
||||
public static final String PROPERTY_SHARE_TYPE = "shareType";
|
||||
public static final String PROPERTY_SHARE_WITH = "shareWith";
|
||||
public static final String PROPERTY_SHARE_WITH_ADDITIONAL_INFO = "shareWithAdditionalInfo";
|
||||
|
||||
private String mSearchString;
|
||||
private int mPage;
|
||||
private int mPerPage;
|
||||
@ -115,7 +122,7 @@ public class GetRemoteShareesOperation extends RemoteOperation<ArrayList<JSONObj
|
||||
protected RemoteOperationResult<ArrayList<JSONObject>> run(OwnCloudClient client) {
|
||||
RemoteOperationResult<ArrayList<JSONObject>> result;
|
||||
|
||||
try {
|
||||
try{
|
||||
Uri requestUri = client.getBaseUri();
|
||||
Uri.Builder uriBuilder = requestUri.buildUpon()
|
||||
.appendEncodedPath(OCS_ROUTE)
|
||||
@ -132,7 +139,7 @@ public class GetRemoteShareesOperation extends RemoteOperation<ArrayList<JSONObj
|
||||
int status = client.executeHttpMethod(getMethod);
|
||||
String response = getMethod.getResponseBodyAsString();
|
||||
|
||||
if (isSuccess(status)) {
|
||||
if(isSuccess(status)) {
|
||||
Log_OC.d(TAG, "Successful response: " + response);
|
||||
|
||||
// Parse the response
|
||||
@ -156,8 +163,8 @@ public class GetRemoteShareesOperation extends RemoteOperation<ArrayList<JSONObj
|
||||
};
|
||||
|
||||
ArrayList<JSONObject> data = new ArrayList<>(); // For result data
|
||||
for (int i = 0; i < 6; i++) {
|
||||
for (int j = 0; j < jsonResults[i].length(); j++) {
|
||||
for (int i=0; i<6; i++) {
|
||||
for(int j=0; j< jsonResults[i].length(); j++){
|
||||
JSONObject jsonResult = jsonResults[i].getJSONObject(j);
|
||||
data.add(jsonResult);
|
||||
Log_OC.d(TAG, "*** Added item: " + jsonResult.getString(PROPERTY_LABEL));
|
||||
@ -167,7 +174,7 @@ public class GetRemoteShareesOperation extends RemoteOperation<ArrayList<JSONObj
|
||||
result = new RemoteOperationResult<>(OK);
|
||||
result.setData(data);
|
||||
|
||||
Log_OC.d(TAG, "*** Get Users or groups completed ");
|
||||
Log_OC.d(TAG, "*** Get Users or groups completed " );
|
||||
|
||||
} else {
|
||||
result = new RemoteOperationResult<>(getMethod);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* ownCloud Android Library is available under MIT license
|
||||
* Copyright (C) 2017 ownCloud GmbH.
|
||||
* Copyright (C) 2019 ownCloud GmbH.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@ -24,22 +24,32 @@
|
||||
|
||||
package com.owncloud.android.lib.resources.shares;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.files.FileUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Contains the data of a Share from the Share API
|
||||
*
|
||||
* @author masensio
|
||||
* @author David A. Velasco
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
public class OCShare implements Parcelable, Serializable {
|
||||
|
||||
/**
|
||||
* Generated - should be refreshed every time the class changes!!
|
||||
*/
|
||||
private static final long serialVersionUID = 4124975224281327921L;
|
||||
|
||||
private static final String TAG = OCShare.class.getSimpleName();
|
||||
|
||||
public static final int DEFAULT_PERMISSION = -1;
|
||||
public static final int READ_PERMISSION_FLAG = 1;
|
||||
public static final int UPDATE_PERMISSION_FLAG = 2;
|
||||
@ -69,25 +79,7 @@ public class OCShare implements Parcelable, Serializable {
|
||||
public static final int FEDERATED_PERMISSIONS_FOR_FOLDER_AFTER_OC9 =
|
||||
FEDERATED_PERMISSIONS_FOR_FOLDER_UP_TO_OC9 +
|
||||
SHARE_PERMISSION_FLAG;
|
||||
/**
|
||||
* Parcelable Methods
|
||||
*/
|
||||
public static final Parcelable.Creator<OCShare> CREATOR = new Parcelable.Creator<OCShare>() {
|
||||
@Override
|
||||
public OCShare createFromParcel(Parcel source) {
|
||||
return new OCShare(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OCShare[] newArray(int size) {
|
||||
return new OCShare[size];
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Generated - should be refreshed every time the class changes!!
|
||||
*/
|
||||
private static final long serialVersionUID = 4124975224281327921L;
|
||||
private static final String TAG = OCShare.class.getSimpleName();
|
||||
private long mId;
|
||||
private long mFileSource;
|
||||
private long mItemSource;
|
||||
@ -99,6 +91,7 @@ public class OCShare implements Parcelable, Serializable {
|
||||
private long mExpirationDate;
|
||||
private String mToken;
|
||||
private String mSharedWithDisplayName;
|
||||
private String mSharedWithAdditionalInfo;
|
||||
private String mName;
|
||||
private boolean mIsFolder;
|
||||
private long mUserId;
|
||||
@ -119,17 +112,6 @@ public class OCShare implements Parcelable, Serializable {
|
||||
mPath = path;
|
||||
}
|
||||
|
||||
/// Getters and Setters
|
||||
|
||||
/**
|
||||
* Reconstruct from parcel
|
||||
*
|
||||
* @param source The source parcel
|
||||
*/
|
||||
protected OCShare(Parcel source) {
|
||||
readFromParcel(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used internally. Reset all file properties
|
||||
*/
|
||||
@ -145,6 +127,7 @@ public class OCShare implements Parcelable, Serializable {
|
||||
mExpirationDate = 0;
|
||||
mToken = "";
|
||||
mSharedWithDisplayName = "";
|
||||
mSharedWithAdditionalInfo = "";
|
||||
mIsFolder = false;
|
||||
mUserId = -1;
|
||||
mRemoteId = -1;
|
||||
@ -152,6 +135,8 @@ public class OCShare implements Parcelable, Serializable {
|
||||
mName = "";
|
||||
}
|
||||
|
||||
/// Getters and Setters
|
||||
|
||||
public long getId() {
|
||||
return mId;
|
||||
}
|
||||
@ -240,6 +225,14 @@ public class OCShare implements Parcelable, Serializable {
|
||||
this.mSharedWithDisplayName = (sharedWithDisplayName != null) ? sharedWithDisplayName : "";
|
||||
}
|
||||
|
||||
public String getSharedWithAdditionalInfo() {
|
||||
return mSharedWithAdditionalInfo;
|
||||
}
|
||||
|
||||
public void setSharedWithAdditionalInfo(String sharedWithAdditionalInfo) {
|
||||
this.mSharedWithAdditionalInfo = sharedWithAdditionalInfo;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return mName;
|
||||
}
|
||||
@ -284,6 +277,30 @@ public class OCShare implements Parcelable, Serializable {
|
||||
return ShareType.PUBLIC_LINK.equals(mShareType) && mShareWith.length() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parcelable Methods
|
||||
*/
|
||||
public static final Parcelable.Creator<OCShare> CREATOR = new Parcelable.Creator<OCShare>() {
|
||||
@Override
|
||||
public OCShare createFromParcel(Parcel source) {
|
||||
return new OCShare(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OCShare[] newArray(int size) {
|
||||
return new OCShare[size];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Reconstruct from parcel
|
||||
*
|
||||
* @param source The source parcel
|
||||
*/
|
||||
protected OCShare(Parcel source) {
|
||||
readFromParcel(source);
|
||||
}
|
||||
|
||||
public void readFromParcel(Parcel source) {
|
||||
mId = source.readLong();
|
||||
|
||||
@ -301,6 +318,7 @@ public class OCShare implements Parcelable, Serializable {
|
||||
mExpirationDate = source.readLong();
|
||||
mToken = source.readString();
|
||||
mSharedWithDisplayName = source.readString();
|
||||
mSharedWithAdditionalInfo = source.readString();
|
||||
mIsFolder = source.readInt() == 0;
|
||||
mUserId = source.readLong();
|
||||
mRemoteId = source.readLong();
|
||||
@ -308,11 +326,13 @@ public class OCShare implements Parcelable, Serializable {
|
||||
mName = source.readString();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return this.hashCode();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeLong(mId);
|
||||
@ -326,11 +346,11 @@ public class OCShare implements Parcelable, Serializable {
|
||||
dest.writeLong(mExpirationDate);
|
||||
dest.writeString(mToken);
|
||||
dest.writeString(mSharedWithDisplayName);
|
||||
dest.writeString(mSharedWithAdditionalInfo);
|
||||
dest.writeInt(mIsFolder ? 1 : 0);
|
||||
dest.writeLong(mUserId);
|
||||
dest.writeLong(mRemoteId);
|
||||
dest.writeString(mShareLink);
|
||||
dest.writeString(mName);
|
||||
}
|
||||
|
||||
}
|
@ -28,6 +28,7 @@ import android.util.Xml;
|
||||
|
||||
import com.owncloud.android.lib.common.network.WebdavUtils;
|
||||
import com.owncloud.android.lib.resources.files.FileUtils;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
@ -36,11 +37,8 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
|
||||
//import android.util.Log;
|
||||
|
||||
/**
|
||||
* Parser for Share API Response
|
||||
*
|
||||
* @author masensio
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
@ -77,6 +75,7 @@ public class ShareXMLParser {
|
||||
private static final String NODE_STORAGE = "storage";
|
||||
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_ADDITIONAL_INFO = "share_with_additional_info";
|
||||
private static final String NODE_NAME = "name";
|
||||
|
||||
private static final String NODE_URL = "url";
|
||||
@ -92,11 +91,6 @@ public class ShareXMLParser {
|
||||
private int mStatusCode;
|
||||
private String mMessage;
|
||||
|
||||
// Constructor
|
||||
public ShareXMLParser() {
|
||||
mStatusCode = -1;
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
public String getStatus() {
|
||||
return mStatus;
|
||||
@ -122,6 +116,11 @@ public class ShareXMLParser {
|
||||
this.mMessage = message;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
public ShareXMLParser() {
|
||||
mStatusCode = -1;
|
||||
}
|
||||
|
||||
public boolean isSuccess() {
|
||||
return mStatusCode == SUCCESS;
|
||||
}
|
||||
@ -140,7 +139,6 @@ public class ShareXMLParser {
|
||||
|
||||
/**
|
||||
* Parse is as response of Share API
|
||||
*
|
||||
* @param is
|
||||
* @return List of ShareRemoteFiles
|
||||
* @throws XmlPullParserException
|
||||
@ -167,16 +165,15 @@ public class ShareXMLParser {
|
||||
|
||||
/**
|
||||
* Parse OCS node
|
||||
*
|
||||
* @param parser
|
||||
* @return List of ShareRemoteFiles
|
||||
* @throws XmlPullParserException
|
||||
* @throws IOException
|
||||
*/
|
||||
private ArrayList<OCShare> readOCS(XmlPullParser parser) throws XmlPullParserException,
|
||||
private ArrayList<OCShare> readOCS (XmlPullParser parser) throws XmlPullParserException,
|
||||
IOException {
|
||||
ArrayList<OCShare> shares = new ArrayList<>();
|
||||
parser.require(XmlPullParser.START_TAG, ns, NODE_OCS);
|
||||
parser.require(XmlPullParser.START_TAG, ns , NODE_OCS);
|
||||
while (parser.next() != XmlPullParser.END_TAG) {
|
||||
if (parser.getEventType() != XmlPullParser.START_TAG) {
|
||||
continue;
|
||||
@ -197,7 +194,6 @@ public class ShareXMLParser {
|
||||
|
||||
/**
|
||||
* Parse Meta node
|
||||
*
|
||||
* @param parser
|
||||
* @throws XmlPullParserException
|
||||
* @throws IOException
|
||||
@ -229,7 +225,6 @@ public class ShareXMLParser {
|
||||
|
||||
/**
|
||||
* Parse Data node
|
||||
*
|
||||
* @param parser
|
||||
* @return
|
||||
* @throws XmlPullParserException
|
||||
@ -281,9 +276,9 @@ public class ShareXMLParser {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse Element node
|
||||
*
|
||||
* @param parser
|
||||
* @return
|
||||
* @throws XmlPullParserException
|
||||
@ -359,6 +354,9 @@ 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_SHARE_WITH_ADDITIONAL_INFO)) {
|
||||
share.setSharedWithAdditionalInfo(readNode(parser, NODE_SHARE_WITH_ADDITIONAL_INFO));
|
||||
|
||||
} else if (name.equalsIgnoreCase(NODE_URL)) {
|
||||
String value = readNode(parser, NODE_URL);
|
||||
share.setShareLink(value);
|
||||
@ -389,15 +387,14 @@ public class ShareXMLParser {
|
||||
|
||||
/**
|
||||
* Parse a node, to obtain its text. Needs readText method
|
||||
*
|
||||
* @param parser
|
||||
* @param node
|
||||
* @return Text of the node
|
||||
* @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);
|
||||
@ -407,7 +404,6 @@ public class ShareXMLParser {
|
||||
|
||||
/**
|
||||
* Read the text from a node
|
||||
*
|
||||
* @param parser
|
||||
* @return Text of the node
|
||||
* @throws IOException
|
||||
@ -424,7 +420,6 @@ public class ShareXMLParser {
|
||||
|
||||
/**
|
||||
* Skip tags in parser procedure
|
||||
*
|
||||
* @param parser
|
||||
* @throws XmlPullParserException
|
||||
* @throws IOException
|
||||
|
Loading…
x
Reference in New Issue
Block a user