<commit_before>### Android Infrastructure

[ ![Download](https://api.bintray.com/packages/albertopeam/android/Concurrency/images/download.svg) ](https://bintray.com/albertopeam/android/Concurrency/_latestVersion)
[![Build Status](https://travis-ci.org/albertopeam/Android-Infrastructure.svg?branch=master)](https://travis-ci.org/albertopeam/Android-Infrastructure)
[![codecov](https://codecov.io/gh/albertopeam/Android-Infrastructure/branch/master/graph/badge.svg)](https://codecov.io/gh/albertopeam/Android-Infrastructure)
[![GitHub license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/albertopeam/Android-Infrastructure/blob/master/LICENSE)

The intention of this library is to help developers to decouple their code
from the Android framework and simplify the execution of asynchronous code, 
providing an environment where the code is synchronous, which is more easy
to read, mantain, scale and test. The other goal is to handle exceptions 
raised during the execution of the code and handle them in an uniform way
without repeat code.


Features:
1. We avoid create threads in the middle of our code.
2. We avoid handle communication between threads.
3. We automate way of canceling tasks, linking those to the framework
component lifecycle.
4. We lead to write synchronous code that is easy to read, maintain, scale
and test.
5. We provide a way of handle exceptions without repeat code.

There are two modules in the repo, one called app and other infrastructure.
The app module shows the usage of the infrastructure module, app is
built based on MVP with the help of Dagger2 DI framework. It is a very
basic example to list, create and destroy notes.
The infrastructure module is the core of the library.


### Install
[Gradle Dependency](#dependency)

### Usage
1. [Create use case executor](#createinfra)
2. [Create exception controller](#createexceptionhandler)
3. [Create an use case](#createusecase)
4. [Connect all to the presenter and the view](#connectopresenter)

### Testing
[Test the activity](#testandroidui)


Install
-------

##### <a name="dependency">Gradle Dependency</a>

The Gradle dependency is available via jCenter.

The minimum API level supported by this library is API 15 (ICE_CREAM_SANDWICH_MR1).

Add the Google Maven repository if you are using a version of Android Studio < 3:
```groovy
allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
    }
}
```

Add the dependency to include Android components Lifecycle(LifecycleActivity, LifecycleFragment), this
isn't needed if you are using a version of [support library](https://developer.android.com/topic/libraries/support-library/revisions.html#26-1-0)>= 26.1.0:
```groovy
compile "android.arch.lifecycle:extensions:1.0.0"
```
For more info, check [documentation](https://developer.android.com/topic/libraries/architecture/adding-components.html)

Add infrastructure dependency:
```groovy
compile 'com.github.albertopeam:infrastructure:0.0.11'
```

Usage
-----
Follow the next steps to create a basic infrastructure to execute
asynchronous code and handle exceptions that are raised during the execution
of the operations.
Then we will wire this infrastructure
to the view and the presenter to create a complete example.


#### <a name="createinfra">1. Create use case executor</a>
The **UseCaseExecutor** object provides the ability to run **UseCase** objects
in a separate thread and when it end running invokes the Android
main thread with the result. This is done behind the scenes.
Another feature is that this **UseCaseExecutor** will handle Exceptions thrown
during the execution of the **UseCase** and report to the caller.
```java
UseCaseExecutor useCaseExecutor = UseCaseExecutorFactory.provide();
```


#### <a name="createexceptionhandler">2. Create exception controller</a>
**ExceptionController** class handles the exceptions that are thrown during
the **UseCase** execution. This will need a list of delegates as parameter,<commit_msg>updated readme to use java 8<commit_after>### Android Infrastructure

[ ![Download](https://api.bintray.com/packages/albertopeam/android/Concurrency/images/download.svg) ](https://bintray.com/albertopeam/android/Concurrency/_latestVersion)
[![Build Status](https://travis-ci.org/albertopeam/Android-Infrastructure.svg?branch=master)](https://travis-ci.org/albertopeam/Android-Infrastructure)
[![codecov](https://codecov.io/gh/albertopeam/Android-Infrastructure/branch/master/graph/badge.svg)](https://codecov.io/gh/albertopeam/Android-Infrastructure)
[![GitHub license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/albertopeam/Android-Infrastructure/blob/master/LICENSE)

The intention of this library is to help developers to decouple their code
from the Android framework and simplify the execution of asynchronous code, 
providing an environment where the code is synchronous, which is more easy
to read, mantain, scale and test. The other goal is to handle exceptions 
raised during the execution of the code and handle them in an uniform way
without repeat code.


Features:
1. We avoid create threads in the middle of our code.
2. We avoid handle communication between threads.
3. We automate way of canceling tasks, linking those to the framework
component lifecycle.
4. We lead to write synchronous code that is easy to read, maintain, scale
and test.
5. We provide a way of handle exceptions without repeat code.

There are two modules in the repo, one called app and other infrastructure.
The app module shows the usage of the infrastructure module, app is
built based on MVP with the help of Dagger2 DI framework. It is a very
basic example to list, create and destroy notes.
The infrastructure module is the core of the library.


### Install
1. [Gradle Dependency](#dependency)
2. [Java 8 compatibility](#java8)

### Usage
1. [Create use case executor](#createinfra)
2. [Create exception controller](#createexceptionhandler)
3. [Create an use case](#createusecase)
4. [Connect all to the presenter and the view](#connectopresenter)

### Testing
[Test the activity](#testandroidui)


Install
-------

##### <a name="dependency">Gradle Dependency</a>

The Gradle dependency is available via jCenter.

The minimum API level supported by this library is API 15 (ICE_CREAM_SANDWICH_MR1).

Add the Google Maven repository if you are using a version of Android Studio < 3:
```groovy
allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
    }
}
```

Add the dependency to include Android components Lifecycle(LifecycleActivity, LifecycleFragment), this
isn't needed if you are using a version of [support library](https://developer.android.com/topic/libraries/support-library/revisions.html#26-1-0)>= 26.1.0:
```groovy
compile "android.arch.lifecycle:extensions:1.0.0"
```
For more info, check [documentation](https://developer.android.com/topic/libraries/architecture/adding-components.html)

Add infrastructure dependency:
```groovy
compile 'com.github.albertopeam:infrastructure:0.0.11'
```

##### <a name="java8">Java 8 compatibility</a>

This library uses Java 8 compatibility so you need to configure it on your module build.gradle
```groovy
android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}
```

Usage
-----
Follow the next steps to create a basic infrastructure to execute
asynchronous code and handle exceptions that are raised during the execution
of the operations.
Then we will wire this infrastructure
to the view and the presenter to create a complete example.


#### <a name="createinfra">1. Create use case executor</a>
The **UseCaseExecutor** object provides the ability to run **UseCase** objects
in a separate thread and when it end running invokes the Android
main thread with the result. This is done behind the scenes.
Another feature is that this **UseCaseExecutor** will handle Exceptions thrown
during the execution of the **UseCase** and report to the caller.
```java
UseCaseExecutor useCaseExecutor = UseCaseExecutorFactory.provide();
```


#### <a name="createexceptionhandler">2. Create exception controller</a>
**ExceptionController** class handles the exceptions that are thrown during
the **UseCase** execution. This will need a list of delegates as parameter,
{'fraction_non_alphanumeric': 0.09567496723460026, 'fraction_numerical': 0.008816871202192303, 'mean_word_length': 5.030172413793103, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 22, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2028132', 'n_tokens_mistral': 2387, 'n_tokens_neox': 2240, 'n_words': 912}