mirror of https://github.com/nextcloud/android
Use scrollable text view instead chunks
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
8e82b5e16c
commit
ac863b3778
|
@ -18,6 +18,7 @@ import androidx.compose.foundation.layout.height
|
|||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
|
|
|
@ -22,13 +22,14 @@ import androidx.compose.foundation.layout.height
|
|||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
|
@ -45,7 +46,6 @@ import androidx.compose.ui.unit.sp
|
|||
import com.nextcloud.client.assistant.extensions.statusData
|
||||
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.lib.resources.assistant.model.Task
|
||||
|
||||
|
@ -56,8 +56,7 @@ fun TaskView(
|
|||
task: Task,
|
||||
showDeleteTaskAlertDialog: (Long) -> Unit
|
||||
) {
|
||||
var loadedChunkSize by remember { mutableIntStateOf(1) }
|
||||
val taskOutputChunks = task.output?.splitIntoChunks(100)
|
||||
val verticalScrollState = rememberScrollState(0)
|
||||
var showMoreActionsBottomSheet by remember { mutableStateOf(false) }
|
||||
|
||||
Column(
|
||||
|
@ -66,11 +65,7 @@ fun TaskView(
|
|||
.clip(RoundedCornerShape(16.dp))
|
||||
.background(MaterialTheme.colorScheme.primary)
|
||||
.combinedClickable(onClick = {
|
||||
if (taskOutputChunks?.size != loadedChunkSize) {
|
||||
loadedChunkSize += 1
|
||||
} else {
|
||||
loadedChunkSize = 1
|
||||
}
|
||||
|
||||
}, onLongClick = {
|
||||
showMoreActionsBottomSheet = true
|
||||
})
|
||||
|
@ -88,23 +83,23 @@ fun TaskView(
|
|||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
taskOutputChunks?.take(loadedChunkSize).let {
|
||||
it?.joinToString("")?.let { output ->
|
||||
HorizontalDivider(modifier = Modifier.padding(horizontal = 4.dp, vertical = 8.dp))
|
||||
task.output?.let {
|
||||
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
|
||||
)
|
||||
Text(
|
||||
text = it,
|
||||
fontSize = 12.sp,
|
||||
color = Color.White,
|
||||
modifier = Modifier
|
||||
.height(100.dp)
|
||||
.verticalScroll(verticalScrollState)
|
||||
.animateContentSize(
|
||||
animationSpec = spring(
|
||||
dampingRatio = Spring.DampingRatioLowBouncy,
|
||||
stiffness = Spring.StiffnessLow
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
Row(
|
||||
|
@ -125,20 +120,6 @@ fun TaskView(
|
|||
Spacer(modifier = Modifier.width(6.dp))
|
||||
|
||||
Text(text = stringResource(id = descriptionId), color = Color.White)
|
||||
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
|
||||
if ((task.output?.length ?: 0) >= 100) {
|
||||
Image(
|
||||
painter = painterResource(
|
||||
id = if (loadedChunkSize != taskOutputChunks?.size) R.drawable.ic_expand_more else R.drawable.ic_expand_less
|
||||
),
|
||||
contentDescription = "expand content icon",
|
||||
colorFilter = ColorFilter.tint(Color.White)
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
}
|
||||
|
||||
if (showMoreActionsBottomSheet) {
|
||||
|
|
|
@ -42,7 +42,7 @@ class AssistantMockRepository(private val giveEmptyTasks: Boolean = false) : Ass
|
|||
null,
|
||||
"12",
|
||||
"",
|
||||
"Give me some long text",
|
||||
"Give me some long text 1",
|
||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc consectetur condimentum augue, sit amet maximus nibh pharetra sodales. Donec blandit nulla vitae diam aliquam, vel viverra sem faucibus. Duis vitae pretium sapien. Curabitur nec libero erat. Nunc pretium eleifend mi non congue. Sed efficitur ullamcorper mi, ac faucibus mi mollis sed. Donec vestibulum enim vel massa sodales facilisis. Integer in consequat nibh. Sed id nisi erat. Donec sollicitudin pharetra massa, id sodales arcu mollis luctus. Donec sed ullamcorper nisl, non euismod metus. Proin eget sollicitudin purus.\n" +
|
||||
"\n" +
|
||||
"Etiam sit amet nisl pretium, facilisis ligula vel, luctus arcu. Nunc bibendum hendrerit ultricies. Integer scelerisque sem arcu, eget fermentum neque pretium in. Curabitur facilisis neque vel leo blandit tincidunt. Nullam at sodales nisl, eu porta leo. Nulla facilisi. Fusce cursus, turpis eget auctor iaculis, eros lectus posuere magna, a tristique purus nunc id quam.\n" +
|
||||
|
@ -74,7 +74,51 @@ class AssistantMockRepository(private val giveEmptyTasks: Boolean = false) : Ass
|
|||
null,
|
||||
"12",
|
||||
"",
|
||||
"Give me some text",
|
||||
"Give me some text 3",
|
||||
"Lorem".getRandomString(300),
|
||||
"",
|
||||
""
|
||||
),
|
||||
Task(
|
||||
4,
|
||||
"FreePrompt",
|
||||
null,
|
||||
"12",
|
||||
"",
|
||||
"Give me some text 4",
|
||||
"Lorem".getRandomString(300),
|
||||
"",
|
||||
""
|
||||
),
|
||||
Task(
|
||||
5,
|
||||
"FreePrompt",
|
||||
null,
|
||||
"12",
|
||||
"",
|
||||
"Give me some text 5",
|
||||
"Lorem".getRandomString(300),
|
||||
"",
|
||||
""
|
||||
),
|
||||
Task(
|
||||
6,
|
||||
"FreePrompt",
|
||||
null,
|
||||
"12",
|
||||
"",
|
||||
"Give me some text 6",
|
||||
"Lorem".getRandomString(300),
|
||||
"",
|
||||
""
|
||||
),
|
||||
Task(
|
||||
7,
|
||||
"FreePrompt",
|
||||
null,
|
||||
"12",
|
||||
"",
|
||||
"Give me some text 7",
|
||||
"Lorem".getRandomString(300),
|
||||
"",
|
||||
""
|
||||
|
|
|
@ -15,14 +15,3 @@ fun String.getRandomString(length: Int) : String {
|
|||
|
||||
return this + result
|
||||
}
|
||||
|
||||
fun String.splitIntoChunks(chunkSize: Int): List<String> {
|
||||
val chunks = mutableListOf<String>()
|
||||
var startIndex = 0
|
||||
while (startIndex < length) {
|
||||
val endIndex = kotlin.math.min(startIndex + chunkSize, length)
|
||||
chunks.add(substring(startIndex, endIndex))
|
||||
startIndex = endIndex
|
||||
}
|
||||
return chunks
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue