Slide 1

Slide 1 text

Android Building Better Applications Activity #07 Androidinight, December 2015

Slide 2

Slide 2 text

- Conventions in android - Tools & Tips currently used by Android Developers - What’s S.O.L.I.D? - Clean Architecture - Answers & Questions Talk Schedule #BuildingBetterApps

Slide 3

Slide 3 text

Erik Jhordan González Reyes Android Developer +Erik Jhordan Rey Caffrey @ErikJhordan_Rey erikcaffrey erikcaffrey.github.io

Slide 4

Slide 4 text

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand. by Martin Fowler”

Slide 5

Slide 5 text

Conventions in Android #AndroidDevelopers

Slide 6

Slide 6 text

Convention in Android is not a set of rules for define structure project or choosing the character sequence to be used for identifiers which denote resources, source code. These are some recommendations but not strict rules, you can create your own convention (in some cases). Conventions -Project structure -Package structure -File naming -Code naming Android Conventions

Slide 7

Slide 7 text

New projects normally follow the android gradle project structure that is defined on the Android Gradle plugin user guide, we can create a different structure depending on the architecture that we are using in our application. Project Structure

Slide 8

Slide 8 text

Generates packages containing specific classes with a specific function or specific environment. Package Structure

Slide 9

Slide 9 text

File Naming Type Recommendation Example Class file Class names are written in UpperCamelCase. NameBaseType SingUpActivity.java Layout file Layout files should match the name of the Class file. The name of the class should end with the name of the layout file. type_name_suffix fragment_sing_up.xml Resources file Resources file names are written in lowercase_underscore. group_type_name_state_suffix btn_icon_send_disabled.png Common files Some files are auto generated but we may create your own files . color.xml , strings.xml, dimens.xml, styles.xml, themes.xml, plurals.xml, integers.xml, config.xml, menu_sing_up.xml

Slide 10

Slide 10 text

Code Naming Type Recommendation Example id’s add an id for RecyclerView in HomeActivity.java type_name rv_home values The name values can be varied only about having a convention for them. Dimens Example property_default_group_type_na me app_bar_height_home spacing_small font_size_small variables I recommend it as well as your id using owercase_underscore or camelCase RecyclerView rv_home; RecyclerView rvHome; Language Rules They try to follow the conventions that the language provides you static final String VARIABLE_EXAMPLE = "CONSTANT";

Slide 11

Slide 11 text

Tools & tips currently used by Android Developers #AndroidDevelopers

Slide 12

Slide 12 text

Android UI - Tangible surfaces - Print-like design - Meaningful motion - Adaptive design

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

Reactive Extensions · RX ReactiveX is a library for composing asynchronous and event-based programs by using observable sequences. public class ReactiveFragment extends Fragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Observable.just("one", "two", "three", "four", "five") .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(/* an Observer */); } }

Slide 15

Slide 15 text

dependencies { compile 'io.reactivex:rxandroid:1.0.1' compile 'io.reactivex:rxjava:1.0.16' } Rx Android

Slide 16

Slide 16 text

https://github.com/ReactiveX/RxAndroid Android + RX http://reactivex.io/

Slide 17

Slide 17 text

Dagger 2 buildscript { repositories { mavenCentral() } dependencies { classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' } }

Slide 18

Slide 18 text

dependencies { compile 'com.google.dagger:dagger:2.0' provided 'com.google.dagger:dagger-compiler:2.0' provided 'org.glassfish:javax.annotation:10.0-b28' } apply plugin: 'com.neenbedankt.android-apt'

Slide 19

Slide 19 text

AppModule InteractorsModule AppComponent MainModule MainComponent Provides CategoryInteractor getFindItemsInteractor(); MainPresenter getMainPresenter(); Provides

Slide 20

Slide 20 text

https://github.com/erikcaffrey/Dagger2-MVP-Sample

Slide 21

Slide 21 text

Android + Dagger 2 http://google.github.io/dagger/

Slide 22

Slide 22 text

Retrolambda (λ) RetroLambda allows you to write less boilerplate code, also clarifies our code making it more readable.

Slide 23

Slide 23 text

Retroλ + Android buildscript { repositories { mavenCentral() } dependencies { classpath 'me.tatarka:gradle-retrolambda:3.2.4' } }

Slide 24

Slide 24 text

// Required because retrolambda is on maven central repositories { mavenCentral() } apply plugin: 'me.tatarka.retrolambda'

Slide 25

Slide 25 text

// defined in the SDK interface OnClickListener { public void onClick(View v); } // your code mButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // do something here } }); Without RetroLambda

Slide 26

Slide 26 text

With RetroLambda mButton.setOnClickListener((View v) -> { // do something here });

Slide 27

Slide 27 text

Without RetroLambda + RX Observable.just("Hello, world!") .subscribe(new Action1() { @Override public void call(String s) { System.out.println(s); } });

Slide 28

Slide 28 text

With RetroLambda + RX Observable.just("Hello, world!") .subscribe( s -> System.out.println(s));

Slide 29

Slide 29 text

https://github.com/evant/gradle-retrolambda Android + retroλ https://github.com/orfjackal/retrolambda

Slide 30

Slide 30 text

Kotlin Kotlin is a JVM based language created by JetBrains, the team behind IntelliJ, which is the base for Android Studio. It´s an object oriented language that includes many ideas from functional programming.

Slide 31

Slide 31 text

buildscript { repositories { jcenter() } dependencies { classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version" } } Kotlin en Android

Slide 32

Slide 32 text

buildscript { ext.kotlin_version = '1.0.0-beta-2423' repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.5.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } Kotlin en Android apply plugin: 'kotlin-android' dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" }

Slide 33

Slide 33 text

https://github.com/erikcaffrey/Kotlin-Examples Android + Kotlin https://kotlinlang.org/docs/tutorials/kotlin-android.html

Slide 34

Slide 34 text

what’s S·O·L·I·D? #AndroidDevelopers

Slide 35

Slide 35 text

#AndroidDevelopers

Slide 36

Slide 36 text

Single responsibility principle Open / Closed principle Liskov substitution principle Interface segregation principle Dependency inversion principle S.O.L.I.D

Slide 37

Slide 37 text

Single responsibility principle S.O.L.I.D A class must have a unique responsibility

Slide 38

Slide 38 text

Open / Closed principle S.O.L.I.D Every module should be open for extension but closed for modification.

Slide 39

Slide 39 text

Liskov substitution principle S.O.L.I.D Child classes should never break the parent class' type definitions.

Slide 40

Slide 40 text

Interface segregation principle S.O.L.I.D States that clients should not be forced to implement interfaces they don't use.

Slide 41

Slide 41 text

Dependency inversion principle S.O.L.I.D Depend upon abstractions. Do not depend upon concrete classes

Slide 42

Slide 42 text

Clean Architecture #AndroidDevelopers

Slide 43

Slide 43 text

Entities Use Cases Controllers Gateways Presenters Devices W eb UI DB External Interfaces

Slide 44

Slide 44 text

Presentation Layer Domain Layer Data Layer Model View Presenter Regular Java Objects Repository Pattern Interactors Boundaries Clean Architecture

Slide 45

Slide 45 text

View Presenter Repository Entity Entity Entity Interactor Interactor Interactor ViewEntity Presentation Layer Domain Layer Data Layer Clean Architecture

Slide 46

Slide 46 text

Clean Architecture Benefits ● Presentation is decoupled from domain ● Domain module can be a layer module. ● DataLayer decouples the rest of the app ● Independent of Frameworks. ● Independent of UI ● Independent of Database

Slide 47

Slide 47 text

Answers & Questions #AndroidDevelopers

Slide 48

Slide 48 text

Thank you! #AndroidDevelopers +Erik Jhordan Rey Caffrey @ErikJhordan_Rey erikcaffrey erikcaffrey.github.io

Slide 49

Slide 49 text

Further Reading #AndroidDevelopers ● https://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html ● http://fernandocejas.com/2014/09/03/architecting-android-the-clean-way/ ● https://speakerdeck.com/rallat/android-development-like-a-pro ● http://es.slideshare.net/PedroVicenteGmezSnch? utm_campaign=profiletracking&utm_medium=sssite&utm_source=ssslidevie w ● https://www.youtube.com/watch?v=ROdIvrLL1ao