Browse Tag

Kotlin

View binding Delegation

Since Kotlin Android Extensions, including Kotlin synthetics, is deprecated we forced to use View Binding. To find out how to Migrate from Kotlin synthetics to Jetpack view binding follow the link.

When you are done, you will find yourself with additional boilerplate code in each fragment. Inspired by this article Simple one-liner ViewBinding in Fragments and Activities with Kotlin I’ve created a little bit modified version of the fragment one-line view binding solution.

Keep Reading

Kotlin logging library – First Medium post

I’m happy to share with you my new article at @AT&T Israel R&D Center Medium blog >>> https://bit.ly/2Noc2SO
The default logging solution is minimal, and I believe that most of us have already written a wrapper class and copied it from project to project.
Originally I created my Logging library in Java and recently I converted it to Kotlin. Now I want to share it with you.

Kotlin DSL tutorial (simplified)

If you are reading this, I assume that you have reached the same point as I have in the past and you decided to dig a little bit and understand what Kotlin DSL is all about.

Upon googling it, I found the following post that explains this topic pretty well. If you wonder why this post exists, it’s because here I’ll try to explain the same topic with the same code example, but in a more detailed manner. I decided to do so because it took me a while to understand it myself and I’d like to simplify it for you.

The whole solution is available in the following file: Github

Keep Reading

Mock final classes on Kotlin

internal class Foo {
    internal fun bar(x: Int, y: Int, zip: Zip) = x + y + zip.doIt()
}
internal class Zip {
    internal fun doIt() = 0
}

When we have two classes like above and try to mock Zip class like below:

Keep Reading

Navigation Component: How to move the Drawer under the ToolBar?

Navigation Drawer Activity Template

Recently I was struggling with Navigation Component and succeded in solving some of its issues. I am happy to share with you the solutions I’ve found.

GitHub Repo: https://github.com/Pulimet/NavigationComponentSample

Create a project and select the template “Navigation Drawer Activity”. You will get the ToolBar, Drawer and navigation stuff for free as shown in the screenshot.

Now, let’s assume that we got a request to move the drawer under the ToolBar. We need to modify activity_main.xml for that.

Create vertical LinearLayout and make it wrapping DrawerLayout

Open app_bar_main.xml copy AppBarLayout and paste it as a first item in the previously created LinearLayout.

Also from the app_bar_main.xml get the include (content_main) and put it as a first child of DrawerLayout instead of existing include of app_bar_main.xml.

Delete app_bar_main.xml file

In v21\styles.xml – remove the line that makes status bar transparent.

Keep Reading