Skip to content

Commit c6c9a6c

Browse files
committed
fix logic
Signed-off-by: alperozturk <alper_ozturk@proton.me>
1 parent 15bd8dc commit c6c9a6c

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

app/src/main/java/com/owncloud/android/ui/fragment/util/SharePermissionManager.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,23 @@ class SharePermissionManager {
9191

9292
fun toggleAllowDownloadAndSync(isChecked: Boolean, share: OCShare?): String? {
9393
val shareAttributes = getShareAttributes(share)?.toMutableList()
94-
val downloadAttributeIndex = shareAttributes?.indexOf(shareAttributes.getDownloadAttribute())
95-
if (downloadAttributeIndex != null && downloadAttributeIndex >= 0) {
96-
val updatedAttribute = shareAttributes[downloadAttributeIndex].copy(isEnabled = isChecked)
97-
shareAttributes[downloadAttributeIndex] = updatedAttribute
94+
if (shareAttributes == null) {
95+
val downloadAttribute = ShareAttributes.createDownloadAttributes(isChecked)
96+
val updatedShareAttributes = listOf(downloadAttribute)
97+
return ShareAttributesJsonHandler.toJson(updatedShareAttributes)
9898
}
9999

100-
if (shareAttributes == null) {
101-
return null
100+
val downloadAttributeIndex = shareAttributes.indexOf(shareAttributes.getDownloadAttribute())
101+
if (downloadAttributeIndex >= 0) {
102+
val updatedAttribute = shareAttributes[downloadAttributeIndex].copy(value = isChecked)
103+
shareAttributes[downloadAttributeIndex] = updatedAttribute
102104
}
103105

104106
return ShareAttributesJsonHandler.toJson(shareAttributes)
105107
}
106108

107109
fun isAllowDownloadAndSyncEnabled(share: OCShare?): Boolean {
108-
return getShareAttributes(share).getDownloadAttribute()?.isEnabled == true
110+
return getShareAttributes(share).getDownloadAttribute()?.value == true
109111
}
110112

111113
private fun getShareAttributes(share: OCShare?): List<ShareAttributes>? {

0 commit comments

Comments
 (0)