From edd42aabd1b161a6c1c1c1fe40f05da6d14e679a Mon Sep 17 00:00:00 2001 From: alperozturk Date: Fri, 13 Dec 2024 10:44:43 +0100 Subject: [PATCH] filter selected tasks for v1 and v2 Signed-off-by: alperozturk --- .../assistant/AssistantRepositoryTests.kt | 8 ++--- .../client/assistant/AssistantViewModel.kt | 2 +- .../repository/AssistantMockRepository.kt | 35 +++++++++---------- .../repository/AssistantRepository.kt | 8 ++--- .../repository/AssistantRepositoryType.kt | 3 +- 5 files changed, 25 insertions(+), 31 deletions(-) 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 29373ac897..bbdae7ebb7 100644 --- a/app/src/androidTest/java/com/nextcloud/client/assistant/AssistantRepositoryTests.kt +++ b/app/src/androidTest/java/com/nextcloud/client/assistant/AssistantRepositoryTests.kt @@ -46,7 +46,7 @@ class AssistantRepositoryTests : AbstractOnServerIT() { } val result = sut?.getTaskList("assistant") - assertTrue(result?.tasks?.isEmpty() == true || (result?.tasks?.size ?: 0) > 0) + assertTrue(result?.isEmpty() == true || (result?.size ?: 0) > 0) } @Test @@ -81,13 +81,11 @@ class AssistantRepositoryTests : AbstractOnServerIT() { sleep(120) - val resultOfTaskList = sut?.getTaskList("assistant") - assertTrue(resultOfTaskList != null) + val taskList = sut?.getTaskList("assistant") + assertTrue(taskList != null) sleep(120) - val taskList = resultOfTaskList?.tasks - assert((taskList?.size ?: 0) > 0) val result = sut?.deleteTask(taskList!!.first().id) 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 e279f36b3c..97b19a73f7 100644 --- a/app/src/main/java/com/nextcloud/client/assistant/AssistantViewModel.kt +++ b/app/src/main/java/com/nextcloud/client/assistant/AssistantViewModel.kt @@ -102,7 +102,7 @@ class AssistantViewModel( val taskType = _selectedTaskType.value?.id ?: return@launch val result = repository.getTaskList(taskType) if (result != null) { - taskList = result.tasks.filter { it.appId == "assistant" } + taskList = result _filteredTaskList.update { taskList?.sortedByDescending { task -> task.id 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 51e484b79c..ec5c295a34 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 @@ -12,7 +12,6 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.resources.assistant.v2.model.Task import com.owncloud.android.lib.resources.assistant.v2.model.TaskInput import com.owncloud.android.lib.resources.assistant.v2.model.TaskInputShape -import com.owncloud.android.lib.resources.assistant.v2.model.TaskList import com.owncloud.android.lib.resources.assistant.v2.model.TaskOutput import com.owncloud.android.lib.resources.assistant.v2.model.TaskOutputShape import com.owncloud.android.lib.resources.assistant.v2.model.TaskTypeData @@ -47,26 +46,24 @@ class AssistantMockRepository(private val giveEmptyTasks: Boolean = false) : Ass return RemoteOperationResult(RemoteOperationResult.ResultCode.OK) } - override fun getTaskList(taskType: String): TaskList { + override fun getTaskList(taskType: String): List { return if (giveEmptyTasks) { - TaskList(listOf()) + listOf() } else { - TaskList( - listOf( - Task( - 1, - "FreePrompt", - null, - "12", - "", - TaskInput("Give me some long text 1"), - TaskOutput("Lorem ipsum".getRandomString(100)), - 1707692337, - 1707692337, - 1707692337, - 1707692337, - 1707692337 - ) + listOf( + Task( + 1, + "FreePrompt", + null, + "12", + "", + TaskInput("Give me some long text 1"), + TaskOutput("Lorem ipsum".getRandomString(100)), + 1707692337, + 1707692337, + 1707692337, + 1707692337, + 1707692337 ) ) } 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 19d6f43352..c1f5ac6aea 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 @@ -19,7 +19,7 @@ import com.owncloud.android.lib.resources.assistant.v2.CreateTaskRemoteOperation import com.owncloud.android.lib.resources.assistant.v2.DeleteTaskRemoteOperationV2 import com.owncloud.android.lib.resources.assistant.v2.GetTaskListRemoteOperationV2 import com.owncloud.android.lib.resources.assistant.v2.GetTaskTypesRemoteOperationV2 -import com.owncloud.android.lib.resources.assistant.v2.model.TaskList +import com.owncloud.android.lib.resources.assistant.v2.model.Task import com.owncloud.android.lib.resources.assistant.v2.model.TaskTypeData import com.owncloud.android.lib.resources.status.NextcloudVersion import com.owncloud.android.lib.resources.status.OCCapability @@ -58,16 +58,16 @@ class AssistantRepository(private val client: NextcloudClient, capability: OCCap } @Suppress("ReturnCount") - override fun getTaskList(taskType: String): TaskList? { + override fun getTaskList(taskType: String): List? { if (supportsV2) { val result = GetTaskListRemoteOperationV2(taskType).execute(client) if (result.isSuccess) { - return result.resultData + return result.resultData.tasks.filter { it.appId == "assistant" } } } else { val result = GetTaskListRemoteOperationV1("assistant").execute(client) if (result.isSuccess) { - return result.resultData.toV2() + return result.resultData.toV2().tasks.filter { it.type == taskType } } } 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 c5a17ba9bc..048eee9614 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 @@ -8,7 +8,6 @@ package com.nextcloud.client.assistant.repository import com.owncloud.android.lib.common.operations.RemoteOperationResult -import com.owncloud.android.lib.resources.assistant.v2.model.TaskList import com.owncloud.android.lib.resources.assistant.v2.model.TaskTypeData interface AssistantRepositoryType { @@ -16,7 +15,7 @@ interface AssistantRepositoryType { fun createTask(input: String, taskType: TaskTypeData): RemoteOperationResult - fun getTaskList(taskType: String): TaskList? + fun getTaskList(taskType: String): List? fun deleteTask(id: Long): RemoteOperationResult }