This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun loadTask() = launch(UI) { // executa na main thread | |
// executa em uma thread separada | |
val result1 = withContext(CommonPool) { // work! } | |
// executa na mesma thread | |
val result2 = withContext(Unconfined) { // work! } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun load() = launch(UI) { | |
try { | |
val result = withContext(CommonPool) { // work! } | |
... | |
} catch (e: IOException) { // exception que pode gerar | |
// exception here! | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.experimental.CommonPool | |
import kotlinx.coroutines.experimental.android.UI | |
import kotlinx.coroutines.experimental.launch | |
import kotlinx.coroutines.experimental.withContext | |
import retrofit2.Call | |
import retrofit2.Retrofit | |
... | |
class Api { | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun performRequest() { | |
api.request( | |
call = service.getUser("jeziellago"), | |
onSuccess = { user -> // fazer algo com o usuário }, | |
onFailure = { error -> // exibir o erro } | |
) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface ApiService { | |
@GET("/users/{username}") | |
fun getUser(@Path("username") username: String): Call<User> | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dependencies { | |
// ML Kit Smart Reply | |
implementation 'com.google.firebase:firebase-ml-natural-language:18.2.0' | |
implementation 'com.google.firebase:firebase-ml-natural-language-smart-reply-model:18.0.0' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
android { | |
// ... | |
aaptOptions { | |
noCompress "tflite" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val localMessage = FirebaseTextMessage.createForLocalUser("Hi, I'm local user.", | |
System.currentTimeMillis()) | |
val remoteUserId = "1234abcde" | |
val remoteMessage = FirebaseTextMessage.createForRemoteUser("Hi, I'm remote user.", | |
System.currentTimeMillis(), | |
remoteUserId) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create smart-reply instance | |
val smartReply = FirebaseNaturalLanguage.getInstance().smartReply | |
// message list | |
val conversation = ArrayList<FirebaseTextMessage>() | |
// add messages on conversation | |
... | |
// get suggested messages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface SendChannel<in E> { | |
suspend fun send(element: E) | |
fun close(): Boolean | |
} | |
interface ReceiveChannel<out E> { | |
suspend fun receive(): E | |
} | |
interface Channel<E> : SendChannel<E>, ReceiveChannel<E> |
OlderNewer