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

Commit 037a2b3

Browse files
committed
Fixed some bugs on how to create shares.
1 parent 45fb12d commit 037a2b3

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShare.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
package com.owncloud.android.lib.resources.shares
2626

27-
import java.io.File
27+
import com.owncloud.android.lib.resources.shares.responses.ItemType
2828

2929
/**
3030
* Contains the data of a Share from the Share API
@@ -38,6 +38,7 @@ data class RemoteShare(
3838
var shareWith: String = "",
3939
var path: String = "",
4040
var token: String = "",
41+
var itemType: String = "",
4142
var sharedWithDisplayName: String = "",
4243
var sharedWithAdditionalInfo: String = "",
4344
var name: String = "",
@@ -46,7 +47,7 @@ data class RemoteShare(
4647
var permissions: Int = DEFAULT_PERMISSION,
4748
var sharedDate: Long = INIT_SHARED_DATE,
4849
var expirationDate: Long = INIT_EXPIRATION_DATE_IN_MILLIS,
49-
var isFolder: Boolean = path.endsWith(File.separator)
50+
var isFolder: Boolean = (itemType == ItemType.FOLDER.fileValue)
5051
) {
5152

5253
companion object {

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/responses/ShareItem.kt

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,69 @@
2323

2424
package com.owncloud.android.lib.resources.shares.responses
2525

26+
import com.owncloud.android.lib.common.network.WebdavUtils
2627
import com.owncloud.android.lib.resources.shares.RemoteShare
2728
import com.owncloud.android.lib.resources.shares.RemoteShare.Companion.DEFAULT_PERMISSION
2829
import com.owncloud.android.lib.resources.shares.RemoteShare.Companion.INIT_EXPIRATION_DATE_IN_MILLIS
2930
import com.owncloud.android.lib.resources.shares.RemoteShare.Companion.INIT_SHARED_DATE
3031
import com.owncloud.android.lib.resources.shares.ShareType
32+
import com.squareup.moshi.Json
3133
import com.squareup.moshi.JsonClass
3234
import java.io.File
3335

3436
@JsonClass(generateAdapter = true)
3537
data class ShareItem(
3638
val id: String? = null,
39+
40+
@Json(name = "share_with")
3741
val shareWith: String? = null,
42+
3843
val path: String? = null,
3944
val token: String? = null,
45+
46+
@Json(name = "item_type")
47+
val itemType: String? = null,
48+
49+
@Json(name = "share_with_displayname")
4050
val sharedWithDisplayName: String? = null,
51+
52+
@Json(name = "share_with_additional_info")
4153
val sharedWithAdditionalInfo: String? = null,
54+
4255
val name: String? = null,
56+
57+
@Json(name = "url")
4358
val shareLink: String? = null,
59+
60+
@Json(name = "share_type")
4461
val shareType: Int? = null,
62+
4563
val permissions: Int? = null,
64+
65+
@Json(name = "stime")
4666
val sharedDate: Long? = null,
47-
val expirationDate: Long? = null,
67+
68+
@Json(name = "expiration")
69+
val expirationDate: String? = null,
4870
) {
4971
fun toRemoteShare() = RemoteShare(
5072
id = id ?: "0",
5173
shareWith = shareWith.orEmpty(),
52-
path = path.orEmpty(),
74+
path = if (itemType == ItemType.FOLDER.fileValue) path.plus(File.separator) else path.orEmpty(),
5375
token = token.orEmpty(),
76+
itemType = itemType.orEmpty(),
5477
sharedWithDisplayName = sharedWithDisplayName.orEmpty(),
5578
sharedWithAdditionalInfo = sharedWithAdditionalInfo.orEmpty(),
5679
name = name.orEmpty(),
5780
shareLink = shareLink.orEmpty(),
5881
shareType = ShareType.values().firstOrNull { it.value == shareType } ?: ShareType.UNKNOWN,
5982
permissions = permissions ?: DEFAULT_PERMISSION,
6083
sharedDate = sharedDate ?: INIT_SHARED_DATE,
61-
expirationDate = expirationDate ?: INIT_EXPIRATION_DATE_IN_MILLIS,
62-
isFolder = path?.endsWith(File.separator) ?: false
84+
expirationDate = expirationDate?.let {
85+
WebdavUtils.parseResponseDate(it)?.time
86+
} ?: INIT_EXPIRATION_DATE_IN_MILLIS,
87+
isFolder = itemType?.equals(ItemType.FOLDER.fileValue) ?: false
6388
)
6489
}
90+
91+
enum class ItemType(val fileValue: String) { FILE("file"), FOLDER("folder") }

0 commit comments

Comments
 (0)