Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Markdown support in text #30

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 1 addition & 1 deletion generativeai-android-sample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ apiKey=YOUR_API_KEY
```
## Features

This sample showcases the following API capablilites:
This sample showcases the following API capabilities:
* Generate Text - demonstrates the Text feature from the SDK
* Photo Reasoning - demonstrates the MultiModal feature from the SDK
* Chat - demonstrates the Multi-turn Conversations feature from the SDK
Expand Down
2 changes: 2 additions & 0 deletions generativeai-android-sample/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,6 @@ dependencies {
debugImplementation("androidx.compose.ui:ui-test-manifest")

implementation("com.google.ai.client.generativeai:generativeai:0.1.1")

implementation("com.github.jeziellago:compose-markdown:0.3.7")
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,14 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.KeyboardCapitalization
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.google.ai.sample.GenerativeViewModelFactory
import com.google.ai.sample.R
import com.google.ai.sample.ui.theme.GenerativeAISample
import dev.jeziellago.compose.markdowntext.MarkdownText
import kotlinx.coroutines.launch

@Composable
Expand Down Expand Up @@ -159,9 +158,10 @@ fun ChatBubbleItem(
shape = bubbleShape,
modifier = Modifier.widthIn(0.dp, maxWidth * 0.9f)
) {
Text(
text = chatMessage.text,
modifier = Modifier.padding(16.dp)
MarkdownText(
markdown = chatMessage.text,
modifier = Modifier.padding(start = 16.dp),
linkColor = Color.Blue
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import com.google.ai.sample.GenerativeViewModelFactory
import coil.size.Precision
import com.google.ai.sample.R
import com.google.ai.sample.util.UriSaver
import dev.jeziellago.compose.markdowntext.MarkdownText
import kotlinx.coroutines.launch

@Composable
Expand Down Expand Up @@ -226,12 +227,13 @@ fun PhotoReasoningScreen(
drawCircle(color = Color.White)
}
)
Text(
text = uiState.outputText, // TODO(thatfiredev): Figure out Markdown support
color = MaterialTheme.colorScheme.onSecondary,
MarkdownText(
markdown = uiState.outputText,
modifier = Modifier
.padding(start = 16.dp)
.fillMaxWidth()
.fillMaxWidth(),
color = MaterialTheme.colorScheme.onSecondary,
linkColor = Color.Blue
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import com.google.ai.sample.GenerativeViewModelFactory
import com.google.ai.sample.R
import com.google.ai.sample.ui.theme.GenerativeAISample
import dev.jeziellago.compose.markdowntext.MarkdownText

@Composable
internal fun SummarizeRoute(
Expand Down Expand Up @@ -145,12 +146,13 @@ fun SummarizeScreen(
drawCircle(color = Color.White)
}
)
Text(
text = uiState.outputText, // TODO(thatfiredev): Figure out Markdown support
color = MaterialTheme.colorScheme.onSecondary,
MarkdownText(
markdown = uiState.outputText,
modifier = Modifier
.padding(start = 16.dp)
.fillMaxWidth()
.fillMaxWidth(),
color = MaterialTheme.colorScheme.onSecondary,
linkColor = Color.Blue
)
}
}
Expand Down
1 change: 1 addition & 0 deletions generativeai-android-sample/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencyResolutionManagement {
mavenLocal()
google()
mavenCentral()
maven(url = "https://jitpack.io") // Jitpack for compose-markdown dependency
}
}

Expand Down