@@ -37,7 +37,6 @@ import androidx.compose.foundation.layout.navigationBarsPadding
3737import androidx.compose.foundation.layout.padding
3838import androidx.compose.foundation.layout.size
3939import androidx.compose.foundation.layout.width
40- import androidx.compose.foundation.layout.wrapContentWidth
4140import androidx.compose.foundation.lazy.LazyColumn
4241import androidx.compose.foundation.lazy.LazyListState
4342import androidx.compose.foundation.lazy.itemsIndexed
@@ -48,7 +47,6 @@ import androidx.compose.foundation.text.BasicTextField
4847import androidx.compose.foundation.text.KeyboardOptions
4948import androidx.compose.foundation.text.selection.SelectionContainer
5049import androidx.compose.material.icons.Icons
51- import androidx.compose.material.icons.filled.AccountCircle
5250import androidx.compose.material.icons.filled.AddCircle
5351import androidx.compose.material.icons.filled.Api
5452import androidx.compose.material.icons.filled.ArrowUpward
@@ -322,11 +320,7 @@ fun MainUI(viewModel: ChatViewModel) {
322320 viewModel.sessions.addAll(Gson ().fromJson(sessionsPref.getString(" sessions" , " []" )!! ,
323321 object : TypeToken <List <String >>() {}.type))
324322 val assistantsPref = context.getSharedPreferences(" assistants" , Context .MODE_PRIVATE )
325- val configsList = mutableListOf<String >()
326323 currentConfig = currentConfigPref.getString(" currentConfig" , " " )!!
327- for (i in assistantsPref.all) {
328- configsList.add(i.key)
329- }
330324 val assistants = JsonParser .parseString(
331325 assistantsPref.getString(
332326 currentConfig,
@@ -336,7 +330,7 @@ fun MainUI(viewModel: ChatViewModel) {
336330 api_url = assistants.get(" apiUrl" ).asString;api_key = assistants.get(" apiKey" ).asString;model =
337331 assistants.get(" model" ).asString;systemPrompt = assistants.get(" systemPrompt" ).asString
338332 if (viewModel.sessions.isEmpty()) {
339- viewModel.sessions.add(" 新对话" + System .currentTimeMillis().toString())
333+ viewModel.sessions.add(" 新对话" + System .currentTimeMillis().toString()+ " \u200B " )
340334 }
341335 viewModel.currentSession = viewModel.sessions.last()
342336 if (history.getString(viewModel.currentSession, " " )!! .isNotEmpty()) {
@@ -356,7 +350,7 @@ fun MainUI(viewModel: ChatViewModel) {
356350 }
357351
358352 // 自动滚动
359- LaunchedEffect (if (viewModel.msgs.isNotEmpty()) viewModel.msgs.last().content.length else 0 ) {
353+ LaunchedEffect (if (viewModel.msgs.isNotEmpty()) viewModel.msgs.last().content.length else 0 ,viewModel.isLoading ) {
360354 if (! lazyListState.isScrollInProgress) {
361355 if (lazyListState.layoutInfo.visibleItemsInfo.lastOrNull()?.index == viewModel.msgs.lastIndex) {
362356 if (distanceToBottomCurrentElement < 500 ) {
@@ -445,13 +439,15 @@ fun MainUI(viewModel: ChatViewModel) {
445439 msg = viewModel.inputMsg,
446440 onMsgChange = { viewModel.inputMsg = it },
447441 onSend = {
442+ viewModel.sessions.remove(viewModel.currentSession)
443+ viewModel.sessions.add(viewModel.currentSession)
448444 if (viewModel.isLoading) {
449445 cancel = true
450446 } else {
451447 try {
452448 if (it.isNotEmpty()) {
453449 if (currentConfig!! .isNotEmpty() && ! api_url.startsWith(" /" )) {
454- if ((viewModel.msgs.isEmpty() || viewModel.msgs.last().role == " system" ) && " 新对话" in viewModel.currentSession) {
450+ if ((( viewModel.msgs.isEmpty() || viewModel.msgs.last().role == " system" )) && viewModel.currentSession.startsWith( " 新对话" ) && viewModel.currentSession.endsWith( " \u200B " ) ) {
455451 val withoutEnter = it.replace(" \n " , " " )
456452 var newName = if (withoutEnter.length > 20 ) {
457453 withoutEnter.substring(0 , 20 )
0 commit comments