reverseBits

Extremely useful Kotlin libraries for Android developers.

Started android development with Kotlin or wanna start? Use these libraries and it will be more awesome.

Let’s go straight to the list,

Android -KTX

A set of Kotlin extensions for Android app development. The goal of Android KTX is to make Android development with Kotlin more concise, pleasant, and idiomatic by leveraging the features of the language such as extension functions/properties, lambdas, named parameters, and parameter defaults. It is an explicit goal of this project to not add any new features to the existing Android APIs

Made by Android team, It has so many useful functions for removing Boilerplate code.

See on Github

KAndroid

Kotlin library for Android providing useful extensions to eliminate boilerplate code in Android SDK and focus on productivity.

This library is amazing you can avoid writing much code for common functions like SearchView query text change, Handler implementation and ViewPager implementation, etc.

see this example

        /* instead of:
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
    override fun onQueryTextChange(q: String): Boolean {
        update(q)
        return false
    }
    
    override fun onQueryTextSubmit(q: String): Boolean {
        return false
    }
}) */
just write:
searchView.onQueryChange { query -> update(query) }
    

Isn’t it amazingly tiny and sweet? Then go use it.

See on Github

ANKO from JetBrains

Anko is a Kotlin library which makes Android application development faster and easier. It makes your code clean and easy to read, and lets you forget about rough edges of the Android SDK for Java.

Anko consists of several parts:

  • Anko Commons: a lightweight library full of helpers for intents, dialogs, logging and so on;
  • Anko Layouts: a fast and type-safe way to write dynamic Android layouts;
  • Anko SQLite: a query DSL and parser collection for Android SQLite;
  • Anko Coroutines: utilities based on the kotlinx.coroutines library.

If you are going to develop Kotlin project then you should never miss this library, it’s lightweight and also help to avoid Boilerplate code.

See on Github

K4Kotlin

A sweet, small set of Kotlin functions to reduce your android boilerplate code

This is another good library, still under development but this guy made it amazingly simple, you should definitely check it out,

Instead of this:

if(myView.getVisibility()  ==  View.VISIBLE)
    myView.setVisibility(View.GONE);
else
    myView.setVisibility(View.VISIBLE);

Do:

myView.toggle()

And many more like this. Go use it.

See on Github

Fuel

The easiest HTTP networking library for Kotlin/Android.

If you use OkHttp or Retrofit they are perfectly fine but it is the option as it is completely build on Kotlin principals.

        //an extension over string (support GET, PUT, POST, DELETE with httpGet(), httpPut(), httpPost(), httpDelete())
"http://httpbin.org/get".httpGet().responseString { request, response, result ->
    //do something with response
    when (result) {
        is Result.Failure -> {
            error = result.getAs()
        }
        is Result.Success -> {
            data = result.getAs()
        }
    }
}
    

See on Github

Kotson

Gson for kotlin

Kotson enables you to parse and write JSON with Google’s Gson using a conciser and easier syntax.

Kotson is a set of extension functions, meaning that it adds utility functions and syntactic sugars to Gson in Kotlin. It does not add new features to Gson nor does it creates new types. It is therefore usable on any Gson object, whether created from java or Kotlin in source or library.

This library is also recommended, as it’s serialization, de-serialization methods are based on Gson, very short and easy to understand.

See on Github

LastAdapter

Don’t write a RecyclerView adapter again. Not even a ViewHolder!

Ever got tired while writing adapters and using View holder pattern? use this one. you gonna love this.
Here is how your adapters will look like,

new LastAdapter(listOfItems, BR.item)
           .map(Header.class, R.layout.item_header)
           .map(Point.class, R.layout.item_point)
           .into(recyclerView);

Done!! Here you go..

See on Github

Kotpref

Android SharedPreference delegation for Kotlin.

This makes Sharedpreferences implementation very easy and like object. You can also use gson serialization with it.

Read and Write

//Write
UserInfo.gameLevel = GameLevel.HARD
UserInfo.name = "chibatching"
UserInfo.code = "DAEF2599-7FC9-49C5-9A11-3C12B14A6898"
UserInfo.age = 30
//Read
Log.d(TAG, "Game level: ${UserInfo.gameLevel}")
Log.d(TAG, "User name: ${UserInfo.name}")
Log.d(TAG, "User code: ${UserInfo.code}")
Log.d(TAG, "User age: ${UserInfo.age}")

Awesome!!

See on Github

Kotterknife

Butter Knife -esque view binding for Kotlin. or in simple words “View “injection” library for Android”.

Made by Legend Jake Wharton


        public class PersonView(context: Context, attrs: AttributeSet?) : LinearLayout(context, attrs) {
  val firstName: TextView by bindView(R.id.first_name)
  val lastName: TextView by bindView(R.id.last_name)

  // Optional binding.
  val details: TextView? by bindOptionalView(R.id.details)

  // List binding.
  val nameViews: List by bindViews(R.id.first_name, R.id.last_name)

  // List binding with optional items being omitted.
  val nameViews: List by bindOptionalViews(R.id.first_name, R.id.middle_name, R.id.last_name)
}
    

See on Github

Kotlin-koi

Koi include many useful extensions and functions, they can help reducing the boilerplate code in Android applications. Specifically, Koi include a powerful extension function named asyncSafe.

Like this 1 below..

        fun networkExtensions() {
    val name = networkTypeName()
    val operator = networkOperator()
    val type = networkType()
    val wifi = isWifi()
    val mobile = isMobile()
    val connected = isConnected()
}
    

This library consists bunch of useful extension functions, so you can save your keystrokes

See on Github

Result

Result<V, E: Exception> is to provide higher abstraction of operation that can be ended with result either success or failure. The is somewhat similar to Kotlin’s nullable types (T?) (https://kotlinlang.org/docs/reference/null-safety.html).

Result.Success represents value in case of success, and Result.Failure represents error in case of failure which is upper bounded with Exception type.

That’s it folks!! Hope u enjoyed this post. Raise your hands if Yes.

Like this post and share if worth 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *