Skip to content

Commit d6d062d

Browse files
Merge pull request #1178 from nextcloud/gps
Add support for metadata: size (width/height) and geolocation
2 parents 593f49c + 1534f87 commit d6d062d

8 files changed

Lines changed: 112 additions & 2 deletions

File tree

55.7 KB
Loading

library/src/androidTest/java/com/owncloud/android/AbstractIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ public static File extractAsset(String fileName, Context context) throws IOExcep
279279

280280
@After
281281
public void after() {
282-
removeOnClient(client);
283-
removeOnClient(client2);
282+
// removeOnClient(client);
283+
// removeOnClient(client2);
284284
}
285285

286286
private void removeOnClient(OwnCloudClient client) {

library/src/androidTest/java/com/owncloud/android/lib/resources/files/ReadFileRemoteOperationIT.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ package com.owncloud.android.lib.resources.files
2323
import com.owncloud.android.AbstractIT
2424
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory
2525
import com.owncloud.android.lib.resources.e2ee.ToggleEncryptionRemoteOperation
26+
import com.owncloud.android.lib.resources.files.model.GeoLocation
27+
import com.owncloud.android.lib.resources.files.model.ImageDimension
2628
import com.owncloud.android.lib.resources.files.model.RemoteFile
2729
import org.junit.Assert.assertEquals
2830
import org.junit.Assert.assertFalse
@@ -58,6 +60,27 @@ class ReadFileRemoteOperationIT : AbstractIT() {
5860
assertEquals(remotePath, (result.data[0] as RemoteFile).remotePath)
5961
}
6062

63+
@Test
64+
fun testMetadata() {
65+
val filePath = getFile("gps.jpg").absolutePath
66+
val remotePath = "/gps.jpg"
67+
68+
assertTrue(
69+
UploadFileRemoteOperation(filePath, remotePath, "image/jpg", RANDOM_MTIME)
70+
.execute(client).isSuccess
71+
)
72+
73+
val result = ReadFileRemoteOperation(remotePath).execute(client)
74+
75+
assertTrue(result.isSuccess)
76+
val remoteFile = result.data[0] as RemoteFile
77+
78+
@Suppress("Detekt.MagicNumber")
79+
assertEquals(ImageDimension(451f, 529f), remoteFile.imageDimension)
80+
@Suppress("Detekt.MagicNumber")
81+
assertEquals(GeoLocation(49.99679166666667, 8.67198611111111), remoteFile.geoLocation)
82+
}
83+
6184
@Test
6285
fun readEncryptedState() {
6386
val remotePath = "/testEncryptedFolder/"

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@
2424
package com.owncloud.android.lib.common.network
2525

2626
import android.net.Uri
27+
import com.google.gson.Gson
2728
import com.owncloud.android.lib.common.utils.Log_OC
2829
import com.owncloud.android.lib.resources.files.model.FileLockType
2930
import com.owncloud.android.lib.resources.files.model.FileLockType.Companion.fromValue
31+
import com.owncloud.android.lib.resources.files.model.GeoLocation
32+
import com.owncloud.android.lib.resources.files.model.ImageDimension
3033
import com.owncloud.android.lib.resources.shares.ShareType
3134
import com.owncloud.android.lib.resources.shares.ShareeUser
3235
import org.apache.jackrabbit.webdav.MultiStatusResponse
@@ -96,6 +99,8 @@ class WebdavEntry constructor(ms: MultiStatusResponse, splitElement: String) {
9699
var lockToken: String? = null
97100
private set
98101
var tags = arrayOfNulls<String>(0)
102+
var imageDimension: ImageDimension? = null
103+
var geoLocation: GeoLocation? = null
99104

100105
enum class MountType {
101106
INTERNAL, EXTERNAL, GROUP
@@ -395,6 +400,18 @@ class WebdavEntry constructor(ms: MultiStatusResponse, splitElement: String) {
395400
}
396401
}
397402

403+
// NC metadata size property <nc:file-metadata-size>
404+
prop = propSet[EXTENDED_PROPERTY_METADATA_SIZE, ncNamespace]
405+
if (prop != null && prop.value != null) {
406+
imageDimension = Gson().fromJson(prop.value.toString(), ImageDimension::class.java)
407+
}
408+
409+
// NC metadata gps property <nc:file-metadata-gps>
410+
prop = propSet[EXTENDED_PROPERTY_METADATA_GPS, ncNamespace]
411+
if (prop != null && prop.value != null) {
412+
geoLocation = Gson().fromJson(prop.value.toString(), GeoLocation::class.java)
413+
}
414+
398415
parseLockProperties(ncNamespace, propSet)
399416
} else {
400417
Log_OC.e("WebdavEntry", "General error, no status for webdav response")
@@ -542,6 +559,8 @@ class WebdavEntry constructor(ms: MultiStatusResponse, splitElement: String) {
542559
const val EXTENDED_PROPERTY_LOCK_TIMEOUT = "lock-timeout"
543560
const val EXTENDED_PROPERTY_LOCK_TOKEN = "lock-token"
544561
const val EXTENDED_PROPERTY_SYSTEM_TAGS = "system-tags"
562+
const val EXTENDED_PROPERTY_METADATA_SIZE = "file-metadata-size"
563+
const val EXTENDED_PROPERTY_METADATA_GPS = "file-metadata-gps"
545564
const val TRASHBIN_FILENAME = "trashbin-filename"
546565
const val TRASHBIN_ORIGINAL_LOCATION = "trashbin-original-location"
547566
const val TRASHBIN_DELETION_TIME = "trashbin-deletion-time"

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ public static DavPropertyNameSet getAllPropSet() {
126126
propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_TIMEOUT, ncNamespace);
127127
propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_TOKEN, ncNamespace);
128128
propSet.add(WebdavEntry.EXTENDED_PROPERTY_SYSTEM_TAGS, ncNamespace);
129+
propSet.add(WebdavEntry.EXTENDED_PROPERTY_METADATA_SIZE, ncNamespace);
130+
propSet.add(WebdavEntry.EXTENDED_PROPERTY_METADATA_GPS, ncNamespace);
129131

130132
return propSet;
131133
}
@@ -165,6 +167,8 @@ public static DavPropertyNameSet getFilePropSet() {
165167
propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_TOKEN, ncNamespace);
166168
propSet.add(WebdavEntry.EXTENDED_PROPERTY_IS_ENCRYPTED, ncNamespace);
167169
propSet.add(WebdavEntry.EXTENDED_PROPERTY_SYSTEM_TAGS, ncNamespace);
170+
propSet.add(WebdavEntry.EXTENDED_PROPERTY_METADATA_SIZE, ncNamespace);
171+
propSet.add(WebdavEntry.EXTENDED_PROPERTY_METADATA_GPS, ncNamespace);
168172

169173
return propSet;
170174
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* Nextcloud Android Library is available under MIT license
2+
*
3+
* @author Tobias Kaminsky
4+
* Copyright (C) 2023 Tobias Kaminsky
5+
* Copyright (C) 2023 Nextcloud GmbH
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*
26+
*/
27+
28+
package com.owncloud.android.lib.resources.files.model
29+
30+
data class GeoLocation(var latitude: Double = -1.0, var longitude: Double = -1.0)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* Nextcloud Android Library is available under MIT license
2+
*
3+
* @author Tobias Kaminsky
4+
* Copyright (C) 2023 Tobias Kaminsky
5+
* Copyright (C) 2023 Nextcloud GmbH
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*
26+
*/
27+
28+
package com.owncloud.android.lib.resources.files.model
29+
30+
data class ImageDimension(var width: Float = -1f, var height: Float = -1f)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class RemoteFile : Parcelable, Serializable {
6868
var lockTimeout: Long = 0
6969
var lockToken: String? = null
7070
var tags: Array<String?>? = null
71+
var imageDimension: ImageDimension? = null
72+
var geoLocation: GeoLocation? = null
7173

7274
constructor() {
7375
resetData()
@@ -119,6 +121,8 @@ class RemoteFile : Parcelable, Serializable {
119121
lockTimeout = we.lockTimeout
120122
lockToken = we.lockToken
121123
tags = we.tags
124+
imageDimension = we.imageDimension
125+
geoLocation = we.geoLocation
122126
}
123127

124128
/**

0 commit comments

Comments
 (0)