Monday, October 3, 2016

Android Links 3

Android round of android links :)

1) Kotlin for Android developers

Why you should consider kotlin as a development language for android

2) ConstraintLayout links
Here are few links that talks about the new layout.
ConstraintLayout, Inside and Out: Part 1
ConstraintLayout, Inside and Out: Part 2


3) MPAndroidChart
This is graphing library which is really useful if you need to add graphs on your app.

4) 80+ Best Resources for Android Developers 2016 (Blogs, Forums & More)
This is a really good list for resource for Android developers.

Wednesday, August 10, 2016

PaperParcel with Kotlin

When I started to code in kotlin, one of the libraries that I found that was really useful is PaperParcel. PaperParcel is a library that would generate Parcelable using annotation. The good thing about it, is that it will reduce the amount of code and mistake you could make if you manually create those classes. Having said that, the library is not purely for Kotlin and it could be used in Java Android project.

To use it in kotlin
You will need to add these to your app build gradle dependencies
compile 'com.github.grandstaish.paperparcel:paperparcel:1.0.0-rc4'
compile 'com.github.grandstaish.paperparcel:paperparcel-kotlin:1.0.0-rc4'
kapt 'com.github.grandstaish.paperparcel:compiler:1.0.0-rc4'
while still in that gradle file, add these before dependencies
kapt {
    generateStubs = true
}
repositories {
    maven { url 'https://jitpack.io' }
}

Now the fun part, this is taken from my app Daily Picture Quotes
@PaperParcel
data class QuoteImage(val id: String = "",
                 val name: String = "",
                 val text_quote: String = "",
                 val url: String = "",
                 val created: String = "",
                 val cursor:String? = "") : PaperParcelable {
    companion object {
        @JvmField val CREATOR = PaperParcelable.Creator(QuoteImage::class.java)
    }
}

Thats about it, you can use QuoteImage to pass around Activities or Fragment or use it with your custom class.

Two things you have to remember is that your data class name must be supplied in PaperParcelable.Creator and every time you make changes to this data class (atleast for me) you have to do rebuild project.

If this interest you then have a check on the kotlin usage section of their github page.

Hope this helps :)

Wednesday, August 3, 2016

Easier way of getting your layout view in kotlin

As an Android developer, findViewById is probably one of the most annoying code piece you will keep using. However there are libraries that ease this daunting task, one of which I constantly use in Java is ButterKnife. Where you would have something like
public class MainActivity extends AppCompatActivity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        mTabLayout = (TabLayout) findViewById(R.id.table_layout);
        mAddBtn = (Button) findViewById(R.id.add_btn);
    }
}

to something cleaner and easier to understand
public class MainActivity extends AppCompatActivity{
    @BindView(R.id.add_btn) Button mAddBtn;
    @BindView(R.id.table_layout) TabLayout mTabLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        ButterKnife.bind(this);
    }
}

Now in kotlin, there are different options that I had encountered so far.
One of which is KotterKnife which is also from Jake Wharton, the creator of ButterKnife. The library has the same awesomeness as ButterKnife, just check out the example on its github page

Another method is anko's find method, I previously blogged about Anko in Android and how you can use it to create UI in code, but anko is more than that. It has a lot of awesome helper functions and one of it is find, which is a shortform for findViewById and the code would look like this
class MainActivity: AppCompatActivity(){
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mTabLayout = find<TabLayout>(R.id.table_layout)
        mAddBtn = find<Button>(R.id.add_btn)
    }
}

Lastly most probably the lazies solution, but might be not be the most readable one is by using Kotlin Android Extensions. It will automatically bind the views to a class which you will just have to import. To configure it, open your app's gradle file and add on the top
apply plugin: 'kotlin-android-extensions'

Then say you have a layout named activity_main.xml with table_layout and add_btn on it. On your kotlin activity, fragment or custom class just add
import kotlinx.android.synthetic.main.activity_main.view.*

And viola, you can already use table_layout and add_btn like this
import kotlinx.android.synthetic.main.activity_main.view.*
class MainActivity: AppCompatActivity(){
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        add_btn.onClick {
            toast("hello world")
        }
    }
}


Monday, August 1, 2016

SMS Quotes - Simply Make Sharable Quotes Rewrite in Kotlin

I just rewrite one of my app completely in kotlin, check it out. Simply Make Sharable Quotes
In light of this i'll blog in the following days what I learned from the rewrite :)

Thursday, June 2, 2016

Conference Developer Videos - New App

Announcing my first kotlin android app Conference Developer Videos. It features videos from different languages and technologies, it also have lists for you to add videos into. Please help rate the app. Thank you in advance :)

Incase you don't have Android, it is on the web at https://www.conferencedevelopervideos.com/

I created a patreon page to those who are willing to help/donate, my plan is that I want it to be my full time job as there are tons of features to include like notifications, make an ios app and a lot more. Help support the site