Log.v(“ThreeTips”, “#17”)

1 — Operator Overloading in Kotlin

Kotlin allows us to provide implementations for a predefined set of operators on our types. These operators have symbolic representation like *,-,+ etc. Lets examine it with a little snippet.

val disposables = CompositeDisposable()
val observable1 = your_observable
disposables.add(observable1)
operator fun CompositeDisposable.plusAssign(disposable: Disposable){
add(disposable)
}
disposables += observable1

2 — Using font in Support Library (As of 26.0.0)

As of Android Support Library 26.0, you must declare both sets of attributes to ensure your fonts load on devices running Android 8.0 (API level 26) or lower. Otherwise your app crashes with following error.

Caused by: java.lang.NullPointerException
at android.graphics.FontFamily.nAddFontFromAssetManager
<font
android:font="@font/product_sans_regular"
android:fontStyle="normal"
android:fontWeight="400"

app:font="@font/product_sans_regular"
app:fontStyle="normal"
app:fontWeight="400" />

3 — Gradle 3.0: “api” vs “implementations”

If you upgraded your gradle plugin to 3.0, you might have seen “compile” is deprecated. You can also see that some documentations are already updated with “implementation”.

//before gradle 3.0
compile
“android.arch.lifecycle:runtime:1.0.3”
//After gradle 3.0
implementation
“android.arch.lifecycle:runtime:1.0.3”

Basically you can use “api” instead of “compile”.

But if you want faster build time in your app, you can do following.

--

--

Software Engineer at Storytel

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store