49
Android Apps with Groovy

Groovy android

Embed Size (px)

Citation preview

Page 1: Groovy android

Android Apps with Groovy

Page 2: Groovy android

About me

● Mario Garcia– Software engineer at Kaleidos

https://github.com/mariogarcia

@marioggar

Page 3: Groovy android

Before I begin...

● Thanks to Tuenti● Disclaimer

– I'm not an Android developer– Questions welcomed :)

Page 4: Groovy android

What is this talk about ?

● Summary– Android is NOT ONLY Java– Your first Grooid app– Groovy features– Useful libraries– Reactive– Testing– Q & A

Page 5: Groovy android

Android is NOT ONLY Java

● Why not Groovy ?– Why not… ?– Chose your poison:

Page 6: Groovy android

Create your first Android/Groovy app

Page 7: Groovy android

Create your first Groovy app

● The Android Studio wizard– Meant for Java– If you go this way, then:

● Create a Java app through the wizard● Add Groovy/Gradle plugin● Add needed basic dependencies● …

Page 8: Groovy android

Create your first Groovy app

● A better way:– Create a basic skeleton with Lazybones– Import as Gradle project to Android Studio– Profit!

Page 9: Groovy android

Create your first Groovy app

● Lazybones– A simple project creation tool– Templates– Really easy to use and extend

Page 10: Groovy android

Create your first Groovy app

● Grooid templates– Lazybones templates for creating:

● Android app, Android lib● Coming soon: Google Glass app

Page 11: Groovy android

Create your first Groovy app

● Gradle– Android Reference build tool– Convention over Configuration– Still thinking of Maven ? check this out:

● https://gradle.org/maven_vs_gradle/

Page 12: Groovy android

Create your first Groovy app

● Android Studio– Reference IDE based on Intellij IDEA– Really helpful specially for UI– Integrates perfectly with Gradle projects

Page 13: Groovy android

Create your first Groovy app

● Demo

Page 14: Groovy android

Groovy featuresout-of-the-box

Page 15: Groovy android

Groovy features

● Domain classes● Get rid of accessors● No need to override constructors● More AST to do pumbling staf

– @AutoExternalize– @Canonical– @Immutable– @InheritConstructors– …. many more

Page 16: Groovy android

Groovy features

● Beans

Page 17: Groovy android

Groovy features

● Constructors

Page 18: Groovy android

Groovy features

● GDK– Groovy extensions to the JDK

● Groovy collections (collect/inject/find)● Safe methods to deal with JDK Classes

– e.g: take(int) : use it instead of substring

Page 19: Groovy android

Groovy features

● NPE and Exceptions– NPE

● ? operator● * operator● Elvis :?

– Exceptions● Go functional || Reactive

– FNZ: Try<T>, Maybe<T>– RxJava/RxAndroid: onError()

Page 20: Groovy android

Groovy features

● Safe operators

Page 21: Groovy android

Groovy Features

● FNZ

Page 22: Groovy android

Groovy features

● Closures● No need to create inner classes anymore● Wherever there is a Functional Interface you can

use a Closure● Also useful when creating DSLs

Page 23: Groovy android

Groovy features

● Closures

Page 24: Groovy android

Groovy features

● Closures (cont)

Page 25: Groovy android

Groovy features

● DSLs

Page 26: Groovy android

Groovy features

● Traits– Have you ever wanted to share some

functionality between an Activity and a ListActivity ?

● Another way to share functionality among class hierarchies

● Used as if it were an interface● IDE friendly

Page 27: Groovy android

Groovy features

Provides waiting spinner

Provides easier call to Toast.makeXXX

● Traits

Page 28: Groovy android

Groovy advancedFeatures

Page 29: Groovy android

Advanced features

● Extension Modules– Add new functionality to existing code– Easy to use and program

● Just classes with static methods● Android Studio recognizes Extension Modules out-of-

the-box

Page 30: Groovy android

Advanced features

Busted!

● Extension modules

Page 31: Groovy android

Advanced features

● Custom ASTs– Add new functionality to existing code

● During compilation time● Extremely powerful● No need for an annotation-processor● Harder to code than Extension Modules

Page 32: Groovy android

Advanced features

● Show a dialog

Page 33: Groovy android

Advanced features

Page 34: Groovy android

Advanced features

Page 35: Groovy android

Advanced features

● Swissknife– Makes easier to deal with view injection and

threading nightmare.● Based on AndroidAnnotations and ButterKnife● Collection of: ASTs, DSLs, Extension Modules

Page 36: Groovy android

ReactiveProgramming

Page 37: Groovy android

Reactive Programming

● RxAndroid + Groovy– Less verbose than using Java:

● Closures and Functional Interface coertion● Composable Closures● Method Reference

Page 38: Groovy android

Code

Page 39: Groovy android

TestingAnd

Quality

Page 40: Groovy android

Testing

● Spock– A better way of testing

● DSL to describe your tests in a fluent way● Compatible with JUnit

Page 41: Groovy android

Testing

● AndroidSpock– Create integration tests

● Under src/androidTest/groovy● Helpers to inject and initialize activities in your tests● Deploys and run tests in the device

Page 42: Groovy android

Testing

● Robospock– Create unit tests

● Based on roboelectric 3.0● no DEXing or deployment time is wasted to execute

your unit tests.

Page 43: Groovy android

Other tools

● Quality code– Codenarc

● Static analysis for Groovy● Highly Configurable● Completely integrated with Gradle

Page 44: Groovy android

References

● Links● Android Studio

– https://developer.android.com/sdk/index.html● Lazybones

– https://github.com/pledbrook/lazybones● Grooid templates

– https://github.com/mariogarcia/grooid-templates● Swissknife

– https://github.com/Arasthel/SwissKnife● AndroidRx

– https://github.com/ReactiveX/RxAndroid

Page 45: Groovy android

References

● Links● Spock

– http://spockframework.github.io/spock/docs/1.0/index.html● Android Spock

– https://github.com/pieces029/android-spock● Robo Spock

– http://robospock.org/● Gradle

– https://gradle.org/● Groovy Lang

– http://www.groovy-lang.org/

Page 46: Groovy android

References

● Links● Codenarc

– http://codenarc.sourceforge.net/● FNZ

– http://mariogarcia.github.io/fnz/

Page 47: Groovy android

Q & A

Page 48: Groovy android

Common question

● Size of Groovy :grooid ?

Page 49: Groovy android

Thanks!!