Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ dependencies {

// Markdown
implementation(libs.compose.markdown)
implementation(libs.richtext)

// Navigation
implementation(libs.hilt.navigation)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.chungjungsoo.gptmobile.presentation.ui.chat

import android.text.util.Linkify
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand All @@ -19,31 +20,24 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.halilibo.richtext.commonmark.CommonmarkAstNodeParser
import com.halilibo.richtext.commonmark.MarkdownParseOptions
import com.halilibo.richtext.markdown.BasicMarkdown
import com.halilibo.richtext.ui.material3.RichText
import dev.chungjungsoo.gptmobile.R
import dev.chungjungsoo.gptmobile.data.model.ApiType
import dev.chungjungsoo.gptmobile.presentation.theme.GPTMobileTheme
import dev.chungjungsoo.gptmobile.util.getPlatformAPIBrandText
import dev.jeziellago.compose.markdowntext.MarkdownText

@Composable
fun UserChatBubble(
modifier: Modifier = Modifier,
text: String
) {
val markdownParseOptions = remember { MarkdownParseOptions(autolink = false) }
val parser = remember(markdownParseOptions) { CommonmarkAstNodeParser(markdownParseOptions) }
val astNode = remember(text) { parser.parse(text.trimIndent()) }
val cardColor = CardColors(
containerColor = MaterialTheme.colorScheme.primaryContainer,
contentColor = MaterialTheme.colorScheme.onPrimaryContainer,
Expand All @@ -56,9 +50,12 @@ fun UserChatBubble(
shape = RoundedCornerShape(32.dp),
colors = cardColor
) {
RichText(modifier = Modifier.padding(16.dp)) {
BasicMarkdown(astNode = astNode)
}
MarkdownText(
modifier = Modifier.padding(16.dp),
markdown = text,
isTextSelectable = true,
linkifyMask = Linkify.WEB_URLS
)
}
}

Expand All @@ -73,9 +70,6 @@ fun OpponentChatBubble(
onCopyClick: () -> Unit = {},
onRetryClick: () -> Unit = {}
) {
val markdownParseOptions = remember { MarkdownParseOptions(autolink = false) }
val parser = remember(markdownParseOptions) { CommonmarkAstNodeParser(markdownParseOptions) }
val astNode = remember(text) { parser.parse(text.trimIndent() + if (isLoading) "▊" else "") }
val cardColor = CardColors(
containerColor = MaterialTheme.colorScheme.secondaryContainer,
contentColor = MaterialTheme.colorScheme.onSecondaryContainer,
Expand All @@ -89,9 +83,12 @@ fun OpponentChatBubble(
shape = RoundedCornerShape(32.dp),
colors = cardColor
) {
RichText(modifier = Modifier.padding(24.dp)) {
BasicMarkdown(astNode = astNode)
}
MarkdownText(
modifier = Modifier.padding(24.dp),
markdown = text.trimIndent() + if (isLoading) "▊" else "",
isTextSelectable = true,
linkifyMask = Linkify.WEB_URLS
)
if (!isLoading) {
BrandText(apiType)
}
Expand Down
5 changes: 2 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ksp = "2.0.20-1.0.25" # Also change with Kotlin version
ktor = "2.3.12"
androidxHilt = "1.2.0"
navigation = "2.8.3"
markdown = "1.0.0-alpha01"
markdown = "0.5.4"
openai = "3.8.2"
serialization = "1.7.3" # Should not update due to kotlin version
splashscreen = "1.0.1"
Expand All @@ -42,7 +42,7 @@ androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
auto-license-core = { group = "com.mikepenz", name = "aboutlibraries-core", version.ref = "autoLicense" }
auto-license-ui = { group = "com.mikepenz", name = "aboutlibraries-compose-m3", version.ref = "autoLicense" }
compose-markdown = { group = "com.halilibo.compose-richtext", name = "richtext-commonmark", version.ref = "markdown" }
compose-markdown = { group = "com.github.jeziellago", name = "compose-markdown", version.ref = "markdown" }
gemini = { group = "com.google.ai.client.generativeai", name = "generativeai", version.ref = "gemini"}
hilt = { group = "com.google.dagger", name = "hilt-android", version.ref = "hilt" }
hilt-compiler = { group = "com.google.dagger", name = "hilt-android-compiler", version.ref = "hilt" }
Expand All @@ -55,7 +55,6 @@ ktor-logging = { group = "io.ktor", name = "ktor-client-logging-jvm", version.re
ktor-serialization = { group = "io.ktor", name = "ktor-serialization-kotlinx-json", version.ref = "ktor" }
openai = { group = "com.aallam.openai", name = "openai-client", version.ref = "openai" }
splashscreen = { group = "androidx.core", name = "core-splashscreen", version.ref = "splashscreen" }
richtext = { group = "com.halilibo.compose-richtext", name = "richtext-ui-material3", version.ref = "markdown"}
room = { group = "androidx.room", name = "room-runtime", version.ref = "room" }
room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" }
room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" }
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}

Expand Down