Why you should use Android Data Binding

Why I started used data binding

After my first blog post about Fastest way for creating RecyclerView Adapter, a couple of you post a comment why I don’t use Data Binding instead of Butterknife. To be honest, I didn’t try to use it simply because I’m used to using Butterknife. I know now that I was terribly wrong, so for every developer like me, here is post to try to convince you to start using data binding.

Continue reading Why you should use Android Data Binding

Use Gradle like a boss

 

Gradle is awesome build tool, and I’m so happy that Android Studio uses it (who ever programmed in Eclipse knows what I’m talking about). I would like to share some tips and tricks.

Update multiple libs version at once

This is really useful with Google’s Android support library, but you will find other examples as well. First, you will need to create extra property, in my example, I name it androidSupportVersion. After that, use this property with your dependencies put a $ sign at the beginning and surround it with curly brackets.

The cool thing about this is that Android Studio will still tell you when a newer version is available.

BuildConfig

This class is automatically generated, and here (with Gradle) you can store some global variables, for example, probably the most common use of this is to have two different API endpoints.

Resources

Similar to previous part, we can use Gradle for generating resources, for example, different name of the app.

You can use all resource types as the type for resValue: array, attr, bool, color, declare-styleable, dimen, fraction, id, integer, plurals, string, style.

Manifest placeholders

We can also define something useful and use it in our app manifest.

And now we can use it in manifest like this:

Signing configs

We can store keystore private info under gradle.properties

and it to the gradle file:

Do you need SHA-1 certificate fingerprint? You could use a keytool, but there is a lot simpler solution. Just run gradle:

Git in Gradle

You can use Git SHA or build time inside your Gradle, for example, you can add Git SHA to your versionNameSuffix just for debug build type.

 

Conclusion

Gradle is an awesome tool for our apps, and I know that there is a lot more. Did I miss something important? Tell me in the comments below.

Android Studio plugins that I use in (almost) every project

Android plugins are a great way to speed up your development process, so here are my favorites:

Android ButterKnife Zelezny

Probably everyone who uses ButterKnife library knows about this one, but still, I need to mention it. This plugin will generate all view bindings for you.

Github

GsonFormat

687474703a2f2f75706c6f61642d696d616765732e6a69616e7368752e696f2f75706c6f61645f696d616765732f3136363836362d666639646333333661663732643764372e6769663f696d6167654d6f6772322f6175746f2d6f7269

This is probably my favorite, this will create you model class from JSON string. It’s really simple to use, just copy/paste your JSON string.

Github

Android Parcelable code generator

Name of this plugin is really self-explanatory. You can easily forget how to write parcelable boilerplate code because this plugin will to work for you.

Github

ADB Idea

Basically, this is the menu with popular A commands, like uninstall, restart, clear data etc.

find_actions

Github

What about you?

What plugins do you use every day? Tell me in the comments.

Fastest way for creating RecyclerView Adapter

Hello world.

First of all, this is my first blog post, so here is a quick intro. I’m will try to share some interesting blog posts about cool things that I know.

We all hate (or at least I do) writing boilerplate code so I would like to share this quick way for writing  RecyclerView Adapter. Before we create an adapter, we need to prepare 2 simple things; one is a class that will be our model, and second will be a layout for an item in the RecyclerView.

Now the fun stuff

Now go to Android Studio > Preferences > Editor > File and code templates and click on that “+” icon for adding the new one.

You may notice that I use ButterKnife library, but you don’t have to, but you should 🙂

Where is my adapter?

Now that we are all set, we need to finally create that adapter. Go to the File > New > and select your RecyclerView adapter template.

Screen Shot 2017-03-22 at 01.48.26

You will see a dialog like this, fill name for you adapter class, item class, and finally your item layout, click OK and… magic. The boring part of your adapter class is already written, all you have to do is make sure that you Inject your views and fill it with data (the fun part).