Kotlin Programming By Example
eBook - ePub

Kotlin Programming By Example

Iyanu Adelekan

Share book
  1. 500 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Kotlin Programming By Example

Iyanu Adelekan

Book details
Book preview
Table of contents
Citations

About This Book

Enhance your Kotlin programming skills by building 3 real-world applicationsAbout This Book• Build three full-fledged, engaging applications from scratch and learn to deploy them• Enhance your app development and programming activities with Kotlin's powerful and intuitive tools and utilities.• Experience the gentle learning curve, expressiveness, and intuitiveness of Kotlin, as you develop your own applicationsWho This Book Is ForThis book is for those who are new to Kotlin or are familiar with the basics, having dabbled with Java until now. Basic programming knowledge is mandatory.What You Will Learn• Learn the building blocks of the Kotlin programming language• Develop powerful RESTful microservices for Android applications• Create reactive Android applications efficiently• Implement an MVC architecture pattern and dependency management using Kotlin• Centralize, transform, and stash data with Logstash• Secure applications using Spring Security• Deploy Kotlin microservices to AWS and Android applications to the Play StoreIn DetailKotlin greatly reduces the verbosity of source code. With Google having announced their support for Kotlin as a first-class language for writing Android apps, now's the time learn how to create apps from scratch with KotlinKotlin Programming By Example takes you through the building blocks of Kotlin, such as functions and classes. You'll explore various features of Kotlin by building three applications of varying complexity. For a quick start to Android development, we look at building a classic game, Tetris, and elaborate on object-oriented programming in Kotlin. Our next application will be a messenger app, a level up in terms of complexity. Before moving onto the third app, we take a look at data persistent methods, helping us learn about the storage and retrieval of useful applications. Our final app is a place reviewer: a web application that will make use of the Google Maps API and Place Picker.By the end of this book, you will have gained experience of of creating and deploying Android applications using Kotlin.Style and approachHere we will build three exciting projects in Kotlin which will demonstrate how to effectively use Kotlin language constructs

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Kotlin Programming By Example an online PDF/ePUB?
Yes, you can access Kotlin Programming By Example by Iyanu Adelekan in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming in Java. We have over one million books available in our catalogue for you to explore.

Information

Year
2018
ISBN
9781788479783
Edition
1

Building the Messenger Android App – Part I

In the previous chapter, we began building the messenger application by designing and implementing a REST application programming interface that the client messenger application will communicate with. Over the course of implementing the backend API, we covered many things, such as working with Spring Boot, RESTful application programming interfaces and how they work, creating databases with PostgreSQL, and deploying Spring Boot web applications to AWS, to name a few.
In this chapter, we will go one step further in our application development journey by implementing the Android Messenger application and integrating it with the RESTful API we created in Chapter 4, Designing and Implementing the Messenger Backend with Spring Boot 2.0. In the process of developing the Messenger Android app, we will learn a vast array of new topics, such as:
  • Building MVP Android applications
  • Server communication via HTTP
  • Working with Retrofit
  • Reactive programming
  • Using token-based authentication in an Android app
Over the course of this chapter, you will learn firsthand how powerful Kotlin is in the Android application development domain. Let's dive into the development of the Messenger app.

Developing the Messenger app

First, we need to create a new Android Studio project for the application. Create a new Android Studio project with the name Messenger and the package name com.example.messenger. Feel free to take a look at Chapter 1, The Fundamentals, to refresh your memory on Android project creation. In the process of project setup, when asked to create a new launcher activity, name the activity LoginActivity and make it an empty activity.

Including project dependencies

Over the course of this chapter, we will make use of a number of external application dependencies. As such, it is important we include them in the project now. Open your module-level build.gradle file and add the following dependencies to it:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7
:
$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:recyclerview-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'

implementation "android.arch.persistence.room:runtime:1.0.0-alpha9-1"
implementation "android.arch.persistence.room:rxjava2:1.0.0-alpha9-1"
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:support-vector-drawable:26.1.0'
annotationProcessor "android.arch.persistence.room:compiler
:1.0.0-alpha9-1"

implementation "com.squareup.retrofit2:retrofit:2.3.0"
implementation "com.squareup.retrofit2:adapter-rxjava2:2.3.0"
implementation "com.squareup.retrofit2:converter-gson:2.3.0"
implementation "io.reactivex.rxjava2:rxandroid:2.0.1"

implementation 'com.github.stfalcon:chatkit:0.2.2'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso
:espresso-core:3.0.1'
}
Ensure that no conflicting Android support library versions exist in the build.gradle file. Now modify the build.gradle project file to include the jcenter and Google repositories as well as the Android build tools dependency:
Top-level build file where you can add configuration options common to all sub-projects/modules:
buildscript {
ext.kotlin_version = '1.1.4-3'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha9'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
repositories {
google()
jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
Don't worry, about what the dependencies added for now, all will be revealed over the course of this chapter.

Developing the Login UI

Once the project is created, create a new package named ui in the com.example.messenger application source package. This package will hold all the user-interface-related classes and logic of the Android application. Create a login package within ui. As you may have guessed, this package will hold classes and logic pertaining to the user-login process. Go ahead and move LoginActivity to the login package. Having moved LoginActivity, our first order of business is to create a suitable layout for the login activity.
Locate the activity_login.xml layout resource file and change the following content:
<?xml ver...

Table of contents