Google+ Badge

Saturday, March 18, 2017

First week with Kotlin

Got my first nearly full week of Kotlin in place. I can't say full week as I started the new job on a Tuesday and there was training involved too. I have the iOS / Swift code to follow as well.

I needed to grab the colors used by the client along with redoing one of the main graphics as an SVG image. Previously I had Adobe Illustrator but I don't have that now so I used Vectr (I know, odd spelling) which was fine for the minor image I needed to so. I also found Krita for graphics editing and I used that to size the Android icons. I used another online helper program to do the new rounded version of the icons as well. First time I have created a set of those.

When working from home I used my personal PC to play music via Media Monkey + a helper program that exposed a web site for me to pause / skip songs. Don't have that working in an office so I started using Clementine but it has a bug where it double plays WMA songs which got annoying so I gave Vox a shot. Nice thing is I could drag and drop the playlist right out of Clementine into Vox and Vox has a plug-in so I can use the multi-media keys on the Microsoft Natural 4000 keyboard to play / pause and change the volume.

Speaking of the keyboard, the first one failed. The space bar would either not work or it would repeat spaces forever. Took it back to Microcenter who does things in what I think is an odd manner. I just wanted to swap keyboard - bad for good - but they don't do that. They will refund the bad one and give you store credit then you have to go find the replacement and go back through the line again to buy it. Seems silly to me but I have a working keyboard. I have used this style of keyboard for a long time. Sure, they have died on me in the past after years of service but I have not had a bad one out of the box.

While at Microcenter I also got a small laptop bag and a mouse pad. They want me to take the laptop home every night. No big deal, makes it easier if I need to work from home anyway. On that subject I ordered a USB C to mini-display port and USB-C to USB adapter to have at home so when I do work from home I can use my big monitor, keyboard and mouse. That showed up Friday from Amazon and they work just fine. There is a rumor I will get a separate power brick to have at home as well.

Back to Kotlin. It is very handy that when you copy in Java code it will auto convert it to Kotlin. Makes learning stuff a ton easier as well. Kotlin sure uses a lot of lines of code to do the same thing. Copied in an enumeration where I had a couple of extra fields associated. Kotlin does it with a one line constructor. Since a lot of the work I have done has been the basic setup I have not really gotten deep into Kotlin yet.

I got the first couple of screens ready, login and then the drawer based menu system. I stubbed out fragments for all the main screens and implemented the basic help screen as well. More colors, drawables and a few layouts. Also battled getting the actionbar colors I wanted with some help from Reddit. Demoed the app to the team and they were happy how far along I had gotten it.

The build.gradle files were my next target. I added some booleans so use the BuildConfig file to control access to menu items. I also setup a version.properties file so I can run tasks to update the build version string and build number for the command line as well. Tossed in some more libraries I knew I will be using in the next steps including play services so I can get a unique ID the Android way.

Next up is getting Retrofit in place. That is where I will start next week. Need to find some decent tutorials on using it with Kotlin. Will tie in some dependency injection as well. There is some documentation for our REST calls but I am also using Charles Proxy to monitor what iOS is doing. Documentation gets out of date so seeing the raw JSON is usually the way to go. Plus I can see all the data in the request header and the response.

I have not really looking into the Swift code yet. I have been in there to grab some assets including a special font they use. Of course I have the app working on the iOS simulator so I can check out the program flow and screen layouts.

I also configured Slate so I can have a configuration for single screen when I detach at work and another configuration when I am running multiple monitors. Very handy to have all the windows move to the correct position when you start up as the Mac is great at starting the programs again but it sucks at getting them in the proper layout.

Friday, March 10, 2017

Moving to Kotlin

I am going to start a new job and my goal is to go Kotlin. I have been writing Android apps in Java for a number of years. Part of that time I also wrote iOS apps in ObjC. At the job I just left I only did Java Android programming.

I learned a lot at the job including ButterKnife, Dagger, Google Analytics, Flurry Analytics, Event Bus, Twillio, BrainTree, Timber, Vector Drawables, and Glide. All of those things make Java programming easier. I also used a number of things that I used at previous jobs including Volley, GSON, AndroidSVG, and  Google Play Services.

Now it is time to move forward into the land of Kotlin. I have been using it for a number of smaller command line utilities. I had used Python for things like that in the past and I found I can whip them out just as quickly in Kotlin plus it let me learn a new language that I could also use for Android.

I then stepped up and converted a small app that I had done in Java to Kotlin using the Anko library and then I wrote an animation test program from scratch from Kotlin using XML for the layout. Gave me a good peek into a number of aspects of Kotlin. I learned how to setup Kotlin for Android. My utilities were done with IntelliJ.

The old company was moving away from native development so there was not desire there to change to a new native language even if we did it bits and pieces at a time. Sure there was no harm doing some one off utilities but no way I was going to get Kotlin into the main apps.

Next up was taking some time to learn what libraries I might be able to use with Kotlin. There was an excellent talk by Jake Wharton about Okio. It started from the base of the pyramid and worked all the way up through OkHTTP, Moshi and Retrofit. Gave me a great understanding of the entire tree and what it is much better than NIO. Excited to use this chain of tools and to get away from the massive boilerplate of Volley when making REST calls. Annotations are your friend.

Don't know if I will use DSL and Anko but I might use the SQLite aspects of it. I like some of what it offers but also like seeing the preview of my layouts in XML. I do plan on using ConstraintLayout as I have used MigLayout for Java desktop and Autolayout for iOS so I think I can pick it up pretty quickly. I can pull off all kinds of things with RelativeLayout, LinearLayout, TableLayout, GridLayout and PercentLayout bit it seems silly to keep mixing all those together.

Scary to make all these changes at the same time. Kotlin will have me looking up how to do some things I already know to do easily in Java and general syntax. I have a decent base of knowledge now but I will probably fall back into old habits for speed. I know there is a lot of new syntax to use with Kotlin. Of course working code is what counts, using every trick may tighten up the code but is not a requirement. As I learn more I am sure I will go back to fairly fresh code and update it. Refactoring as you learn is a good idea.

I have watched enough Kotlin videos to know what bits and pieces are there so I will attempt to use as much as I have learned. I also think the iOS code written in Swift by the current developer will help me make the switch as it has a lot of the same programming patterns used by Kotlin.

Having a solid Android understanding is huge. I already know what I can do in Android, know about Activity and Fragment life cycles, know what the various Views do and can do recycler views with multiple row types. It will be more about learning syntax of a language and how to tie things together using Kotlin patterns.

Nervous and excited for this new life adventure. Not going to miss the old semicolon and constant null pointer checks. Will take a little bit but I bet my programming speed increases and I actually end up writing less code than I have been writing in Java.