diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/CreateTaskRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/CreateTaskRemoteOperation.kt index 72f566dd5..efb877227 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/CreateTaskRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/CreateTaskRemoteOperation.kt @@ -12,11 +12,12 @@ import com.nextcloud.common.NextcloudClient import com.nextcloud.operations.PostMethod import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult +import com.owncloud.android.lib.resources.assistant.model.TaskTypeData import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.RequestBody.Companion.toRequestBody import org.apache.commons.httpclient.HttpStatus -class CreateTaskRemoteOperation(private val input: String, private val type: String) : +class CreateTaskRemoteOperation(private val input: String, private val taskType: TaskTypeData) : RemoteOperation() { override fun run(client: NextcloudClient): RemoteOperationResult { val inputField = hashMapOf("input" to input) @@ -24,7 +25,7 @@ class CreateTaskRemoteOperation(private val input: String, private val type: Str val requestBody = hashMapOf( "input" to inputField, - "type" to type, + "type" to taskType.id, "appId" to "assistant", "customId" to "" ) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt b/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt index de88b6fa6..719efb065 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt @@ -10,30 +10,31 @@ package com.owncloud.android.lib.resources.assistant.model import com.google.gson.annotations.SerializedName -enum class TaskIds(val id: String) { - GenerateText("core:text2text"), - ExtractTopics("core:text2text:topics"), - GenerateHeadline("core:text2text:headline"), - Summarize("core:text2text:summary") -} +private const val generateTextId = "core:text2text" +private const val extractTopicsId = "core:text2text:topics" +private const val generateHeadlineId = "core:text2text:headline" +private const val summarizeId = "core:text2text:summary" data class TaskTypes(val types: TaskType) data class TaskType( - @SerializedName("core:text2text") - val generateText: GenerateText, - @SerializedName("core:text2text:topics") - val extractTopics: ExtractTopics, - @SerializedName("core:text2text:headline") - val generateHeadline: GenerateHeadline, - @SerializedName("core:text2text:summary") - val summarize: Summarize + @SerializedName(generateTextId) + val generateText: TaskTypeData, + @SerializedName(extractTopicsId) + val extractTopics: TaskTypeData, + @SerializedName(generateHeadlineId) + val generateHeadline: TaskTypeData, + @SerializedName(summarizeId) + val summarize: TaskTypeData ) -data class GenerateText(val name: String, val description: String) - -data class ExtractTopics(val name: String, val description: String) +data class TaskTypeData(val id: String?, val name: String?, val description: String?) -data class GenerateHeadline(val name: String, val description: String) - -data class Summarize(val name: String, val description: String) +fun TaskTypes.toTaskTypeDataList(): List { + return listOf( + types.generateText to generateTextId, + types.extractTopics to extractTopicsId, + types.generateHeadline to generateHeadlineId, + types.summarize to summarizeId + ).map { (taskData, id) -> taskData.copy(id = taskData.id ?: id) } +}