Realtime applications using Android Architecture Components with Kotlin

Android Architecture Components version 1.0.0 has now been released, this means their API’s are now stable and you should be more comfortable with adopting it in your projects.

What are Android Architecture Components?

Android Architecture components (AAC) are a set of Android libraries that help you structure your application in a way that is robust, testable, and maintainable.

In this post, we are going to discuss how to structure an Android Application’s code for realtime updates using Android Architecture Components. We will be talking specifically about using ViewModel and LiveData to build an Android application that will be updating in realtime.

https://blog.pusher.com/realtime-applications-using-android-architecture-components-kotlin/

Advertisements

Javalin – Simple REST APIs for Java and Kotlin

Javalin is a very lightweight web framework for Kotlin and Java, inspired by Sparkjava and koa.js. Javalin is written in Kotlin with a few functional interfaces written in Java. This was necessary to provide an enjoyable and near identical experience for both Kotlin and Java developers.

Javalin is really more library than framework; you don’t need to extend or implement anything and there are very few “Javalin-concepts” you have to learn.

REST API Simplicity

Javalin started as a fork of the Spark Java and Kotlin web framework but quickly turned into a ground-up rewrite influenced by koa.js. All of these web frameworks are inspired by the modern micro web framework grandfather: Sinatra, so if you’re coming from Ruby then Javalin shouldn’t feel too unfamiliar.

Javalin is not aiming to be a full web framework, but rather just a lightweight REST API library. There is no concept of MVC, but there is support for template engines, websockets, and static file serving for convenience. This allows you to use Javalin for both creating your RESTful API backend, as well as serving an index.html with static resources (in case you’re creating an SPA). This is practical if you don’t want to deploy to apache or nginx in addition to your Javalin service. If you wish to use Javalin to create web-pages instead of just REST APIs, there are some simple template engine wrappers available for a quick and easy setup.

If you want a more established Java web framework, you could try Spark. If you want a more established Kotlin web framework, you can try the Spark Kotlin Wrapper.

https://javalin.io/

 

How to make complex requests simple with RxJava in Kotlin

It is a common problem in Android development when your API is not sending you exactly the same data, what you want to show in your views, so you need to implement more complex requests. Possibly your app needs to make multiple requests, that wait for each other, or call multiple requests after the previous one finished. Sometimes you even need to combine these two approaches. This can be challenging in plain Java and will often result in unreadable code, what is also painful to test.

Today I’m going to show you in a simple example how this can be achieved in a clean way using RxJava. The example is written in Kotlin, what makes the code more concise and easy to read. If you are completely new to RxJava or Kotlin, I suggest you catch up on the basics. There are some great resources here as well.

https://blog.mindorks.com/how-to-make-complex-requests-simple-with-rxjava-in-kotlin-ccec004c5d10

What do 17 Google Developers Experts for Android think about Kotlin?

Google has already expressed several times that they don’t have anything against Kotlin, and that they’re not preventing us from using it while the compiler still generates valid bytecode.

But many people is still waiting for an official support, something that could never happen.

While we wait until that moment though, I thought it would be nice to know what the Google Developers Experts for Android think about it.

If you hadn’t heard about it, Google Developers Experts (GDEs) is a program that recognizes outstanding developers the effort to be a reference on the field they are involved in.

I contacted some of these Android Experts (the list is huge!), and I got answers from 17 of them. Thanks a lot for being so nice and taking your time to answer!

I’ve just asked them to tell us a bit about them, and what they think about Kotlin. The answers are obviously unmodified, so you will find voices for and against (or not so for) the language.

I really hope this helps you form an idea of how Kotlin is being a game changer, and that, at least, is a language to take into account if you are an Android developer.

Without further delay, here it is the opinion of our GDEs in no particular order:…

https://antonioleiva.com/google-kotlin/

Litho: A declarative UI framework for Android

Litho is a declarative framework for building efficient user interfaces (UI) on Android. It allows you to write highly-optimized Android views through a simple functional API based on Java annotations. It was primarily built to implement complex scrollable UIs based on RecyclerView.

With Litho, you build your UI in terms of components instead of interacting directly with traditional Android views. A component is essentially a function that takes immutable inputs, called props, and returns a component hierarchy describing your user interface.

@LayoutSpec
class HelloComponentSpec {

  @OnCreateLayout
  static ComponentLayout onCreateLayout(
      ComponentContext c,
      @Prop String name) {

    return Text.create(c)
        .text("Hello, " + name)
        .textSizeRes(R.dimen.my_text_size)
        .textColor(Color.BLACK)
        .withLayout()
        .paddingDip(ALL, 10)
        .build();
  }
}

You simply declare what you want to display and Litho takes care of rendering it in the most efficient way by computing layout in a background thread, automatically flattening your view hierarchy, and incrementally rendering complex components.

Have a look at our Tutorial for a step-by-step guide on using Litho in your app. You can also read the quick start guide on how to write and use your own Litho components.

http://fblitho.com/

The myth of using Scala as a better Java

When people talk about their experience with Scala, they often say that it is possible to use Scala as a better Java. And indeed, many companies, especially the ones that adopted Scala around 2008-2009, didn’t want to give up the familiar tooling and simply integrated Scala into existing workflows based on Maven. At that time, calling Scala an improved version of Java was questionable but at least justifiable. However, it’s no longer the case. For the most part, contemporary Scala shops don’t use Maven as a build tool, don’t use Spring as a DI container and rarely, if ever, resort to classical design patterns. What do they use then?

http://appliedscala.com/blog/2017/myth-of-scala-as-better-java/