|
@@ -4,19 +4,19 @@ import androidx.compose.animation.AnimatedVisibility
|
|
|
import androidx.compose.foundation.layout.*
|
|
|
import androidx.compose.foundation.lazy.LazyColumn
|
|
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
|
|
-import androidx.compose.foundation.lazy.items
|
|
|
import androidx.compose.foundation.shape.CircleShape
|
|
|
import androidx.compose.material.icons.Icons
|
|
|
import androidx.compose.material.icons.filled.KeyboardDoubleArrowDown
|
|
|
import androidx.compose.material3.*
|
|
|
import androidx.compose.runtime.*
|
|
|
-import androidx.compose.runtime.livedata.observeAsState
|
|
|
import androidx.compose.ui.Modifier
|
|
|
import androidx.compose.ui.graphics.Color
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
import androidx.constraintlayout.compose.ConstraintLayout
|
|
|
import androidx.hilt.navigation.compose.hiltViewModel
|
|
|
import androidx.navigation.NavHostController
|
|
|
+import androidx.paging.compose.collectAsLazyPagingItems
|
|
|
+import androidx.paging.compose.itemKey
|
|
|
import io.nexilis.alpha.ui.components.ContentChat
|
|
|
import io.nexilis.alpha.ui.components.InputChat
|
|
|
import io.nexilis.alpha.ui.components.LeftBubbleChat
|
|
@@ -34,7 +34,8 @@ fun Chat(
|
|
|
me: Buddy
|
|
|
) {
|
|
|
val messageModel: MessageViewModel = hiltViewModel()
|
|
|
- val list by messageModel.getOpposite(pin).observeAsState()
|
|
|
+ val flow = remember { messageModel.getOpposite(pin) }
|
|
|
+ val lazyPagingItems = flow.collectAsLazyPagingItems()
|
|
|
val listState = rememberLazyListState()
|
|
|
val scope = rememberCoroutineScope()
|
|
|
ConstraintLayout(
|
|
@@ -49,17 +50,13 @@ fun Chat(
|
|
|
modifier = Modifier
|
|
|
.fillMaxSize()
|
|
|
.constrainAs(lazyColumn) {
|
|
|
- start.linkTo(parent.start)
|
|
|
- top.linkTo(parent.top)
|
|
|
- end.linkTo(parent.end)
|
|
|
bottom.linkTo(input.top)
|
|
|
- }
|
|
|
- .padding(bottom = 32.dp),
|
|
|
+ },
|
|
|
state = listState,
|
|
|
reverseLayout = true
|
|
|
) {
|
|
|
- list?.let { l ->
|
|
|
- items(items = l) { message ->
|
|
|
+ items(count = lazyPagingItems.itemCount, key = lazyPagingItems.itemKey { it.message_id }) { index ->
|
|
|
+ lazyPagingItems[index]?.let { message ->
|
|
|
ListItem(modifier = Modifier.fillMaxWidth(), headlineContent = {
|
|
|
Row(
|
|
|
modifier = Modifier.fillMaxWidth(),
|