Android Mobile Development

First Application step by step

Tools to use

  • Android SDK

  • Android Emulator GenyMotion

  • Android Studio

  • Gradle build system

Contents

  • RESTful Web Services

  • Event Driven

  • Dependency Injection

  • Optimise gradle builds

  • Read logcat 

  • MVP approach 

Application

A basic client for login/register with a REST api. Then we will retrieve songs from iTunes REST API service

SPECS

  • Sign in for an existing user

  • Sign up for a new user

  • List the songs by iTunes

 

RESTful Web Services

  • POST /users/login.php - Login a user

  • POST /users/register.php - Register a user

  • GET /search - Returns a list with songs (iTunes REST)

Use Cases

User Login Use Case

data

  • username
  • password

result

  • redirects to songs list

Songs list Use Case

data

  • term

result

  • show songs
  • user authenticated

User  Register Use Case

data

  • username
  • password
  • email

result

  • user registered

Number of screens

User Login Screen has ->  1 Activity + 1 Fragment

User Registeer Screen  ->  1 Activity + 1 Fragment

Songs list screen  ->  1 Activity + 1 Fragment

Advise

Prefer screen by each feature separately

App Architecture

Decide & Setup libraries

RESTful API library

Retrofit by Square

Event Driven

Otto by Square

Views

Butterknife by Square

Image fetcher

Picasso

Optimise gradle builds

# The Gradle daemon aims to improve the startup and execution time of Gradle.
# When set to true the Gradle daemon is to run the build.
org.gradle.daemon=true

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
org.gradle.parallel=true

# Enables new incubating mode that makes Gradle selective when configuring projects.
# Only relevant projects are configured which results in faster builds for large multi-projects.
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:configuration_on_demand
org.gradle.configureondemand=true

Read logcat
Demo on screen

What is MVP?

The MVP pattern allows separate the presentation layer from the logic, so that everything about how the interface works is separated from how we represent it on screen. 

Why use MVP?

In Android we have a problem arising from the fact that Android activities are closely coupled to both interface and data access mechanisms.

 

MVP makes views independent from our data source. We divide the application into at least three different layers, which let us test them independently. With MVP we are able to take most of logic out from the activities so that we can test it without using instrumentation tests.

How to implement MVP (1)

The presenter

The presenter is responsible to act as the middle man between view and model. It retrieves data from the model and returns it formatted to the view. But unlike the typical MVC, it also decides what happens when you interact with the view.

How to implement MVP (2)

The View

The view, usually implemented by an Activity (it may be a Fragment, a View… depending on how the app is structured), will contain a reference to the presenter. The only thing that the view will do is calling a method from the presenter every time there is an interface action (a button click for example).

How to implement MVP (3)

The model

In an application with a good layered architecture, this model would only be the gateway to the domain layer or business logic

MVP + Uncle Bob Clean Architecture

Clean Architecture Naive Example

Does not include Dagger2 in order to be easier to Padawans to understand the first step for a clean architecture 

 “Before software can be reusable it first has to be usable.”

Ralph Johnson (computer scientist)

 

Thank you!!!

 

Questions???

 

Made with Slides.com