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.nextcloud.client.assistant.repository.AssistantRepository
|
||||||
import com.owncloud.android.AbstractOnServerIT
|
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 com.owncloud.android.lib.resources.status.NextcloudVersion
|
||||||
import org.junit.Assert.assertTrue
|
import org.junit.Assert.assertTrue
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
|
@ -35,7 +37,7 @@ class AssistantRepositoryTests : AbstractOnServerIT() {
|
||||||
val result = sut?.getTaskTypes()
|
val result = sut?.getTaskTypes()
|
||||||
assertTrue(result?.isSuccess == true)
|
assertTrue(result?.isSuccess == true)
|
||||||
|
|
||||||
val taskTypes = result?.resultData?.types
|
val taskTypes = result?.resultData?.toTaskTypeDataList()
|
||||||
assertTrue(taskTypes?.isNotEmpty() == true)
|
assertTrue(taskTypes?.isNotEmpty() == true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,8 +65,12 @@ class AssistantRepositoryTests : AbstractOnServerIT() {
|
||||||
}
|
}
|
||||||
|
|
||||||
val input = "Give me some random output for test purpose"
|
val input = "Give me some random output for test purpose"
|
||||||
val type = "OCP\\TextProcessing\\FreePromptTaskType"
|
val taskType = TaskTypeData(
|
||||||
val result = sut?.createTask(input, type)
|
"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)
|
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.ScreenOverlayState
|
||||||
import com.nextcloud.client.assistant.model.ScreenState
|
import com.nextcloud.client.assistant.model.ScreenState
|
||||||
import com.nextcloud.client.assistant.repository.AssistantRepositoryType
|
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.R
|
||||||
import com.owncloud.android.lib.resources.assistant.model.Task
|
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.Dispatchers
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
@ -36,11 +36,11 @@ class AssistantViewModel(
|
||||||
private val _snackbarMessageId = MutableStateFlow<Int?>(null)
|
private val _snackbarMessageId = MutableStateFlow<Int?>(null)
|
||||||
val snackbarMessageId: StateFlow<Int?> = _snackbarMessageId
|
val snackbarMessageId: StateFlow<Int?> = _snackbarMessageId
|
||||||
|
|
||||||
private val _selectedTaskType = MutableStateFlow<AssistantTaskType?>(null)
|
private val _selectedTaskType = MutableStateFlow<TaskTypeData?>(null)
|
||||||
val selectedTaskType: StateFlow<AssistantTaskType?> = _selectedTaskType
|
val selectedTaskType: StateFlow<TaskTypeData?> = _selectedTaskType
|
||||||
|
|
||||||
private val _taskTypes = MutableStateFlow<List<AssistantTaskType>?>(null)
|
private val _taskTypes = MutableStateFlow<List<TaskTypeData>?>(null)
|
||||||
val taskTypes: StateFlow<List<AssistantTaskType>?> = _taskTypes
|
val taskTypes: StateFlow<List<TaskTypeData>?> = _taskTypes
|
||||||
|
|
||||||
private var taskList: List<Task>? = null
|
private var taskList: List<Task>? = null
|
||||||
|
|
||||||
|
@ -52,9 +52,9 @@ class AssistantViewModel(
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("MagicNumber")
|
@Suppress("MagicNumber")
|
||||||
fun createTask(input: String, type: String) {
|
fun createTask(input: String, taskType: TaskTypeData) {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
val result = repository.createTask(input, type)
|
val result = repository.createTask(input, taskType)
|
||||||
|
|
||||||
val messageId = if (result.isSuccess) {
|
val messageId = if (result.isSuccess) {
|
||||||
R.string.assistant_screen_task_create_success_message
|
R.string.assistant_screen_task_create_success_message
|
||||||
|
@ -69,7 +69,7 @@ class AssistantViewModel(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun selectTaskType(task: AssistantTaskType) {
|
fun selectTaskType(task: TaskTypeData) {
|
||||||
_selectedTaskType.update {
|
_selectedTaskType.update {
|
||||||
task
|
task
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ class AssistantViewModel(
|
||||||
val taskTypesResult = repository.getTaskTypes()
|
val taskTypesResult = repository.getTaskTypes()
|
||||||
|
|
||||||
if (taskTypesResult.isSuccess) {
|
if (taskTypesResult.isSuccess) {
|
||||||
val result = taskTypesResult.resultData.toAssistantTaskTypeList()
|
val result = taskTypesResult.resultData.toTaskTypeDataList()
|
||||||
_taskTypes.update {
|
_taskTypes.update {
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,13 +44,13 @@ import com.nextcloud.client.assistant.model.ScreenState
|
||||||
import com.nextcloud.client.assistant.repository.AssistantMockRepository
|
import com.nextcloud.client.assistant.repository.AssistantMockRepository
|
||||||
import com.nextcloud.client.assistant.task.TaskView
|
import com.nextcloud.client.assistant.task.TaskView
|
||||||
import com.nextcloud.client.assistant.taskTypes.TaskTypesRow
|
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.composeActivity.ComposeActivity
|
||||||
import com.nextcloud.ui.composeComponents.alertDialog.SimpleAlertDialog
|
import com.nextcloud.ui.composeComponents.alertDialog.SimpleAlertDialog
|
||||||
import com.nextcloud.ui.composeComponents.bottomSheet.MoreActionsBottomSheet
|
import com.nextcloud.ui.composeComponents.bottomSheet.MoreActionsBottomSheet
|
||||||
import com.nextcloud.utils.extensions.showShareIntent
|
import com.nextcloud.utils.extensions.showShareIntent
|
||||||
import com.owncloud.android.R
|
import com.owncloud.android.R
|
||||||
import com.owncloud.android.lib.resources.assistant.model.Task
|
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.ClipboardUtil
|
||||||
import com.owncloud.android.utils.DisplayUtils
|
import com.owncloud.android.utils.DisplayUtils
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
|
@ -102,8 +102,8 @@ fun AssistantScreen(viewModel: AssistantViewModel, activity: Activity) {
|
||||||
@Composable
|
@Composable
|
||||||
private fun ShowScreenState(
|
private fun ShowScreenState(
|
||||||
screenState: ScreenState?,
|
screenState: ScreenState?,
|
||||||
selectedTaskType: AssistantTaskType?,
|
selectedTaskType: TaskTypeData?,
|
||||||
taskTypes: List<AssistantTaskType>?,
|
taskTypes: List<TaskTypeData>?,
|
||||||
viewModel: AssistantViewModel,
|
viewModel: AssistantViewModel,
|
||||||
filteredTaskList: List<Task>?
|
filteredTaskList: List<Task>?
|
||||||
) {
|
) {
|
||||||
|
@ -143,7 +143,7 @@ private fun ShowLinearProgressIndicator(screenState: ScreenState?, pullToRefresh
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun AddFloatingActionButton(modifier: Modifier, selectedTaskType: AssistantTaskType?, viewModel: AssistantViewModel) {
|
private fun AddFloatingActionButton(modifier: Modifier, selectedTaskType: TaskTypeData?, viewModel: AssistantViewModel) {
|
||||||
FloatingActionButton(
|
FloatingActionButton(
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
onClick = {
|
onClick = {
|
||||||
|
@ -181,8 +181,8 @@ private fun ShowOverlayState(
|
||||||
description = state.taskType.description,
|
description = state.taskType.description,
|
||||||
defaultInput = state.input,
|
defaultInput = state.input,
|
||||||
addTask = { input ->
|
addTask = { input ->
|
||||||
state.taskType.id?.let { taskTypeId ->
|
state.taskType.let { taskType ->
|
||||||
viewModel.createTask(input = input, type = taskTypeId)
|
viewModel.createTask(input = input, taskType = taskType)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
dismiss = {
|
dismiss = {
|
||||||
|
@ -218,7 +218,7 @@ private fun ShowOverlayState(
|
||||||
R.drawable.ic_edit,
|
R.drawable.ic_edit,
|
||||||
R.string.action_edit
|
R.string.action_edit
|
||||||
) {
|
) {
|
||||||
val taskType = AssistantTaskType(
|
val taskType = TaskTypeData(
|
||||||
state.task.type,
|
state.task.type,
|
||||||
activity.getString(R.string.assistant_screen_add_task_alert_dialog_title),
|
activity.getString(R.string.assistant_screen_add_task_alert_dialog_title),
|
||||||
null
|
null
|
||||||
|
@ -252,8 +252,8 @@ private fun ShowOverlayState(
|
||||||
@Composable
|
@Composable
|
||||||
private fun AssistantContent(
|
private fun AssistantContent(
|
||||||
taskList: List<Task>,
|
taskList: List<Task>,
|
||||||
taskTypes: List<AssistantTaskType>?,
|
taskTypes: List<TaskTypeData>?,
|
||||||
selectedTaskType: AssistantTaskType?,
|
selectedTaskType: TaskTypeData?,
|
||||||
viewModel: AssistantViewModel
|
viewModel: AssistantViewModel
|
||||||
) {
|
) {
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
|
@ -282,7 +282,7 @@ private fun AssistantContent(
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun EmptyTaskList(selectedTaskType: AssistantTaskType?, taskTypes: List<AssistantTaskType>?, viewModel: AssistantViewModel) {
|
private fun EmptyTaskList(selectedTaskType: TaskTypeData?, taskTypes: List<TaskTypeData>?, viewModel: AssistantViewModel) {
|
||||||
val text = stringResource(
|
val text = stringResource(
|
||||||
id = R.string.assistant_screen_no_task_available_text,
|
id = R.string.assistant_screen_no_task_available_text,
|
||||||
selectedTaskType?.name ?: ""
|
selectedTaskType?.name ?: ""
|
||||||
|
|
|
@ -7,11 +7,11 @@
|
||||||
|
|
||||||
package com.nextcloud.client.assistant.model
|
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.Task
|
||||||
|
import com.owncloud.android.lib.resources.assistant.model.TaskTypeData
|
||||||
|
|
||||||
sealed class ScreenOverlayState {
|
sealed class ScreenOverlayState {
|
||||||
data class DeleteTask(val id: Long): 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()
|
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.TaskInput
|
||||||
import com.owncloud.android.lib.resources.assistant.model.TaskList
|
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.TaskOutput
|
||||||
|
import com.owncloud.android.lib.resources.assistant.model.TaskTypeData
|
||||||
import com.owncloud.android.lib.resources.assistant.model.TaskTypes
|
import com.owncloud.android.lib.resources.assistant.model.TaskTypes
|
||||||
|
|
||||||
@Suppress("MagicNumber")
|
@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)
|
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.GetTaskListRemoteOperation
|
||||||
import com.owncloud.android.lib.resources.assistant.GetTaskTypesRemoteOperation
|
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.TaskList
|
||||||
|
import com.owncloud.android.lib.resources.assistant.model.TaskTypeData
|
||||||
import com.owncloud.android.lib.resources.assistant.model.TaskTypes
|
import com.owncloud.android.lib.resources.assistant.model.TaskTypes
|
||||||
|
|
||||||
class AssistantRepository(private val client: NextcloudClient) : AssistantRepositoryType {
|
class AssistantRepository(private val client: NextcloudClient) : AssistantRepositoryType {
|
||||||
|
@ -22,8 +23,8 @@ class AssistantRepository(private val client: NextcloudClient) : AssistantReposi
|
||||||
return GetTaskTypesRemoteOperation().execute(client)
|
return GetTaskTypesRemoteOperation().execute(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createTask(input: String, type: String): RemoteOperationResult<Void> {
|
override fun createTask(input: String, taskType: TaskTypeData): RemoteOperationResult<Void> {
|
||||||
return CreateTaskRemoteOperation(input, type).execute(client)
|
return CreateTaskRemoteOperation(input, taskType).execute(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getTaskList(taskType: String): RemoteOperationResult<TaskList> {
|
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.common.operations.RemoteOperationResult
|
||||||
import com.owncloud.android.lib.resources.assistant.model.TaskList
|
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
|
import com.owncloud.android.lib.resources.assistant.model.TaskTypes
|
||||||
|
|
||||||
interface AssistantRepositoryType {
|
interface AssistantRepositoryType {
|
||||||
fun getTaskTypes(): RemoteOperationResult<TaskTypes>
|
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>
|
fun getTaskList(taskType: String): RemoteOperationResult<TaskList>
|
||||||
|
|
||||||
|
|
|
@ -20,10 +20,10 @@ import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.nextcloud.client.assistant.taskTypes.model.AssistantTaskType
|
import com.owncloud.android.lib.resources.assistant.model.TaskTypeData
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TaskTypesRow(selectedTaskType: AssistantTaskType?, data: List<AssistantTaskType>?, selectTaskType: (AssistantTaskType) -> Unit) {
|
fun TaskTypesRow(selectedTaskType: TaskTypeData?, data: List<TaskTypeData>?, selectTaskType: (TaskTypeData) -> Unit) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.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