Wednesday, November 1, 2017

Kotlin 101

I finished my initial conversion of the app into Kotlin.  On the whole, it went really well.  Kotlin is very easy to pick up.  My only stumbling block was getting use to some of the syntax changes.  The ones that took me the longest to get used to was the method and constructor changes, but even those were really minor stumbling blocks.  I pretty much just followed along with the official language documentation at https://kotlinlang.org/.

I did bring in to Kotlin libraries up front: KotterKnife and Anko Sqlite.  KotterKnife is the kotlin version of ButterKnife.  Since I am a big fan of ButterKnife, it was a gimme to try KotterKnife.  It was a little tricky to bring in but I found the answer at https://github.com/JakeWharton/kotterknife/issues/15.  Follow the directions listed and it should work.

I may try the full Anko in my next iteration, but the is for the future.   The Anko Sqlite solved a lot of my questions about how I was going to do my Database management stuff. 

I was able to remove a lot of stuff or simplify my utilities do to the very useful ability called extensions. This lets you add methods to a class without need to extend it.  That is like having a sonic screwdriver in the toolbox.  

This is my initial attempt at Kotlin for Android so it is a little clumsy.   I will slowly improve it over the next few weeks.

Before I forget I also brought in ContentProviders instead of having a single database manipulation utility class.  I will talk about them in my next post.  I also did a few minor UI tweaks in favor simplifying the interactions.

I have not fixed any of the tests yet.   I plan on doing those after I figure out more about Anko.

As usual, the repository can be found at https://github.com/fsk-software/mynotes.