<commit_before>---
layout: post
title: 'Support of Kotlin & Architecture Components'
date: '2017-05-23 14:28:10'
tags:
- android
categories:
- Android Architecture
---

![kotlin-arch](/content/images/2017/5/kotlin-arch.png){: .center-image }

# Official support of Kotlin on Android

The last Google I/O 2017, the Android team announced the [official support of Kotlin programming language](https://developer.android.com/kotlin/index.html). Kotlin is a JVM based object-oriented language that includes many ideas from functional programming. It is a brilliantly designed, mature language that will make Android development faster and as enjoyable and fun as possible.

![kotlin-annunce](https://raw.githubusercontent.com/erikcaffrey/erikcaffrey.github.io/775e33add7e712a474f12b5e88ec6f52fd21591f/content/images/2017/5/kotlin_annunce.jpg){: .center-image }

[Kotlin](https://kotlinlang.org/) was created by JetBrains, the team behind IntelliJ, which is the base for Android Studio. Kotlin team started the journey 6 years ago, and 2 years ago the Android community and industry around the world started to experiment with this language. Companies like Expedia, Flipboard, Pinterest or Square are using Kotlin in their production apps already. Kotlin official support by Google is a very good news and a chance to use a modern and powerful language. It's another way to create Android apps, that will help solving common headaches such as runtime exceptions (NPE) and source code verbosity. Kotlin is easy to get started and it has already been adopted by several major developers. It also plays well with the Java programming language; the effortless interoperation between the two languages has been a large part of Kotlin's appeal can be introduced gradually into existing projects, which means that your existing skills and technology investments are preserved.

# Getting started With Kotlin

The [Kotlin plugin](https://plugins.jetbrains.com/plugin/6954-kotlin), developed by JetBrains, is available for the current version Android Studio. But another good news that came up at Google I/O is that now the plugin is bundled with Android Studio 3.0, and JetBrains will continue to work on the Android Studio plugin, collaborating closely with the Android Studio team. Android Studio 3.0 is already available -and usable- as a Preview version.

![kotlin-annunce](https://raw.githubusercontent.com/erikcaffrey/erikcaffrey.github.io/master/content/images/2017/5/kotlin_support.jpg){: .center-image }
If you are interested in learning more about the Kotlin programming language to create or modify your Android apps here I added some resources that can be useful.

#### Resources to start with Kotlin on Android

* [Getting started with Android and Kotlin by Jetbrains](https://kotlinlang.org/docs/tutorials/kotlin-android.html)
* [Get Started with Kotlin on Android by Google](https://developer.android.com/kotlin/get-started.html)
* [Kotlin Lang Reference](https://kotlinlang.org/docs/reference/)
* [Kotlin Blog by Jetbrains](https://blog.jetbrains.com/kotlin/)
* [Kotlin Kapt Annotation processing](https://kotlinlang.org/docs/reference/kapt.html)
* [Kotlin for Android Developers by <NAME>](https://antonioleiva.com/kotlin-android-developers-book/)

# Android Architecture Components

We know that writing quality software is hard and complex, it is not only about satisfying requirements and features. For some time, the community has been exploring various architectures and patterns to create better apps. Google had nothing on these topics until one year ago when they released [Android Architecture Blue Prints](https://github.com/googlesamples/android-architecture) a collection of samples to discuss and showcase different architectural tools and patterns for Android apps created by different developers round the world.

Couple moths ago, Google Launched the [Android Architecture Components Framework](https://developer.android.com/topic/libraries/architecture/index.html). It is a set of libraries and guidelines that will help you design flexible, testable and maintainable apps, reduce boilerplate code, manage your UI components lifecycle and handle data, helping to create Android applications using separation of concerns (SoC).

The **Android Architecture Components** is a collection of libraries and guidelines proposed by Google to create testable and maintainable android apps but this framework too has another big feature (the most important for me) is focused in solve the problem of configuration changes such as screen rotations.

Basically is composed to **four core components**:

**Handling lifecycles**
Set of classes and interfaces that allow you manage the lifecycle of an activity or fragment.
**Live Data**
Observable with super powers basically keeps a value and allows this value to be observed it across lifecycle changes.
**ViewModel**
A class designed to store and manage UI-related data so that the data survives configuration changes such as screen rotations.


```gradle

  //Lifecycles, LiveData and ViewModel

  compile "android.arch.lifecycle:runtime:1.0.0-alpha4"
  compile "android.arch.lifecycle:extensions:1.0.0-alpha4"
  kapt "android.arch.lifecycle:compiler:1.0.0-alpha4"
  ```

**Room**
Abstraction or wrapper over SQLite to allow a easy database access.

```graldle
  //Room

  compile "android.arch.persistence.room:runtime:1.0.0-alpha4"
  kapt "android.arch.persistence.room:compiler:1.0.0-alpha4"
  testCompile "android.arch.persistence.room:testing:1.0.0-alpha4"

  // Room RxJava 2
  compile "android.arch.persistence.room:rxjava2:$archVersion"

```

**Note:** you should consider architecture components libraries are still in alpha so I don't recommend use it on production can be risky, usually alpha versions are changing constantly before the release version but can be very useful for you understand how architecture components works if you want to use them in a future.

# Kotlin Devises architecture

Kotlin Devises is a sample project used to practice Kotlin and Android Architecture Components.


## View

## ViewModel

## Repository

## Room


# IN PROGRESS ....


The following diagram shows all the modules that Google recommended and how they interact with one another:

![kotlin-arch](/content/images/2017/5/currency-arch.png){: .center-image }

### Demo
![](https://raw.githubusercontent.com/erikcaffrey/Android-Architecture-Components-Kotlin/master/art/demo.png)

#### Source Code on Github
[Android-Architecture-Components-Kotlin](https://github.com/erikcaffrey/Android-Architecture-Components-Kotlin).


#### Resources to start with Android Architecture Components

* [Android Architecture Components](https://developer.android.com/topic/libraries/architecture/index.html)
* [Adding Components to your Project](https://developer.android.com/topic/libraries/architecture/adding-components.html)<commit_msg>fixed kotlin post 6<commit_after>---
layout: post
title: 'Support of Kotlin & Architecture Components'
date: '2017-05-23 14:28:10'
tags:
- android
categories:
- Android Architecture
---

![kotlin-arch](/content/images/2017/5/kotlin-arch.png){: .center-image }

# Official support of Kotlin on Android

The last Google I/O 2017, the Android team announced the [official support of Kotlin programming language](https://developer.android.com/kotlin/index.html). Kotlin is a JVM based object-oriented language that includes many ideas from functional programming. It is a brilliantly designed, mature language that will make Android development faster and as enjoyable and fun as possible.

![kotlin-annunce](https://raw.githubusercontent.com/erikcaffrey/erikcaffrey.github.io/775e33add7e712a474f12b5e88ec6f52fd21591f/content/images/2017/5/kotlin_annunce.jpg){: .center-image }

[Kotlin](https://kotlinlang.org/) was created by JetBrains, the team behind IntelliJ, which is the base for Android Studio. Kotlin team started the journey 6 years ago, and 2 years ago the Android community and industry around the world started to experiment with this language. Companies like Expedia, Flipboard, Pinterest or Square are using Kotlin in their production apps already. Kotlin official support by Google is a very good news and a chance to use a modern and powerful language. It's another way to create Android apps, that will help solving common headaches such as runtime exceptions (NPE) and source code verbosity. Kotlin is easy to get started and it has already been adopted by several major developers. It also plays well with the Java programming language; the effortless interoperation between the two languages has been a large part of Kotlin's appeal can be introduced gradually into existing projects, which means that your existing skills and technology investments are preserved.

# Getting started With Kotlin

The [Kotlin plugin](https://plugins.jetbrains.com/plugin/6954-kotlin), developed by JetBrains, is available for the current version Android Studio. But another good news that came up at Google I/O is that now the plugin is bundled with Android Studio 3.0, and JetBrains will continue to work on the Android Studio plugin, collaborating closely with the Android Studio team. Android Studio 3.0 is already available -and usable- as a Preview version.

![kotlin-annunce](https://raw.githubusercontent.com/erikcaffrey/erikcaffrey.github.io/master/content/images/2017/5/kotlin_support.jpg){: .center-image }
If you are interested in learning more about the Kotlin programming language to create or modify your Android apps here I added some resources that can be useful.

#### Resources to start with Kotlin on Android

* [Getting started with Android and Kotlin by Jetbrains](https://kotlinlang.org/docs/tutorials/kotlin-android.html)
* [Get Started with Kotlin on Android by Google](https://developer.android.com/kotlin/get-started.html)
* [Kotlin Lang Reference](https://kotlinlang.org/docs/reference/)
* [Kotlin Blog by Jetbrains](https://blog.jetbrains.com/kotlin/)
* [Kotlin Kapt Annotation processing](https://kotlinlang.org/docs/reference/kapt.html)
* [Kotlin for Android Developers by <NAME>](https://antonioleiva.com/kotlin-android-developers-book/)

# Android Architecture Components

We know that writing quality software is hard and complex, it is not only about satisfying requirements and features. For some time, the community has been exploring various architectures and patterns to create better apps. Google had nothing on these topics until one year ago when they released [Android Architecture Blue Prints](https://github.com/googlesamples/android-architecture) a collection of samples to discuss and showcase different architectural tools and patterns for Android apps created by different developers round the world.

Couple moths ago, Google Launched the [Android Architecture Components Framework](https://developer.android.com/topic/libraries/architecture/index.html). It is a set of libraries and guidelines that will help you design flexible, testable and maintainable apps, reduce boilerplate code, manage your UI components lifecycle and handle data, helping to create Android applications using separation of concerns (SoC).

The **Android Architecture Components** is a collection of libraries and guidelines proposed by Google to create testable and maintainable android apps but this framework too has another relevant feature, is focused in solve the problem of configuration changes such as screen rotations (another change of lifecycle).

Basically is composed to **four core components**:

#### Handling lifecycles
Set of classes and interfaces that allow you manage the lifecycle of an activity or fragment.

#### Live Data
Observable with super powers basically keeps a value and allows this value to be observed it across lifecycle changes.

#### ViewModel
A class designed to store and manage UI-related data so that the data survives configuration changes such as screen rotations.

```gradle

  //Lifecycles, LiveData and ViewModel

  compile "android.arch.lifecycle:runtime:1.0.0-alpha4"
  compile "android.arch.lifecycle:extensions:1.0.0-alpha4"
  kapt "android.arch.lifecycle:compiler:1.0.0-alpha4"
  ```

#### Room
Abstraction or wrapper over SQLite to allow a easy database access ().

```graldle
  //Room

  compile "android.arch.persistence.room:runtime:1.0.0-alpha4"
  kapt "android.arch.persistence.room:compiler:1.0.0-alpha4"
  testCompile "android.arch.persistence.room:testing:1.0.0-alpha4"

  // Room RxJava 2
  compile "android.arch.persistence.room:rxjava2:$archVersion"

```

**Note:** you should consider architecture components libraries are still in alpha so I don't recommend use it on production can be risky, usually alpha versions are changing constantly before the release version but can be very useful for you understand how architecture components works if you want to use them in a future.

# Kotlin Devises architecture

Kotlin Devises is a sample project used to practice Kotlin and Android Architecture Components.


## View

## ViewModel

## Repository

## Room


# IN PROGRESS ....


The following diagram shows all the modules that Google recommended and how they interact with one another:

![kotlin-arch](/content/images/2017/5/currency-arch.png){: .center-image }

### Demo
![](https://raw.githubusercontent.com/erikcaffrey/Android-Architecture-Components-Kotlin/master/art/demo.png)

#### Source Code on Github
[Android-Architecture-Components-Kotlin](https://github.com/erikcaffrey/Android-Architecture-Components-Kotlin).


#### Resources to start with Android Architecture Components

* [Android Architecture Components](https://developer.android.com/topic/libraries/architecture/index.html)
* [Adding Components to your Project](https://developer.android.com/topic/libraries/architecture/adding-components.html)
{'fraction_non_alphanumeric': 0.07751994198694706, 'fraction_numerical': 0.014430746918056563, 'mean_word_length': 5.078007933010136, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 34, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3432419', 'n_tokens_mistral': 3772, 'n_tokens_neox': 3508, 'n_words': 1535}