Skip to content

Commit e5ebd2e

Browse files
committed
fix crash
Signed-off-by: alperozturk <[email protected]>
1 parent 4cb2022 commit e5ebd2e

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

app/src/main/java/com/nextcloud/ui/fileactions/ClientIntegration.kt

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import androidx.core.graphics.createBitmap
1919
import androidx.core.graphics.drawable.toDrawable
2020
import androidx.core.net.toUri
2121
import androidx.lifecycle.lifecycleScope
22+
import com.google.gson.Gson
2223
import com.google.gson.GsonBuilder
2324
import com.google.gson.JsonElement
2425
import com.google.gson.JsonParser
@@ -28,6 +29,7 @@ import com.nextcloud.android.lib.resources.clientintegration.ClientIntegrationUI
2829
import com.nextcloud.android.lib.resources.clientintegration.Element
2930
import com.nextcloud.android.lib.resources.clientintegration.ElementTypeAdapter
3031
import com.nextcloud.android.lib.resources.clientintegration.Endpoint
32+
import com.nextcloud.android.lib.resources.clientintegration.TooltipResponse
3133
import com.nextcloud.client.account.User
3234
import com.nextcloud.common.JSONRequestBody
3335
import com.nextcloud.operations.GetMethod
@@ -170,7 +172,12 @@ class ClientIntegration(
170172
var output: ClientIntegrationUI?
171173
try {
172174
output = parseClientIntegrationResult(response)
173-
startClientIntegration(endpoint, output)
175+
if (output.root != null) {
176+
startClientIntegration(endpoint, output)
177+
} else {
178+
val tooltipResponse = parseTooltipResult(response)
179+
context.showToast(tooltipResponse.tooltip)
180+
}
174181
} catch (_: JsonSyntaxException) {
175182
if (result == HttpStatus.SC_OK) {
176183
context.showToast(context.resources.getString(R.string.action_triggered))
@@ -182,9 +189,17 @@ class ClientIntegration(
182189
}
183190
}
184191

185-
private fun startClientIntegration(endpoint: Endpoint, clientIntegrationUI: ClientIntegrationUI) {
192+
private fun parseTooltipResult(response: String?): TooltipResponse {
193+
val element: JsonElement = JsonParser.parseString(response)
194+
return Gson()
195+
.fromJson(element, object : TypeToken<ServerResponse<TooltipResponse>>() {})
196+
.ocs
197+
.data
198+
}
199+
200+
private fun startClientIntegration(endpoint: Endpoint, data: ClientIntegrationUI) {
186201
sheet.lifecycleScope.launch(Dispatchers.IO) {
187-
val integrationScreen = ComposeDestination.ClientIntegrationScreen(endpoint.name, clientIntegrationUI)
202+
val integrationScreen = ComposeDestination.ClientIntegrationScreen(endpoint.name, data)
188203

189204
val bundle = Bundle().apply {
190205
putParcelable(ComposeActivity.DESTINATION, integrationScreen)

0 commit comments

Comments
 (0)