Skip to content

Commit

Permalink
test compose
Browse files Browse the repository at this point in the history
  • Loading branch information
REBOOTERS committed Oct 19, 2024
1 parent 4c2ff30 commit d87d71f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 35 deletions.
4 changes: 2 additions & 2 deletions imitate/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ dependencies {
// robolectric

implementation group: 'commons-io', name: 'commons-io', version: '20030203.000550'
implementation project(path: ':subs:game')
// implementation project(path: ':subs:game')
implementation project(path: ':subs:gif-revert')
implementation project(path: ':subs:ai')
implementation project(path: ':subs:cpp_native')
// implementation project(path: ':subs:cpp_native')
implementation project(path: ':subs:compose')

implementation 'com.jaredrummler:simple-mvp:1.0.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.engineer.compose.ui.MainComposeActivity
import com.engineer.imitate.databinding.ActivityKotlinRootBinding
import com.engineer.imitate.model.FragmentItem
import com.engineer.imitate.room.SchoolDatabase
import com.engineer.imitate.ui.activity.ReverseGifActivity
import com.engineer.imitate.util.*
import com.example.cpp_native.app.NativeRoot
import com.gyf.immersionbar.ImmersionBar
import com.scwang.smart.refresh.footer.ClassicsFooter
import com.scwang.smart.refresh.header.BezierRadarHeader
Expand Down Expand Up @@ -82,8 +80,8 @@ class KotlinRootActivity : AppCompatActivity() {

// autoStartPage()

NativeRoot.init()
NativeRoot.test()
// NativeRoot.init()
// NativeRoot.test()
val patchViewModel = ViewModelProvider(this)[PatchViewModel::class.java]
patchViewModel.copyFile()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import com.alibaba.android.arouter.facade.annotation.Route
import com.andrefrsousa.superbottomsheet.SuperBottomSheetFragment
import com.bumptech.glide.Glide
import com.engineer.ai.DigitalClassificationActivity
import com.engineer.android.game.ui.GameRootActivity
import com.engineer.imitate.R
import com.engineer.imitate.databinding.FragmentEntranceBinding
import com.engineer.imitate.ui.activity.CLActivity
Expand Down Expand Up @@ -166,7 +165,7 @@ class EntranceFragment : Fragment() {
}

viewBinding.game.setOnClickListener {
startActivity(Intent(context, GameRootActivity::class.java))
// startActivity(Intent(context, GameRootActivity::class.java))
}

viewBinding.shell.setOnClickListener { startActivity(Intent(context, RunShellActivity::class.java)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.content.Context
import android.util.Log
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import com.example.cpp_native.internal.PatchUtil
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -78,7 +77,7 @@ suspend fun mergeFile(context: Context): Boolean {
val oldFile = baseDir + "lastest.txt"
val patchFile = baseDir + "diff.patch"
withContext(Dispatchers.IO) {
PatchUtil.patchAPK(oldFile, result, patchFile)
// PatchUtil.patchAPK(oldFile, result, patchFile)
}

val mergeResult = FileUtils.fileRead(result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.lifecycle.viewmodel.compose.viewModel
import com.engineer.compose.R
import com.engineer.compose.ui.preview.ChatMessageItemPre
Expand Down Expand Up @@ -79,6 +80,13 @@ fun ChatScreen(
val msg by viewModel.messageList.observeAsState()
val temp = provideTestChat()
val kk by viewModel.kkk.observeAsState("11")

viewModel.messageList.observe(LocalLifecycleOwner.current) {
if (it.size > 1) {
Log.e("ChatListPage", "list = ${it[1].text}")
}
}

Column(modifier = Modifier.fillMaxSize()) {
Text(text = kk, modifier = Modifier.size(1.dp))
// 消息列表
Expand Down Expand Up @@ -150,6 +158,7 @@ fun MessageList(messages: ArrayList<ChatMessage>?, modifier: Modifier) {
@Preview
@Composable
fun ChatMessageItem(@PreviewParameter(ChatMessageItemPre::class, 2) message: ChatMessage) {
Log.d("TAG_TAG", message.text)
Row(
modifier = Modifier
.fillMaxWidth()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,34 +47,44 @@ class ChatViewModel : ViewModel() {

private fun mockRequestResult() {
val mockResponse =
"天空呈现蓝色的原因主要与光的散射有关。当太阳光进入大气层后,大气中的气体分子和悬浮微粒会对阳光进行散射。散射的强度与光的波长有关,波长较短的紫光散射强度最大,其次是蓝光,而波长较长的红光和黄光的散射强度较弱。\n" +
"\n" +
"由于蓝光在散射过程中受到的散射强度较大,因此更容易向四面八方散射,这使得我们看到的天空呈现出蓝色。同时,由于人眼对紫光并不敏感,因此即使紫光散射强度最大,我们看到的天空也不会是紫色,而是蓝色。\n" +
"\n" +
"此外,天空的颜色也会随着时间和地点的变化而有所不同。在日出和日落时,由于阳光需要穿过更厚的大气层,散射效果更加显著,天空可能会呈现出橙色或红色。而在晴朗的天气下,由于大气中尘埃和水滴较少,散射作用相对较弱,天空则会呈现出深蓝色。\n" +
"\n" +
"总之,天空之所以是蓝色的,主要是由于大气对阳光中蓝光的强烈散射作用所致。".toCharArray()
val sb = StringBuilder()

Thread {
for (c in mockResponse) {
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
} else {
val newMsg = ChatMessage("Bot", sb.toString(), false)
history.add(newMsg)
}
Log.d(TAG, "history $history")
"天空呈现蓝色的原因主要与光的散射有关。当太阳光进入大气层后,大气中的气体分子和悬浮微粒会对阳光进行散射".toCharArray()
val sb = StringBuffer()

_messageList.postValue(history)
val subThread = true
if (subThread) {
Thread {
sendData(sb, mockResponse, subThread)
}.start()
} else {
sendData(sb, mockResponse, subThread)
}

//

}

private fun sendData(sb: StringBuffer, mockResponse: CharArray, subThread: Boolean) {

for (c in mockResponse) {
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
} else {
val newMsg = ChatMessage("Bot", sb.toString(), false)
history.add(newMsg)
}
Log.d(TAG, "history $history")

if (subThread) {
_messageList.postValue(history)
Thread.sleep(10)
} else {
_messageList.value = history
}
}.start()
}
}
}

0 comments on commit d87d71f

Please sign in to comment.