mirror of
https://github.com/nextcloud/android.git
synced 2024-12-19 07:22:06 +03:00
Use task types for create operation
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
4796b67943
commit
ac3c735d97
9 changed files with 40 additions and 57 deletions
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Int?>(null)
|
||||
val snackbarMessageId: StateFlow<Int?> = _snackbarMessageId
|
||||
|
||||
private val _selectedTaskType = MutableStateFlow<AssistantTaskType?>(null)
|
||||
val selectedTaskType: StateFlow<AssistantTaskType?> = _selectedTaskType
|
||||
private val _selectedTaskType = MutableStateFlow<TaskTypeData?>(null)
|
||||
val selectedTaskType: StateFlow<TaskTypeData?> = _selectedTaskType
|
||||
|
||||
private val _taskTypes = MutableStateFlow<List<AssistantTaskType>?>(null)
|
||||
val taskTypes: StateFlow<List<AssistantTaskType>?> = _taskTypes
|
||||
private val _taskTypes = MutableStateFlow<List<TaskTypeData>?>(null)
|
||||
val taskTypes: StateFlow<List<TaskTypeData>?> = _taskTypes
|
||||
|
||||
private var taskList: List<Task>? = 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
|
||||
}
|
||||
|
|
|
@ -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<AssistantTaskType>?,
|
||||
selectedTaskType: TaskTypeData?,
|
||||
taskTypes: List<TaskTypeData>?,
|
||||
viewModel: AssistantViewModel,
|
||||
filteredTaskList: List<Task>?
|
||||
) {
|
||||
|
@ -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<Task>,
|
||||
taskTypes: List<AssistantTaskType>?,
|
||||
selectedTaskType: AssistantTaskType?,
|
||||
taskTypes: List<TaskTypeData>?,
|
||||
selectedTaskType: TaskTypeData?,
|
||||
viewModel: AssistantViewModel
|
||||
) {
|
||||
LazyColumn(
|
||||
|
@ -282,7 +282,7 @@ private fun AssistantContent(
|
|||
}
|
||||
|
||||
@Composable
|
||||
private fun EmptyTaskList(selectedTaskType: AssistantTaskType?, taskTypes: List<AssistantTaskType>?, viewModel: AssistantViewModel) {
|
||||
private fun EmptyTaskList(selectedTaskType: TaskTypeData?, taskTypes: List<TaskTypeData>?, viewModel: AssistantViewModel) {
|
||||
val text = stringResource(
|
||||
id = R.string.assistant_screen_no_task_available_text,
|
||||
selectedTaskType?.name ?: ""
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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<Void> {
|
||||
override fun createTask(input: String, taskType: TaskTypeData): RemoteOperationResult<Void> {
|
||||
return RemoteOperationResult<Void>(RemoteOperationResult.ResultCode.OK)
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Void> {
|
||||
return CreateTaskRemoteOperation(input, type).execute(client)
|
||||
override fun createTask(input: String, taskType: TaskTypeData): RemoteOperationResult<Void> {
|
||||
return CreateTaskRemoteOperation(input, taskType).execute(client)
|
||||
}
|
||||
|
||||
override fun getTaskList(taskType: String): RemoteOperationResult<TaskList> {
|
||||
|
|
|
@ -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<TaskTypes>
|
||||
|
||||
fun createTask(input: String, type: String): RemoteOperationResult<Void>
|
||||
fun createTask(input: String, taskType: TaskTypeData): RemoteOperationResult<Void>
|
||||
|
||||
fun getTaskList(taskType: String): RemoteOperationResult<TaskList>
|
||||
|
||||
|
|
|
@ -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<AssistantTaskType>?, selectTaskType: (AssistantTaskType) -> Unit) {
|
||||
fun TaskTypesRow(selectedTaskType: TaskTypeData?, data: List<TaskTypeData>?, selectTaskType: (TaskTypeData) -> Unit) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
* Nextcloud - Android Client
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2024 Alper Ozturk <alper.ozturk@nextcloud.com>
|
||||
* 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<AssistantTaskType> {
|
||||
return arrayListOf<AssistantTaskType>().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))
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue