|
@@ -1,10 +1,8 @@
|
|
package io.nexilis.alpha.ui.main
|
|
package io.nexilis.alpha.ui.main
|
|
|
|
|
|
import Attachments
|
|
import Attachments
|
|
-import android.text.format.DateUtils
|
|
|
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
|
import androidx.compose.foundation.background
|
|
import androidx.compose.foundation.background
|
|
-import androidx.compose.foundation.combinedClickable
|
|
|
|
import androidx.compose.foundation.layout.*
|
|
import androidx.compose.foundation.layout.*
|
|
import androidx.compose.foundation.lazy.LazyColumn
|
|
import androidx.compose.foundation.lazy.LazyColumn
|
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
|
@@ -13,41 +11,41 @@ import androidx.compose.foundation.shape.RoundedCornerShape
|
|
import androidx.compose.foundation.text.KeyboardOptions
|
|
import androidx.compose.foundation.text.KeyboardOptions
|
|
import androidx.compose.material.icons.Icons
|
|
import androidx.compose.material.icons.Icons
|
|
import androidx.compose.material.icons.automirrored.filled.Send
|
|
import androidx.compose.material.icons.automirrored.filled.Send
|
|
-import androidx.compose.material.icons.filled.AccessTime
|
|
|
|
-import androidx.compose.material.icons.filled.Done
|
|
|
|
-import androidx.compose.material.icons.filled.DoneAll
|
|
|
|
import androidx.compose.material3.*
|
|
import androidx.compose.material3.*
|
|
import androidx.compose.runtime.*
|
|
import androidx.compose.runtime.*
|
|
import androidx.compose.runtime.livedata.observeAsState
|
|
import androidx.compose.runtime.livedata.observeAsState
|
|
import androidx.compose.runtime.saveable.rememberSaveable
|
|
import androidx.compose.runtime.saveable.rememberSaveable
|
|
-import androidx.compose.ui.Alignment
|
|
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.graphics.Color
|
|
import androidx.compose.ui.graphics.Color
|
|
import androidx.compose.ui.graphics.graphicsLayer
|
|
import androidx.compose.ui.graphics.graphicsLayer
|
|
import androidx.compose.ui.layout.onSizeChanged
|
|
import androidx.compose.ui.layout.onSizeChanged
|
|
-import androidx.compose.ui.platform.LocalContext
|
|
|
|
import androidx.compose.ui.text.TextRange
|
|
import androidx.compose.ui.text.TextRange
|
|
import androidx.compose.ui.text.input.KeyboardCapitalization
|
|
import androidx.compose.ui.text.input.KeyboardCapitalization
|
|
import androidx.compose.ui.text.input.TextFieldValue
|
|
import androidx.compose.ui.text.input.TextFieldValue
|
|
import androidx.compose.ui.unit.dp
|
|
import androidx.compose.ui.unit.dp
|
|
import androidx.hilt.navigation.compose.hiltViewModel
|
|
import androidx.hilt.navigation.compose.hiltViewModel
|
|
import androidx.navigation.NavHostController
|
|
import androidx.navigation.NavHostController
|
|
|
|
+import io.nexilis.alpha.ui.components.LeftBubbleChat
|
|
|
|
+import io.nexilis.alpha.ui.components.RightBubbleChat
|
|
import io.nexilis.alpha.ui.viewmodel.MainViewModel
|
|
import io.nexilis.alpha.ui.viewmodel.MainViewModel
|
|
-import io.nexilis.service.core.BlueSky
|
|
|
|
import io.nexilis.service.core.WhiteTransparent
|
|
import io.nexilis.service.core.WhiteTransparent
|
|
|
|
+import io.nexilis.service.data.entities.Buddy
|
|
import io.nexilis.service.data.entities.Message
|
|
import io.nexilis.service.data.entities.Message
|
|
import io.nexilis.service.data.viewmodels.BuddyViewModel
|
|
import io.nexilis.service.data.viewmodels.BuddyViewModel
|
|
import io.nexilis.service.data.viewmodels.MessageStatusViewModel
|
|
import io.nexilis.service.data.viewmodels.MessageStatusViewModel
|
|
import io.nexilis.service.data.viewmodels.MessageViewModel
|
|
import io.nexilis.service.data.viewmodels.MessageViewModel
|
|
|
|
|
|
-@OptIn(ExperimentalFoundationApi::class)
|
|
|
|
@Composable
|
|
@Composable
|
|
-fun Chat(navController: NavHostController, pin: String, mainViewModel: MainViewModel) {
|
|
|
|
|
|
+fun Chat(
|
|
|
|
+ navController: NavHostController,
|
|
|
|
+ pin: String,
|
|
|
|
+ mainViewModel: MainViewModel,
|
|
|
|
+ buddyViewModel: BuddyViewModel,
|
|
|
|
+ me: Buddy?
|
|
|
|
+) {
|
|
var textInput by rememberSaveable(stateSaver = TextFieldValue.Saver) {
|
|
var textInput by rememberSaveable(stateSaver = TextFieldValue.Saver) {
|
|
mutableStateOf(TextFieldValue("", TextRange(0, 7)))
|
|
mutableStateOf(TextFieldValue("", TextRange(0, 7)))
|
|
}
|
|
}
|
|
- val buddyViewModel: BuddyViewModel = hiltViewModel()
|
|
|
|
- val me by buddyViewModel.me.observeAsState()
|
|
|
|
val buddy by buddyViewModel.getBuddy(pin).observeAsState()
|
|
val buddy by buddyViewModel.getBuddy(pin).observeAsState()
|
|
val messageModel: MessageViewModel = hiltViewModel()
|
|
val messageModel: MessageViewModel = hiltViewModel()
|
|
val list by messageModel.getOpposite(pin).observeAsState()
|
|
val list by messageModel.getOpposite(pin).observeAsState()
|
|
@@ -83,96 +81,28 @@ fun Chat(navController: NavHostController, pin: String, mainViewModel: MainViewM
|
|
horizontalArrangement = if (message?.f_pin == me?.f_pin) Arrangement.End else Arrangement.Start
|
|
horizontalArrangement = if (message?.f_pin == me?.f_pin) Arrangement.End else Arrangement.Start
|
|
) {
|
|
) {
|
|
if (message?.f_pin == me?.f_pin) {
|
|
if (message?.f_pin == me?.f_pin) {
|
|
- Spacer(modifier = Modifier.weight(0.2f))
|
|
|
|
- Column(
|
|
|
|
- modifier = Modifier
|
|
|
|
- .weight(weight = 0.8f, fill = false)
|
|
|
|
|
|
+ Spacer(modifier = Modifier.weight(0.1f))
|
|
|
|
+ RightBubbleChat(
|
|
|
|
+ modifier = Modifier.weight(weight = 0.9f, fill = false),
|
|
|
|
+ message = message,
|
|
|
|
+ messageStatusModel = messageStatusModel
|
|
) {
|
|
) {
|
|
Text(
|
|
Text(
|
|
- modifier = Modifier
|
|
|
|
- .align(Alignment.End)
|
|
|
|
- .graphicsLayer {
|
|
|
|
-// shadowElevation = 2.dp.toPx()
|
|
|
|
- shape = RoundedCornerShape(16.dp)
|
|
|
|
- clip = true
|
|
|
|
- }
|
|
|
|
- .combinedClickable(onLongClick = {}, onClick = {})
|
|
|
|
- .background(color = MaterialTheme.colorScheme.primaryContainer)
|
|
|
|
- .padding(8.dp),
|
|
|
|
text = list?.get(it)?.message_text ?: "",
|
|
text = list?.get(it)?.message_text ?: "",
|
|
style = MaterialTheme.typography.bodyMedium,
|
|
style = MaterialTheme.typography.bodyMedium,
|
|
)
|
|
)
|
|
- Row(
|
|
|
|
- modifier = Modifier
|
|
|
|
- .padding(3.dp)
|
|
|
|
- .align(Alignment.End)
|
|
|
|
- ) {
|
|
|
|
- Text(
|
|
|
|
- text = DateUtils.formatDateTime(
|
|
|
|
- LocalContext.current,
|
|
|
|
- list?.get(it)?.server_date ?: 0,
|
|
|
|
- DateUtils.FORMAT_SHOW_TIME
|
|
|
|
- ),
|
|
|
|
- color = MaterialTheme.colorScheme.onPrimaryContainer,
|
|
|
|
- style = MaterialTheme.typography.bodySmall,
|
|
|
|
- )
|
|
|
|
- Spacer(modifier = Modifier.width(6.dp))
|
|
|
|
- message?.message_id?.let {
|
|
|
|
- val messageStatus by messageStatusModel.get(it, pin)
|
|
|
|
- .observeAsState()
|
|
|
|
- Icon(
|
|
|
|
- imageVector = when (messageStatus?.status) {
|
|
|
|
- 1, 2 -> Icons.Default.Done
|
|
|
|
- 3 -> Icons.Default.DoneAll
|
|
|
|
- 4 -> Icons.Default.DoneAll
|
|
|
|
- else -> Icons.Default.AccessTime
|
|
|
|
- },
|
|
|
|
- contentDescription = "",
|
|
|
|
- modifier = Modifier
|
|
|
|
- .align(Alignment.Bottom)
|
|
|
|
- .size(16.dp),
|
|
|
|
- tint = if (messageStatus?.status == 4) Color.BlueSky else Color.Gray
|
|
|
|
- )
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- Column(
|
|
|
|
- modifier = Modifier
|
|
|
|
- .weight(weight = 0.8f, fill = false)
|
|
|
|
|
|
+ LeftBubbleChat(
|
|
|
|
+ modifier = Modifier.weight(weight = 0.9f, fill = false),
|
|
|
|
+ message = message
|
|
) {
|
|
) {
|
|
Text(
|
|
Text(
|
|
- modifier = Modifier
|
|
|
|
- .align(Alignment.Start)
|
|
|
|
- .graphicsLayer {
|
|
|
|
-// shadowElevation = 2.dp.toPx()
|
|
|
|
- shape = RoundedCornerShape(16.dp)
|
|
|
|
- clip = true
|
|
|
|
- }
|
|
|
|
- .combinedClickable(onLongClick = {}, onClick = {})
|
|
|
|
- .background(color = MaterialTheme.colorScheme.surface)
|
|
|
|
- .padding(8.dp),
|
|
|
|
text = list?.get(it)?.message_text ?: "",
|
|
text = list?.get(it)?.message_text ?: "",
|
|
style = MaterialTheme.typography.bodyMedium,
|
|
style = MaterialTheme.typography.bodyMedium,
|
|
)
|
|
)
|
|
- Row(
|
|
|
|
- modifier = Modifier
|
|
|
|
- .padding(3.dp)
|
|
|
|
- .align(Alignment.End)
|
|
|
|
- ) {
|
|
|
|
- Text(
|
|
|
|
- text = DateUtils.formatDateTime(
|
|
|
|
- LocalContext.current,
|
|
|
|
- list?.get(it)?.server_date ?: 0,
|
|
|
|
- DateUtils.FORMAT_SHOW_TIME
|
|
|
|
- ),
|
|
|
|
- color = MaterialTheme.colorScheme.onSurface,
|
|
|
|
- style = MaterialTheme.typography.bodySmall,
|
|
|
|
- )
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
- Spacer(modifier = Modifier.weight(0.2f))
|
|
|
|
|
|
+ Spacer(modifier = Modifier.weight(0.1f))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}, colors = ListItemDefaults.colors(containerColor = Color.Transparent))
|
|
}, colors = ListItemDefaults.colors(containerColor = Color.Transparent))
|