Share
Embed
Building better android applications
Activity #07 Androidinight, December 2015 , Mexico City
Erik Jhordan Rey
December 16, 2015
Transcript
49 slides
-
- Conventions in android - Tools & Tips currently used
by Android Developers - What’s S.O.L.I.D? - Clean Architecture - Answers & Questions Talk Schedule #BuildingBetterApps -
Erik Jhordan González Reyes Android Developer +Erik Jhordan Rey Caffrey
@ErikJhordan_Rey erikcaffrey erikcaffrey.github.io -
“Any fool can write code that a computer can understand.
Good programmers write code that humans can understand. by Martin Fowler” -
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 -
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 -
Generates packages containing specific classes with a specific function or
specific environment. Package Structure -
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 -
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"; -
Android UI - Tangible surfaces - Print-like design - Meaningful
motion - Adaptive design -
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 */); } } -
Dagger 2 buildscript { repositories { mavenCentral() } dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' } } -
Retrolambda (λ) RetroLambda allows you to write less boilerplate code,
also clarifies our code making it more readable. -
Retroλ + Android buildscript { repositories { mavenCentral() } dependencies
{ classpath 'me.tatarka:gradle-retrolambda:3.2.4' } } -
// Required because retrolambda is on maven central repositories {
mavenCentral() } apply plugin: 'me.tatarka.retrolambda' -
// 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 -
Without RetroLambda + RX Observable.just("Hello, world!") .subscribe(new Action1<String>() { @Override
public void call(String s) { System.out.println(s); } }); -
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. -
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" } -
Single responsibility principle Open / Closed principle Liskov substitution principle
Interface segregation principle Dependency inversion principle S.O.L.I.D -
Open / Closed principle S.O.L.I.D Every module should be open
for extension but closed for modification. -
Liskov substitution principle S.O.L.I.D Child classes should never break the
parent class' type definitions. -
Interface segregation principle S.O.L.I.D States that clients should not be
forced to implement interfaces they don't use. -
Dependency inversion principle S.O.L.I.D Depend upon abstractions. Do not depend
upon concrete classes -
Entities Use Cases Controllers Gateways Presenters Devices W eb UI
DB External Interfaces -
Presentation Layer Domain Layer Data Layer Model View Presenter Regular
Java Objects Repository Pattern Interactors Boundaries Clean Architecture -
View Presenter Repository Entity Entity Entity Interactor Interactor Interactor ViewEntity
Presentation Layer Domain Layer Data Layer Clean Architecture -
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 -
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