Skip to content

Instantly share code, notes, and snippets.

@kartikarora
Last active October 24, 2024 23:09
Show Gist options
  • Save kartikarora/386333dba62ce58bc2d232df5c958d7f to your computer and use it in GitHub Desktop.
Save kartikarora/386333dba62ce58bc2d232df5c958d7f to your computer and use it in GitHub Desktop.
Activity 8 Step 2
...
val geminiInterface = GeminiInterface()
val scope = CoroutineScope(Dispatchers.IO)
val generatedQuote = scope.async(Dispatchers.IO) {
geminiInterface.getSingleQuote(currentTopicName)
}
updateAppWidgetState(context, glanceId) { prefs ->
val quote = sampleData.firstOrNull {
it.name == currentTopicName
}?.quotes?.random() ?: generatedQuote.await()
prefs[QuoteWidget.KEY_QUOTE] = quote?.text ?: "Quote not found"
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment