-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: gohj99 <[email protected]>
- Loading branch information
Showing
9 changed files
with
294 additions
and
114 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
app/src/main/java/com/gohj99/telewatch/ui/main/ItemsLazyColumn.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.gohj99.telewatch.ui.main | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Column | ||
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.lazy.LazyColumn | ||
import androidx.compose.foundation.lazy.items | ||
import androidx.compose.material3.Card | ||
import androidx.compose.material3.CardDefaults | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.MutableState | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.unit.dp | ||
|
||
// 定义一个数据类 | ||
data class Chat(val id: Long, val title: String, val message: String) | ||
|
||
fun <T> MutableState<List<T>>.add(item: T) { | ||
val updatedList = this.value.toMutableList() | ||
updatedList.add(item) | ||
this.value = updatedList | ||
} | ||
|
||
@Composable | ||
fun ChatLazyColumn(itemsList: MutableState<List<Chat>>, callback: (Chat) -> Unit) { | ||
LazyColumn( | ||
modifier = Modifier | ||
.fillMaxSize() // 确保 LazyColumn 填满父容器 | ||
.padding(horizontal = 16.dp) // 只在左右添加 padding | ||
) { | ||
items(itemsList.value) { item -> | ||
ChatView(item, callback) | ||
} | ||
item { | ||
Spacer(modifier = Modifier.height(30.dp)) // 添加一个高度为 50dp 的 Spacer | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun ChatView(item: Chat, callback: (Chat) -> Unit) { | ||
Card( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(vertical = 6.dp) | ||
.clickable { callback(item) }, | ||
elevation = CardDefaults.cardElevation(4.dp), | ||
colors = CardDefaults.cardColors( | ||
containerColor = Color(0xFF2C323A) // 设置 Card 的背景颜色 | ||
) | ||
) { | ||
Column(modifier = Modifier.padding(start = 12.dp, top = 9.dp, end = 14.dp, bottom = 9.dp)) { | ||
Text(text = item.title, color = Color.White) | ||
if (item.message.isNotEmpty()) { | ||
Text(text = item.message, color = Color(0xFF728AA5)) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.