1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-06 15:36:45 +00:00

Open file in web with a specific app

This commit is contained in:
Abel García de Prada 2023-03-28 10:32:24 +02:00 committed by Juan Carlos Garrote
parent f35daacdf1
commit 393ec6e07e
3 changed files with 24 additions and 8 deletions

View File

@ -30,7 +30,6 @@ import com.owncloud.android.lib.common.network.WebdavUtils
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.appregistry.GetUrlToOpenInWebRemoteOperation.OpenInWebParams.Companion.PARAM_FILE_ID
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonClass
import com.squareup.moshi.Moshi
@ -43,14 +42,16 @@ import java.util.concurrent.TimeUnit
class GetUrlToOpenInWebRemoteOperation(
val openWithWebEndpoint: String,
val fileId: String,
val appName: String,
) : RemoteOperation<String>() {
override fun run(client: OwnCloudClient): RemoteOperationResult<String> {
return try {
val openInWebRequestBody = OpenInWebParams(fileId).toRequestBody()
val openInWebRequestBody = OpenInWebParams(fileId, appName).toRequestBody()
val stringUrl = client.baseUri.toString() + WebdavUtils.encodePath(openWithWebEndpoint) + "?$PARAM_FILE_ID=$fileId"
val stringUrl =
client.baseUri.toString() + WebdavUtils.encodePath(openWithWebEndpoint)
val postMethod = PostMethod(URL(stringUrl), openInWebRequestBody).apply {
setReadTimeout(TIMEOUT, TimeUnit.MILLISECONDS)
@ -77,12 +78,19 @@ class GetUrlToOpenInWebRemoteOperation(
private fun isSuccess(status: Int) = status == HttpConstants.HTTP_OK || status == HttpConstants.HTTP_MULTI_STATUS
data class OpenInWebParams(val fileId: String) {
data class OpenInWebParams(
val fileId: String,
val appName: String,
) {
fun toRequestBody(): RequestBody =
FormBody.Builder().build()
FormBody.Builder()
.add(PARAM_FILE_ID, fileId)
.add(PARAM_APP_NAME, appName)
.build()
companion object {
const val PARAM_FILE_ID = "file_id"
const val PARAM_APP_NAME = "app_name"
}
}

View File

@ -29,5 +29,9 @@ import com.owncloud.android.lib.resources.appregistry.responses.AppRegistryRespo
interface AppRegistryService : Service {
fun getAppRegistry(): RemoteOperationResult<AppRegistryResponse>
fun getUrlToOpenInWeb(openWebEndpoint: String, fileId: String): RemoteOperationResult<String>
fun getUrlToOpenInWeb(
openWebEndpoint: String,
fileId: String,
appName: String,
): RemoteOperationResult<String>
}

View File

@ -32,6 +32,10 @@ class OCAppRegistryService(override val client: OwnCloudClient) : AppRegistrySer
override fun getAppRegistry(): RemoteOperationResult<AppRegistryResponse> =
GetRemoteAppRegistryOperation().execute(client)
override fun getUrlToOpenInWeb(openWebEndpoint: String, fileId: String): RemoteOperationResult<String> =
GetUrlToOpenInWebRemoteOperation(openWithWebEndpoint = openWebEndpoint, fileId = fileId).execute(client)
override fun getUrlToOpenInWeb(openWebEndpoint: String, fileId: String, appName: String): RemoteOperationResult<String> =
GetUrlToOpenInWebRemoteOperation(
openWithWebEndpoint = openWebEndpoint,
fileId = fileId,
appName = appName
).execute(client)
}