Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Kotlin First - Taking Advantage of Kotlin for A...

Kotlin First - Taking Advantage of Kotlin for Android Development // 360AnDev 2020

What does it mean to be "Kotlin First"?

How can you start taking full advantage of Kotlin for Android development?

Nate Ebel

July 23, 2020
Tweet

More Decks by Nate Ebel

Other Decks in Programming

Transcript

  1. Kotlin First Taking Full Advantage of Kotlin for Android Development

    ANDROID DEVELOPER @n8ebel www.goobar.io Nate Ebel
  2. Taking Full Advantage of Kotlin Migrating Java Syntax & Features

    Kotlin Standard Library Coroutines & Flow Jetpack Compose Kotlin Multiplatform
  3. Taking Full Advantage of Kotlin Get Started With Kotlin Idiomatic

    Kotlin Going Full Kotlin Kotlin Beyond Android
  4. Taking Full Advantage of Kotlin Idiomatic Kotlin Going Full Kotlin

    Kotlin Beyond Android New Projects Converting Java Experimentation
  5. Taking Full Advantage of Kotlin Going Full Kotlin Kotlin Beyond

    Android New Projects Converting Java Experimentation Syntax Kotlin Standard Library Language Features
  6. Taking Full Advantage of Kotlin Kotlin Beyond Android New Projects

    Converting Java Experimentation Syntax Kotlin Standard Library Language Features Android Jetpack Coroutines/Flow Buildscripts/Libraries
  7. Taking Full Advantage of Kotlin New Projects Converting Java Experimentation

    Syntax Kotlin Standard Library Language Features Android Jetpack Coroutines/Flow Buildscripts/Libraries Kotlin Multiplatform Server-side Kotlin Kotlin Scripting
  8. • arrayOf() / listOf() / mapOf() • filter() • map()

    • orEmpty() • getOrElse() • isNullOrEmpty() / isNullOrBlank() Kotlin Standard Library
  9. val awesomeThing = listOf("360AnDev", null, "Kotlin") .filterNotNull() .filter { it.length

    > 6 } .getOrElse(0) { "There were no awesome things longer than 6 chars" }
  10. val awesomeThing = listOf("360AnDev", null, "Kotlin") .filterNotNull() .filter { it.length

    > 6 } .getOrElse(0) { "There were no awesome things longer than 6 chars" } .let { AwesomeThing(it) }
  11. sealed class ViewState { object Loading : ViewState() data class

    Error(val error: Throwable?) data class Success(val data: List<String>) } Sealed Classes
  12. @Query(“SELECT * FROM Repos”) suspend fun getRepos(): List<Repo> @Query(“SELECT *

    FROM Repos”) Fun getRepos(): Flow<List<Repo#>> Room KTX
  13. import org.jetbrains.kotlin.config.KotlinCompilerVersion plugins { id(“com.android.application”) kotlin(“android”) kotlin(“android.extensions”) } android {

    compileSdkVersion(29) … } dependencies { iplementation(“com.android.support:appcompat-v7:27.1.1”) } build.gradle.kts
  14. class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) {

    super.onCreate(savedInstanceState) setContent { RepoItem() } } }
  15. fun main(args: Array<String>) { val server = embeddedServer(Netty, 8080) {

    routing { get(“/“) { call.respondText(“Hello World!”, ContentType.Text.HTML) } get(“/tasks”) { #// return tasks } } } server.start(wait = true) } Simple Ktor service
  16. Taking Full Advantage of Kotlin Project Samples & Defaults Libraries

    & Tooling Recommended Language & Patterns Usefulness Beyond Android