2024-06-22 04:25:20 +08:00
|
|
|
package com.aiosman.riderpro
|
2024-07-13 21:55:39 +08:00
|
|
|
|
2024-06-22 04:25:20 +08:00
|
|
|
import androidx.annotation.DrawableRes
|
|
|
|
|
import androidx.compose.foundation.Image
|
2024-07-13 21:55:39 +08:00
|
|
|
import androidx.compose.foundation.background
|
2024-06-22 04:25:20 +08:00
|
|
|
import androidx.compose.foundation.border
|
2024-07-13 21:55:39 +08:00
|
|
|
import androidx.compose.foundation.clickable
|
2024-06-22 04:25:20 +08:00
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
|
|
|
import androidx.compose.foundation.layout.Box
|
|
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
|
|
import androidx.compose.foundation.layout.Row
|
2024-07-13 21:55:39 +08:00
|
|
|
import androidx.compose.foundation.layout.Spacer
|
2024-06-22 04:25:20 +08:00
|
|
|
import androidx.compose.foundation.layout.defaultMinSize
|
|
|
|
|
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.offset
|
|
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
|
|
import androidx.compose.foundation.layout.size
|
2024-07-13 21:55:39 +08:00
|
|
|
import androidx.compose.foundation.layout.width
|
2024-06-22 04:25:20 +08:00
|
|
|
import androidx.compose.foundation.layout.wrapContentWidth
|
|
|
|
|
import androidx.compose.foundation.lazy.LazyColumn
|
2024-07-13 21:55:39 +08:00
|
|
|
import androidx.compose.material.icons.Icons
|
|
|
|
|
import androidx.compose.material.icons.filled.Build
|
2024-06-22 04:25:20 +08:00
|
|
|
import androidx.compose.material3.CircularProgressIndicator
|
2024-07-13 22:30:34 +08:00
|
|
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
2024-07-13 21:55:39 +08:00
|
|
|
import androidx.compose.material3.Icon
|
2024-06-22 04:25:20 +08:00
|
|
|
import androidx.compose.material3.LocalTextStyle
|
2024-07-13 22:30:34 +08:00
|
|
|
import androidx.compose.material3.ModalBottomSheet
|
2024-06-22 04:25:20 +08:00
|
|
|
import androidx.compose.material3.Text
|
2024-07-18 11:53:43 +08:00
|
|
|
import androidx.compose.material3.rememberModalBottomSheetState
|
2024-06-22 04:25:20 +08:00
|
|
|
import androidx.compose.runtime.Composable
|
2024-07-13 22:30:34 +08:00
|
|
|
import androidx.compose.runtime.getValue
|
|
|
|
|
import androidx.compose.runtime.mutableStateOf
|
2024-06-22 04:25:20 +08:00
|
|
|
import androidx.compose.runtime.remember
|
2024-07-13 22:30:34 +08:00
|
|
|
import androidx.compose.runtime.setValue
|
2024-06-22 04:25:20 +08:00
|
|
|
import androidx.compose.ui.Alignment
|
|
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
|
import androidx.compose.ui.graphics.Color
|
|
|
|
|
import androidx.compose.ui.res.painterResource
|
|
|
|
|
import androidx.compose.ui.res.stringResource
|
|
|
|
|
import androidx.compose.ui.text.PlatformTextStyle
|
|
|
|
|
import androidx.compose.ui.text.TextStyle
|
|
|
|
|
import androidx.compose.ui.text.font.FontWeight
|
|
|
|
|
import androidx.compose.ui.text.style.LineHeightStyle
|
|
|
|
|
import androidx.compose.ui.text.style.TextAlign
|
2024-07-13 21:55:39 +08:00
|
|
|
import androidx.compose.ui.tooling.preview.Preview
|
|
|
|
|
import androidx.compose.ui.tooling.preview.PreviewParameter
|
2024-06-22 04:25:20 +08:00
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
|
import androidx.compose.ui.unit.em
|
|
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
|
|
import androidx.paging.LoadState
|
|
|
|
|
import androidx.paging.Pager
|
|
|
|
|
import androidx.paging.PagingConfig
|
|
|
|
|
import androidx.paging.compose.collectAsLazyPagingItems
|
|
|
|
|
|
2024-07-13 21:55:39 +08:00
|
|
|
private val DATA = (0..60).toList().map { momentTestItem }
|
2024-06-22 04:25:20 +08:00
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
fun PagingBackendSample() {
|
|
|
|
|
val myBackend = remember { TestBackend(DATA) }
|
|
|
|
|
val pager = remember {
|
|
|
|
|
Pager(
|
|
|
|
|
PagingConfig(
|
|
|
|
|
pageSize = myBackend.DataBatchSize,
|
|
|
|
|
enablePlaceholders = true,
|
|
|
|
|
maxSize = 200
|
|
|
|
|
)
|
|
|
|
|
) {
|
|
|
|
|
myBackend.getAllData()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
val lazyPagingItems = pager.flow.collectAsLazyPagingItems()
|
|
|
|
|
|
|
|
|
|
LazyColumn {
|
|
|
|
|
if (lazyPagingItems.loadState.refresh == LoadState.Loading) {
|
|
|
|
|
item {
|
|
|
|
|
MomentListLoading()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
items(count = lazyPagingItems.itemCount) { index ->
|
|
|
|
|
val item = lazyPagingItems[index]
|
|
|
|
|
if (item != null) {
|
|
|
|
|
MomentCard(item)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (lazyPagingItems.loadState.append == LoadState.Loading) {
|
|
|
|
|
item {
|
|
|
|
|
MomentListLoading()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Composable
|
2024-07-13 21:55:39 +08:00
|
|
|
fun MomentCard(momentItem: MomentItem) {
|
2024-06-22 04:25:20 +08:00
|
|
|
Column(
|
|
|
|
|
modifier = Modifier.fillMaxWidth()
|
2024-07-13 21:55:39 +08:00
|
|
|
) {
|
2024-06-22 04:25:20 +08:00
|
|
|
MomentTopRowGroup(momentItem = momentItem)
|
|
|
|
|
MomentContentGroup(momentItem = momentItem)
|
2024-07-13 21:55:39 +08:00
|
|
|
val momentOperateBtnBoxModifier = Modifier
|
|
|
|
|
.fillMaxHeight()
|
|
|
|
|
.weight(1f)
|
|
|
|
|
ModificationListHeader()
|
2024-06-22 04:25:20 +08:00
|
|
|
MomentBottomOperateRowGroup(momentOperateBtnBoxModifier)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Composable
|
2024-07-13 21:55:39 +08:00
|
|
|
fun ModificationListHeader() {
|
|
|
|
|
val navController = LocalNavController.current
|
|
|
|
|
Box(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.padding(16.dp)
|
|
|
|
|
) {
|
|
|
|
|
Box(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.background(Color(0xFFF8F8F8))
|
|
|
|
|
.padding(4.dp)
|
|
|
|
|
.clickable {
|
|
|
|
|
navController.navigate("ModificationList")
|
|
|
|
|
}
|
|
|
|
|
) {
|
|
|
|
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
|
|
|
|
Box(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.background(Color(0xFFEB4869))
|
|
|
|
|
.padding(8.dp)
|
|
|
|
|
) {
|
|
|
|
|
Icon(
|
|
|
|
|
Icons.Filled.Build,
|
|
|
|
|
contentDescription = "Modification Icon",
|
|
|
|
|
tint = Color.White, // Assuming the icon should be white
|
|
|
|
|
modifier = Modifier.size(12.dp)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
Spacer(modifier = Modifier.width(12.dp))
|
|
|
|
|
Text(
|
|
|
|
|
text = "Modification List",
|
|
|
|
|
color = Color(0xFF333333),
|
|
|
|
|
fontSize = 14.sp,
|
|
|
|
|
textAlign = TextAlign.Left
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
fun MomentName(name: String) {
|
2024-06-22 04:25:20 +08:00
|
|
|
Text(
|
|
|
|
|
modifier = Modifier,
|
|
|
|
|
textAlign = TextAlign.Start,
|
|
|
|
|
text = name,
|
2024-07-13 21:55:39 +08:00
|
|
|
color = Color(0f, 0f, 0f),
|
|
|
|
|
fontSize = 16.sp, style = TextStyle(fontWeight = FontWeight.Bold)
|
|
|
|
|
)
|
2024-06-22 04:25:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Composable
|
2024-07-13 21:55:39 +08:00
|
|
|
fun MomentFollowBtn() {
|
|
|
|
|
Box(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.size(width = 53.dp, height = 18.dp)
|
|
|
|
|
.padding(start = 8.dp),
|
|
|
|
|
contentAlignment = Alignment.Center
|
|
|
|
|
) {
|
2024-06-22 04:25:20 +08:00
|
|
|
Image(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxSize(),
|
|
|
|
|
painter = painterResource(id = R.drawable.follow_bg),
|
|
|
|
|
contentDescription = ""
|
|
|
|
|
)
|
2024-07-13 21:55:39 +08:00
|
|
|
Text(
|
|
|
|
|
text = "Follow",
|
2024-06-22 04:25:20 +08:00
|
|
|
color = Color.White,
|
2024-07-13 21:55:39 +08:00
|
|
|
fontSize = 12.sp
|
|
|
|
|
)
|
2024-06-22 04:25:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Composable
|
2024-07-13 21:55:39 +08:00
|
|
|
fun MomentPostLocation(location: String) {
|
|
|
|
|
Text(
|
|
|
|
|
text = location,
|
|
|
|
|
color = Color(0f, 0f, 0f, 0.6f),
|
|
|
|
|
fontSize = 12.sp
|
|
|
|
|
)
|
2024-06-22 04:25:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Composable
|
2024-07-13 21:55:39 +08:00
|
|
|
fun MomentPostTime(time: String) {
|
|
|
|
|
Text(
|
|
|
|
|
modifier = Modifier.padding(start = 8.dp),
|
|
|
|
|
text = time, color = Color(0f, 0f, 0f, 0.6f),
|
2024-06-22 04:25:20 +08:00
|
|
|
fontSize = 12.sp
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Composable
|
2024-07-13 21:55:39 +08:00
|
|
|
fun MomentTopRowGroup(momentItem: MomentItem) {
|
|
|
|
|
Row(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.height(40.dp)
|
|
|
|
|
.padding(top = 0.dp, bottom = 0.dp, start = 24.dp, end = 24.dp)
|
|
|
|
|
) {
|
2024-06-22 04:25:20 +08:00
|
|
|
Image(
|
|
|
|
|
painter = painterResource(id = momentItem.avatar),
|
|
|
|
|
contentDescription = ""
|
|
|
|
|
)
|
|
|
|
|
Column(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.defaultMinSize()
|
|
|
|
|
.padding(start = 12.dp, end = 12.dp)
|
|
|
|
|
) {
|
2024-07-13 21:55:39 +08:00
|
|
|
Row(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.height(22.dp),
|
2024-06-22 04:25:20 +08:00
|
|
|
verticalAlignment = Alignment.CenterVertically
|
2024-07-13 21:55:39 +08:00
|
|
|
) {
|
2024-06-22 04:25:20 +08:00
|
|
|
MomentName(momentItem.nickname)
|
|
|
|
|
MomentFollowBtn()
|
|
|
|
|
}
|
2024-07-13 21:55:39 +08:00
|
|
|
Row(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.height(21.dp),
|
2024-06-22 04:25:20 +08:00
|
|
|
verticalAlignment = Alignment.CenterVertically
|
2024-07-13 21:55:39 +08:00
|
|
|
) {
|
2024-06-22 04:25:20 +08:00
|
|
|
MomentPostLocation(momentItem.location)
|
|
|
|
|
MomentPostTime(momentItem.time)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Composable
|
2024-07-13 21:55:39 +08:00
|
|
|
fun MomentContentGroup(momentItem: MomentItem) {
|
|
|
|
|
Text(
|
|
|
|
|
text = momentItem.momentTextContent,
|
2024-06-22 04:25:20 +08:00
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.padding(top = 22.dp, bottom = 16.dp, start = 24.dp, end = 24.dp),
|
|
|
|
|
fontSize = 16.sp
|
|
|
|
|
)
|
|
|
|
|
Image(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth(),
|
|
|
|
|
painter = painterResource(id = momentItem.momentPicture),
|
|
|
|
|
contentDescription = ""
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Composable
|
2024-07-13 21:55:39 +08:00
|
|
|
fun MomentOperateBtn(@DrawableRes icon: Int, count: String) {
|
|
|
|
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
2024-06-22 04:25:20 +08:00
|
|
|
Image(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.size(width = 24.dp, height = 24.dp),
|
|
|
|
|
painter = painterResource(id = icon),
|
2024-07-13 21:55:39 +08:00
|
|
|
contentDescription = ""
|
|
|
|
|
)
|
|
|
|
|
Text(
|
|
|
|
|
text = count,
|
2024-06-22 04:25:20 +08:00
|
|
|
modifier = Modifier.padding(start = 7.dp),
|
2024-07-13 21:55:39 +08:00
|
|
|
fontSize = 12.sp,
|
|
|
|
|
)
|
2024-06-22 04:25:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
2024-07-13 21:55:39 +08:00
|
|
|
|
2024-07-13 22:30:34 +08:00
|
|
|
@OptIn(ExperimentalMaterial3Api::class)
|
2024-06-22 04:25:20 +08:00
|
|
|
@Composable
|
2024-07-13 21:55:39 +08:00
|
|
|
fun MomentBottomOperateRowGroup(modifier: Modifier) {
|
2024-07-13 22:30:34 +08:00
|
|
|
var showCommentModal by remember { mutableStateOf(false) }
|
|
|
|
|
if (showCommentModal) {
|
|
|
|
|
ModalBottomSheet(
|
|
|
|
|
onDismissRequest = { showCommentModal = false },
|
2024-07-18 11:53:43 +08:00
|
|
|
containerColor = Color.White,
|
|
|
|
|
sheetState = rememberModalBottomSheetState(
|
|
|
|
|
skipPartiallyExpanded = true
|
|
|
|
|
)
|
2024-07-13 22:30:34 +08:00
|
|
|
) {
|
|
|
|
|
CommentModalContent()
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-13 21:55:39 +08:00
|
|
|
Row(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.height(56.dp)
|
|
|
|
|
) {
|
|
|
|
|
Box(
|
|
|
|
|
modifier = modifier,
|
2024-06-22 04:25:20 +08:00
|
|
|
contentAlignment = Alignment.Center
|
2024-07-13 21:55:39 +08:00
|
|
|
) {
|
2024-06-22 04:25:20 +08:00
|
|
|
MomentOperateBtn(icon = R.drawable.rider_pro_like, count = "21")
|
|
|
|
|
}
|
2024-07-13 21:55:39 +08:00
|
|
|
Box(
|
2024-07-13 22:30:34 +08:00
|
|
|
modifier = modifier.clickable {
|
|
|
|
|
showCommentModal = true
|
|
|
|
|
},
|
2024-06-22 04:25:20 +08:00
|
|
|
contentAlignment = Alignment.Center
|
2024-07-13 21:55:39 +08:00
|
|
|
) {
|
2024-06-22 04:25:20 +08:00
|
|
|
MomentOperateBtn(icon = R.drawable.rider_pro_moment_comment, count = "43")
|
|
|
|
|
}
|
2024-07-13 21:55:39 +08:00
|
|
|
Box(
|
|
|
|
|
modifier = modifier,
|
2024-06-22 04:25:20 +08:00
|
|
|
contentAlignment = Alignment.Center
|
2024-07-13 21:55:39 +08:00
|
|
|
) {
|
2024-06-22 04:25:20 +08:00
|
|
|
MomentOperateBtn(icon = R.drawable.rider_pro_share, count = "33")
|
|
|
|
|
}
|
2024-07-13 21:55:39 +08:00
|
|
|
Box(
|
|
|
|
|
modifier = modifier,
|
2024-06-22 04:25:20 +08:00
|
|
|
contentAlignment = Alignment.Center
|
2024-07-13 21:55:39 +08:00
|
|
|
) {
|
2024-06-22 04:25:20 +08:00
|
|
|
MomentOperateBtn(icon = R.drawable.rider_pro_favoriate, count = "211")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Composable
|
2024-07-13 21:55:39 +08:00
|
|
|
fun MomentListLoading() {
|
2024-06-22 04:25:20 +08:00
|
|
|
CircularProgressIndicator(
|
|
|
|
|
modifier =
|
|
|
|
|
Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.wrapContentWidth(Alignment.CenterHorizontally),
|
|
|
|
|
color = Color.Red
|
|
|
|
|
)
|
|
|
|
|
}
|