Skip to content

Commit 890ae2f

Browse files
surinder-tsysalperozturk96
authored andcommitted
minor albums api fixes
Signed-off-by: Surinder Kumar <surinder.kumar@t-systems.com>
1 parent d0c0749 commit 890ae2f

7 files changed

Lines changed: 109 additions & 94 deletions

File tree

library/src/main/java/com/owncloud/android/lib/common/utils/WebDavFileUtils.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Nextcloud Android Library
33
*
4-
* SPDX-FileCopyrightText: 2025 TSI-mc <surinder.kumar@t-systems.com>
4+
* SPDX-FileCopyrightText: 2026 TSI-mc <surinder.kumar@t-systems.com>
55
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
66
* SPDX-FileCopyrightText: 2017 Mario Danic <mario@lovelyhq.com>
77
* SPDX-License-Identifier: MIT
@@ -72,11 +72,16 @@ public ArrayList<RemoteFile> readData(MultiStatus remoteData,
7272
* folder and its direct children.
7373
* @param client Client instance to the remote server where the data were
7474
* retrieved.
75-
* @return
75+
* @return list of remote file
7676
*/
7777
public List<RemoteFile> readAlbumData(MultiStatus remoteData, OwnCloudClient client) {
7878
String baseUrl = client.getBaseUri() + "/remote.php/dav/photos/" + client.getUserId();
79-
String encodedPath = Uri.parse(baseUrl).getEncodedPath();
79+
Uri uri = Uri.parse(baseUrl);
80+
if (uri == null) {
81+
return Collections.emptyList();
82+
}
83+
84+
String encodedPath = uri.getEncodedPath();
8085
if (encodedPath == null) {
8186
return Collections.emptyList();
8287
}

library/src/main/java/com/owncloud/android/lib/resources/albums/CopyFileToAlbumRemoteOperation.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Nextcloud Android Library
33
*
4-
* SPDX-FileCopyrightText: 2025 TSI-mc <surinder.kumar@t-systems.com>
4+
* SPDX-FileCopyrightText: 2026 TSI-mc <surinder.kumar@t-systems.com>
55
* SPDX-License-Identifier: MIT
66
*/
77
package com.owncloud.android.lib.resources.albums
@@ -47,8 +47,6 @@ class CopyFileToAlbumRemoteOperation @JvmOverloads constructor(
4747
if (mTargetRemotePath == mSrcRemotePath) {
4848
// nothing to do!
4949
result = RemoteOperationResult(ResultCode.OK)
50-
} else if (mTargetRemotePath.startsWith(mSrcRemotePath)) {
51-
result = RemoteOperationResult(ResultCode.INVALID_COPY_INTO_DESCENDANT)
5250
} else {
5351
/** perform remote operation */
5452
var copyMethod: CopyMethod? = null

library/src/main/java/com/owncloud/android/lib/resources/albums/PhotoAlbumEntry.kt

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Nextcloud Android Library
33
*
4-
* SPDX-FileCopyrightText: 2025 TSI-mc <surinder.kumar@t-systems.com>
4+
* SPDX-FileCopyrightText: 2026 TSI-mc <surinder.kumar@t-systems.com>
55
* SPDX-License-Identifier: MIT
66
*/
77

@@ -15,9 +15,8 @@ import org.apache.jackrabbit.webdav.property.DavPropertySet
1515
import org.apache.jackrabbit.webdav.xml.Namespace
1616
import org.json.JSONException
1717
import org.json.JSONObject
18-
import java.text.SimpleDateFormat
19-
import java.util.Date
20-
import java.util.Locale
18+
import java.net.URLDecoder
19+
import java.nio.charset.StandardCharsets
2120

2221
class PhotoAlbumEntry(
2322
response: MultiStatusResponse
@@ -29,7 +28,6 @@ class PhotoAlbumEntry(
2928
private val dateRange: String?
3029

3130
companion object {
32-
private val dateFormat = SimpleDateFormat("MMM yyyy", Locale.US)
3331
private const val MILLIS = 1000L
3432
}
3533

@@ -70,27 +68,27 @@ class PhotoAlbumEntry(
7068

7169
val albumName: String
7270
get() {
73-
return href
74-
.removeSuffix("/")
75-
.substringAfterLast("/")
76-
.takeIf { it.isNotEmpty() } ?: ""
71+
// use decoder to show correct path
72+
return URLDecoder.decode(
73+
href
74+
.removeSuffix("/")
75+
.substringAfterLast("/")
76+
.takeIf { it.isNotEmpty() } ?: "", StandardCharsets.UTF_8.name())
7777
}
7878

79-
val createdDate: String
79+
val createdDate: Long
8080
get() {
81-
val currentDate = Date(System.currentTimeMillis())
82-
81+
val defaultTimeStamp = System.currentTimeMillis()
8382
return try {
84-
val obj = JSONObject(dateRange ?: return dateFormat.format(currentDate))
83+
val obj = JSONObject(dateRange ?: return defaultTimeStamp)
8584
val startTimestamp = obj.optLong("start", 0)
8685
if (startTimestamp > 0) {
87-
dateFormat.format(Date(startTimestamp * MILLIS))
86+
startTimestamp * MILLIS
8887
} else {
89-
dateFormat.format(currentDate)
88+
defaultTimeStamp
9089
}
91-
} catch (e: JSONException) {
92-
e.printStackTrace()
93-
dateFormat.format(currentDate)
90+
} catch (_: JSONException) {
91+
defaultTimeStamp
9492
}
9593
}
9694
}

library/src/main/java/com/owncloud/android/lib/resources/albums/RemoveAlbumFileRemoteOperation.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Nextcloud Android Library
33
*
4-
* SPDX-FileCopyrightText: 2025 TSI-mc <surinder.kumar@t-systems.com>
4+
* SPDX-FileCopyrightText: 2026 TSI-mc <surinder.kumar@t-systems.com>
55
* SPDX-License-Identifier: MIT
66
*/
77
package com.owncloud.android.lib.resources.albums
@@ -10,6 +10,7 @@ import android.net.Uri
1010
import com.nextcloud.common.SessionTimeOut
1111
import com.nextcloud.common.defaultSessionTimeOut
1212
import com.owncloud.android.lib.common.OwnCloudClient
13+
import com.owncloud.android.lib.common.network.WebdavUtils
1314
import com.owncloud.android.lib.common.operations.RemoteOperation
1415
import com.owncloud.android.lib.common.operations.RemoteOperationResult
1516
import com.owncloud.android.lib.common.utils.Log_OC
@@ -29,7 +30,7 @@ class RemoveAlbumFileRemoteOperation
2930
var result: RemoteOperationResult<Any>
3031
var delete: DeleteMethod? = null
3132
val webDavUrl = "${client.davUri}/photos/"
32-
val encodedPath = ("${client.userId}${Uri.encode(this.mRemotePath)}").replace("%2F", "/")
33+
val encodedPath = "${client.userId}${WebdavUtils.encodePath(this.mRemotePath)}"
3334
val fullFilePath = "$webDavUrl$encodedPath"
3435

3536
try {
@@ -40,15 +41,14 @@ class RemoveAlbumFileRemoteOperation
4041
sessionTimeOut.readTimeOut,
4142
sessionTimeOut.connectionTimeOut
4243
)
43-
delete.responseBodyAsString
4444
result =
45-
RemoteOperationResult<Any>(
45+
RemoteOperationResult(
4646
delete.succeeded() || status == HttpStatus.SC_NOT_FOUND,
4747
delete
4848
)
4949
Log_OC.i(TAG, "Remove ${this.mRemotePath} : ${result.logMessage}")
5050
} catch (e: Exception) {
51-
result = RemoteOperationResult<Any>(e)
51+
result = RemoteOperationResult(e)
5252
Log_OC.e(TAG, "Remove ${this.mRemotePath} : ${result.logMessage}", e)
5353
} finally {
5454
delete?.releaseConnection()

library/src/main/java/com/owncloud/android/lib/resources/albums/RemoveAlbumRemoteOperation.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Nextcloud Android Library
33
*
4-
* SPDX-FileCopyrightText: 2025 TSI-mc <surinder.kumar@t-systems.com>
4+
* SPDX-FileCopyrightText: 2026 TSI-mc <surinder.kumar@t-systems.com>
55
* SPDX-License-Identifier: MIT
66
*/
77
package com.owncloud.android.lib.resources.albums
@@ -48,7 +48,6 @@ class RemoveAlbumRemoteOperation
4848
sessionTimeOut.readTimeOut,
4949
sessionTimeOut.connectionTimeOut
5050
)
51-
delete.responseBodyAsString
5251
result =
5352
RemoteOperationResult<Any>(
5453
delete.succeeded() || status == HttpStatus.SC_NOT_FOUND,
Lines changed: 61 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Nextcloud Android Library
33
*
4-
* SPDX-FileCopyrightText: 2025 TSI-mc <surinder.kumar@t-systems.com>
4+
* SPDX-FileCopyrightText: 2026 TSI-mc <surinder.kumar@t-systems.com>
55
* SPDX-License-Identifier: MIT
66
*/
77
package com.owncloud.android.lib.resources.albums
@@ -13,65 +13,72 @@ import com.owncloud.android.lib.common.network.WebdavUtils
1313
import com.owncloud.android.lib.common.operations.RemoteOperation
1414
import com.owncloud.android.lib.common.operations.RemoteOperationResult
1515
import com.owncloud.android.lib.common.utils.Log_OC
16+
import org.apache.commons.httpclient.HttpStatus
1617
import org.apache.jackrabbit.webdav.client.methods.MoveMethod
1718

1819
class RenameAlbumRemoteOperation
19-
@JvmOverloads
20-
constructor(
21-
private val mOldRemotePath: String,
22-
val newAlbumName: String,
23-
private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut
24-
) : RemoteOperation<Any>() {
25-
/**
26-
* Performs the operation.
27-
*
28-
* @param client Client object to communicate with the remote ownCloud server.
29-
*/
30-
@Deprecated("Deprecated in Java")
31-
@Suppress("TooGenericExceptionCaught")
32-
override fun run(client: OwnCloudClient): RemoteOperationResult<Any>? {
33-
var result: RemoteOperationResult<Any>? = null
34-
var move: MoveMethod? = null
35-
val url = "${client.baseUri}/remote.php/dav/photos/${client.userId}/albums"
36-
try {
37-
if (this.newAlbumName != this.mOldRemotePath) {
38-
move =
39-
MoveMethod(
40-
"$url${WebdavUtils.encodePath(mOldRemotePath)}",
41-
"$url${
42-
WebdavUtils.encodePath(
43-
newAlbumName
44-
)
45-
}",
46-
true
20+
@JvmOverloads
21+
constructor(
22+
private val mOldRemotePath: String,
23+
val newAlbumName: String,
24+
private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut
25+
) : RemoteOperation<Any>() {
26+
/**
27+
* Performs the operation.
28+
*
29+
* @param client Client object to communicate with the remote ownCloud server.
30+
*/
31+
@Deprecated("Deprecated in Java")
32+
@Suppress("TooGenericExceptionCaught")
33+
override fun run(client: OwnCloudClient): RemoteOperationResult<Any>? {
34+
if (this.newAlbumName == this.mOldRemotePath) {
35+
return RemoteOperationResult(RemoteOperationResult.ResultCode.OK)
36+
}
37+
38+
var result: RemoteOperationResult<Any>? = null
39+
var move: MoveMethod? = null
40+
val url = "${client.baseUri}/remote.php/dav/photos/${client.userId}/albums"
41+
try {
42+
move =
43+
MoveMethod(
44+
"$url${WebdavUtils.encodePath(mOldRemotePath)}",
45+
"$url${
46+
WebdavUtils.encodePath(
47+
newAlbumName
4748
)
48-
client.executeMethod(
49-
move,
50-
sessionTimeOut.readTimeOut,
51-
sessionTimeOut.connectionTimeOut
52-
)
53-
result = RemoteOperationResult<Any>(move.succeeded(), move)
54-
Log_OC.i(
55-
TAG,
56-
"Rename ${this.mOldRemotePath} to ${this.newAlbumName} : ${result.logMessage}"
57-
)
58-
client.exhaustResponse(move.responseBodyAsStream)
59-
}
60-
} catch (e: Exception) {
61-
result = RemoteOperationResult<Any>(e)
62-
Log_OC.e(
63-
TAG,
64-
"Rename ${this.mOldRemotePath} to ${this.newAlbumName} : ${result.logMessage}",
65-
e
49+
}",
50+
false
6651
)
67-
} finally {
68-
move?.releaseConnection()
52+
client.executeMethod(
53+
move,
54+
sessionTimeOut.readTimeOut,
55+
sessionTimeOut.connectionTimeOut
56+
)
57+
result = RemoteOperationResult<Any>(move.succeeded(), move)
58+
Log_OC.i(
59+
TAG,
60+
"Rename ${this.mOldRemotePath} to ${this.newAlbumName} : ${result.logMessage}"
61+
)
62+
// album name already exist
63+
if (!result.isSuccess && result.httpCode == HttpStatus.SC_PRECONDITION_FAILED) {
64+
result = RemoteOperationResult<Any>(RemoteOperationResult.ResultCode.INVALID_OVERWRITE)
6965
}
70-
71-
return result
66+
client.exhaustResponse(move.responseBodyAsStream)
67+
} catch (e: Exception) {
68+
result = RemoteOperationResult<Any>(e)
69+
Log_OC.e(
70+
TAG,
71+
"Rename ${this.mOldRemotePath} to ${this.newAlbumName} : ${result.logMessage}",
72+
e
73+
)
74+
} finally {
75+
move?.releaseConnection()
7276
}
7377

74-
companion object {
75-
private val TAG: String = RenameAlbumRemoteOperation::class.java.simpleName
76-
}
78+
return result
79+
}
80+
81+
companion object {
82+
private val TAG: String = RenameAlbumRemoteOperation::class.java.simpleName
7783
}
84+
}

library/src/main/java/com/owncloud/android/lib/resources/albums/ToggleAlbumFavoriteRemoteOperation.kt

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
/*
22
* Nextcloud Android Library
33
*
4-
* SPDX-FileCopyrightText: 2025 TSI-mc <surinder.kumar@t-systems.com>
4+
* SPDX-FileCopyrightText: 2026 TSI-mc <surinder.kumar@t-systems.com>
55
* SPDX-License-Identifier: MIT
66
*/
77
package com.owncloud.android.lib.resources.albums
88

9-
import android.net.Uri
109
import com.nextcloud.common.SessionTimeOut
1110
import com.nextcloud.common.defaultSessionTimeOut
1211
import com.owncloud.android.lib.common.OwnCloudClient
1312
import com.owncloud.android.lib.common.network.WebdavEntry
13+
import com.owncloud.android.lib.common.network.WebdavUtils
1414
import com.owncloud.android.lib.common.operations.RemoteOperation
1515
import com.owncloud.android.lib.common.operations.RemoteOperationResult
16+
import com.owncloud.android.lib.resources.files.ToggleFavoriteRemoteOperation
1617
import org.apache.commons.httpclient.HttpStatus
1718
import org.apache.jackrabbit.webdav.client.methods.PropPatchMethod
1819
import org.apache.jackrabbit.webdav.property.DavPropertyNameSet
@@ -24,30 +25,37 @@ import java.io.IOException
2425
class ToggleAlbumFavoriteRemoteOperation
2526
@JvmOverloads
2627
constructor(
27-
private val makeItFavorited: Boolean,
28+
private val markAsFavorite: Boolean,
2829
private val filePath: String,
2930
private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut
3031
) : RemoteOperation<Any>() {
3132
@Deprecated("Deprecated in Java")
33+
@Suppress("ReturnCount")
3234
override fun run(client: OwnCloudClient): RemoteOperationResult<Any> {
35+
if (filePath.isEmpty() || filePath.isBlank()) {
36+
return RemoteOperationResult(RemoteOperationResult.ResultCode.OK)
37+
}
38+
39+
// when file is in local db the remotePath will be actual path instead of albums path
40+
// to perform operation we have to call files dav uri
41+
if (!filePath.contains("/albums/")) {
42+
return ToggleFavoriteRemoteOperation(markAsFavorite, filePath).execute(client)
43+
}
44+
3345
var result: RemoteOperationResult<Any>
3446
var propPatchMethod: PropPatchMethod? = null
3547
val newProps = DavPropertySet()
3648
val removeProperties = DavPropertyNameSet()
37-
if (this.makeItFavorited) {
3849
val favoriteProperty =
3950
DefaultDavProperty<Any>(
4051
"oc:favorite",
41-
"1",
52+
if(markAsFavorite) "1" else "0",
4253
Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)
4354
)
4455
newProps.add(favoriteProperty)
45-
} else {
46-
removeProperties.add("oc:favorite", Namespace.getNamespace(WebdavEntry.NAMESPACE_OC))
47-
}
4856

4957
val webDavUrl = "${client.davUri}/photos/"
50-
val encodedPath = ("${client.userId}${Uri.encode(this.filePath)}").replace("%2F", "/")
58+
val encodedPath = "${client.userId}${WebdavUtils.encodePath(this.filePath)}"
5159
val fullFilePath = "$webDavUrl$encodedPath"
5260

5361
try {

0 commit comments

Comments
 (0)