Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AssistantRepositoryTests : AbstractOnServerIT() {
}

runBlocking {
val result = sut?.getTaskTypes()
val result = sut?.fetchTaskTypes()
assertTrue(result?.isNotEmpty() == true)
}
}
Expand Down
72 changes: 48 additions & 24 deletions app/src/main/java/com/nextcloud/client/assistant/AssistantScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,17 @@ import com.nextcloud.client.assistant.translate.TranslationViewModel
import com.nextcloud.ui.composeActivity.ComposeActivity
import com.nextcloud.ui.composeActivity.ComposeViewModel
import com.nextcloud.ui.composeComponents.alertDialog.SimpleAlertDialog
import com.nextcloud.ui.composeComponents.alertDialog.TaskSelectionAlertDialog
import com.nextcloud.ui.composeComponents.bottomSheet.MoreActionsBottomSheet
import com.nextcloud.utils.extensions.getChat
import com.owncloud.android.R
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.OCCapability
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

private const val CHAT_INPUT_DELAY = 100L
private const val PULL_TO_REFRESH_DELAY = 1500L
Expand Down Expand Up @@ -116,17 +119,24 @@ fun AssistantScreen(
}

LaunchedEffect(selectedText) {
selectedText?.let {
if (it.isBlank()) {
selectedText?.let { copiedText ->
if (copiedText.isBlank()) {
return@LaunchedEffect
}

if (pagerState.currentPage == AssistantPage.Conversation.id) {
pagerState.scrollToPage(AssistantPage.Content.id)
}

viewModel.updateInputBarText(it)
snackbarHostState.showSnackbar(activity.getString(R.string.assistant_screen_text_selected))
scope.launch(Dispatchers.IO) {
val types = viewModel.getRemoteRepository().fetchTaskTypes()
if (!types.isNullOrEmpty()) {
withContext(Dispatchers.Main) {
viewModel.updateScreenOverlayState(ScreenOverlayState.TaskTypes(copiedText, types))
snackbarHostState.showSnackbar(activity.getString(R.string.assistant_screen_text_selected))
}
}
}
}
}

Expand Down Expand Up @@ -367,29 +377,43 @@ private fun InputBar(sessionId: Long?, selectedTaskType: TaskTypeData?, viewMode
@Suppress("LongMethod")
@Composable
private fun OverlayState(state: ScreenOverlayState?, activity: Activity, viewModel: AssistantViewModel) {
when (state) {
is ScreenOverlayState.DeleteTask -> {
SimpleAlertDialog(
title = stringResource(id = R.string.assistant_screen_delete_task_alert_dialog_title),
description = stringResource(id = R.string.assistant_screen_delete_task_alert_dialog_description),
dismiss = { viewModel.updateScreenOverlayState(null) },
onComplete = { viewModel.deleteTask(state.id) }
)
}
state?.let {
when (state) {
is ScreenOverlayState.DeleteTask -> {
SimpleAlertDialog(
title = stringResource(id = R.string.assistant_screen_delete_task_alert_dialog_title),
description = stringResource(id = R.string.assistant_screen_delete_task_alert_dialog_description),
onDismiss = { viewModel.updateScreenOverlayState(null) },
onComplete = { viewModel.deleteTask(state.id) }
)
}

is ScreenOverlayState.TaskActions -> {
val actions = state.getActions(activity, onDeleteCompleted = { deleteTask ->
viewModel.updateScreenOverlayState(deleteTask)
})
is ScreenOverlayState.TaskActions -> {
val actions = state.getActions(activity, onDeleteCompleted = { deleteTask ->
viewModel.updateScreenOverlayState(deleteTask)
})

MoreActionsBottomSheet(
title = state.task.getInputTitle(),
actions = actions,
dismiss = { viewModel.updateScreenOverlayState(null) }
)
}
MoreActionsBottomSheet(
title = state.task.getInputTitle(),
actions = actions,
onDismiss = { viewModel.updateScreenOverlayState(null) }
)
}

is ScreenOverlayState.TaskTypes -> {
TaskSelectionAlertDialog(state.taskTypes, onDismiss = {
viewModel.updateScreenOverlayState(null)
}, onConfirm = {
viewModel.selectTaskType(it)
viewModel.updateInputBarText(state.copiedText)

else -> Unit
if (it.isTranslate()) {
viewModel.updateTranslationTaskState(true)
viewModel.updateScreenState(AssistantScreenState.Translation(null))
}
})
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class AssistantViewModel(
}

private fun fetchTaskTypes() = viewModelScope.launch(Dispatchers.IO) {
val result = remoteRepository.getTaskTypes()
val result = remoteRepository.fetchTaskTypes()
if (result.isNullOrEmpty()) {
_screenState.value = AssistantScreenState.emptyTaskTypes()
return@launch
Expand Down Expand Up @@ -379,6 +379,7 @@ class AssistantViewModel(
}

fun onTranslationScreenDismissed() {
updateInputBarText("")
updateTranslationTaskState(false)
selectTask(null)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private fun ConversationList(

MoreActionsBottomSheet(
actions = bottomSheetAction,
dismiss = { selectedConversationId = -1L }
onDismiss = { selectedConversationId = -1L }
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.nextcloud.client.assistant.extensions.getInputAndOutput
import com.nextcloud.utils.extensions.showShareIntent
import com.owncloud.android.R
import com.owncloud.android.lib.resources.assistant.v2.model.Task
import com.owncloud.android.lib.resources.assistant.v2.model.TaskTypeData
import com.owncloud.android.utils.ClipboardUtil

sealed class ScreenOverlayState {
Expand Down Expand Up @@ -52,4 +53,5 @@ sealed class ScreenOverlayState {
})
)
}
data class TaskTypes(val copiedText: String, val taskTypes: List<TaskTypeData>) : ScreenOverlayState()
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import com.owncloud.android.lib.resources.assistant.v2.model.TaskTypeData
import com.owncloud.android.lib.resources.assistant.v2.model.TranslationRequest

interface AssistantRemoteRepository {
suspend fun getTaskTypes(): List<TaskTypeData>?
suspend fun fetchTaskTypes(): List<TaskTypeData>?

suspend fun createTask(input: String, taskType: TaskTypeData): RemoteOperationResult<Void>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class AssistantRemoteRepositoryImpl(private val client: NextcloudClient, capabil

private val supportsV2 = capability.version.isNewerOrEqual(NextcloudVersion.nextcloud_30)

override suspend fun getTaskTypes(): List<TaskTypeData>? = withContext(Dispatchers.IO) {
override suspend fun fetchTaskTypes(): List<TaskTypeData>? = withContext(Dispatchers.IO) {
if (supportsV2) {
val result = GetTaskTypesRemoteOperationV2().execute(client)
if (result.isSuccess) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.owncloud.android.lib.resources.assistant.v2.model.TranslationRequest

@Suppress("MagicNumber")
class MockAssistantRemoteRepository(private val giveEmptyTasks: Boolean = false) : AssistantRemoteRepository {
override suspend fun getTaskTypes(): List<TaskTypeData> = listOf(
override suspend fun fetchTaskTypes(): List<TaskTypeData> = listOf(
TaskTypeData(
id = "core:text2text",
name = "Free text to text prompt",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fun SimpleAlertDialog(
heightFraction: Float? = null,
content: @Composable (() -> Unit)? = null,
onComplete: () -> Unit,
dismiss: () -> Unit
onDismiss: () -> Unit
) {
val modifier = if (heightFraction != null) {
Modifier
Expand All @@ -46,7 +46,7 @@ fun SimpleAlertDialog(
iconContentColor = MaterialTheme.colorScheme.onPrimaryContainer,
titleContentColor = MaterialTheme.colorScheme.onPrimaryContainer,
textContentColor = MaterialTheme.colorScheme.onPrimaryContainer,
onDismissRequest = { dismiss() },
onDismissRequest = { onDismiss() },
title = {
Text(text = title)
},
Expand All @@ -66,15 +66,15 @@ fun SimpleAlertDialog(
confirmButton = {
FilledTonalButton(onClick = {
onComplete()
dismiss()
onDismiss()
}) {
Text(
stringResource(id = R.string.common_ok)
)
}
},
dismissButton = {
TextButton(onClick = { dismiss() }) {
TextButton(onClick = { onDismiss() }) {
Text(
stringResource(id = R.string.common_cancel)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2026 Alper Ozturk <alper.ozturk@nextcloud.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
package com.nextcloud.ui.composeComponents.alertDialog

import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import com.owncloud.android.lib.resources.assistant.v2.model.TaskTypeData

@Suppress("LongMethod")
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun TaskSelectionAlertDialog(taskTypes: List<TaskTypeData>, onDismiss: () -> Unit, onConfirm: (TaskTypeData) -> Unit) {
Dialog(onDismissRequest = onDismiss) {
Surface(
shape = MaterialTheme.shapes.extraLarge,
tonalElevation = 6.dp
) {
LazyColumn(
modifier = Modifier.padding(vertical = 16.dp)
) {
items(taskTypes) { task ->
TextButton(
onClick = {
onConfirm(task)
onDismiss()
},
modifier = Modifier.padding(horizontal = 8.dp)
) {
Text(
text = task.name,
style = MaterialTheme.typography.bodyLarge
)
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ import kotlinx.coroutines.launch
@SuppressLint("ResourceAsColor")
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MoreActionsBottomSheet(title: String? = null, actions: List<Triple<Int, Int, () -> Unit>>, dismiss: () -> Unit) {
fun MoreActionsBottomSheet(title: String? = null, actions: List<Triple<Int, Int, () -> Unit>>, onDismiss: () -> Unit) {
val sheetState = rememberModalBottomSheetState()
val scope = rememberCoroutineScope()

ModalBottomSheet(
modifier = Modifier.padding(top = 32.dp),
containerColor = colorScheme.surface,
onDismissRequest = {
dismiss()
onDismiss()
},
sheetState = sheetState
) {
Expand Down Expand Up @@ -73,7 +73,7 @@ fun MoreActionsBottomSheet(title: String? = null, actions: List<Triple<Int, Int,
.launch { sheetState.hide() }
.invokeOnCompletion {
if (!sheetState.isVisible) {
dismiss()
onDismiss()
action.third()
}
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<string name="assistant_screen_delete_task_alert_dialog_title">Delete task</string>
<string name="assistant_screen_delete_task_alert_dialog_description">Are you sure you want to delete this task?</string>
<string name="assistant_screen_task_more_actions_bottom_sheet_delete_action">Delete Task</string>
<string name="assistant_screen_select_task_type_label">Choose an option</string>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kra-mo texts are updated feel free to make suggestion

<string name="assistant_screen_task_create_success_message">Task created</string>
<string name="assistant_screen_task_create_fail_message">An error occurred while creating the task</string>
<string name="assistant_screen_task_delete_success_message">Task deleted</string>
Expand Down
Loading