You are on page 1of 22

Kotlin :

Short fun Story Tale


Sidiq Permana
@nouvrizky10

Budi Oktaviyan
Suryanto

Associate Mobile Developer


Co-Founder of Kotlin ID
Null Safety can be fun
Courtesy by http://www.nick-asia.com/
WHAT IS KOTLIN ?

Statically typed programming language for modern multi


platform applications build for JVM, Android, Browser and
Native
THE REASON WHY YOU SHOULD GIVE IT A TRY
THE EVOLUTION OF HOLY
findViewById()
TextView tvResult = (TextView) findViewById(R.id.tv_result); Lovely Java
@BindView(R.id.tv_result) Georgeous ButterKnife
TextView tvResult;

MainActivityBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);


MainViewModel viewModel = new MainViewModel();
binding.setViewModel(viewModel);

<TextView
The Great DataBinding
android:id="@+id/tv_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{viewModel.name}" />

val tvResult = findViewById(R.id.tv_result) as? TextView The Pure Kotlin

val tvResult = find<TextView>(R.id.tv_result) The Cool Anko


All Hail Android Extensions!

tvResult.text = "Result"
No need findViewById or ViewInjection Anymore !

Courtesy by http://www.nick-asia.com/
THE LISTENER JOURNEY

btnMain.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) { Lovely Java (AGAIN)
// TODO coba godain janda sebelah rumah
}
});

@OnClick(R.id.btn_main) Georgeous ButterKnife (AGAIN)


public void onBtnMainClick() {
// TODO jaga mata kalau lagi di mall
}
LAMBDA EXPRESSION

btnMain.setOnClickListener {
TODO("Sederhana lebih seru gan")
}

Courtesy by http://www.nick-asia.com/
THE MAGIC OF with()

with(movie) {
val text = "$name on $year"
tvTitle.text = text
}
THE FABULOUS when() and for..range

Makes loop for..range GREAT AGAIN!


when (type) { for (index in mantans.indices) {
1 -> return "Perawan" if (mantan in 1..100) {
2 -> return "Janda" println("Mantan ke $index")
else -> return "Gak Jelas!" }
} }

Sorry, we have better than the old lady b**ch switch..case


PAINLESS FOR DOING BACKGROUND
doAsync {
val result = URL(apiUrl).readText()
Simplifying the AsyncTask
uiThread {
tvResult.text = result
}
}

async(UI) {
val users: Deferred<List<User>> = bg { getUsers() }
showUsers(users.await())
}

Coroutine in Action!
THEY ARE ALREADY USING KOTLIN

And many more including YOU


(maybe)
The Tools
With Kotlin Plugin

No Plugin Needed!
HOW DO YOU START ?
1. Learn Kotlin as Language secara
KAFFAH a.k.a Menyeluruh
2. Understanding about LAMBDA Expression
3. And Yeah FUNCTIONAL PROGRAMMING
4. Start Your Android Project with
Kotlin enabled
LETS CODE!

You might also like