Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Recipes of Clean Android

Avatar for AAverin AAverin
October 17, 2016

Recipes of Clean Android

A talk about recipes of clean android – different patterns that can be applied to android architecture and code to make cleaner and better.

There's no video, but text of the presentation can be found here: https://docs.google.com/document/d/15QYmR3FyXbLgFyCFTG-jeGoq9VkTDGog5qMLlLcsZMo/edit?usp=sharing

Avatar for AAverin

AAverin

October 17, 2016

Other Decks in Programming

Transcript

  1. About me - Started as J2ME games developer - Android

    since 1.6 - Some mobile C++ experience - Few years frontend javascript - Lots of Android freelancing - Senior Android Developer @ WeltN24
  2. WeltN24 News app Lots of text and media Full native

    Dynamic content Not released yet
  3. WeltN24 - Started as 3, now team of 5 developers

    - MVP + Databinding, Clean architecture - RxJava, Dagger2 - Widget-base server-controlled UI - 13 screens, minimum Fragments - Maximum test coverage, some UI tests - 6mb apk - All code written in Kotlin
  4. Issue Because apps now are: - More independent of the

    web - More complex - Take longer to develop - Have a longer maintenance lifecycle - Have more people working on the code - Have better reach They need to be: - Stable - Extendable - Maintainable - With nice UX/UI
  5. Solution: Split into ViewExtensions View (Activity) I N T E

    R F A C E Presenter EventsDelegate INTERFACE SnackbarViewExtension EventsDelegate INTERFACE TabsViewExtension EventsDelegate INTERFACE RecyclerViewExtension
  6. Solution: Android Databinding - Developed and maintained by Google -

    Yigit Boyar and George Mount - Easy to integrate and use - Removes lots of boilerplate code - You can let ViewExtensions do the binding - Supports: binding from data objects, event handling, custom utils classes and variables, includes with binding, expressions, resources, observable fields, 2 way binding, custom values binding, custom properties
  7. Solution: Separate concerns Model Repository give & keep data, talk

    to others WebService talk to API and transform entities ApiService API for particular service, retrofit interface Cache Cache and apply prune strategy (time, number of entries) Presenter / Interactor Data layer UI layer
  8. Solution: Reactive Don’t let Loaders, AsyncTasks and Threads bite you.

    And they will Use RxJava! Calm the dog! 2 problems: - Difficult to get into - Highly addictive once you do
  9. Solution: RxBus + BusSubscriber patterns BusSubscriber can help with unsubscription

    to avoid memory leaks GlobalRxBus: events from Data layer, broadcasts ActivityRxBus: Local activity events, Navigation events, events from Recycler items Singleton Activity scope
  10. Solution: Resolution Strategy UIResolution RxHttpResolution NetworkResolution LocationResolution onError Broadcast Location

    Timeout UIResolver Persistent Snackbar Snackbar with Retry Login Dialog Information Snackbar Log
  11. Issue: Complex Adapters Item1 (T1) Item2 (T1) Item3 (T2) Item4

    (T2) Item5 (T3) Item6 (T3) Item7 (T4) A D A P T E R onCreateViewHolder onBindViewHolder ViewHolder T1 ViewHolder T2 ViewHolder T3 ViewHolder T4
  12. Solution: PartedAdapter Item1 (T1) -> AdapterPartT1 Item2 (T1) -> AdapterPartT1

    Item3 (T2) -> AdapterPartT2 Item4 (T2) -> AdapterPartT2 Item5 (T3) -> AdapterPartT3 Item6 (T3) -> AdapterPartT3 Item7 (T4) -> AdapterPartT4 P A R T E D A D A P T E R AdapterPart onCreateViewHolder onBindViewHolder
  13. Solution: PageObjects EspressoScreen: - One for every app screen -

    Implements real Espresso - Can open other screens EspressoTest: - Only talks to EspressoScreens - Doesn’t have Espresso