|
@@ -28,6 +28,7 @@ import androidx.compose.material3.MaterialTheme
|
|
import androidx.compose.material3.Text
|
|
import androidx.compose.material3.Text
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.getValue
|
|
import androidx.compose.runtime.getValue
|
|
|
|
+import androidx.compose.runtime.mutableIntStateOf
|
|
import androidx.compose.runtime.mutableStateOf
|
|
import androidx.compose.runtime.mutableStateOf
|
|
import androidx.compose.runtime.remember
|
|
import androidx.compose.runtime.remember
|
|
import androidx.compose.runtime.setValue
|
|
import androidx.compose.runtime.setValue
|
|
@@ -43,6 +44,8 @@ import androidx.compose.ui.unit.dp
|
|
import androidx.compose.ui.unit.sp
|
|
import androidx.compose.ui.unit.sp
|
|
import com.nextcloud.client.assistant.extensions.statusData
|
|
import com.nextcloud.client.assistant.extensions.statusData
|
|
import com.nextcloud.ui.composeComponents.bottomSheet.MoreActionsBottomSheet
|
|
import com.nextcloud.ui.composeComponents.bottomSheet.MoreActionsBottomSheet
|
|
|
|
+import com.nextcloud.utils.extensions.getRandomString
|
|
|
|
+import com.nextcloud.utils.extensions.splitIntoChunks
|
|
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
|
|
|
|
|
|
@@ -53,7 +56,8 @@ fun TaskView(
|
|
task: Task,
|
|
task: Task,
|
|
showDeleteTaskAlertDialog: (Long) -> Unit
|
|
showDeleteTaskAlertDialog: (Long) -> Unit
|
|
) {
|
|
) {
|
|
- var expanded by remember { mutableStateOf(false) }
|
|
|
|
|
|
+ var loadedChunkSize by remember { mutableIntStateOf(1) }
|
|
|
|
+ val taskOutputChunks = task.output?.splitIntoChunks(100)
|
|
var showMoreActionsBottomSheet by remember { mutableStateOf(false) }
|
|
var showMoreActionsBottomSheet by remember { mutableStateOf(false) }
|
|
|
|
|
|
Column(
|
|
Column(
|
|
@@ -62,7 +66,11 @@ fun TaskView(
|
|
.clip(RoundedCornerShape(16.dp))
|
|
.clip(RoundedCornerShape(16.dp))
|
|
.background(MaterialTheme.colorScheme.primary)
|
|
.background(MaterialTheme.colorScheme.primary)
|
|
.combinedClickable(onClick = {
|
|
.combinedClickable(onClick = {
|
|
- expanded = !expanded
|
|
|
|
|
|
+ if (taskOutputChunks?.size != loadedChunkSize) {
|
|
|
|
+ loadedChunkSize += 1
|
|
|
|
+ } else {
|
|
|
|
+ loadedChunkSize = 1
|
|
|
|
+ }
|
|
}, onLongClick = {
|
|
}, onLongClick = {
|
|
showMoreActionsBottomSheet = true
|
|
showMoreActionsBottomSheet = true
|
|
})
|
|
})
|
|
@@ -80,21 +88,23 @@ fun TaskView(
|
|
|
|
|
|
Spacer(modifier = Modifier.height(16.dp))
|
|
Spacer(modifier = Modifier.height(16.dp))
|
|
|
|
|
|
- task.output?.let {
|
|
|
|
- HorizontalDivider(modifier = Modifier.padding(horizontal = 4.dp, vertical = 8.dp))
|
|
|
|
-
|
|
|
|
- Text(
|
|
|
|
- text = if (expanded) it else it.take(100) + "...",
|
|
|
|
- fontSize = 12.sp,
|
|
|
|
- color = Color.White,
|
|
|
|
- modifier = Modifier
|
|
|
|
- .animateContentSize(
|
|
|
|
- animationSpec = spring(
|
|
|
|
- dampingRatio = Spring.DampingRatioLowBouncy,
|
|
|
|
- stiffness = Spring.StiffnessLow
|
|
|
|
|
|
+ taskOutputChunks?.take(loadedChunkSize).let {
|
|
|
|
+ it?.joinToString("")?.let { output ->
|
|
|
|
+ HorizontalDivider(modifier = Modifier.padding(horizontal = 4.dp, vertical = 8.dp))
|
|
|
|
+
|
|
|
|
+ Text(
|
|
|
|
+ text = output,
|
|
|
|
+ fontSize = 12.sp,
|
|
|
|
+ color = Color.White,
|
|
|
|
+ modifier = Modifier
|
|
|
|
+ .animateContentSize(
|
|
|
|
+ animationSpec = spring(
|
|
|
|
+ dampingRatio = Spring.DampingRatioLowBouncy,
|
|
|
|
+ stiffness = Spring.StiffnessLow
|
|
|
|
+ )
|
|
)
|
|
)
|
|
- )
|
|
|
|
- )
|
|
|
|
|
|
+ )
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
Row(
|
|
Row(
|
|
@@ -121,7 +131,7 @@ fun TaskView(
|
|
if ((task.output?.length ?: 0) >= 100) {
|
|
if ((task.output?.length ?: 0) >= 100) {
|
|
Image(
|
|
Image(
|
|
painter = painterResource(
|
|
painter = painterResource(
|
|
- id = if (!expanded) R.drawable.ic_expand_more else R.drawable.ic_expand_less
|
|
|
|
|
|
+ id = if (loadedChunkSize != taskOutputChunks?.size) R.drawable.ic_expand_more else R.drawable.ic_expand_less
|
|
),
|
|
),
|
|
contentDescription = "expand content icon",
|
|
contentDescription = "expand content icon",
|
|
colorFilter = ColorFilter.tint(Color.White)
|
|
colorFilter = ColorFilter.tint(Color.White)
|
|
@@ -153,21 +163,7 @@ fun TaskView(
|
|
@Preview
|
|
@Preview
|
|
@Composable
|
|
@Composable
|
|
private fun TaskViewPreview() {
|
|
private fun TaskViewPreview() {
|
|
- val output =
|
|
|
|
- "Lorem Ipsum is simply dummy text of the printing and " +
|
|
|
|
- "typesetting industry. Lorem Ipsum has been the " +
|
|
|
|
- "industry's standard dummy text ever since the 1500s, " +
|
|
|
|
- "when an unknown printer took a galley of type and " +
|
|
|
|
- "scrambled it to make a type specimen book. " +
|
|
|
|
- "It has survived not only five centuries, but also " +
|
|
|
|
- "the leap into electronic typesetting, remaining" +
|
|
|
|
- " essentially unchanged. It wLorem Ipsum is simply dummy" +
|
|
|
|
- " text of the printing and typesetting industry. " +
|
|
|
|
- "Lorem Ipsum has been the industry's standard dummy " +
|
|
|
|
- "text ever since the 1500s, when an unknown printer took a" +
|
|
|
|
- " galley of type and scrambled it to make a type specimen book. " +
|
|
|
|
- "It has survived not only five centuries, but also the leap " +
|
|
|
|
- "into electronic typesetting, remaining essentially unchanged."
|
|
|
|
|
|
+ val output = "Lorem".getRandomString(100)
|
|
|
|
|
|
TaskView(
|
|
TaskView(
|
|
task = Task(
|
|
task = Task(
|