Skip to content

Commit

Permalink
Merge pull request #7 from KaushalVasava/add_multi_image_chat
Browse files Browse the repository at this point in the history
Add Linkify text and update gemini pro vision to gemini-1.5-flash model
  • Loading branch information
KaushalVasava authored Aug 26, 2024
2 parents 68ced3a + ede2128 commit 7f4700d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ data class ChatMessageEntity(

class ListConverters {
private var gson: Gson = Gson()

@TypeConverter
fun stringToStringList(data: String): List<String> {
val listType = object : TypeToken<List<String>>() {}.type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.lahsuak.apps.geminiai.ui.screen.ChatRoute
import com.lahsuak.apps.geminiai.ui.screen.MenuScreen
import com.lahsuak.apps.geminiai.ui.theme.GeminiAITheme
Expand Down Expand Up @@ -59,4 +61,4 @@ class MainActivity : ComponentActivity() {
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.lahsuak.apps.geminiai.ui.component

import android.text.method.LinkMovementMethod
import android.text.util.Linkify
import android.widget.TextView
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.viewinterop.AndroidView
import androidx.core.text.util.LinkifyCompat

@Composable
fun LinkifyText(
text: AnnotatedString?, color: Color,
modifier: Modifier = Modifier,
) {
val context = LocalContext.current
val customLinkifyTextView = remember {
TextView(context)
}
AndroidView(modifier = modifier, factory = { customLinkifyTextView }) { textView ->
textView.text = text ?: ""

textView.setTextColor(color.hashCode())
textView.setLinkTextColor(Color.Blue.hashCode())
LinkifyCompat.addLinks(textView, Linkify.ALL)
textView.movementMethod = LinkMovementMethod.getInstance()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import com.google.ai.sample.util.UriSaver
import com.lahsuak.apps.geminiai.R
import com.lahsuak.apps.geminiai.data.mapper.toChatMessageEntity
import com.lahsuak.apps.geminiai.data.model.ChatMessageEntity
import com.lahsuak.apps.geminiai.ui.component.LinkifyText
import com.lahsuak.apps.geminiai.ui.component.RoundedTextField
import com.lahsuak.apps.geminiai.ui.model.ChatMessage
import com.lahsuak.apps.geminiai.ui.model.Role
Expand Down Expand Up @@ -294,9 +295,9 @@ fun ChatBubbleItem(
}
}
}
Text(
text = formatCode(chatMessage.text),
modifier = Modifier.padding(16.dp)
LinkifyText(text = formatCode(chatMessage.text),
modifier = Modifier.padding(16.dp),
color = MaterialTheme.colorScheme.onSurface
)
Row(
Modifier.fillMaxWidth(),
Expand Down Expand Up @@ -431,6 +432,7 @@ fun MessageInput(
onSendMessage(userMessage, imageUris)
onValueChange("")
resetScroll()
keyboard?.hide()
isMessageSent = true
} else {
context.speakToAdd(speakLauncher)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class ChatViewModel(
}

val generativeModel = geminiAIRepo.getGenerativeModel(
"gemini-pro-vision",
"gemini-1.5-flash",
geminiAIRepo.provideConfig()
)
var outputContent = ""
Expand Down

0 comments on commit 7f4700d

Please sign in to comment.