Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit 5be4eca

Browse files
committed
Added a new property, so that, we can retrieve the shares within the propfind
1 parent 2dc6f30 commit 5be4eca

File tree

5 files changed

+137
-2
lines changed

5 files changed

+137
-2
lines changed

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/DavUtils.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ package com.owncloud.android.lib.common.http.methods.webdav
2626
import at.bitfire.dav4jvm.Property
2727
import at.bitfire.dav4jvm.PropertyUtils.getAllPropSet
2828
import at.bitfire.dav4jvm.PropertyUtils.getQuotaPropset
29+
import com.owncloud.android.lib.common.http.methods.webdav.properties.OCShareTypes
2930

3031
object DavUtils {
3132
@JvmStatic val allPropset: Array<Property.Name>
32-
get() = getAllPropSet()
33+
get() = getAllPropSet().plus(OCShareTypes.NAME)
3334

3435
val quotaPropSet: Array<Property.Name>
3536
get() = getQuotaPropset()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* ownCloud Android Library is available under MIT license
2+
* Copyright (C) 2022 ownCloud GmbH.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*
23+
*/
24+
package com.owncloud.android.lib.common.http.methods.webdav.properties
25+
26+
import at.bitfire.dav4jvm.Property
27+
import at.bitfire.dav4jvm.XmlUtils
28+
import org.xmlpull.v1.XmlPullParser
29+
30+
class OCShareTypes : ShareTypeListProperty() {
31+
32+
class Factory : ShareTypeListProperty.Factory() {
33+
34+
override fun create(parser: XmlPullParser) =
35+
create(parser, OCShareTypes())
36+
37+
override fun getName(): Property.Name = NAME
38+
}
39+
40+
companion object {
41+
@JvmField
42+
val NAME = Property.Name(XmlUtils.NS_OWNCLOUD, "share-types")
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* ownCloud Android Library is available under MIT license
2+
* Copyright (C) 2022 ownCloud GmbH.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*
23+
*/
24+
package com.owncloud.android.lib.common.http.methods.webdav.properties
25+
26+
import at.bitfire.dav4jvm.Property
27+
import at.bitfire.dav4jvm.PropertyFactory
28+
import at.bitfire.dav4jvm.XmlUtils
29+
import org.xmlpull.v1.XmlPullParser
30+
import java.util.LinkedList
31+
32+
abstract class ShareTypeListProperty : Property {
33+
34+
val shareTypes = LinkedList<String>()
35+
36+
override fun toString() = "share types =[" + shareTypes.joinToString(", ") + "]"
37+
38+
abstract class Factory : PropertyFactory {
39+
40+
fun create(parser: XmlPullParser, list: ShareTypeListProperty): ShareTypeListProperty {
41+
XmlUtils.readTextPropertyList(parser, Property.Name(XmlUtils.NS_OWNCLOUD, "share-type"), list.shareTypes)
42+
return list
43+
}
44+
45+
}
46+
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@
2424

2525
package com.owncloud.android.lib.resources.files;
2626

27+
import at.bitfire.dav4jvm.PropertyRegistry;
2728
import at.bitfire.dav4jvm.Response;
2829
import com.owncloud.android.lib.common.OwnCloudClient;
2930
import com.owncloud.android.lib.common.accounts.AccountUtils;
3031
import com.owncloud.android.lib.common.http.HttpConstants;
3132
import com.owncloud.android.lib.common.http.methods.webdav.DavConstants;
3233
import com.owncloud.android.lib.common.http.methods.webdav.DavUtils;
3334
import com.owncloud.android.lib.common.http.methods.webdav.PropfindMethod;
35+
import com.owncloud.android.lib.common.http.methods.webdav.properties.OCShareTypes;
3436
import com.owncloud.android.lib.common.network.WebdavUtils;
3537
import com.owncloud.android.lib.common.operations.RemoteOperation;
3638
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@@ -72,6 +74,7 @@ protected RemoteOperationResult<ArrayList<RemoteFile>> run(OwnCloudClient client
7274
RemoteOperationResult<ArrayList<RemoteFile>> result = null;
7375

7476
try {
77+
PropertyRegistry.INSTANCE.register(OCShareTypes.Factory.class.newInstance());
7578
PropfindMethod propfindMethod = new PropfindMethod(
7679
new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)),
7780
DavConstants.DEPTH_1,

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoteFile.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,14 @@
4040
import at.bitfire.dav4jvm.property.OCSize;
4141
import at.bitfire.dav4jvm.property.QuotaAvailableBytes;
4242
import at.bitfire.dav4jvm.property.QuotaUsedBytes;
43+
import com.owncloud.android.lib.common.http.methods.webdav.properties.OCShareTypes;
44+
import com.owncloud.android.lib.resources.shares.ShareType;
45+
import timber.log.Timber;
4346

4447
import java.io.File;
4548
import java.io.Serializable;
4649
import java.math.BigDecimal;
50+
import java.util.LinkedList;
4751
import java.util.List;
4852

4953
/**
@@ -85,6 +89,8 @@ public RemoteFile[] newArray(int size) {
8589
private BigDecimal mQuotaUsedBytes;
8690
private BigDecimal mQuotaAvailableBytes;
8791
private String mPrivateLink;
92+
private boolean mSharedByLink;
93+
private boolean mSharedWithSharee;
8894

8995
public RemoteFile() {
9096
resetData();
@@ -153,6 +159,23 @@ public RemoteFile(final Response davResource, String userId) {
153159
if (property instanceof OCPrivatelink) {
154160
this.setPrivateLink(((OCPrivatelink) property).getLink());
155161
}
162+
if (property instanceof OCShareTypes) {
163+
LinkedList<String> list = ((OCShareTypes) property).getShareTypes();
164+
for (int i = 0; i < list.size(); i++) {
165+
ShareType shareType = ShareType.Companion.fromValue(Integer.parseInt(list.get(i)));
166+
if (shareType == null) {
167+
Timber.d("Illegal share type value: " + list.get(i));
168+
continue;
169+
}
170+
if (shareType.equals(ShareType.PUBLIC_LINK)) {
171+
this.setSharedViaLink(true);
172+
} else if (shareType.equals(ShareType.USER) ||
173+
shareType.equals(ShareType.FEDERATED) ||
174+
shareType.equals(ShareType.GROUP)) {
175+
this.setSharedWithSharee(true);
176+
}
177+
}
178+
}
156179
}
157180
}
158181

@@ -266,6 +289,22 @@ public void setPrivateLink(String privateLink) {
266289
mPrivateLink = privateLink;
267290
}
268291

292+
public void setSharedWithSharee(boolean shareWithSharee) {
293+
mSharedWithSharee = shareWithSharee;
294+
}
295+
296+
public boolean isSharedWithSharee() {
297+
return mSharedWithSharee;
298+
}
299+
300+
public void setSharedViaLink(boolean sharedViaLink) {
301+
mSharedByLink = sharedViaLink;
302+
}
303+
304+
public boolean isSharedByLink() {
305+
return mSharedByLink;
306+
}
307+
269308
/**
270309
* Used internally. Reset all file properties
271310
*/
@@ -282,6 +321,8 @@ private void resetData() {
282321
mQuotaUsedBytes = null;
283322
mQuotaAvailableBytes = null;
284323
mPrivateLink = null;
324+
mSharedWithSharee = false;
325+
mSharedByLink = false;
285326
}
286327

287328
public void readFromParcel(Parcel source) {
@@ -319,4 +360,4 @@ public void writeToParcel(Parcel dest, int flags) {
319360
dest.writeSerializable(mQuotaAvailableBytes);
320361
dest.writeString(mPrivateLink);
321362
}
322-
}
363+
}

0 commit comments

Comments
 (0)