Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit 173b12e

Browse files
abelgardepJuancaG05
authored andcommitted
Retrieve the list of available apps to open in web
1 parent 602ab41 commit 173b12e

File tree

4 files changed

+202
-0
lines changed

4 files changed

+202
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/* ownCloud Android Library is available under MIT license
2+
* @author Abel García de Prada
3+
*
4+
* Copyright (C) 2023 ownCloud GmbH.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*
25+
*/
26+
package com.owncloud.android.lib.resources.appregistry
27+
28+
import com.owncloud.android.lib.common.OwnCloudClient
29+
import com.owncloud.android.lib.common.http.HttpConstants
30+
import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod
31+
import com.owncloud.android.lib.common.operations.RemoteOperation
32+
import com.owncloud.android.lib.common.operations.RemoteOperationResult
33+
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK
34+
import com.owncloud.android.lib.resources.appregistry.responses.AppRegistryResponse
35+
import com.squareup.moshi.JsonAdapter
36+
import com.squareup.moshi.Moshi
37+
import timber.log.Timber
38+
import java.net.URL
39+
40+
class GetRemoteAppRegistryOperation : RemoteOperation<AppRegistryResponse>() {
41+
42+
override fun run(client: OwnCloudClient): RemoteOperationResult<AppRegistryResponse> {
43+
var result: RemoteOperationResult<AppRegistryResponse>
44+
45+
try {
46+
val uriBuilder = client.baseUri.buildUpon().apply {
47+
appendEncodedPath(APP_REGISTRY_ENDPOINT)
48+
}
49+
val getMethod = GetMethod(URL(uriBuilder.build().toString()))
50+
val status = client.executeHttpMethod(getMethod)
51+
52+
val response = getMethod.getResponseBodyAsString()
53+
54+
if (status == HttpConstants.HTTP_OK) {
55+
Timber.d("Successful response $response")
56+
57+
// Parse the response
58+
val moshi: Moshi = Moshi.Builder().build()
59+
val adapter: JsonAdapter<AppRegistryResponse> = moshi.adapter(AppRegistryResponse::class.java)
60+
val appRegistryResponse: AppRegistryResponse = response?.let { adapter.fromJson(it) } ?: AppRegistryResponse(value = emptyList())
61+
62+
result = RemoteOperationResult(OK)
63+
result.data = appRegistryResponse
64+
65+
Timber.d("Get AppRegistry completed and parsed to ${result.data}")
66+
} else {
67+
result = RemoteOperationResult(getMethod)
68+
Timber.e("Failed response while getting app registry from the server status code: $status; response message: $response")
69+
}
70+
71+
} catch (e: Exception) {
72+
result = RemoteOperationResult(e)
73+
Timber.e(e, "Exception while getting app registry")
74+
}
75+
76+
return result
77+
}
78+
79+
companion object {
80+
private const val APP_REGISTRY_ENDPOINT = "app/list"
81+
}
82+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* ownCloud Android Library is available under MIT license
2+
* @author Abel García de Prada
3+
*
4+
* Copyright (C) 2023 ownCloud GmbH.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*
25+
*/
26+
package com.owncloud.android.lib.resources.appregistry.responses
27+
28+
import com.squareup.moshi.Json
29+
import com.squareup.moshi.JsonClass
30+
31+
@JsonClass(generateAdapter = true)
32+
data class AppRegistryResponse(
33+
@Json(name = "mime-types")
34+
val value: List<AppRegistryMimeTypeResponse>
35+
)
36+
37+
@JsonClass(generateAdapter = true)
38+
data class AppRegistryMimeTypeResponse(
39+
@Json(name = "mime_type") val mimeType: String,
40+
val ext: String? = null,
41+
@Json(name = "app_providers")
42+
val appProviders: List<AppRegistryProviderResponse>,
43+
val name: String? = null,
44+
val icon: String? = null,
45+
val description: String? = null,
46+
@Json(name = "allow_creation")
47+
val allowCreation: Boolean? = null,
48+
@Json(name = "default_application")
49+
val defaultApplication: String? = null
50+
)
51+
52+
@JsonClass(generateAdapter = true)
53+
data class AppRegistryProviderResponse(
54+
val name: String,
55+
val icon: String,
56+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* ownCloud Android Library is available under MIT license
2+
* Copyright (C) 2023 ownCloud GmbH.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*/
23+
package com.owncloud.android.lib.resources.appregistry.services
24+
25+
import com.owncloud.android.lib.common.operations.RemoteOperationResult
26+
import com.owncloud.android.lib.resources.Service
27+
import com.owncloud.android.lib.resources.appregistry.responses.AppRegistryResponse
28+
29+
interface AppRegistryService : Service {
30+
fun getAppRegistry(): RemoteOperationResult<AppRegistryResponse>
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* ownCloud Android Library is available under MIT license
2+
* Copyright (C) 2023 ownCloud GmbH.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*/
23+
package com.owncloud.android.lib.resources.appregistry.services
24+
25+
import com.owncloud.android.lib.common.OwnCloudClient
26+
import com.owncloud.android.lib.common.operations.RemoteOperationResult
27+
import com.owncloud.android.lib.resources.appregistry.responses.AppRegistryResponse
28+
import com.owncloud.android.lib.resources.appregistry.GetRemoteAppRegistryOperation
29+
30+
class OCAppRegistryService(override val client: OwnCloudClient) : AppRegistryService {
31+
override fun getAppRegistry(): RemoteOperationResult<AppRegistryResponse> =
32+
GetRemoteAppRegistryOperation().execute(client)
33+
}

0 commit comments

Comments
 (0)