Skip to content

Commit 28151a6

Browse files
committed
update files
1 parent 15ecd8c commit 28151a6

File tree

6 files changed

+104
-13
lines changed

6 files changed

+104
-13
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
*.project
1212
*.settings/
1313
*.classpath
14-
.info.json
14+
.info.json
15+
/.kotlin/

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
plugins {
4-
id 'com.android.application' version '8.7.1' apply false
5-
id 'com.android.library' version '8.7.1' apply false
4+
id 'com.android.application' version '8.7.2' apply false
5+
id 'com.android.library' version '8.7.2' apply false
66
id 'org.jetbrains.kotlin.android' version '2.0.20' apply false
77
id 'com.google.devtools.ksp' version '2.0.10-1.0.24' apply false
88
id 'org.jetbrains.kotlin.plugin.compose' version '2.0.20' apply false

buildSrc/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dependencies {
99
// implementation localGroovy()
1010
implementation 'org.jetbrains.kotlin:kotlin-stdlib:2.0.0'
1111
// 添加了这个,就可以看 Android Gradle 插件的源码了
12-
implementation 'com.android.tools.build:gradle-api:8.7.1'
12+
implementation 'com.android.tools.build:gradle-api:8.7.2'
1313
// implementation "org.jetbrains.kotlin:kotlin-script-runtime:1.3.40"
1414
implementation 'com.google.code.gson:gson:2.11.0'
1515
implementation 'com.android.tools:common:31.6.0'

subs/compose/src/main/java/com/engineer/compose/ui/ChatActivity.kt

-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ fun ChatScreen(
8181
val msg by viewModel.messageList.observeAsState(ArrayList<ChatMessage>())
8282
val msg1 by viewModel.messages.collectAsState()
8383
val temp = provideTestChat()
84-
val kk by viewModel.kkk.observeAsState("11")
8584

8685
viewModel.messageList.observe(LocalLifecycleOwner.current) {
8786
if (it.size > 1) {
@@ -90,7 +89,6 @@ fun ChatScreen(
9089
}
9190

9291
Column(modifier = Modifier.fillMaxSize()) {
93-
Text(text = kk, modifier = Modifier.size(1.dp))
9492
LazyColumn(
9593

9694
) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package com.engineer.compose.ui
2+
3+
import android.util.Log
4+
import android.widget.Toast
5+
import androidx.compose.foundation.layout.Column
6+
import androidx.compose.foundation.layout.fillMaxSize
7+
import androidx.compose.foundation.layout.padding
8+
import androidx.compose.foundation.rememberScrollState
9+
import androidx.compose.foundation.verticalScroll
10+
import androidx.compose.material3.Button
11+
import androidx.compose.material3.Text
12+
import androidx.compose.runtime.Composable
13+
import androidx.compose.runtime.getValue
14+
import androidx.compose.runtime.mutableIntStateOf
15+
import androidx.compose.runtime.mutableStateListOf
16+
import androidx.compose.runtime.mutableStateOf
17+
import androidx.compose.runtime.remember
18+
import androidx.compose.runtime.setValue
19+
import androidx.compose.ui.Modifier
20+
import androidx.compose.ui.graphics.Color
21+
import androidx.compose.ui.platform.LocalContext
22+
import androidx.compose.ui.tooling.preview.Preview
23+
import androidx.compose.ui.unit.dp
24+
25+
private const val TAG = "ComposeView"
26+
27+
28+
@Preview
29+
@Composable
30+
fun DemoCard() {
31+
var count by remember { mutableIntStateOf(0) }
32+
var list by remember { mutableStateOf(ArrayList<String>()) }
33+
val list2 = remember { mutableStateListOf<String>() }
34+
val list3 = remember { mutableStateListOf("") }
35+
var list4 = remember { mutableStateOf(ArrayList<String>())}
36+
37+
Log.i(TAG,"count -> ${count::class}")
38+
Log.i(TAG,"list -> ${list::class}")
39+
Log.i(TAG,"list2 -> ${list2::class}")
40+
Log.i(TAG,"list3 -> ${list3::class}")
41+
Log.i(TAG,"list4 -> ${list4::class}")
42+
43+
44+
Column(
45+
modifier = Modifier
46+
.fillMaxSize()
47+
.verticalScroll(rememberScrollState())
48+
) {
49+
// Text(modifier = Modifier.padding(start = 10.dp), color = Color.Red, text = "$list")
50+
// Text(modifier = Modifier.padding(start = 10.dp), color = Color.Red, text = "${list4.value}")
51+
// Text(modifier = Modifier.padding(start = 10.dp), color = Color.Blue, text = "$count")
52+
ContentA(list)
53+
ContentA(list2.toList())
54+
ContentA(list3.toList())
55+
ContentA(list4.value)
56+
// ContentB(count)
57+
// ContentC(list, count)
58+
59+
val context = LocalContext.current
60+
Button(modifier = Modifier.padding(5.dp), onClick = {
61+
Toast.makeText(context, "you clicked me", Toast.LENGTH_SHORT).show()
62+
count++
63+
list.add(count.toString())
64+
list2.add(count.toString())
65+
list3.add(count.toString())
66+
list4.value = ArrayList(list)
67+
}) {
68+
Text(text = "click me")
69+
}
70+
}
71+
}
72+
73+
@Composable
74+
fun ContentA(list: List<String>) {
75+
Log.d(TAG, "ContentA() called with: list = $list")
76+
Text(modifier = Modifier.padding(start = 10.dp), color = Color.Red, text = "$list")
77+
}
78+
79+
@Composable
80+
fun ContentB(num: Int) {
81+
Log.d(TAG, "ContentB() called with: num = $num")
82+
Text(modifier = Modifier.padding(start = 10.dp), color = Color.Blue, text = num.toString())
83+
}
84+
85+
@Composable
86+
fun ContentD(list: List<String>) {
87+
Log.d(TAG, "ContentD() called with: list = $list")
88+
Text(modifier = Modifier.padding(start = 10.dp), color = Color.Red, text = "$list")
89+
}
90+
91+
92+
@Composable
93+
fun ContentC(list: ArrayList<String>, num: Int) {
94+
Log.d(TAG, "ContentC() called with: list = $list, num = $num")
95+
Column {
96+
Text(modifier = Modifier.padding(start = 10.dp), color = Color.Red, text = "$list")
97+
Text(modifier = Modifier.padding(start = 10.dp), color = Color.Blue, text = num.toString())
98+
}
99+
}

subs/compose/src/main/java/com/engineer/compose/viewmodel/ChatViewModel.kt

-7
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,19 @@ class ChatViewModel : ViewModel() {
6363
val history = _messageList.value ?: ArrayList()
6464
val lastMsg = history.last()
6565
sb.append(c)
66-
kkk.postValue(sb.toString())
6766
if (lastMsg.sender == "Bot") {
6867
val newMsg = ChatMessage("Bot", sb.toString(), false)
6968
history[history.size -1 ] = newMsg
70-
7169
_messageList.value = ArrayList(history)
72-
7370
} else {
7471
val newMsg = ChatMessage("Bot", sb.toString(), false)
7572
history.add(newMsg)
7673
_messageList.value = history
7774
}
78-
// _messageList.postValue(history)
79-
8075
delay(10)
8176
Log.d(TAG, "history ${_messageList.value}")
8277
}
8378
}
84-
85-
8679
}
8780

8881
private val _messages = MutableStateFlow<List<ChatMessage>>(emptyList())

0 commit comments

Comments
 (0)