-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[FEATURE REQUEST] Update space image #4705
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
Open
joragua
wants to merge
9
commits into
master
Choose a base branch
from
feature/update_space_image
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b670765
feat: add edit space image option in bottom sheet dialog for space ma…
joragua beff40d
feat: launch SAF intent for selected image mime types when editing sp…
joragua c3bf3f6
feat: upload chosen file to .space directory
joragua 7dcca12
feat: implement methods and network operation to update the space ima…
joragua 23fec7b
test: add new tests for OCRemoteSpacesDataSourceTest and OCSpacesRepo…
joragua 05c2ae9
chore: add calens file
joragua 17e9a29
refactor: improve strings for space image editing
joragua 3c78e65
refactor: create constants for image mime types
joragua 0749466
docs: calens changelog updated
ownclouders 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
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,7 @@ | ||
| Enhancement: Update space image | ||
|
|
||
| A new option to update the space image has been added to the bottom sheet, available | ||
| only to users with the required permissions when the three-dot menu button is tapped. | ||
|
|
||
| https://github.com/owncloud/android/issues/4691 | ||
| https://github.com/owncloud/android/pull/4705 |
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
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
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
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
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
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
104 changes: 104 additions & 0 deletions
104
.../src/main/java/com/owncloud/android/lib/resources/spaces/EditRemoteSpaceImageOperation.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,104 @@ | ||
| /** | ||
| * ownCloud Android client application | ||
| * | ||
| * @author Jorge Aguado Recio | ||
| * | ||
| * Copyright (C) 2025 ownCloud GmbH. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License version 2, | ||
| * as published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
|
|
||
| package com.owncloud.android.lib.resources.spaces | ||
|
|
||
| import com.owncloud.android.lib.common.OwnCloudClient | ||
| import com.owncloud.android.lib.common.http.HttpConstants | ||
| import com.owncloud.android.lib.common.http.HttpConstants.CONTENT_TYPE_JSON | ||
| import com.owncloud.android.lib.common.http.methods.nonwebdav.PatchMethod | ||
| import com.owncloud.android.lib.common.operations.RemoteOperation | ||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult | ||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode | ||
| import com.owncloud.android.lib.resources.spaces.responses.SpaceResponse | ||
| import com.squareup.moshi.JsonAdapter | ||
| import com.squareup.moshi.Moshi | ||
| import okhttp3.MediaType.Companion.toMediaType | ||
| import okhttp3.RequestBody.Companion.toRequestBody | ||
| import org.json.JSONArray | ||
| import org.json.JSONObject | ||
| import timber.log.Timber | ||
| import java.net.URL | ||
|
|
||
| class EditRemoteSpaceImageOperation( | ||
| private val spaceId: String, | ||
| private val imageId: String | ||
| ): RemoteOperation<SpaceResponse>() { | ||
| override fun run(client: OwnCloudClient): RemoteOperationResult<SpaceResponse> { | ||
| var result: RemoteOperationResult<SpaceResponse> | ||
| try { | ||
| val moshi = Moshi.Builder().build() | ||
|
|
||
| val uriBuilder = client.baseUri.buildUpon().apply { | ||
| appendEncodedPath(GRAPH_API_SPACES_PATH) | ||
| appendEncodedPath(spaceId) | ||
| } | ||
|
|
||
| val specialFolder = JSONObject().apply { | ||
| put(SPACE_NAME_BODY_PARAM, SPACE_NAME_BODY_PARAM_VALUE) | ||
| } | ||
|
|
||
| val specialEntry = JSONObject().apply { | ||
| put(SPACE_ID_BODY_PARAM, imageId) | ||
| put(SPACE_SPECIAL_FOLDER_BODY_PARAM, specialFolder) | ||
| } | ||
|
|
||
| val requestBody = JSONObject().apply { | ||
| put(SPACE_SPECIAL_BODY_PARAM, JSONArray().apply { put(specialEntry) }) | ||
| }.toString().toRequestBody(CONTENT_TYPE_JSON.toMediaType()) | ||
|
|
||
|
|
||
| val patchMethod = PatchMethod(URL(uriBuilder.build().toString()), requestBody) | ||
|
|
||
| val status = client.executeHttpMethod(patchMethod) | ||
|
|
||
| val response = patchMethod.getResponseBodyAsString() | ||
|
|
||
| if (status == HttpConstants.HTTP_OK) { | ||
| Timber.d("Successful response: $response") | ||
|
|
||
| val responseAdapter: JsonAdapter<SpaceResponse> = moshi.adapter(SpaceResponse::class.java) | ||
|
|
||
| result = RemoteOperationResult(ResultCode.OK) | ||
| result.data = responseAdapter.fromJson(response) | ||
|
|
||
| Timber.d("Update of space completed and parsed to ${result.data}") | ||
| } else { | ||
| result = RemoteOperationResult(patchMethod) | ||
| Timber.e("Failed response while updating the space; status code: $status, response: $response") | ||
| } | ||
| } catch (e: Exception) { | ||
| result = RemoteOperationResult(e) | ||
| Timber.e(e, "Exception while updating the space $spaceId") | ||
| } | ||
| return result | ||
| } | ||
|
|
||
| companion object { | ||
| private const val GRAPH_API_SPACES_PATH = "graph/v1.0/drives/" | ||
| private const val SPACE_SPECIAL_BODY_PARAM = "special" | ||
| private const val SPACE_ID_BODY_PARAM = "id" | ||
| private const val SPACE_SPECIAL_FOLDER_BODY_PARAM = "specialFolder" | ||
| private const val SPACE_NAME_BODY_PARAM = "name" | ||
| private const val SPACE_NAME_BODY_PARAM_VALUE = "image" | ||
| } | ||
|
|
||
| } |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.