Skip to content

Commit

Permalink
update files
Browse files Browse the repository at this point in the history
  • Loading branch information
REBOOTERS committed Nov 10, 2024
1 parent 15ecd8c commit 28151a6
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
*.project
*.settings/
*.classpath
.info.json
.info.json
/.kotlin/
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

plugins {
id 'com.android.application' version '8.7.1' apply false
id 'com.android.library' version '8.7.1' apply false
id 'com.android.application' version '8.7.2' apply false
id 'com.android.library' version '8.7.2' apply false
id 'org.jetbrains.kotlin.android' version '2.0.20' apply false
id 'com.google.devtools.ksp' version '2.0.10-1.0.24' apply false
id 'org.jetbrains.kotlin.plugin.compose' version '2.0.20' apply false
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies {
// implementation localGroovy()
implementation 'org.jetbrains.kotlin:kotlin-stdlib:2.0.0'
// 添加了这个,就可以看 Android Gradle 插件的源码了
implementation 'com.android.tools.build:gradle-api:8.7.1'
implementation 'com.android.tools.build:gradle-api:8.7.2'
// implementation "org.jetbrains.kotlin:kotlin-script-runtime:1.3.40"
implementation 'com.google.code.gson:gson:2.11.0'
implementation 'com.android.tools:common:31.6.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ fun ChatScreen(
val msg by viewModel.messageList.observeAsState(ArrayList<ChatMessage>())
val msg1 by viewModel.messages.collectAsState()
val temp = provideTestChat()
val kk by viewModel.kkk.observeAsState("11")

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

Column(modifier = Modifier.fillMaxSize()) {
Text(text = kk, modifier = Modifier.size(1.dp))
LazyColumn(

) {
Expand Down
99 changes: 99 additions & 0 deletions subs/compose/src/main/java/com/engineer/compose/ui/ComposeDemo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.engineer.compose.ui

import android.util.Log
import android.widget.Toast
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

private const val TAG = "ComposeView"


@Preview
@Composable
fun DemoCard() {
var count by remember { mutableIntStateOf(0) }
var list by remember { mutableStateOf(ArrayList<String>()) }
val list2 = remember { mutableStateListOf<String>() }
val list3 = remember { mutableStateListOf("") }
var list4 = remember { mutableStateOf(ArrayList<String>())}

Log.i(TAG,"count -> ${count::class}")
Log.i(TAG,"list -> ${list::class}")
Log.i(TAG,"list2 -> ${list2::class}")
Log.i(TAG,"list3 -> ${list3::class}")
Log.i(TAG,"list4 -> ${list4::class}")


Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState())
) {
// Text(modifier = Modifier.padding(start = 10.dp), color = Color.Red, text = "$list")
// Text(modifier = Modifier.padding(start = 10.dp), color = Color.Red, text = "${list4.value}")
// Text(modifier = Modifier.padding(start = 10.dp), color = Color.Blue, text = "$count")
ContentA(list)
ContentA(list2.toList())
ContentA(list3.toList())
ContentA(list4.value)
// ContentB(count)
// ContentC(list, count)

val context = LocalContext.current
Button(modifier = Modifier.padding(5.dp), onClick = {
Toast.makeText(context, "you clicked me", Toast.LENGTH_SHORT).show()
count++
list.add(count.toString())
list2.add(count.toString())
list3.add(count.toString())
list4.value = ArrayList(list)
}) {
Text(text = "click me")
}
}
}

@Composable
fun ContentA(list: List<String>) {
Log.d(TAG, "ContentA() called with: list = $list")
Text(modifier = Modifier.padding(start = 10.dp), color = Color.Red, text = "$list")
}

@Composable
fun ContentB(num: Int) {
Log.d(TAG, "ContentB() called with: num = $num")
Text(modifier = Modifier.padding(start = 10.dp), color = Color.Blue, text = num.toString())
}

@Composable
fun ContentD(list: List<String>) {
Log.d(TAG, "ContentD() called with: list = $list")
Text(modifier = Modifier.padding(start = 10.dp), color = Color.Red, text = "$list")
}


@Composable
fun ContentC(list: ArrayList<String>, num: Int) {
Log.d(TAG, "ContentC() called with: list = $list, num = $num")
Column {
Text(modifier = Modifier.padding(start = 10.dp), color = Color.Red, text = "$list")
Text(modifier = Modifier.padding(start = 10.dp), color = Color.Blue, text = num.toString())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,19 @@ class ChatViewModel : ViewModel() {
val history = _messageList.value ?: ArrayList()
val lastMsg = history.last()
sb.append(c)
kkk.postValue(sb.toString())
if (lastMsg.sender == "Bot") {
val newMsg = ChatMessage("Bot", sb.toString(), false)
history[history.size -1 ] = newMsg

_messageList.value = ArrayList(history)

} else {
val newMsg = ChatMessage("Bot", sb.toString(), false)
history.add(newMsg)
_messageList.value = history
}
// _messageList.postValue(history)

delay(10)
Log.d(TAG, "history ${_messageList.value}")
}
}


}

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

0 comments on commit 28151a6

Please sign in to comment.