Skip to content

Commit e148648

Browse files
committed
implement allow download and sync
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent 25a222f commit e148648

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed

app/src/main/java/it/niedermann/owncloud/notes/share/NoteShareActivity.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,14 +859,22 @@ public void setPasswordToShare(@NotNull OCShare share, @Nullable String password
859859

860860
executorService.submit(() -> {
861861
{
862+
boolean isDownloadAndAllowsSyncEnabled = repository.isAllowDownloadAndSync(share);
863+
864+
String attributes = UpdateShareRequest.Companion.createAttributes(
865+
repository.getCapabilities(),
866+
isDownloadAndAllowsSyncEnabled,
867+
share.getShareType()
868+
);
869+
862870
final var requestBody = new UpdateShareRequest(
863871
share.getPermissions(),
864872
password,
865873
share.getNote(),
866874
share.getLabel(),
867875
DateUtil.INSTANCE.getExpirationDate(share.getExpirationDate()),
868876
Boolean.toString(share.isHideFileDownload()),
869-
""
877+
attributes
870878
);
871879
final var result = repository.updateShare(share.getId(), requestBody);
872880

app/src/main/java/it/niedermann/owncloud/notes/share/NoteShareDetailActivity.kt

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ import it.niedermann.owncloud.notes.persistence.isSuccess
2727
import it.niedermann.owncloud.notes.share.dialog.ExpirationDatePickerDialogFragment
2828
import it.niedermann.owncloud.notes.share.helper.SharePermissionManager
2929
import it.niedermann.owncloud.notes.share.model.QuickPermissionType
30-
import it.niedermann.owncloud.notes.share.model.ShareAttributesV1
31-
import it.niedermann.owncloud.notes.share.model.ShareAttributesV2
3230
import it.niedermann.owncloud.notes.share.model.UpdateShareRequest
3331
import it.niedermann.owncloud.notes.share.repository.ShareRepository
3432
import it.niedermann.owncloud.notes.shared.util.DisplayUtils
@@ -332,18 +330,7 @@ class NoteShareDetailActivity :
332330
allowDownloadAndSync.visibility = View.VISIBLE
333331

334332
share?.let {
335-
val entity = repository.getShareByPathAndDisplayName(it)
336-
val attributes = entity?.attributes ?: return
337-
share?.attributes = attributes
338-
339-
val capabilities = repository.getCapabilities()
340-
val shouldUseShareAttributesV2 = (capabilities.nextcloudMajorVersion?.toInt() ?: 0) >= 30
341-
val isDownloadAndAllowsSyncEnabled = if (shouldUseShareAttributesV2) {
342-
ShareAttributesV2.getAttributes(attributes).first().value
343-
} else {
344-
ShareAttributesV1.getAttributes(attributes).first().enabled
345-
}
346-
333+
val isDownloadAndAllowsSyncEnabled = repository.isAllowDownloadAndSync(it)
347334
binding.allowDownloadAndSync.isChecked = isDownloadAndAllowsSyncEnabled
348335
}
349336
}

app/src/main/java/it/niedermann/owncloud/notes/share/model/UpdateShareRequest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ data class UpdateShareRequest(
4343
val attributes: String? = null
4444
) {
4545
companion object {
46-
fun createAttributes(capabilities: Capabilities, allowDownloadAndSync: Boolean, type: ShareType): String {
47-
if (type != ShareType.INTERNAL && type != ShareType.USER) {
46+
fun createAttributes(capabilities: Capabilities, allowDownloadAndSync: Boolean, type: ShareType?): String {
47+
if (type == null || (type != ShareType.INTERNAL && type != ShareType.USER)) {
4848
return "[]"
4949
}
5050

app/src/main/java/it/niedermann/owncloud/notes/share/repository/ShareRepository.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import it.niedermann.owncloud.notes.persistence.entity.Note
2121
import it.niedermann.owncloud.notes.persistence.entity.ShareEntity
2222
import it.niedermann.owncloud.notes.share.model.CreateShareRequest
2323
import it.niedermann.owncloud.notes.share.model.CreateShareResponse
24+
import it.niedermann.owncloud.notes.share.model.ShareAttributesV1
25+
import it.niedermann.owncloud.notes.share.model.ShareAttributesV2
2426
import it.niedermann.owncloud.notes.share.model.UpdateSharePermissionRequest
2527
import it.niedermann.owncloud.notes.share.model.UpdateShareRequest
2628
import it.niedermann.owncloud.notes.share.model.toOCShareList
@@ -129,6 +131,18 @@ class ShareRepository(private val applicationContext: Context, private val accou
129131
return notesRepository.getShareByPathAndDisplayName(share)
130132
}
131133

134+
fun isAllowDownloadAndSync(share: OCShare): Boolean {
135+
val entity = getShareByPathAndDisplayName(share)
136+
val attributes = entity?.attributes ?: return false
137+
val capabilities = notesRepository.capabilities
138+
val shouldUseShareAttributesV2 = (capabilities.nextcloudMajorVersion?.toInt() ?: 0) >= 30
139+
return if (shouldUseShareAttributesV2) {
140+
ShareAttributesV2.getAttributes(attributes).first().value
141+
} else {
142+
ShareAttributesV1.getAttributes(attributes).first().enabled
143+
}
144+
}
145+
132146
private fun LinkedTreeMap<*, *>.getList(key: String): ArrayList<*>? = this[key] as? ArrayList<*>
133147

134148
/**

0 commit comments

Comments
 (0)