Skip to content

Commit 36034ff

Browse files
committed
parse tags
Signed-off-by: alperozturk <alper_ozturk@proton.me>
1 parent 0437079 commit 36034ff

2 files changed

Lines changed: 20 additions & 16 deletions

File tree

library/src/main/java/com/owncloud/android/lib/common/network/WebdavEntry.kt

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -388,23 +388,20 @@ class WebdavEntry constructor(ms: MultiStatusResponse, splitElement: String) {
388388
}
389389

390390
prop = propSet[EXTENDED_PROPERTY_SYSTEM_TAGS, ncNamespace]
391-
if (prop != null && prop.value != null) {
392-
if (prop.value is ArrayList<*>) {
393-
val list = prop.value as ArrayList<*>
394-
val tempList: MutableList<String> = ArrayList(list.size)
395-
for (i in list.indices) {
396-
val element = list[i] as Element
397-
tempList.add(element.firstChild.textContent)
391+
if (prop?.value != null) {
392+
tags = when (prop.value) {
393+
is ArrayList<*> -> (prop.value as ArrayList<*>)
394+
.filterIsInstance<Element>()
395+
.map { parseTag(it) }
396+
.toTypedArray()
397+
398+
is Element -> {
399+
val element = (prop.value as Element)
400+
val tag = parseTag(element)
401+
arrayOf(tag)
398402
}
399-
tags = tempList.toTypedArray()
400-
} else {
401-
// single item or empty
402-
val element = prop.value as Element
403-
val value = element.firstChild.textContent
404403

405-
if (value != null) {
406-
tags = arrayOf(value)
407-
}
404+
else -> emptyArray()
408405
}
409406
}
410407

@@ -467,6 +464,12 @@ class WebdavEntry constructor(ms: MultiStatusResponse, splitElement: String) {
467464
}
468465
}
469466

467+
private fun parseTag(element: Element): Tag {
468+
val name = element.firstChild.textContent
469+
val color = element.getAttribute("nc:color")
470+
return Tag(name, color)
471+
}
472+
470473
private fun parseLockProperties(
471474
ncNamespace: Namespace,
472475
propSet: DavPropertySet

library/src/main/java/com/owncloud/android/lib/resources/files/model/RemoteFile.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package com.owncloud.android.lib.resources.files.model
88

99
import android.os.Parcel
1010
import android.os.Parcelable
11+
import com.owncloud.android.lib.common.network.Tag
1112
import com.owncloud.android.lib.common.network.WebdavEntry
1213
import com.owncloud.android.lib.common.network.WebdavEntry.MountType
1314
import com.owncloud.android.lib.resources.files.FileUtils
@@ -50,7 +51,7 @@ class RemoteFile : Parcelable, Serializable {
5051
var lockOwnerEditor: String? = null
5152
var lockTimeout: Long = 0
5253
var lockToken: String? = null
53-
var tags: Array<String?>? = null
54+
var tags: Array<Tag?>? = null
5455
var imageDimension: ImageDimension? = null
5556
var geoLocation: GeoLocation? = null
5657
var hidden = false

0 commit comments

Comments
 (0)