更改目录结构
This commit is contained in:
228
app/src/main/java/com/aiosman/riderpro/ui/message/Message.kt
Normal file
228
app/src/main/java/com/aiosman/riderpro/ui/message/Message.kt
Normal file
@@ -0,0 +1,228 @@
|
||||
package com.aiosman.riderpro.ui.message
|
||||
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.draw.shadow
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.paging.LoadState
|
||||
import androidx.paging.Pager
|
||||
import androidx.paging.PagingConfig
|
||||
import androidx.paging.compose.collectAsLazyPagingItems
|
||||
import com.aiosman.riderpro.ui.index.tabs.moment.MomentListLoading
|
||||
import com.aiosman.riderpro.R
|
||||
import com.aiosman.riderpro.model.ChatNotificationData
|
||||
import com.aiosman.riderpro.model.TestChatBackend
|
||||
|
||||
val chatNotificationData = ChatNotificationData(
|
||||
R.drawable.default_avatar,
|
||||
"Tokunaga Yae",
|
||||
"Memphis",
|
||||
"3 minutes ago",
|
||||
6
|
||||
)
|
||||
|
||||
private val ChatData = (0..10).toList().map { chatNotificationData }
|
||||
|
||||
@Composable
|
||||
fun MessagePage(){
|
||||
val myBackend = remember { TestChatBackend(ChatData) }
|
||||
val pager = remember {
|
||||
Pager(
|
||||
PagingConfig(
|
||||
pageSize = myBackend.DataBatchSize,
|
||||
enablePlaceholders = true,
|
||||
maxSize = 200
|
||||
)
|
||||
) {
|
||||
myBackend.getAllData()
|
||||
}
|
||||
}
|
||||
val lazyPagingItems = pager.flow.collectAsLazyPagingItems()
|
||||
MessageTopSwitchBtnGroup()
|
||||
MessageBarrierLine()
|
||||
MessageNotification()
|
||||
LazyColumn (
|
||||
modifier = Modifier.padding(bottom = 20.dp)
|
||||
){
|
||||
if (lazyPagingItems.loadState.refresh == LoadState.Loading) {
|
||||
item {
|
||||
MomentListLoading()
|
||||
}
|
||||
}
|
||||
items(count = lazyPagingItems.itemCount) { index ->
|
||||
val item = lazyPagingItems[index]
|
||||
if (item != null) {
|
||||
ChatItem(item)
|
||||
}
|
||||
}
|
||||
if (lazyPagingItems.loadState.append == LoadState.Loading) {
|
||||
item {
|
||||
MomentListLoading()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun MessageTopSwitchBtnGroup(){
|
||||
Column (
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(113.dp)
|
||||
) {
|
||||
Row(modifier = Modifier.fillMaxSize()){
|
||||
val notificationBtnModifier = Modifier
|
||||
.fillMaxHeight()
|
||||
.weight(1f)
|
||||
NotificationBtn(notificationBtnModifier,drawableId = R.drawable.rider_pro_like,
|
||||
displayText = "LIKE")
|
||||
NotificationBtn(notificationBtnModifier,drawableId = R.drawable.rider_pro_followers,
|
||||
displayText = "FOLLOWERS")
|
||||
NotificationBtn(notificationBtnModifier,drawableId = R.drawable.rider_pro_comments,
|
||||
displayText = "COMMENTS")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun MessageBarrierLine(){
|
||||
Box(modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(1.dp)
|
||||
.padding(start = 24.dp, end = 24.dp)
|
||||
.border(width = 1.dp, Color(0f, 0f, 0f, 0.1f))
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun NotificationBtn(modifier: Modifier, drawableId: Int, displayText: String){
|
||||
Box(modifier = modifier,
|
||||
contentAlignment = Alignment.Center){
|
||||
Column(modifier = Modifier
|
||||
.size(width = 79.dp, height = 88.dp),
|
||||
verticalArrangement = Arrangement.Top,
|
||||
horizontalAlignment = Alignment.CenterHorizontally){
|
||||
Box(modifier = Modifier
|
||||
.padding(top = 8.dp)
|
||||
.size(width = 55.dp, height = 55.dp)
|
||||
.shadow(
|
||||
spotColor = Color.White,
|
||||
ambientColor = Color(0f, 0f, 0f, 0.4f),
|
||||
elevation = 12.dp,
|
||||
),
|
||||
contentAlignment = Alignment.Center,
|
||||
){
|
||||
Image(
|
||||
modifier = Modifier
|
||||
.size(width = 24.dp, height = 24.dp),
|
||||
painter = painterResource(id = drawableId),
|
||||
contentDescription = ""
|
||||
)
|
||||
}
|
||||
Text(
|
||||
modifier = Modifier.padding(top = 8.dp),
|
||||
text = displayText,
|
||||
fontSize = 12.sp, style = TextStyle(fontWeight = FontWeight.Bold)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun MessageNotification(){
|
||||
Row(modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(88.dp)
|
||||
.padding(start = 22.dp, top = 20.dp, bottom = 20.dp, end = 24.dp),
|
||||
verticalAlignment = Alignment.CenterVertically){
|
||||
Box(modifier = Modifier
|
||||
.size(width = 48.dp, height = 48.dp)
|
||||
.border(width = 1.dp, Color(0f, 0f, 0f, 0.1f), RoundedCornerShape(2.dp)),
|
||||
contentAlignment = Alignment.Center){
|
||||
Icon(
|
||||
modifier = Modifier
|
||||
.size(width = 24.dp, height = 24.dp),
|
||||
painter = painterResource(R.drawable.rider_pro_notification),
|
||||
contentDescription = ""
|
||||
)
|
||||
}
|
||||
Text(text = "NOTIFICATIONS", fontSize = 18.sp, modifier = Modifier.padding(start = 12.dp), style = TextStyle(fontWeight = FontWeight.Bold))
|
||||
Box(modifier = Modifier.fillMaxSize(),
|
||||
contentAlignment = Alignment.CenterEnd){
|
||||
Box(modifier = Modifier
|
||||
.height(18.dp)
|
||||
.clip(RoundedCornerShape(10.dp))
|
||||
.background(Color.Red),
|
||||
contentAlignment = Alignment.Center){
|
||||
Text(text = "18", fontSize = 10.sp, color = Color.White, modifier = Modifier.padding(start = 6.dp, end = 6.dp, top = 2.dp, bottom = 2.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ChatItem(chatNotificationData: ChatNotificationData){
|
||||
Row(modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(88.dp)
|
||||
.padding(start = 22.dp, top = 20.dp, bottom = 20.dp, end = 24.dp),
|
||||
verticalAlignment = Alignment.CenterVertically){
|
||||
Image(modifier = Modifier
|
||||
.size(width = 48.dp, height = 48.dp)
|
||||
.clip(RoundedCornerShape(2.dp)),
|
||||
painter = painterResource(chatNotificationData.avatar),
|
||||
contentDescription = "")
|
||||
Column (
|
||||
modifier = Modifier.fillMaxHeight().padding(start = 12.dp),
|
||||
verticalArrangement = Arrangement.SpaceAround
|
||||
){
|
||||
Text(text = chatNotificationData.name, fontSize = 18.sp, style = TextStyle(fontWeight = FontWeight.Bold))
|
||||
Text(text = chatNotificationData.message, fontSize = 14.sp,
|
||||
color = Color(0f, 0f, 0f, 0.6f))
|
||||
}
|
||||
|
||||
Box(modifier = Modifier.fillMaxSize(),
|
||||
contentAlignment = Alignment.CenterEnd){
|
||||
Column (
|
||||
modifier = Modifier.fillMaxHeight(),
|
||||
verticalArrangement = Arrangement.SpaceAround,
|
||||
horizontalAlignment = Alignment.End
|
||||
){
|
||||
Text(text = chatNotificationData.time, fontSize = 12.sp,color = Color(0f, 0f, 0f, 0.4f))
|
||||
Box(modifier = Modifier
|
||||
.height(18.dp)
|
||||
.clip(RoundedCornerShape(10.dp))
|
||||
.background(Color.Red),
|
||||
contentAlignment = Alignment.Center){
|
||||
Text(text = chatNotificationData.unread.toString(), fontSize = 10.sp, color = Color.White, modifier = Modifier.padding(start = 6.dp, end = 6.dp, top = 2.dp, bottom = 2.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
271
app/src/main/java/com/aiosman/riderpro/ui/message/MessageList.kt
Normal file
271
app/src/main/java/com/aiosman/riderpro/ui/message/MessageList.kt
Normal file
@@ -0,0 +1,271 @@
|
||||
package com.aiosman.riderpro.ui.message
|
||||
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
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.lazy.LazyColumn
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.aiosman.riderpro.LocalNavController
|
||||
import com.aiosman.riderpro.R
|
||||
import com.aiosman.riderpro.ui.composables.StatusBarMaskLayout
|
||||
import com.aiosman.riderpro.ui.composables.BottomNavigationPlaceholder
|
||||
import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
||||
|
||||
|
||||
@Preview(showBackground = true)
|
||||
@Composable
|
||||
fun NotificationsScreen() {
|
||||
val navController = LocalNavController.current
|
||||
val systemUiController = rememberSystemUiController()
|
||||
LaunchedEffect(Unit) {
|
||||
systemUiController.setNavigationBarColor(Color.Transparent)
|
||||
}
|
||||
StatusBarMaskLayout(darkIcons = true) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth().weight(1f)
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 24.dp, vertical = 16.dp)
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.rider_pro_message_title),
|
||||
contentDescription = "Back",
|
||||
modifier = Modifier.width(120.dp)
|
||||
)
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
) {
|
||||
NotificationIndicator(10, R.drawable.rider_pro_like, "LIKE") {
|
||||
navController.navigate("Likes")
|
||||
}
|
||||
NotificationIndicator(10, R.drawable.rider_pro_followers, "FOLLOWERS"){
|
||||
navController.navigate("Followers")
|
||||
}
|
||||
NotificationIndicator(10, R.drawable.rider_pro_comments, "COMMENTS"){
|
||||
navController.navigate("Comments")
|
||||
|
||||
}
|
||||
}
|
||||
HorizontalDivider(color = Color(0xFFEbEbEb), modifier = Modifier.padding(16.dp))
|
||||
NotificationCounterItem(24)
|
||||
LazyColumn(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.fillMaxSize()
|
||||
) {
|
||||
item {
|
||||
repeat(20) {
|
||||
MessageItem(
|
||||
MessageItemData(
|
||||
userName = "Onyama Limba",
|
||||
message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
|
||||
timeAgo = "3 days ago",
|
||||
profileImage = R.drawable.default_avatar
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
BottomNavigationPlaceholder()
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun NotificationIndicator(
|
||||
notificationCount: Int,
|
||||
iconRes: Int,
|
||||
label: String,
|
||||
onClick: () -> Unit
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.align(Alignment.TopCenter)
|
||||
.clickable {
|
||||
onClick()
|
||||
}
|
||||
) {
|
||||
if (notificationCount > 0) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.background(Color(0xFFE53935), RoundedCornerShape(8.dp))
|
||||
.padding(4.dp)
|
||||
.align(Alignment.TopEnd)
|
||||
) {
|
||||
Text(
|
||||
text = notificationCount.toString(),
|
||||
color = Color.White,
|
||||
fontSize = 10.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
modifier = Modifier.align(Alignment.Center)
|
||||
)
|
||||
}
|
||||
}
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier.padding(16.dp)
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(id = iconRes),
|
||||
contentDescription = label,
|
||||
modifier = Modifier.size(24.dp)
|
||||
)
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
) {
|
||||
Text(label, modifier = Modifier.align(Alignment.Center))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun NotificationCounterItem(count: Int) {
|
||||
Row(
|
||||
modifier = Modifier.padding(vertical = 16.dp, horizontal = 32.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Box(
|
||||
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.rider_pro_notification),
|
||||
contentDescription = "",
|
||||
modifier = Modifier
|
||||
.size(24.dp)
|
||||
|
||||
)
|
||||
|
||||
}
|
||||
Spacer(modifier = Modifier.width(24.dp))
|
||||
Text("NOTIFICATIONS", fontSize = 18.sp)
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
if (count > 0) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.background(Color(0xFFE53935), RoundedCornerShape(16.dp))
|
||||
.padding(horizontal = 8.dp, vertical = 2.dp)
|
||||
) {
|
||||
Text(
|
||||
text = count.toString(),
|
||||
color = Color.White,
|
||||
fontSize = 12.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
modifier = Modifier.padding(4.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class MessageItemData(
|
||||
val userName: String,
|
||||
val message: String,
|
||||
val timeAgo: String,
|
||||
val profileImage: Int
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun MessageItem(messageItemData: MessageItemData) {
|
||||
Row(
|
||||
modifier = Modifier.padding(16.dp)
|
||||
) {
|
||||
Box() {
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.default_avatar),
|
||||
contentDescription = "",
|
||||
modifier = Modifier
|
||||
.size(48.dp)
|
||||
.clip(RoundedCornerShape(4.dp))
|
||||
)
|
||||
}
|
||||
Column(
|
||||
modifier = Modifier.weight(1f)
|
||||
) {
|
||||
Text(
|
||||
text = "Onyama Limba",
|
||||
fontSize = 16.sp,
|
||||
modifier = Modifier.padding(start = 16.dp)
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
Text(
|
||||
text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
|
||||
fontSize = 14.sp,
|
||||
modifier = Modifier.padding(start = 16.dp),
|
||||
maxLines = 1,
|
||||
color = Color(0x99000000)
|
||||
)
|
||||
}
|
||||
// Spacer(modifier = Modifier.weight(1f))
|
||||
Column(
|
||||
horizontalAlignment = Alignment.End
|
||||
) {
|
||||
Text(
|
||||
text = "3 days ago",
|
||||
fontSize = 14.sp,
|
||||
color = Color(0x66000000)
|
||||
)
|
||||
Spacer(modifier = Modifier.height(6.dp))
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
.background(Color(0xFFE53935))
|
||||
.padding(4.dp)
|
||||
) {
|
||||
Text(
|
||||
text = "24",
|
||||
color = Color.White,
|
||||
fontSize = 12.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
modifier = Modifier.align(Alignment.Center)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user