-
Notifications
You must be signed in to change notification settings - Fork 94
Remove share attributes & use OCShare extensions #1758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c938326
useV2
alperozturk96 d3e30e7
useV2
alperozturk96 74a89ae
useV2
alperozturk96 3e52ee0
useV2
alperozturk96 21beee4
add OCShare ext
alperozturk96 bb94fbc
toggleAllowDownloadAndSync must not be extension thus user can create…
alperozturk96 0303be5
fix
alperozturk96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
...ary/src/main/java/com/owncloud/android/lib/resources/shares/attributes/ShareAttributes.kt
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
.../java/com/owncloud/android/lib/resources/shares/attributes/ShareAttributesDeserializer.kt
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
...n/java/com/owncloud/android/lib/resources/shares/attributes/ShareAttributesJsonHandler.kt
This file was deleted.
Oops, something went wrong.
69 changes: 69 additions & 0 deletions
69
...y/src/main/java/com/owncloud/android/lib/resources/shares/extensions/OCShareExtensions.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Nextcloud Android Library | ||
* | ||
* SPDX-FileCopyrightText: 2025 Alper Ozturk <[email protected]> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
package com.owncloud.android.lib.resources.shares.extensions | ||
|
||
import com.owncloud.android.lib.resources.shares.OCShare | ||
import org.json.JSONArray | ||
import org.json.JSONObject | ||
|
||
private const val KEY = "key" | ||
private const val SCOPE_KEY = "scope" | ||
private const val DOWNLOAD_KEY = "download" | ||
private const val PERMISSIONS_KEY = "permissions" | ||
private const val VALUE_KEY = "value" | ||
private const val ENABLED_KEY = "enabled" | ||
|
||
fun toggleAllowDownloadAndSync( | ||
attributes: String?, | ||
isChecked: Boolean, | ||
useV2DownloadAttributes: Boolean | ||
): String? { | ||
var jsonArray = JSONArray() | ||
if (!attributes.isNullOrEmpty()) { | ||
jsonArray = JSONArray(attributes) | ||
} | ||
|
||
val downloadAttr = jsonArray.findDownloadAttribute() | ||
val enabledKey = getEnabledKey(useV2DownloadAttributes) | ||
|
||
if (downloadAttr != null) { | ||
downloadAttr.put(enabledKey, isChecked) | ||
} else { | ||
jsonArray.put( | ||
JSONObject().apply { | ||
put(KEY, DOWNLOAD_KEY) | ||
put(SCOPE_KEY, PERMISSIONS_KEY) | ||
put(enabledKey, isChecked) | ||
} | ||
) | ||
} | ||
|
||
return jsonArray.toString() | ||
} | ||
|
||
@Suppress("ReturnCount") | ||
fun OCShare?.isAllowDownloadAndSyncEnabled(useV2DownloadAttributes: Boolean): Boolean { | ||
if (this?.attributes.isNullOrEmpty()) return false | ||
|
||
val jsonArray = JSONArray(this.attributes) | ||
val downloadAttr = jsonArray.findDownloadAttribute() ?: return false | ||
val enabledKey = getEnabledKey(useV2DownloadAttributes) | ||
|
||
return downloadAttr.optBoolean(enabledKey, false) | ||
} | ||
|
||
private fun JSONArray.findDownloadAttribute(): JSONObject? = | ||
(0 until length()) | ||
.asSequence() | ||
.map { getJSONObject(it) } | ||
.find { | ||
it.optString(KEY) == DOWNLOAD_KEY && | ||
it.optString(SCOPE_KEY) == PERMISSIONS_KEY | ||
} | ||
|
||
private fun getEnabledKey(isV2: Boolean): String = if (isV2) VALUE_KEY else ENABLED_KEY |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cannot be implemented as an extension, as the share object does not exist at the time of share creation. Therefore, optional attributes should be passed as a string parameter instead.