diff --git a/app/src/androidTest/java/com/nextcloud/client/assistant/AssistantRepositoryTests.kt b/app/src/androidTest/java/com/nextcloud/client/assistant/AssistantRepositoryTests.kt index aa3eefb8c2..6895f6e3b9 100644 --- a/app/src/androidTest/java/com/nextcloud/client/assistant/AssistantRepositoryTests.kt +++ b/app/src/androidTest/java/com/nextcloud/client/assistant/AssistantRepositoryTests.kt @@ -9,6 +9,8 @@ package com.nextcloud.client.assistant import com.nextcloud.client.assistant.repository.AssistantRepository import com.owncloud.android.AbstractOnServerIT +import com.owncloud.android.lib.resources.assistant.model.TaskTypeData +import com.owncloud.android.lib.resources.assistant.model.toTaskTypeDataList import com.owncloud.android.lib.resources.status.NextcloudVersion import org.junit.Assert.assertTrue import org.junit.Before @@ -35,7 +37,7 @@ class AssistantRepositoryTests : AbstractOnServerIT() { val result = sut?.getTaskTypes() assertTrue(result?.isSuccess == true) - val taskTypes = result?.resultData?.types + val taskTypes = result?.resultData?.toTaskTypeDataList() assertTrue(taskTypes?.isNotEmpty() == true) } @@ -63,8 +65,12 @@ class AssistantRepositoryTests : AbstractOnServerIT() { } val input = "Give me some random output for test purpose" - val type = "OCP\\TextProcessing\\FreePromptTaskType" - val result = sut?.createTask(input, type) + val taskType = TaskTypeData( + "core:text2text", + "Free text to text prompt", + "Runs an arbitrary prompt through a language model that returns a reply" + ) + val result = sut?.createTask(input, taskType) assertTrue(result?.isSuccess == true) } diff --git a/app/src/main/java/com/nextcloud/client/assistant/AssistantViewModel.kt b/app/src/main/java/com/nextcloud/client/assistant/AssistantViewModel.kt index 579e0233a8..a314571ae0 100644 --- a/app/src/main/java/com/nextcloud/client/assistant/AssistantViewModel.kt +++ b/app/src/main/java/com/nextcloud/client/assistant/AssistantViewModel.kt @@ -12,10 +12,10 @@ import androidx.lifecycle.viewModelScope import com.nextcloud.client.assistant.model.ScreenOverlayState import com.nextcloud.client.assistant.model.ScreenState import com.nextcloud.client.assistant.repository.AssistantRepositoryType -import com.nextcloud.client.assistant.taskTypes.model.AssistantTaskType -import com.nextcloud.client.assistant.taskTypes.model.toAssistantTaskTypeList import com.owncloud.android.R import com.owncloud.android.lib.resources.assistant.model.Task +import com.owncloud.android.lib.resources.assistant.model.TaskTypeData +import com.owncloud.android.lib.resources.assistant.model.toTaskTypeDataList import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableStateFlow @@ -36,11 +36,11 @@ class AssistantViewModel( private val _snackbarMessageId = MutableStateFlow(null) val snackbarMessageId: StateFlow = _snackbarMessageId - private val _selectedTaskType = MutableStateFlow(null) - val selectedTaskType: StateFlow = _selectedTaskType + private val _selectedTaskType = MutableStateFlow(null) + val selectedTaskType: StateFlow = _selectedTaskType - private val _taskTypes = MutableStateFlow?>(null) - val taskTypes: StateFlow?> = _taskTypes + private val _taskTypes = MutableStateFlow?>(null) + val taskTypes: StateFlow?> = _taskTypes private var taskList: List? = null @@ -52,9 +52,9 @@ class AssistantViewModel( } @Suppress("MagicNumber") - fun createTask(input: String, type: String) { + fun createTask(input: String, taskType: TaskTypeData) { viewModelScope.launch(Dispatchers.IO) { - val result = repository.createTask(input, type) + val result = repository.createTask(input, taskType) val messageId = if (result.isSuccess) { R.string.assistant_screen_task_create_success_message @@ -69,7 +69,7 @@ class AssistantViewModel( } } - fun selectTaskType(task: AssistantTaskType) { + fun selectTaskType(task: TaskTypeData) { _selectedTaskType.update { task } @@ -82,7 +82,7 @@ class AssistantViewModel( val taskTypesResult = repository.getTaskTypes() if (taskTypesResult.isSuccess) { - val result = taskTypesResult.resultData.toAssistantTaskTypeList() + val result = taskTypesResult.resultData.toTaskTypeDataList() _taskTypes.update { result } diff --git a/app/src/main/java/com/nextcloud/client/assistant/AsssistantScreen.kt b/app/src/main/java/com/nextcloud/client/assistant/AsssistantScreen.kt index 97bb8b2649..2e8b8c627b 100644 --- a/app/src/main/java/com/nextcloud/client/assistant/AsssistantScreen.kt +++ b/app/src/main/java/com/nextcloud/client/assistant/AsssistantScreen.kt @@ -44,13 +44,13 @@ import com.nextcloud.client.assistant.model.ScreenState import com.nextcloud.client.assistant.repository.AssistantMockRepository import com.nextcloud.client.assistant.task.TaskView import com.nextcloud.client.assistant.taskTypes.TaskTypesRow -import com.nextcloud.client.assistant.taskTypes.model.AssistantTaskType import com.nextcloud.ui.composeActivity.ComposeActivity import com.nextcloud.ui.composeComponents.alertDialog.SimpleAlertDialog import com.nextcloud.ui.composeComponents.bottomSheet.MoreActionsBottomSheet import com.nextcloud.utils.extensions.showShareIntent import com.owncloud.android.R import com.owncloud.android.lib.resources.assistant.model.Task +import com.owncloud.android.lib.resources.assistant.model.TaskTypeData import com.owncloud.android.utils.ClipboardUtil import com.owncloud.android.utils.DisplayUtils import kotlinx.coroutines.delay @@ -102,8 +102,8 @@ fun AssistantScreen(viewModel: AssistantViewModel, activity: Activity) { @Composable private fun ShowScreenState( screenState: ScreenState?, - selectedTaskType: AssistantTaskType?, - taskTypes: List?, + selectedTaskType: TaskTypeData?, + taskTypes: List?, viewModel: AssistantViewModel, filteredTaskList: List? ) { @@ -143,7 +143,7 @@ private fun ShowLinearProgressIndicator(screenState: ScreenState?, pullToRefresh } @Composable -private fun AddFloatingActionButton(modifier: Modifier, selectedTaskType: AssistantTaskType?, viewModel: AssistantViewModel) { +private fun AddFloatingActionButton(modifier: Modifier, selectedTaskType: TaskTypeData?, viewModel: AssistantViewModel) { FloatingActionButton( modifier = modifier, onClick = { @@ -181,8 +181,8 @@ private fun ShowOverlayState( description = state.taskType.description, defaultInput = state.input, addTask = { input -> - state.taskType.id?.let { taskTypeId -> - viewModel.createTask(input = input, type = taskTypeId) + state.taskType.let { taskType -> + viewModel.createTask(input = input, taskType = taskType) } }, dismiss = { @@ -218,7 +218,7 @@ private fun ShowOverlayState( R.drawable.ic_edit, R.string.action_edit ) { - val taskType = AssistantTaskType( + val taskType = TaskTypeData( state.task.type, activity.getString(R.string.assistant_screen_add_task_alert_dialog_title), null @@ -252,8 +252,8 @@ private fun ShowOverlayState( @Composable private fun AssistantContent( taskList: List, - taskTypes: List?, - selectedTaskType: AssistantTaskType?, + taskTypes: List?, + selectedTaskType: TaskTypeData?, viewModel: AssistantViewModel ) { LazyColumn( @@ -282,7 +282,7 @@ private fun AssistantContent( } @Composable -private fun EmptyTaskList(selectedTaskType: AssistantTaskType?, taskTypes: List?, viewModel: AssistantViewModel) { +private fun EmptyTaskList(selectedTaskType: TaskTypeData?, taskTypes: List?, viewModel: AssistantViewModel) { val text = stringResource( id = R.string.assistant_screen_no_task_available_text, selectedTaskType?.name ?: "" diff --git a/app/src/main/java/com/nextcloud/client/assistant/model/ScreenOverlayState.kt b/app/src/main/java/com/nextcloud/client/assistant/model/ScreenOverlayState.kt index 8ef3410d76..2b44a4e130 100644 --- a/app/src/main/java/com/nextcloud/client/assistant/model/ScreenOverlayState.kt +++ b/app/src/main/java/com/nextcloud/client/assistant/model/ScreenOverlayState.kt @@ -7,11 +7,11 @@ package com.nextcloud.client.assistant.model -import com.nextcloud.client.assistant.taskTypes.model.AssistantTaskType import com.owncloud.android.lib.resources.assistant.model.Task +import com.owncloud.android.lib.resources.assistant.model.TaskTypeData sealed class ScreenOverlayState { data class DeleteTask(val id: Long): ScreenOverlayState() - data class AddTask(val taskType: AssistantTaskType, val input: String): ScreenOverlayState() + data class AddTask(val taskType: TaskTypeData, val input: String): ScreenOverlayState() data class TaskActions(val task: Task): ScreenOverlayState() } diff --git a/app/src/main/java/com/nextcloud/client/assistant/repository/AssistantMockRepository.kt b/app/src/main/java/com/nextcloud/client/assistant/repository/AssistantMockRepository.kt index cf2e14e7b7..6d40e51e41 100644 --- a/app/src/main/java/com/nextcloud/client/assistant/repository/AssistantMockRepository.kt +++ b/app/src/main/java/com/nextcloud/client/assistant/repository/AssistantMockRepository.kt @@ -13,6 +13,7 @@ import com.owncloud.android.lib.resources.assistant.model.Task import com.owncloud.android.lib.resources.assistant.model.TaskInput import com.owncloud.android.lib.resources.assistant.model.TaskList import com.owncloud.android.lib.resources.assistant.model.TaskOutput +import com.owncloud.android.lib.resources.assistant.model.TaskTypeData import com.owncloud.android.lib.resources.assistant.model.TaskTypes @Suppress("MagicNumber") @@ -23,7 +24,7 @@ class AssistantMockRepository(private val giveEmptyTasks: Boolean = false) : Ass } } - override fun createTask(input: String, type: String): RemoteOperationResult { + override fun createTask(input: String, taskType: TaskTypeData): RemoteOperationResult { return RemoteOperationResult(RemoteOperationResult.ResultCode.OK) } diff --git a/app/src/main/java/com/nextcloud/client/assistant/repository/AssistantRepository.kt b/app/src/main/java/com/nextcloud/client/assistant/repository/AssistantRepository.kt index 1689ac021f..14d9b86ab5 100644 --- a/app/src/main/java/com/nextcloud/client/assistant/repository/AssistantRepository.kt +++ b/app/src/main/java/com/nextcloud/client/assistant/repository/AssistantRepository.kt @@ -14,6 +14,7 @@ import com.owncloud.android.lib.resources.assistant.DeleteTaskRemoteOperation import com.owncloud.android.lib.resources.assistant.GetTaskListRemoteOperation import com.owncloud.android.lib.resources.assistant.GetTaskTypesRemoteOperation import com.owncloud.android.lib.resources.assistant.model.TaskList +import com.owncloud.android.lib.resources.assistant.model.TaskTypeData import com.owncloud.android.lib.resources.assistant.model.TaskTypes class AssistantRepository(private val client: NextcloudClient) : AssistantRepositoryType { @@ -22,8 +23,8 @@ class AssistantRepository(private val client: NextcloudClient) : AssistantReposi return GetTaskTypesRemoteOperation().execute(client) } - override fun createTask(input: String, type: String): RemoteOperationResult { - return CreateTaskRemoteOperation(input, type).execute(client) + override fun createTask(input: String, taskType: TaskTypeData): RemoteOperationResult { + return CreateTaskRemoteOperation(input, taskType).execute(client) } override fun getTaskList(taskType: String): RemoteOperationResult { diff --git a/app/src/main/java/com/nextcloud/client/assistant/repository/AssistantRepositoryType.kt b/app/src/main/java/com/nextcloud/client/assistant/repository/AssistantRepositoryType.kt index e8a0d2fb67..c653d47153 100644 --- a/app/src/main/java/com/nextcloud/client/assistant/repository/AssistantRepositoryType.kt +++ b/app/src/main/java/com/nextcloud/client/assistant/repository/AssistantRepositoryType.kt @@ -9,12 +9,13 @@ package com.nextcloud.client.assistant.repository import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.resources.assistant.model.TaskList +import com.owncloud.android.lib.resources.assistant.model.TaskTypeData import com.owncloud.android.lib.resources.assistant.model.TaskTypes interface AssistantRepositoryType { fun getTaskTypes(): RemoteOperationResult - fun createTask(input: String, type: String): RemoteOperationResult + fun createTask(input: String, taskType: TaskTypeData): RemoteOperationResult fun getTaskList(taskType: String): RemoteOperationResult diff --git a/app/src/main/java/com/nextcloud/client/assistant/taskTypes/TaskTypesRow.kt b/app/src/main/java/com/nextcloud/client/assistant/taskTypes/TaskTypesRow.kt index 976d8603c9..99a336de45 100644 --- a/app/src/main/java/com/nextcloud/client/assistant/taskTypes/TaskTypesRow.kt +++ b/app/src/main/java/com/nextcloud/client/assistant/taskTypes/TaskTypesRow.kt @@ -20,10 +20,10 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp -import com.nextcloud.client.assistant.taskTypes.model.AssistantTaskType +import com.owncloud.android.lib.resources.assistant.model.TaskTypeData @Composable -fun TaskTypesRow(selectedTaskType: AssistantTaskType?, data: List?, selectTaskType: (AssistantTaskType) -> Unit) { +fun TaskTypesRow(selectedTaskType: TaskTypeData?, data: List?, selectTaskType: (TaskTypeData) -> Unit) { Row( modifier = Modifier .fillMaxWidth() diff --git a/app/src/main/java/com/nextcloud/client/assistant/taskTypes/model/AssistantTaskType.kt b/app/src/main/java/com/nextcloud/client/assistant/taskTypes/model/AssistantTaskType.kt deleted file mode 100644 index 2da8192465..0000000000 --- a/app/src/main/java/com/nextcloud/client/assistant/taskTypes/model/AssistantTaskType.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Nextcloud - Android Client - * - * SPDX-FileCopyrightText: 2024 Alper Ozturk - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -package com.nextcloud.client.assistant.taskTypes.model - -import com.owncloud.android.lib.resources.assistant.model.TaskIds -import com.owncloud.android.lib.resources.assistant.model.TaskTypes - -data class AssistantTaskType( - val id: String?, - val name: String?, - val description: String? -) - -fun TaskTypes.toAssistantTaskTypeList(): List { - return arrayListOf().apply { - add(AssistantTaskType(TaskIds.GenerateText.id, types.generateText.name, types.generateText.description)) - add(AssistantTaskType(TaskIds.ExtractTopics.id, types.extractTopics.name, types.extractTopics.description)) - add(AssistantTaskType(TaskIds.GenerateHeadline.id, types.generateHeadline.name, types.generateHeadline.description)) - add(AssistantTaskType(TaskIds.Summarize.id, types.summarize.name, types.summarize.description)) - } -}