From 8046569a0ad75355174a6b8d548379fc0c61d29a Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 31 Mar 2024 12:24:53 +0300 Subject: [PATCH 1/3] Add counter, and git make my day and i delete all my work) --- .../main/kotlin/ai/elimu/soga/feature/chat/ChatViewModel.kt | 4 ++++ app/src/main/res/values/colors.xml | 3 +++ 2 files changed, 7 insertions(+) diff --git a/app/src/main/kotlin/ai/elimu/soga/feature/chat/ChatViewModel.kt b/app/src/main/kotlin/ai/elimu/soga/feature/chat/ChatViewModel.kt index c86d533..afe5cab 100644 --- a/app/src/main/kotlin/ai/elimu/soga/feature/chat/ChatViewModel.kt +++ b/app/src/main/kotlin/ai/elimu/soga/feature/chat/ChatViewModel.kt @@ -13,6 +13,9 @@ import kotlinx.coroutines.launch class ChatViewModel( generativeModel: GenerativeModel ) : ViewModel() { + + var pointCounter = 0.0f; + private val chat = generativeModel.startChat( history = listOf( content(role = "user") { text("You'll act as a friendly tutor who helps 6-year-old children learn basic math. Use emojis when you create word problems. Your name is Nya.") }, @@ -57,6 +60,7 @@ class ChatViewModel( isPending = false ) ) + if (modelResponse.contains("hhvhv") || modelResponse.contains("there") || modelResponse.contains("Correct")) { pointCounter += 0.1f } } } catch (e: Exception) { _uiState.value.replaceLastPendingMessage() diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index f8c6127..12b61b1 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -7,4 +7,7 @@ #FF018786 #FF000000 #FFFFFFFF + #FFFFC94A + + \ No newline at end of file From caa764df065f13761c5b572590041dc6bd0aa091 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 31 Mar 2024 13:09:31 +0300 Subject: [PATCH 2/3] We back) --- .../ai/elimu/soga/feature/chat/ChatScreen.kt | 17 ++++++++++++++++- .../ai/elimu/soga/feature/chat/ChatViewModel.kt | 4 +++- .../main/kotlin/ai/elimu/soga/ui/theme/Color.kt | 2 ++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/ai/elimu/soga/feature/chat/ChatScreen.kt b/app/src/main/kotlin/ai/elimu/soga/feature/chat/ChatScreen.kt index 586e69a..f5dee1a 100644 --- a/app/src/main/kotlin/ai/elimu/soga/feature/chat/ChatScreen.kt +++ b/app/src/main/kotlin/ai/elimu/soga/feature/chat/ChatScreen.kt @@ -40,10 +40,16 @@ import androidx.compose.ui.unit.dp import androidx.lifecycle.viewmodel.compose.viewModel import ai.elimu.soga.GenerativeViewModelFactory import ai.elimu.soga.R +import ai.elimu.soga.ui.theme.Gold80 import androidx.compose.foundation.Image +import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.CircleShape +import androidx.compose.material3.LinearProgressIndicator import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.Shape +import androidx.compose.ui.graphics.StrokeCap import kotlinx.coroutines.launch import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.painterResource @@ -57,6 +63,15 @@ internal fun ChatRoute( val coroutineScope = rememberCoroutineScope() Scaffold( + topBar = { + LinearProgressIndicator( + progress = chatViewModel.pointCounter, + modifier = Modifier.height(30.dp).fillMaxWidth().padding(10.dp,0.dp), + color = Gold80, + trackColor = Color.Black, + strokeCap = StrokeCap.Round, + ) + }, bottomBar = { MessageInput( onSendMessage = { inputText -> @@ -208,7 +223,7 @@ fun MessageInput( .fillMaxWidth() .weight(0.15f) ) { - Icon( + Icon( Icons.Default.Send, contentDescription = stringResource(R.string.action_send), modifier = Modifier diff --git a/app/src/main/kotlin/ai/elimu/soga/feature/chat/ChatViewModel.kt b/app/src/main/kotlin/ai/elimu/soga/feature/chat/ChatViewModel.kt index afe5cab..1ab1eee 100644 --- a/app/src/main/kotlin/ai/elimu/soga/feature/chat/ChatViewModel.kt +++ b/app/src/main/kotlin/ai/elimu/soga/feature/chat/ChatViewModel.kt @@ -46,6 +46,8 @@ class ChatViewModel( ) ) + + viewModelScope.launch { try { val response = chat.sendMessage(userMessage) @@ -60,7 +62,7 @@ class ChatViewModel( isPending = false ) ) - if (modelResponse.contains("hhvhv") || modelResponse.contains("there") || modelResponse.contains("Correct")) { pointCounter += 0.1f } + if (modelResponse.contains("\uD83C\uDF1F") || modelResponse.contains("correct") || modelResponse.contains("Correct")) { pointCounter += 0.1f } } } catch (e: Exception) { _uiState.value.replaceLastPendingMessage() diff --git a/app/src/main/kotlin/ai/elimu/soga/ui/theme/Color.kt b/app/src/main/kotlin/ai/elimu/soga/ui/theme/Color.kt index 33a1a28..27bc624 100644 --- a/app/src/main/kotlin/ai/elimu/soga/ui/theme/Color.kt +++ b/app/src/main/kotlin/ai/elimu/soga/ui/theme/Color.kt @@ -9,3 +9,5 @@ val Pink80 = Color(0xFFEFB8C8) val Purple40 = Color(0xFF6650a4) val PurpleGrey40 = Color(0xFF625b71) val Pink40 = Color(0xFF7D5260) + +val Gold80 = Color(0xFFFFC94A) \ No newline at end of file From 888d1cf298f0fbaa05878a081d95c818c96e63f8 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 31 Mar 2024 15:07:40 +0300 Subject: [PATCH 3/3] We back) --- .../main/kotlin/ai/elimu/soga/feature/chat/ChatScreen.kt | 4 ++++ .../main/kotlin/ai/elimu/soga/feature/chat/ChatUiState.kt | 2 ++ .../main/kotlin/ai/elimu/soga/feature/chat/ChatViewModel.kt | 6 +++++- settings.gradle.kts | 1 - 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/ai/elimu/soga/feature/chat/ChatScreen.kt b/app/src/main/kotlin/ai/elimu/soga/feature/chat/ChatScreen.kt index f5dee1a..7e6b418 100644 --- a/app/src/main/kotlin/ai/elimu/soga/feature/chat/ChatScreen.kt +++ b/app/src/main/kotlin/ai/elimu/soga/feature/chat/ChatScreen.kt @@ -41,6 +41,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel import ai.elimu.soga.GenerativeViewModelFactory import ai.elimu.soga.R import ai.elimu.soga.ui.theme.Gold80 +import android.util.Log import androidx.compose.foundation.Image import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.size @@ -58,12 +59,15 @@ import androidx.compose.ui.res.painterResource internal fun ChatRoute( chatViewModel: ChatViewModel = viewModel(factory = GenerativeViewModelFactory) ) { + Log.i("Mytag","ChatRoute") val chatUiState by chatViewModel.uiState.collectAsState() val listState = rememberLazyListState() val coroutineScope = rememberCoroutineScope() + Scaffold( topBar = { + // backgroundColor="transparent" LinearProgressIndicator( progress = chatViewModel.pointCounter, modifier = Modifier.height(30.dp).fillMaxWidth().padding(10.dp,0.dp), diff --git a/app/src/main/kotlin/ai/elimu/soga/feature/chat/ChatUiState.kt b/app/src/main/kotlin/ai/elimu/soga/feature/chat/ChatUiState.kt index 854bf5e..36389c1 100644 --- a/app/src/main/kotlin/ai/elimu/soga/feature/chat/ChatUiState.kt +++ b/app/src/main/kotlin/ai/elimu/soga/feature/chat/ChatUiState.kt @@ -1,5 +1,6 @@ package ai.elimu.soga.feature.chat +import android.util.Log import androidx.compose.runtime.toMutableStateList class ChatUiState( @@ -18,6 +19,7 @@ class ChatUiState( val newMessage = lastMessage.apply { isPending = false } _messages.removeLast() _messages.add(newMessage) + Log.i("Mytag","ChatUiState") } } } diff --git a/app/src/main/kotlin/ai/elimu/soga/feature/chat/ChatViewModel.kt b/app/src/main/kotlin/ai/elimu/soga/feature/chat/ChatViewModel.kt index 1ab1eee..cbeecb8 100644 --- a/app/src/main/kotlin/ai/elimu/soga/feature/chat/ChatViewModel.kt +++ b/app/src/main/kotlin/ai/elimu/soga/feature/chat/ChatViewModel.kt @@ -1,5 +1,6 @@ package ai.elimu.soga.feature.chat +import android.util.Log import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.google.ai.client.generativeai.GenerativeModel @@ -54,6 +55,8 @@ class ChatViewModel( _uiState.value.replaceLastPendingMessage() + Log.i("NumberGenerated","Number 2") + response.text?.let { modelResponse -> _uiState.value.addMessage( ChatMessage( @@ -62,7 +65,8 @@ class ChatViewModel( isPending = false ) ) - if (modelResponse.contains("\uD83C\uDF1F") || modelResponse.contains("correct") || modelResponse.contains("Correct")) { pointCounter += 0.1f } + if (modelResponse.contains("\uD83C\uDF1F") || modelResponse.contains("Nya") || modelResponse.contains("Correct") || modelResponse.contains("that's right") || modelResponse.contains("fantastic")) { pointCounter += 0.1f + Log.i("Mytag","viewModelScope") } } } catch (e: Exception) { _uiState.value.replaceLastPendingMessage() diff --git a/settings.gradle.kts b/settings.gradle.kts index d175187..19888c9 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -15,5 +15,4 @@ dependencyResolutionManagement { } } -rootProject.name = "Soga" include(":app")