Nicholas Gustilo
Director of Engineering, Apalon NYC.
● nicholas.gustilo@iacapps.com
● https://www.linkedin.com/in/nicholas-gustilo-b893a561
Apalon Translation Tool
I am pleased to announce, that today we are releasing an open source translation
tool that dramatically simplifies the management of strings of Android apps. The
tool consists of:
● Uses a google spreadsheet to manage all translated strings.
● A gradle plugin
● A library (jar file)
● Call ./gradlew updateTranslations
● https://github.com/Apalon/translation-tool
Agenda
1. What is clean architecture and why should you care?
2. App organization and naming.
3. Process and libraries.
4. Reactive programming (costs / benefits)
5. Questions
What is Clean Architecture?
● What do I mean by architecture?
○ Organization of the code, including, naming conventions and package organization, libraries
chosen, the design patterns used and structure of the source code.
● What do we mean by “clean”?
○ Tidy (not messy)? Organized? Not dirty? Clear? Understandable? Simple? Modular!
● Useful links
○ http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
○ http://www.codingthearchitecture.com/2011/11/22/re_clean_architecture.html
What are the benefits of clean architecture?
● Easy to understand - for example, easily map app to code.
● Easier to refactor. Easier to debug and fix.
● Easy for multiple engineers to work on at the same time.
Practical Clean Architecture Tips
1. Organize your code and use good naming conventions
2. Make code modular (how?)
3. Less is more. Use tools that minimize the code that needs to be maintained.
4. Use consistent design patterns (Reactive/MVC/MVP).
App Organization (packages) and Naming
● Demo
Process and Libraries
● Process: Agile (2 week sprints), Android Studio, gradle, git, GitLab, JIRA
● Libraries: butterknife, okhttp3, retrofit, picasso
● Libraries (reactive): rxjava, rx-bindings, rx-preferences, retrofit
● Libraries (other): stetho, leak-canary, apalon-translation-tool
Reactive
What is Reactive? Why should you care? Is it worth the effort?
Reactive - Costs
● Substantial learning curve.
● Clash of APIs (very different from much of android).
● MUST unsubscribe or you have memory leaks.
Reactive - Benefits
Reactive programming combines three features into a compelling technology.
1. Observable/Subscriber design pattern.
2. Thread management
3. Operators to “transform” data
Reactive - Observable/Subscriber
● Observable has a one-to-many relationship with subscribers (or subscriber
objects) so that when the observables state changes all the subscribers are
notified automatically.
● For example, public Observable<List<Item>> getImages()
● Subscriber is an object that “subscribes” to an observable and when notified
is able to process changes using the data provided by the observable.
● For example, this.model.getImages().subscribe(images -> { … });
Reactive - Life Cycle
Reactive - Thread Management
● Compared to standard Android threading technologies reactive handles
threading in a very simple and elegant way.
Reactive - Thread Management
Reactive - Thread Management
Reactive - Thread Management
● Thread management in reactive code is compacted and clear.
Reactive - Operators
● Rxjava supports many operators. Most operators take an Observable as input
and return an Observable. This allows “chaining” of many operators together.
For example, to merge and filter the output of an Observable or control how
an Observable emits data.
Reactive - Operators
Reactive is Awesome! Use it.
Reactive programming combines three features into a compelling technology.
1. Observable/Subscriber design pattern → More modular code.
2. Thread management → Cleaner, easier thread management → more
responsive applications.
3. Operators to “transform” data → Very powerful and (usually) clear way of
managing and controlling data.
Reactive - Architecture Tips
1. In Call Recorder For Me and Coloring Book For Me almost all data is
managed using reactive programming.
2. Activities/Fragments. Subscribe in onResume. Unsubscribe in onPause().
a. Tip: use CompositeSubscription objects.
3. Presenters. Subscribe in UI (view) onAttachedToWindow(). Unsubscribe in UI
(view) onDetachFromWindow().
Reactive - Links
● https://github.com/ReactiveX/RxJava/wiki
● http://reactivex.io/documentation/observable.html
● http://blog.danlew.net/2014/09/15/grokking-rxjava-part-1/
● https://gist.github.com/staltz/868e7e9bc2a7b8c1f754
● http://davesexton.com/blog/post/To-Use-Subject-Or-Not-To-Use-Subject.aspx
● http://tomstechnicalblog.blogspot.com/2016/03/rxjava-problem-with-subjects.
html
Extra - Apalon Translation Tool
Demo
Extra - Subjects
● Subjects are like Observable you can call from anywhere at anytime.
● Easy way to create a “hot” Observable.
● Helps create more modular code.
● Is NOT always thread safe and has gotchas.
○ http://davesexton.com/blog/post/To-Use-Subject-Or-Not-To-Use-Subject.aspx
○ http://tomstechnicalblog.blogspot.com/2016/03/rxjava-problem-with-subjects.html
Extra - Subjects
● private final BehaviorSubject<List<Palette>> paletteBehaviorSubject =
BehaviorSubject.create();
● public BehaviorSubject<List<Category>> getCategoriesObservable() { return
categoriesBehaviorSubject; }
● paletteBehaviorSubject.onNext(paletteList);
Extra - Rx-preferences
● if( MyPreferences.get().isPremium().get() ) { … }
● MyPreferences.get().isPremium().set(true);
● MyPreferences.get().isPremium().asObservable().subscribe (premiumFlag →
{ … });

Nicholas Gustilo "Clean Android: building great mobile apps"

  • 2.
    Nicholas Gustilo Director ofEngineering, Apalon NYC. ● nicholas.gustilo@iacapps.com ● https://www.linkedin.com/in/nicholas-gustilo-b893a561
  • 4.
    Apalon Translation Tool Iam pleased to announce, that today we are releasing an open source translation tool that dramatically simplifies the management of strings of Android apps. The tool consists of: ● Uses a google spreadsheet to manage all translated strings. ● A gradle plugin ● A library (jar file) ● Call ./gradlew updateTranslations ● https://github.com/Apalon/translation-tool
  • 5.
    Agenda 1. What isclean architecture and why should you care? 2. App organization and naming. 3. Process and libraries. 4. Reactive programming (costs / benefits) 5. Questions
  • 6.
    What is CleanArchitecture? ● What do I mean by architecture? ○ Organization of the code, including, naming conventions and package organization, libraries chosen, the design patterns used and structure of the source code. ● What do we mean by “clean”? ○ Tidy (not messy)? Organized? Not dirty? Clear? Understandable? Simple? Modular! ● Useful links ○ http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod ○ http://www.codingthearchitecture.com/2011/11/22/re_clean_architecture.html
  • 7.
    What are thebenefits of clean architecture? ● Easy to understand - for example, easily map app to code. ● Easier to refactor. Easier to debug and fix. ● Easy for multiple engineers to work on at the same time.
  • 8.
    Practical Clean ArchitectureTips 1. Organize your code and use good naming conventions 2. Make code modular (how?) 3. Less is more. Use tools that minimize the code that needs to be maintained. 4. Use consistent design patterns (Reactive/MVC/MVP).
  • 9.
    App Organization (packages)and Naming ● Demo
  • 10.
    Process and Libraries ●Process: Agile (2 week sprints), Android Studio, gradle, git, GitLab, JIRA ● Libraries: butterknife, okhttp3, retrofit, picasso ● Libraries (reactive): rxjava, rx-bindings, rx-preferences, retrofit ● Libraries (other): stetho, leak-canary, apalon-translation-tool
  • 11.
    Reactive What is Reactive?Why should you care? Is it worth the effort?
  • 12.
    Reactive - Costs ●Substantial learning curve. ● Clash of APIs (very different from much of android). ● MUST unsubscribe or you have memory leaks.
  • 13.
    Reactive - Benefits Reactiveprogramming combines three features into a compelling technology. 1. Observable/Subscriber design pattern. 2. Thread management 3. Operators to “transform” data
  • 14.
    Reactive - Observable/Subscriber ●Observable has a one-to-many relationship with subscribers (or subscriber objects) so that when the observables state changes all the subscribers are notified automatically. ● For example, public Observable<List<Item>> getImages() ● Subscriber is an object that “subscribes” to an observable and when notified is able to process changes using the data provided by the observable. ● For example, this.model.getImages().subscribe(images -> { … });
  • 15.
  • 16.
    Reactive - ThreadManagement ● Compared to standard Android threading technologies reactive handles threading in a very simple and elegant way.
  • 17.
  • 18.
  • 19.
    Reactive - ThreadManagement ● Thread management in reactive code is compacted and clear.
  • 20.
    Reactive - Operators ●Rxjava supports many operators. Most operators take an Observable as input and return an Observable. This allows “chaining” of many operators together. For example, to merge and filter the output of an Observable or control how an Observable emits data.
  • 21.
  • 22.
    Reactive is Awesome!Use it. Reactive programming combines three features into a compelling technology. 1. Observable/Subscriber design pattern → More modular code. 2. Thread management → Cleaner, easier thread management → more responsive applications. 3. Operators to “transform” data → Very powerful and (usually) clear way of managing and controlling data.
  • 23.
    Reactive - ArchitectureTips 1. In Call Recorder For Me and Coloring Book For Me almost all data is managed using reactive programming. 2. Activities/Fragments. Subscribe in onResume. Unsubscribe in onPause(). a. Tip: use CompositeSubscription objects. 3. Presenters. Subscribe in UI (view) onAttachedToWindow(). Unsubscribe in UI (view) onDetachFromWindow().
  • 24.
    Reactive - Links ●https://github.com/ReactiveX/RxJava/wiki ● http://reactivex.io/documentation/observable.html ● http://blog.danlew.net/2014/09/15/grokking-rxjava-part-1/ ● https://gist.github.com/staltz/868e7e9bc2a7b8c1f754 ● http://davesexton.com/blog/post/To-Use-Subject-Or-Not-To-Use-Subject.aspx ● http://tomstechnicalblog.blogspot.com/2016/03/rxjava-problem-with-subjects. html
  • 25.
    Extra - ApalonTranslation Tool Demo
  • 26.
    Extra - Subjects ●Subjects are like Observable you can call from anywhere at anytime. ● Easy way to create a “hot” Observable. ● Helps create more modular code. ● Is NOT always thread safe and has gotchas. ○ http://davesexton.com/blog/post/To-Use-Subject-Or-Not-To-Use-Subject.aspx ○ http://tomstechnicalblog.blogspot.com/2016/03/rxjava-problem-with-subjects.html
  • 27.
    Extra - Subjects ●private final BehaviorSubject<List<Palette>> paletteBehaviorSubject = BehaviorSubject.create(); ● public BehaviorSubject<List<Category>> getCategoriesObservable() { return categoriesBehaviorSubject; } ● paletteBehaviorSubject.onNext(paletteList);
  • 28.
    Extra - Rx-preferences ●if( MyPreferences.get().isPremium().get() ) { … } ● MyPreferences.get().isPremium().set(true); ● MyPreferences.get().isPremium().asObservable().subscribe (premiumFlag → { … });