Skip to content

Commit 46df3d2

Browse files
committed
fix gemini rest api not work
1 parent 144baaa commit 46df3d2

File tree

7 files changed

+57
-52
lines changed

7 files changed

+57
-52
lines changed

composeApp/src/commonMain/kotlin/com/coding/meet/gaminiaikmp/data/models/GeminiRequestBodyDto.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ data class RequestPart(
1818
@Serializable
1919
data class RequestInlineData(
2020
@SerialName("mimeType") val mimeType: String,
21-
@SerialName("com/coding/meet/gaminiaikmp/data") val data: String
21+
@SerialName("data") val data: String
2222
)

composeApp/src/commonMain/kotlin/com/coding/meet/gaminiaikmp/presentation/components/MessageLayout.kt

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.coding.meet.gaminiaikmp.presentation.components
22

3-
import androidx.compose.animation.core.*
43
import androidx.compose.foundation.Image
54
import androidx.compose.foundation.background
65
import androidx.compose.foundation.layout.*
@@ -12,7 +11,6 @@ import androidx.compose.material3.IconButton
1211
import androidx.compose.material3.IconButtonDefaults
1312
import androidx.compose.material3.Text
1413
import androidx.compose.runtime.Composable
15-
import androidx.compose.runtime.getValue
1614
import androidx.compose.runtime.rememberCoroutineScope
1715
import androidx.compose.ui.Alignment
1816
import androidx.compose.ui.Modifier
@@ -43,7 +41,7 @@ import org.jetbrains.compose.resources.painterResource
4341

4442

4543
@Composable
46-
fun MessageItem(chatMessage: ChatMessage) {
44+
fun MessageItem(chatMessage: ChatMessage, rotate: Float) {
4745
val coroutineScope = rememberCoroutineScope()
4846
val clipboardManager = LocalClipboardManager.current
4947
val isGEMINIMessage = chatMessage.participant != Role.YOU
@@ -53,17 +51,7 @@ fun MessageItem(chatMessage: ChatMessage) {
5351
Role.YOU -> borderColor
5452
Role.ERROR -> redColor
5553
}
56-
val infiniteTransition = rememberInfiniteTransition(label = "")
57-
val rotate by infiniteTransition.animateFloat(
58-
initialValue = 0f,
59-
targetValue = 360f,
60-
animationSpec = infiniteRepeatable(
61-
animation = tween(
62-
durationMillis = 1000,
63-
easing = EaseOutSine
64-
)
65-
), label = ""
66-
)
54+
6755
val horizontalAlignment = if (isGEMINIMessage) {
6856
Alignment.Start
6957
} else {
@@ -108,29 +96,18 @@ fun MessageItem(chatMessage: ChatMessage) {
10896
.clip(cardShape)
10997
.padding(2.dp)
11098
.drawWithContent {
111-
rotate(
112-
if (chatMessage.isPending) {
99+
if (chatMessage.isPending) {
100+
rotate(
113101
rotate
114-
} else {
115-
0f
116-
}
117-
) {
118-
drawCircle(
119-
brush = if (chatMessage.isPending && chatMessage.participant == Role.YOU) {
120-
Brush.sweepGradient(
102+
) {
103+
drawCircle(
104+
brush = Brush.sweepGradient(
121105
circleColors
122-
)
123-
} else {
124-
Brush.linearGradient(
125-
listOf(
126-
backgroundColor,
127-
backgroundColor
128-
)
129-
)
130-
},
131-
radius = size.width,
132-
blendMode = BlendMode.SrcIn,
133-
)
106+
),
107+
radius = size.width,
108+
blendMode = BlendMode.SrcIn,
109+
)
110+
}
134111
}
135112
drawContent()
136113
}.background(backgroundColor, cardShape)
@@ -149,7 +126,7 @@ fun MessageItem(chatMessage: ChatMessage) {
149126
Image(
150127
bitmap,
151128
contentDescription = null,
152-
modifier = Modifier.height(192.dp).clip(RoundedCornerShape(16.dp)),
129+
modifier = Modifier.heightIn(max = 192.dp).clip(RoundedCornerShape(16.dp)),
153130
contentScale = ContentScale.FillHeight,
154131
)
155132
}

composeApp/src/commonMain/kotlin/com/coding/meet/gaminiaikmp/presentation/components/TextLayout.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ import com.mikepenz.markdown.model.DefaultMarkdownTypography
1616
@Composable
1717
fun CommonTextComposable(message: String, isGEMINIMessage: Boolean) {
1818
SelectionContainer {
19+
// Text(
20+
// text = message,
21+
// modifier = Modifier.padding(
22+
// start = 10.dp,
23+
// top = 10.dp,
24+
// end = 10.dp,
25+
// bottom = if (isGEMINIMessage) 3.dp else 10.dp,
26+
// ),
27+
// style = TextStyle(color = whiteColor)
28+
// )
1929
Markdown(
2030
content = message,
2131
modifier = Modifier.padding(
@@ -47,7 +57,9 @@ fun CommonTextComposable(message: String, isGEMINIMessage: Boolean) {
4757
MaterialTheme.typography.bodyMedium,
4858
MaterialTheme.typography.bodyMedium,
4959
MaterialTheme.typography.bodyMedium,
50-
MaterialTheme.typography.bodyMedium
60+
MaterialTheme.typography.bodyMedium,
61+
MaterialTheme.typography.bodyMedium,
62+
MaterialTheme.typography.bodyMedium,
5163
),
5264
)
5365
}

composeApp/src/commonMain/kotlin/com/coding/meet/gaminiaikmp/presentation/screens/chatscreen/ChatScreen.kt

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package com.coding.meet.gaminiaikmp.presentation.screens.chatscreen
22

3+
import androidx.compose.animation.core.*
34
import androidx.compose.foundation.Image
45
import androidx.compose.foundation.background
56
import androidx.compose.foundation.clickable
67
import androidx.compose.foundation.layout.*
78
import androidx.compose.foundation.lazy.LazyColumn
89
import androidx.compose.foundation.lazy.LazyRow
910
import androidx.compose.foundation.lazy.items
10-
import androidx.compose.foundation.lazy.rememberLazyListState
1111
import androidx.compose.foundation.shape.CircleShape
1212
import androidx.compose.foundation.shape.RoundedCornerShape
1313
import androidx.compose.material.icons.Icons
@@ -18,6 +18,7 @@ import androidx.compose.material.icons.filled.Close
1818
import androidx.compose.material.icons.filled.Delete
1919
import androidx.compose.material3.*
2020
import androidx.compose.runtime.Composable
21+
import androidx.compose.runtime.getValue
2122
import androidx.compose.ui.Alignment
2223
import androidx.compose.ui.Modifier
2324
import androidx.compose.ui.draw.clip
@@ -85,12 +86,13 @@ fun ChatScreen(
8586
),
8687
onClick = {
8788
if (!chatUiState.isApiLoading) {
88-
if (chatUiState.message.isNotEmpty()){
89+
if (chatUiState.message.isNotEmpty()) {
8990
chatViewModel.isDeleteShowDialog = true
9091
}
91-
}else{
92+
} else {
9293
mainViewModel.alertTitleText = "API Call in Progress"
93-
mainViewModel.alertDescText = "Please wait while there is already an API call going on, so please be patient."
94+
mainViewModel.alertDescText =
95+
"Please wait while there is already an API call going on, so please be patient."
9496
mainViewModel.isAlertDialogShow = true
9597
}
9698
}) {
@@ -131,19 +133,29 @@ fun ChatScreen(
131133
if (chatUiState.isLoading) {
132134
LoadingAnimation(Modifier.fillMaxWidth().wrapContentSize())
133135
} else {
134-
val lazyListState = rememberLazyListState()
136+
val infiniteTransition = rememberInfiniteTransition(label = "")
137+
val rotate by infiniteTransition.animateFloat(
138+
initialValue = 0f,
139+
targetValue = 360f,
140+
animationSpec = infiniteRepeatable(
141+
animation = tween(
142+
durationMillis = 1000,
143+
easing = EaseOutSine
144+
)
145+
), label = ""
146+
)
135147
LazyColumn(
136148
Modifier.fillMaxSize().background(lightBackgroundColor),
137-
lazyListState,
149+
chatViewModel.lazyListState,
138150
reverseLayout = true,
139-
verticalArrangement = if (chatUiState.message.isEmpty()) Arrangement.Center else Arrangement.Bottom,
151+
verticalArrangement = if (chatUiState.message.isEmpty()) Arrangement.Center else Arrangement.Bottom,
140152
contentPadding = PaddingValues(horizontal = 10.dp),
141153
) {
142154
if (chatUiState.message.isNotEmpty()) {
143155
items(chatUiState.message, key = {
144156
it.messageId
145157
}) {
146-
MessageItem(it)
158+
MessageItem(it, rotate)
147159
}
148160
} else {
149161
item {
@@ -172,7 +184,8 @@ fun ChatScreen(
172184
modifier = Modifier.padding(4.dp).height(192.dp).clip(RoundedCornerShape(16.dp)),
173185
)
174186

175-
Icon(Icons.Default.Close,
187+
Icon(
188+
Icons.Default.Close,
176189
tint = whiteColor,
177190
contentDescription = "remove",
178191
modifier = Modifier.padding(end = 8.dp).clip(CircleShape)

composeApp/src/commonMain/kotlin/com/coding/meet/gaminiaikmp/presentation/screens/chatscreen/ChatViewModel.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.coding.meet.gaminiaikmp.presentation.screens.chatscreen
22

3+
import androidx.compose.foundation.lazy.LazyListState
34
import androidx.compose.runtime.getValue
45
import androidx.compose.runtime.mutableStateListOf
56
import androidx.compose.runtime.mutableStateOf
@@ -40,6 +41,8 @@ class ChatViewModel(
4041
var failedMessageId by mutableStateOf("")
4142

4243

44+
val lazyListState = LazyListState()
45+
4346
fun getMessageList(isClicked: Boolean = false) {
4447

4548
viewModelScope.launch(appCoroutineDispatchers.io) {

composeApp/src/commonMain/kotlin/com/coding/meet/gaminiaikmp/utils/Constant.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package com.coding.meet.gaminiaikmp.utils
22

33
const val BASE_URL = "https://generativelanguage.googleapis.com/"
44
const val DB_NAME = "GeminiApiChatDB.db"
5-
const val GEMINI_PRO = "gemini-pro"
6-
const val GEMINI_PRO_VISION = "gemini-pro-vision"
5+
const val GEMINI_PRO = "gemini-1.5-flash"
6+
const val GEMINI_PRO_VISION = "gemini-1.5-flash"
77
enum class TYPE{
88
MOBILE,
99
DESKTOP,

gradle/libs.versions.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ androidx-core-ktx = "1.13.1"
1010
androidx-espresso-core = "3.6.1"
1111
androidx-material = "1.12.0"
1212
androidx-test-junit = "1.2.1"
13-
compose = "1.7.5"
13+
compose = "1.7.6"
1414
coreSplashscreen = "1.0.1"
1515
kotlinx-datetime = "0.6.1"
1616
compose-plugin = "1.7.0"
@@ -19,15 +19,15 @@ kotlin = "2.0.21"
1919
mpfilepicker = "3.1.0"
2020
koin = "4.0.0"
2121
koinComposeMultiplatform = "4.0.0"
22-
multiplatformMarkdownRenderer = "0.26.0"
22+
multiplatformMarkdownRenderer = "0.27.0"
2323
multiplatformSettingsNoArg = "1.1.1"
2424
sqldelight = "2.0.2"
2525
ktor = "3.0.1"
2626
coroutines = "1.9.0"
2727
kermit = "2.0.4"
2828
buildkonfig = "0.15.1"
2929
kstore = "0.8.0"
30-
viewmodelCompose = "2.8.0"
30+
viewmodelCompose = "2.8.2"
3131

3232

3333
[libraries]

0 commit comments

Comments
 (0)