Neko 4.0.0-alpha1 - changes and new features

While I'm hacking the GSoC away, I finally released the first alpha version of the fourth Neko iteration. Plenty of things has changed, so I suggest looking through the post and start updating your projects. You can always check a sample project to see if it works for you.

The following library versions are the newest and proved to work together:

New class - neko.App (breaking change)

neko.App that takes care of Neko initialization. To use it you must specify it is an application class in AndroidManifest (example). If you are using a custom Application class, then extend neko.App with it.

neko.App contains a static field instance that reliably stores the Application context. It means context accessible from anywhere, woot!

  • Because much of initialization moved to neko.App, SplashActivity is less cluttered now (example).

New syntax for defactivity (breaking change)

What has changed is how you define methods. Example:

(defactivity your.package.name.MainActivity
  :key :main
  :features [:no-title]

  (onCreate [this bundle]
    (.superOnCreate this bundle)
    ...)

  (onResume [this]
    (.superOnResume this)
    ...))

A few points to note here:

  • Supercalls are not anymore generated by the macro, you have to do it yourself. All Activity lifecycle methods (onCreate, onStart, onStop etc.) require a super call, and some of the others. Some methods though don't need a super call, or require them as a default case (onOptionsItemSelected).
  • Keep in mind that some Activity methods return a boolean value (onOptionsItemSelected, onCreateOptionsMenu), and you have to explicitly make sure it happens.
  • It is advisable to define all Activity methods in the macro, not to use MainActivity-onSomething methods. That approach might still work in regular builds, but will break Skummet.
  • Hint. To keep the nice fn-like indentation in Emacs, add this to your init.el:
    (add-hook 'clojure-mode-hook
              (lambda ()
                (put 'defactivity 'clojure-backtracking-indent '(4 (2)))))
    

Overall, the new defactivity expects some more SDK knowledge, but is less magical and more predictable.

neko.init and neko.compilation removed

The latest release of org.clojure-android/clojure handles dynamic compilation initialization by itself, and neko.App takes care of Neko initialization. So there is no need anymore for those two namespaces.

neko.data refactored (breaking change)

neko.data namespace now only contains the like-map function. Utilities for working with SharedPreferences were moved to neko.data.shared-prefs.

neko.data.shared-prefs

First of all, there is a new cool way to work with SharedPreferences which was invented by @Malabarba. It is called defpreferences.

(defpreferences pref-atom "some_sharedprefs_file")

This creates an atom called pref-atom that is bound to the SP file. Whenever an atom changes, the underlying SP file changes accordingly. In other words, it is an atom that preserves its state between restarts! See more information here.

Nevertheless, the low-level functions like get-shared-preferences are still here if you need them. But some of them have changed too:

  • assoc! was renamed to put to match with Android API.
  • assoc-arbitraty and get-arbitrary were removed. If you want to put an arbitrary data type into SharedPreferences, you can still pr-str and read-string manually, but it is no longer encouraged. For storing bigger data chunks it is better to use SQLite.

neko.intent

neko.intent/intent enables more convenient creation of Intent objects. See the description here.

neko.dialog.alert

This namespace is finally rewritten, and now conforms the rest of Neko. Example of usage.

Tests

Since I'm working on CoA testing framework as my GSoC proposal, Neko received some test treatment too. I will describe my progress in more detail in the upcoming post, but for now let's just say that Neko is automatically tested on Travis CI, with coverage no less.

This is all I have for now. As always, please report bugs and ask questions on #clojure-android channel at Freenode, on the mailing list, or in Github issues.