Allegro Tech Talks Warszawa #6 — Android

Typical Android devs meeting… (source: pixabay)

On 11th October, I took part in Allegro Tech Talks #6 in Warsaw (more details about the event can be found here). The meetup was organized by Allegro — one of the popular Polish e-commerce destinations with about 17 million users monthly and over 1.1 million items sold via the platform daily. The talks, as the topic suggests, mainly concerned issues related to Android apps development.

First talk: Android, Redux and Kotlin

Redux is widely known in the web front-end development, as a general state container. Its use in React via JavaScript or TypeScript became the de-facto standard for many projects. Yet, for a mobile developer like me, the presented concepts were new, as in Android, the recommended patterns to follow are Mode View ViewModel (MVVM) or Model View Presenter (MVP). So if there are strong recommendations, why should we bother using an alternative approach? The answer may depend on the specific use case, so instead of answering directly, let’s see the main features of Redux and discuss the pros and cons of using it.

In contrast to MVVM or MVP based architectures where we have 3 typical layers, with Redux the app is expressed with the use of a broader spectrum of components:

  • Store: stores the state, when action is dispatched, updates the state with help of reducers
  • State: object that holds information required to render screen
  • Action: describes changes of the state
  • Reducer: joins previous state with action and returns new state
  • Middleware: when an action is dispatched, the store sends the action to the middleware. The middleware does something (api call, logging, IO operations, etc.) and updates the action and sends it back to the store

Pros: The objectives of dividing the logic into these components is to get a predictable and testable structure with a consistent development flow, which is easy to debug… and as it was shown on the presentation — Redux indeed helps with all that.

Cons: It seems that using Redux requires writing more code than usual and takes time to learn — for a mobile developer familiar with traditional approaches, some concepts are not natural. Is it worth the effort? Time will tell.

The most interesting point of this presentation was how to implement middleware with Redux pattern; it really helps in development and it is well separated from other application layers. I will give redux a try in future projects — this approach looks interesting. More info about redux in Android here.

Second talk: Coroutines

This talk convinced me to visit this meetup, because a week before I started to use Coroutines in a green field project that we started in Jit Team. If you haven’t tried coroutines yet, I encourage you to give it a go now! A nice introduction is to be found here at Google’s codelabs.

The presentation helped me to resolve problems I faced while coding the app.

  • How to deal with 3rd party library callbacks like Firebase?
     Just use suspendCoroutine. It blocks coroutine and waits until resume() or resumeWithException() is called.
  • How to make Streams, equivalent to Subjects in RxJava. Coroutines offers channels. Channel is a non-blocking primitive for communication between sender using SendChannel and receiver using ReceiveChannel. Below you can find an example of how to send and receive updates from Firebase database.

Unfortunately, at this point, Channels are in experimental phase, it’s not recommended to use it on production. So, abstain from changing to channels from RxJava for now. A stable version of Channels should be available soon.

Third talk: integrating Google Assistant

Google Assistant is a powerful tool for communication with devices like smartphones, fridges, TVs etc. It uses voice recognition and offers more than 1 million actions like, “what is the weather like”, “what’s 20% of 40?” and so on… and of course, it is integrated with Android.

The presentation showed how to implement custom action, such as “Ok Google, what is the price of a scooter?”. Amazingly, it is really simple. Adding your customer actions is a task for a one developer, assuming that the backend is ready to serve appropriate data.

Summary

The talks were well prepared and the topics were interesting. I will definitely participate in the next Allegro Tech Talks in Warsaw. If you are nearby, maybe we will meet there.