|
23 | 23 |
|
24 | 24 | package com.owncloud.android.lib.resources.shares.responses
|
25 | 25 |
|
| 26 | +import com.owncloud.android.lib.common.network.WebdavUtils |
26 | 27 | import com.owncloud.android.lib.resources.shares.RemoteShare
|
27 | 28 | import com.owncloud.android.lib.resources.shares.RemoteShare.Companion.DEFAULT_PERMISSION
|
28 | 29 | import com.owncloud.android.lib.resources.shares.RemoteShare.Companion.INIT_EXPIRATION_DATE_IN_MILLIS
|
29 | 30 | import com.owncloud.android.lib.resources.shares.RemoteShare.Companion.INIT_SHARED_DATE
|
30 | 31 | import com.owncloud.android.lib.resources.shares.ShareType
|
| 32 | +import com.squareup.moshi.Json |
31 | 33 | import com.squareup.moshi.JsonClass
|
32 | 34 | import java.io.File
|
33 | 35 |
|
34 | 36 | @JsonClass(generateAdapter = true)
|
35 | 37 | data class ShareItem(
|
36 | 38 | val id: String? = null,
|
| 39 | + |
| 40 | + @Json(name = "share_with") |
37 | 41 | val shareWith: String? = null,
|
| 42 | + |
38 | 43 | val path: String? = null,
|
39 | 44 | val token: String? = null,
|
| 45 | + |
| 46 | + @Json(name = "item_type") |
| 47 | + val itemType: String? = null, |
| 48 | + |
| 49 | + @Json(name = "share_with_displayname") |
40 | 50 | val sharedWithDisplayName: String? = null,
|
| 51 | + |
| 52 | + @Json(name = "share_with_additional_info") |
41 | 53 | val sharedWithAdditionalInfo: String? = null,
|
| 54 | + |
42 | 55 | val name: String? = null,
|
| 56 | + |
| 57 | + @Json(name = "url") |
43 | 58 | val shareLink: String? = null,
|
| 59 | + |
| 60 | + @Json(name = "share_type") |
44 | 61 | val shareType: Int? = null,
|
| 62 | + |
45 | 63 | val permissions: Int? = null,
|
| 64 | + |
| 65 | + @Json(name = "stime") |
46 | 66 | val sharedDate: Long? = null,
|
47 |
| - val expirationDate: Long? = null, |
| 67 | + |
| 68 | + @Json(name = "expiration") |
| 69 | + val expirationDate: String? = null, |
48 | 70 | ) {
|
49 | 71 | fun toRemoteShare() = RemoteShare(
|
50 | 72 | id = id ?: "0",
|
51 | 73 | shareWith = shareWith.orEmpty(),
|
52 |
| - path = path.orEmpty(), |
| 74 | + path = if (itemType == ItemType.FOLDER.fileValue) path.plus(File.separator) else path.orEmpty(), |
53 | 75 | token = token.orEmpty(),
|
| 76 | + itemType = itemType.orEmpty(), |
54 | 77 | sharedWithDisplayName = sharedWithDisplayName.orEmpty(),
|
55 | 78 | sharedWithAdditionalInfo = sharedWithAdditionalInfo.orEmpty(),
|
56 | 79 | name = name.orEmpty(),
|
57 | 80 | shareLink = shareLink.orEmpty(),
|
58 | 81 | shareType = ShareType.values().firstOrNull { it.value == shareType } ?: ShareType.UNKNOWN,
|
59 | 82 | permissions = permissions ?: DEFAULT_PERMISSION,
|
60 | 83 | 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 |
63 | 88 | )
|
64 | 89 | }
|
| 90 | + |
| 91 | +enum class ItemType(val fileValue: String) { FILE("file"), FOLDER("folder") } |
0 commit comments