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

Building better android applications

Building better android applications

Activity #07 Androidinight, December 2015 , Mexico City

Erik Jhordan Rey

December 16, 2015
Tweet

More Decks by Erik Jhordan Rey

Other Decks in Programming

Transcript

  1. - Conventions in android - Tools & Tips currently used

    by Android Developers - What’s S.O.L.I.D? - Clean Architecture - Answers & Questions Talk Schedule #BuildingBetterApps
  2. Erik Jhordan González Reyes Android Developer +Erik Jhordan Rey Caffrey

    @ErikJhordan_Rey erikcaffrey erikcaffrey.github.io
  3. “Any fool can write code that a computer can understand.

    Good programmers write code that humans can understand. by Martin Fowler”
  4. 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
  5. 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
  6. 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
  7. 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";
  8. 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 */); } }
  9. Dagger 2 buildscript { repositories { mavenCentral() } dependencies {

    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' } }
  10. Retrolambda (λ) RetroLambda allows you to write less boilerplate code,

    also clarifies our code making it more readable.
  11. Retroλ + Android buildscript { repositories { mavenCentral() } dependencies

    { classpath 'me.tatarka:gradle-retrolambda:3.2.4' } }
  12. // Required because retrolambda is on maven central repositories {

    mavenCentral() } apply plugin: 'me.tatarka.retrolambda'
  13. // 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
  14. 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.
  15. 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" }
  16. Single responsibility principle Open / Closed principle Liskov substitution principle

    Interface segregation principle Dependency inversion principle S.O.L.I.D
  17. Open / Closed principle S.O.L.I.D Every module should be open

    for extension but closed for modification.
  18. Presentation Layer Domain Layer Data Layer Model View Presenter Regular

    Java Objects Repository Pattern Interactors Boundaries Clean Architecture
  19. View Presenter Repository Entity Entity Entity Interactor Interactor Interactor ViewEntity

    Presentation Layer Domain Layer Data Layer Clean Architecture
  20. 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