This workshop will have you build a modern notepad app using the Kotlin language.
It will also lean on other modern tools such as Room for persistence, RxJava for observing, and ThreeTenABP for date handling.
Before the session begins, please install Android Studio 3.0 Beta 2 and make sure this repo builds successfully.
Please make sure you either have a device and cable to run the application, or that you have an emulator set up and running ahead of time.
We will occasionally be referring directly to the Room documentation. We will also be taking a quick look at Anko:
In the first section, we get our tools set up, fire up the emulator, and introduce everybody to our excellent helpers: Tre Murillo, Steven Anyanwu, Enrique Portillo, and Josh Shin. We will examine our gradle configuration, and also create a basic main activity, and go over some of the auto-generated Kotlin code.
- Tools
- Kotlin's Gradle plugins
- Basic syntax
- Lambdas
- Death to
findViewById
!
Moving on, we will look into the Kotlin annotation processor. We'll also create our Note
data object, complete with JSR-310 date field.
After that we'll set up all of Room's required scaffolding, such as TypeConverter
, RoomDatabase
, and our DAO
. We'll create a couple of query functions as well!
- Annotation Processing
- Java->Kotlin autoconversion
- Nullability
- Type Inference
@JvmStatic
and singletons- varargs
Now that we've set up the core of our persistence logic, let's write a quick smoke test to make sure everything is hooked up properly. We'll demonstrate the power of the Kotlin auto-converter by directly converting a sample test from the Room website.
- Testing with Kotlin
lateinit
- The
apply
function Foo::class.java
Here we set up our recycler adapter, abstract out our database objects into the DataStore
singleton, and introduce RxJava!
- How Kotlin handles inner classes
- Secondary & primary constructors
- Null coalescing
- Subscript operator for collections
- private setters
The final stretch! Let's add some convenience extensions to LayoutInflater and RxJava, set up our composition Activity, and introduce Anko for easy async execution.
- Convenience extensions
when
expression- Anko for async