Android widget for Dragon Go Server

19 Jun 2017

Android  Kotlin  Technology 

Originally posted at https://tech.labs.oliverwyman.com/blog/2017/06/19/android-widget-for-dragon-go-server/

I’m a fan of Go, (the game, very much not the language), but I don’t ever seem to get around to having time to play it in person. Thankfully some folks made the Dragon Go Server which is a sort of ‘play by web’ server for playing games of Go over an extended period, and means I can play a move or so a day instead. The only problem that seems to keep happening is that I’ll get enthused about it again, start a bunch of games, play the first few moves, and then forget about it.  This is particularly annoying as if I forget about things for long enough I end up losing the games by default from timeout. What I really need is something to remind me how long I’ve got before this all happens…

Given I pay a decent amount of attention to my phone already, adding a widget to it sounded like the bright plan. I wanted to do this properly though, with an actual Account and Sync Provider rather than just hacking it together (partially because I’m considering building a full offline+sync client for playing Go games later on), and a few years ago I started building this. I’d worked my way through Udi Cohen‘s excellent authenticator tutorial and I was planning on doing the sync adaptor as well, but got distracted by something else. Recently however I’d been hearing good things about Kotlin from some of my colleagues, and this felt like a good thing to try it out with, and meant I could actually finally get around to finishing this!

My overall experience of Kotlin was excellent: it feels like how the Java design goals could be re-implemented given the last 20 years of improvements in programming language design. It’s still held back a bit by the need for Java interop (e.g. the null-safety works less well when dealing with any existing Java code like, say, all of the Android APIs), but the little things like string interpolation really add up. The most stunning bit was IntelliJ pretty much just converting my entire code base for me. Without that I’d be somewhat less willing to rewrite everything in a new language, but I’d be happy now to use Kotlin from the start with new Android projects.

So what’s the end result: well, it’s now live. The widget shows time till next timeout (“h” for hours and “d” for days) on the top line and “ ()”, and the border indicates overall status: Green for nothing to play, Orange for games to play, Red if you’re down to <1 day left. I you touch the widget, it’ll update and go White while it’s doing that (it also auto-updates every hour or so). Source code is available in the usual location.

Previously: How to actually secure IoT devices Next: Tailgate: calendar data for books