11package com.chatgptlite.wanted.ui.conversations
22
3+ import androidx.compose.animation.animateContentSize
34import androidx.compose.foundation.layout.*
45import androidx.compose.foundation.lazy.LazyColumn
56import androidx.compose.foundation.lazy.rememberLazyListState
7+ import androidx.compose.foundation.shape.RoundedCornerShape
8+ import androidx.compose.material.icons.Icons
9+ import androidx.compose.material.icons.filled.Stop
10+ import androidx.compose.material3.ExtendedFloatingActionButton
11+ import androidx.compose.material3.Icon
612import androidx.compose.material3.Surface
13+ import androidx.compose.material3.Text
714import androidx.compose.runtime.Composable
815import androidx.compose.runtime.collectAsState
916import androidx.compose.runtime.getValue
17+ import androidx.compose.ui.Alignment
1018import androidx.compose.ui.Modifier
19+ import androidx.compose.ui.graphics.Color
1120import androidx.compose.ui.platform.testTag
1221import androidx.compose.ui.tooling.preview.Preview
1322import androidx.compose.ui.unit.dp
1423import androidx.hilt.navigation.compose.hiltViewModel
24+ import com.chatgptlite.wanted.constants.conversationTestTag
1525import com.chatgptlite.wanted.models.MessageModel
1626import com.chatgptlite.wanted.ui.conversations.components.MessageCard
1727import com.chatgptlite.wanted.ui.conversations.components.TextInput
@@ -27,19 +37,18 @@ fun Conversation() {
2737 ) {
2838 Box (Modifier .fillMaxSize()) {
2939 Column (Modifier .fillMaxSize()) {
30- MessageList (modifier = Modifier
31- .weight(1f )
32- .padding(horizontal = 16 .dp))
40+ MessageList (
41+ modifier = Modifier
42+ .weight(1f )
43+ .padding(horizontal = 16 .dp)
44+ )
3345 TextInput ()
3446 }
3547 }
3648 }
3749 }
3850}
3951
40-
41- const val ConversationTestTag = " ConversationTestTag"
42-
4352@Composable
4453fun MessageList (
4554 modifier : Modifier = Modifier ,
@@ -49,6 +58,7 @@ fun MessageList(
4958
5059 val conversationId by conversationViewModel.currentConversationState.collectAsState()
5160 val messagesMap by conversationViewModel.messagesState.collectAsState()
61+ val isFabExpanded by conversationViewModel.isFabExpanded.collectAsState()
5262
5363 val messages: List <MessageModel > =
5464 if (messagesMap[conversationId] == null ) listOf () else messagesMap[conversationId]!!
@@ -58,7 +68,7 @@ fun MessageList(
5868 contentPadding =
5969 WindowInsets .statusBars.add(WindowInsets (top = 90 .dp)).asPaddingValues(),
6070 modifier = Modifier
61- .testTag(ConversationTestTag )
71+ .testTag(conversationTestTag )
6272 .fillMaxSize(),
6373 reverseLayout = true ,
6474 state = listState,
@@ -76,11 +86,33 @@ fun MessageList(
7686 }
7787 }
7888 }
89+ ExtendedFloatingActionButton (
90+ text = {
91+ Text (text = " Stop Generating" , color = Color .White )
92+ },
93+ icon = {
94+ Icon (
95+ imageVector = Icons .Default .Stop ,
96+ contentDescription = " Stop Generating" ,
97+ tint = Color .White ,
98+ modifier = Modifier
99+ .size(35 .dp)
100+ )
101+ },
102+ onClick = {
103+ conversationViewModel.stopReceivingResults()
104+ },
105+ shape = RoundedCornerShape (16 .dp),
106+ modifier = Modifier
107+ .align(Alignment .BottomEnd )
108+ .padding(bottom = 16 .dp)
109+ .animateContentSize(),
110+ expanded = isFabExpanded,
111+ )
79112 }
80113}
81114
82115
83-
84116@Preview(showBackground = true )
85117@Composable
86118fun DefaultPreview2 () {
0 commit comments