SlideShare a Scribd company logo
Kotlin
One language to dominate them all
About us
Sergio Casero
Hernández
Daniel Llanos
Muñoz
@sergioch23
sergio.casero@worldline.com
@Dany4794
daniel.llanos@worldline.com
Votlin
What is that?
Android
Web
iOS
Backend
Votlin
All Business Development Maker
Thanks
@Kotlin team, take a look to KotlinConf
app:
https://github.com/JetBrains/kotlinconf-app
@MarcinMoskala, He has 2 multiplatform
repos that are really helpful:
https://github.com/MarcinMoskala
@wiyarmir, he has also a multiplatform
project:
https://github.com/wiyarmir
@victorfriasv for the Votlin logo! Looks
really nice! :)
https://www.linkedin.com/in/victorfriasv
@JacoboCL, moral support!!
https://github.com/JacoboCL
What is Kotlin?
Kotlin
- Born in 2012
- Created by JetBrains
- 100% interoperability with Java programming
Language
- Compiles to Bytecode, assembler, LLVM, JS…
- Official Android Language since May of 2017
- Kotlin version: v1.2.71
- Kotlin Native version: v0.9.3
Kotlin features
● Data classes
● Singletons
● Extension functions
● Lambdas
● Null safety
● Inmutable
● High order functions
● Smart casting
● Named parameters
● When
Multiplatform!!
data class Rate(val id: Int, val value: Int)
object EmptyResultException
fun ImageView.load(drawableId: Int) {
Glide.with(this)
.load(drawableId)
.into(this)
}
Architecture
Arquitecture
native
BackendcommonAndroid
web
Dependencies
org.gradle.parallel=true
# kotlin
kotlin_version=1.3.0-rc-131
kotlin_native_version=0.9.2-dev-3973
kotlin.incremental.multiplatform=true
# kotlin libraries
coroutines_version=0.30.2-eap13
serialization_version=0.7.3-eap-13
serialization_plugin=1.3.0-rc-26
# android
INCLUDE_ANDROID=true
gradle_android_version=3.1.3
anko_version=0.10.5
# backend
squash_version=0.2.3
ktor_version=1.0.0-beta-1
# Arrow
arrow_version=0.7.3
settings.gradle
rootProject.name = 'votlin-app'
enableFeaturePreview('GRADLE_METADATA')
include 'backend'
include 'common'
include 'frontend'
include 'ios'
if (INCLUDE_ANDROID == "true") {
include 'android', 'android:app'
}
Common dependencies
apply plugin: 'kotlin-platform-common'
apply plugin: 'kotlinx-serialization'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-
common:$serialization_version"
implementation "io.ktor:ktor-client-core:$ktor_version"
implementation "io.ktor:ktor-client-json:$ktor_version"
testCompile "org.jetbrains.kotlin:kotlin-test-common:$kotlin_version"
}
Plugins
Kotlin mandatory
libs
Ktor client
Client Architecture
Client Architecture
Splash View Home View Detail View
Splash
Presenter
List Presenter
Detail
Presenter
Platform
Splash View
Platform
Home View
Pltaform
Detail View
Repositories
Use Cases
Local
DataSource
Remote
DataSource
Common
DataSource
Platform Local
DataSource
Repositories
Impl
Error Handler Executor
Platform
Error Handler
Platform
Executor
Models
Sharing Models
Client Backend
Domain
Models
@Serializable
data class Talk(val id: Int,
val name: String,
val description: String,
val speakers: List<Speaker>,
val track: Track,
val time: Time)
@Serializable
data class Speaker(
val twitter: String,
val linkedin: String,
val name: String,
val bio: String,
val photoUrl: String)
@Serializable
data class TalksResponse(val talks: List<Talk>)
@Serializable
data class Rate(val id: Int, val value: Int)
enum class Track {
BUSINESS, DEVELOPMENT, MAKER, ALL
}
Executor and Error Handler
interface Executor {
val main: CoroutineDispatcher
}
interface ErrorHandler {
fun convert(error: Error): String
}
Coroutines
private fun getTalks(track: Track) {
GlobalScope.launch(context = executor.main) {
val talks = when (track) {
Track.ALL -> getAllTalks(repository)
else -> getTalksByTrack(track, repository)
}
view.showTalks(talks)
view.hideProgress()
}
}
Presenter
abstract class Presenter<out V : Presenter.View>(protected val
errorHandler: ErrorHandler, val view: V) {
abstract fun initialize()
abstract fun destroy()
protected fun onError(callback: (String) -> Unit): (Error) -> Unit = {
view.hideProgress()
callback(errorHandler.convert(it))
}
interface View {
fun showProgress()
fun hideProgress()
fun showError(error: String)
fun showMessage(message: String)
}
}
Presenters
class DetailPresenter(private val repository: Repository, private val executor: Executor,
errorHandler: ErrorHandler, view: DetailView)
: Presenter<DetailView>(errorHandler, view) {
override fun initialize() {
view.showProgress()
GlobalScope.launch(executor.main) {
val talk = getTalkDetail(view.getTalkId(), repository)
view.showTalk(talk)
view.hideProgress()
}
}
fun onBackClicked() {
view.navigateToList()
}
fun onRateChange(rate: Int) {
GlobalScope.launch(executor.new) {
rateTalk(Rate(id = view.getTalkId(), value =
rate), repository)
}
view.showRate(rate)
Use Cases
suspend fun getAllTalks(repository: Repository): List<Talk> =
repository.getTalks()
suspend fun getTalkDetail(id: Int, repository: Repository): Talk =
repository.getTalk(talkId = id)
suspend fun getTalksByTrack(track: Track, repository: Repository):
List<Talk> = repository.getTalksByTrack(track = track)
suspend fun rateTalk(rate: Rate, repository: Repository): Unit =
repository.rateTalk(rate = rate)
fun saveTalk(talk: Talk, repository: Repository): Unit =
repository.saveTalk(talk = talk)
fun getTalkRate(talkId: Int, repository: Repository): Int =
repository.getRate(talkId = talkId)
Remote data source
class CommonRemoteDataSource : RemoteDataSource {
private val endPoint: String = "ENDPOINT"
private val client: HttpClient = HttpClient {}
override suspend fun getTalks(): List<Talk> =
JSON.parse<TalksResponse>(client.get { apiUrl("talk") }).talks
override suspend fun getTalk(talkId: Int): Talk = JSON.parse(client.get {
apiUrl("talk/$talkId") })
override suspend fun getTalksByTrack(track: String): List<Talk> =
JSON.parse<TalksResponse>(client.get { apiUrl("talk/$track") }).talks
override suspend fun rateTalk(rate: Rate): Unit = client.post {
apiUrl("talk/rate")
body = JSON.stringify(rate)
}
}
Backend
Web Client - React. Dependencies
apply plugin: 'kotlin-platform-jvm'
apply plugin: 'kotlinx-serialization'
apply plugin: 'application'
apply plugin: 'com.github.johnrengelman.shadow'
mainClassName = 'com.votlin.backend.ServerKt'
dependencies {
expectedBy project(":common")
implementation "io.ktor:ktor-client-apache:$ktor_version"
implementation "io.ktor:ktor-client-json-jvm:$ktor_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation "io.ktor:ktor-server-netty:$ktor_version"
implementation "io.ktor:ktor-gson:$ktor_version"
implementation 'org.jetbrains.exposed:exposed:0.10.5'
implementation "mysql:mysql-connector-java:5.1.46"
}
Plugins
Main Class
Getting common code
Ktor clients (optional)
Kotlin libs
Server engine, gson
serializer, and
database libraries
Backend. Ktor
fun main(args: Array<String>) {
embeddedServer(Netty, 10000) {
// Database
Database.connect(url = "jdbc:mysql://localhost:3306/edd", driver =
"com.mysql.jdbc.Driver", user = "user", password = "pass")
// Serialize json
install(ContentNegotiation) {
gson {}
}
// Modules
main()
}.start(wait = true)
}
Creating the server
Database
Install
components
Backend. Modules
fun Application.talks() {
routing {
route("/talk") {
//GET
get { call.respond(TalksResponse(getTalks())) }
get("/business") { call.respond(TalksResponse(getTrackTalks(Track.BUSINESS))) }
get("/development") { call.respond(TalksResponse(getTrackTalks(Track.DEVELOPMENT)))
}
get("/maker") { call.respond(TalksResponse(getTrackTalks(Track.MAKER))) }
get("/{id}") { call.parameters["id"]?.toIntOrNull()?.let { id -> call.respond(getTalkById(id = id))
} }
// POST
post("/rate") { call.respond(addTalkRating(call.receive())) }
}
}
}
Backend. Use cases
object TalkVo : Table("talk") {
val id: Column<Int> = integer("id").autoIncrement().primaryKey()
val name: Column<String> = varchar("name", 100)
val description: Column<String> = text("description")
val track: Column<String> = varchar("track", 11)
val start: Column<Long> = long("start")
val end: Column<Long> = long("end")
}
fun getTalkById(id: Int): Talk
= transaction { TalkVo.select { TalkVo.id eq id }.first()
}.toTalk(getTalkSpeakers(talkId = id))
fun getTalks(): List<Talk> = transaction { TalkVo.selectAll().toList()
}.map {
it.toTalk(getTalkSpeakers(it[TalkVo.id]))
}
Android
Android client. Diagram
App
Splash Activity Talks Activity Detail Activity
Splash
Presenter
List Presenter
Detail
Presenter
Android client. Dependencies
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-platform-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlinx-serialization'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 27
defaultConfig {
applicationId 'com.votlin.android'
minSdkVersion 16
targetSdkVersion 27
multiDexEnabled true
versionCode 1
versionName '0.0.1'
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
...
}
dependencies {
expectedBy project(':common')
...
Plugins
Android configuration
Getting common code
Android dependencies
Android client. Activities
class DetailActivity : RootActivity<DetailView>(), DetailView {
override val layoutResourceId: Int = R.layout.activity_detail
override val presenter: DetailPresenter by instance()
override val activityModule: Kodein.Module = Kodein.Module {
bind<DetailPresenter>() with provider {
DetailPresenter(
view = this@DetailActivity,
errorHandler = instance(),
executor = instance(),
repository = instance())
}
}
override fun registerListeners() {
rate.setOnRatingBarChangeListener { _, rate, _ ->
presenter.onRateChange(rate = rate.toInt())
}
}
override fun getTalkId(): Int {
return intent.extras.getInt(TALK_ID)
}
override fun showRate(value: Int) {
rate.rating = value.toFloat()
}
...
Implement common view
Common presenter instance
Presenter -> DoSomething()
View -> DoSomething()
Android - Demo
Web Client - React
Web Client - React. Dependencies
apply plugin: 'kotlin2js'
apply plugin: 'kotlin-dce-js'
apply plugin: 'org.jetbrains.kotlin.frontend'
apply plugin: 'kotlinx-serialization'
apply plugin: 'kotlin-platform-js'
dependencies {
expectedBy project(":common")
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
compile "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serialization_version"
compile "org.jetbrains.kotlinx:kotlinx-html-js:0.6.11"
compile "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$coroutines_version"
compile "org.jetbrains:kotlin-react:16.5.2-pre.56-kotlin-1.2.71"
compile "org.jetbrains:kotlin-react-dom:16.5.2-pre.56-kotlin-1.2.71"
compile "io.ktor:ktor-client-core-js:$ktor_version"
testCompile "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version"
}
Plugins
Getting common code
Serialization and stdlib
Coroutines
React
Ktor
Web Client - React. LifeCycle
abstract class RootScreen<P : RProps, S : ScreenState, out V : Presenter.View> : RComponent<P, S>(),
Presenter.View {
abstract val presenter: Presenter<V>
override fun componentDidMount() {
presenter.initialize()
}
override fun showProgress() {
setState { progress = true }
}
override fun hideProgress() {
setState { progress = false }
}
}
interface ScreenState : RState {
var progress: Boolean
}
class HomeScreen : RootScreen<HomeProps, HomeState, TalksListView>(), TalksListView {}
Similar to onCreate() on
Android
Screen sample
Web Client - React. Diagram
App
Splash Screen Home Screen Detail Screen
Splash
Presenter
List Presenter
Detail
Presenter
Web Client - React. Navigation
abstract class App : RComponent<RProps, AppState>() {
init {
state = AppState()
}
override fun RBuilder.render() {
div("app") {
when (state.screen) {
Screen.SPLASH -> splash { setState { screen = it } }
Screen.HOME -> home {
setState {
talkId = it
screen = Screen.DETAIL
}
}
Screen.DETAIL -> detail(state.talkId) { setState { screen = it } }
}
}
}
}
React - Demo
iOS
iOS client. Diagram
AppDelegate
LaunchScreen AllVC DetailVC
List Presenter
Detail
Presenter
BusinessVC DevelopmentVC
TalksListViewController
iOS client. Dependencies
apply plugin: 'kotlin-platform-native'
configurations {
compilerPlugin
}
dependencies {
expectedBy project(':common')
implementation "io.ktor:ktor-client-ios:$ktor_version"
implementation "io.ktor:ktor-client-json-ios:$ktor_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serialization_version"
compilerPlugin "org.jetbrains.kotlin:kotlin-serialization-unshaded:$serialization_plugin"
}
def pluginPath = configurations.compilerPlugin.files.first().canonicalPath
def pluginArgument = '-Xplugin=' + pluginPath
sourceSets {
main {
component {
targets = ['ios_x64', 'ios_arm64']
outputKinds = [FRAMEWORK]
extraOpts '-Xdisable=devirtualization', '-linker-options', '-iphoneos_version_min 9.0.0', pluginArgument
}
}
}
Plugins
Getting common code
Compile to iOS! :)
iOS client. Kotlin library
Turn off bitcode
Add common build as build phase
Add framework search
iOS Client. ViewControllers
import ios
class TalksListViewController: UIViewController,
TalksListView {
private lazy var presenter : TalksListPresenter =
TalksListPresenter(view: self, errorHandler:
IosErrorHandler())
override func viewDidLoad() {
super.viewDidLoad()
presenter.initialize()
presenter.onTrackChanged(track: track)
}
func showTalks(talks: [Talk]) {
self.talks = talks
}
…
}
Import common module
Implement common view
Common presenter instance
Presenter -> DoSomething()
View -> DoSomething()
iOS - Demo
New platforms? Demo time! :)
Votlin
What is that?
Android
Web
iOS
Desktop
Backend
Thanks
https://github.com/sergiocasero/votlin-app
Any questions?
We,re
hiring!!
We,re
hiring!!

More Related Content

Similar to Kotlin - A language to dominate them all

Building Modern Apps using Android Architecture Components
Building Modern Apps using Android Architecture ComponentsBuilding Modern Apps using Android Architecture Components
Building Modern Apps using Android Architecture Components
Hassan Abid
 
softshake 2014 - Java EE
softshake 2014 - Java EEsoftshake 2014 - Java EE
softshake 2014 - Java EE
Alexis Hassler
 
Extending Retrofit for fun and profit
Extending Retrofit for fun and profitExtending Retrofit for fun and profit
Extending Retrofit for fun and profit
Matthew Clarke
 
Building Dojo in the Cloud
Building Dojo in the CloudBuilding Dojo in the Cloud
Building Dojo in the Cloud
James Thomas
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
Siarzh Miadzvedzeu
 
mobl
moblmobl
mobl
zefhemel
 
Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
Daniel Cukier
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)
Jose Manuel Pereira Garcia
 
State ofappdevelopment
State ofappdevelopmentState ofappdevelopment
State ofappdevelopment
gillygize
 
Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition!
Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition! Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition!
Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition!
Michel Schudel
 
«Продакшн в Kotlin DSL» Сергей Рыбалкин
«Продакшн в Kotlin DSL» Сергей Рыбалкин«Продакшн в Kotlin DSL» Сергей Рыбалкин
«Продакшн в Kotlin DSL» Сергей Рыбалкин
Mail.ru Group
 
Android development with Scala and SBT
Android development with Scala and SBTAndroid development with Scala and SBT
Android development with Scala and SBT
Anton Yalyshev
 
CP3108B (Mozilla) Sharing Session on Add-on SDK
CP3108B (Mozilla) Sharing Session on Add-on SDKCP3108B (Mozilla) Sharing Session on Add-on SDK
CP3108B (Mozilla) Sharing Session on Add-on SDK
Mifeng
 
Red Hat JBoss BRMS and BPMS Workbench and Rich Client Technology
Red Hat JBoss BRMS and BPMS Workbench and Rich Client TechnologyRed Hat JBoss BRMS and BPMS Workbench and Rich Client Technology
Red Hat JBoss BRMS and BPMS Workbench and Rich Client Technology
Mark Proctor
 
Kotlin 在 Web 方面的应用
Kotlin 在 Web 方面的应用Kotlin 在 Web 方面的应用
Kotlin 在 Web 方面的应用
Shengyou Fan
 
Introduction to OSGi (Tokyo JUG)
Introduction to OSGi (Tokyo JUG)Introduction to OSGi (Tokyo JUG)
Introduction to OSGi (Tokyo JUG)njbartlett
 
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
Daniel Fisher
 
Html5 For Jjugccc2009fall
Html5 For Jjugccc2009fallHtml5 For Jjugccc2009fall
Html5 For Jjugccc2009fall
Shumpei Shiraishi
 
5.node js
5.node js5.node js
5.node js
Geunhyung Kim
 
Adopting F# at SBTech
Adopting F# at SBTechAdopting F# at SBTech
Adopting F# at SBTech
Antya Dev
 

Similar to Kotlin - A language to dominate them all (20)

Building Modern Apps using Android Architecture Components
Building Modern Apps using Android Architecture ComponentsBuilding Modern Apps using Android Architecture Components
Building Modern Apps using Android Architecture Components
 
softshake 2014 - Java EE
softshake 2014 - Java EEsoftshake 2014 - Java EE
softshake 2014 - Java EE
 
Extending Retrofit for fun and profit
Extending Retrofit for fun and profitExtending Retrofit for fun and profit
Extending Retrofit for fun and profit
 
Building Dojo in the Cloud
Building Dojo in the CloudBuilding Dojo in the Cloud
Building Dojo in the Cloud
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
 
mobl
moblmobl
mobl
 
Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)
 
State ofappdevelopment
State ofappdevelopmentState ofappdevelopment
State ofappdevelopment
 
Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition!
Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition! Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition!
Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition!
 
«Продакшн в Kotlin DSL» Сергей Рыбалкин
«Продакшн в Kotlin DSL» Сергей Рыбалкин«Продакшн в Kotlin DSL» Сергей Рыбалкин
«Продакшн в Kotlin DSL» Сергей Рыбалкин
 
Android development with Scala and SBT
Android development with Scala and SBTAndroid development with Scala and SBT
Android development with Scala and SBT
 
CP3108B (Mozilla) Sharing Session on Add-on SDK
CP3108B (Mozilla) Sharing Session on Add-on SDKCP3108B (Mozilla) Sharing Session on Add-on SDK
CP3108B (Mozilla) Sharing Session on Add-on SDK
 
Red Hat JBoss BRMS and BPMS Workbench and Rich Client Technology
Red Hat JBoss BRMS and BPMS Workbench and Rich Client TechnologyRed Hat JBoss BRMS and BPMS Workbench and Rich Client Technology
Red Hat JBoss BRMS and BPMS Workbench and Rich Client Technology
 
Kotlin 在 Web 方面的应用
Kotlin 在 Web 方面的应用Kotlin 在 Web 方面的应用
Kotlin 在 Web 方面的应用
 
Introduction to OSGi (Tokyo JUG)
Introduction to OSGi (Tokyo JUG)Introduction to OSGi (Tokyo JUG)
Introduction to OSGi (Tokyo JUG)
 
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
 
Html5 For Jjugccc2009fall
Html5 For Jjugccc2009fallHtml5 For Jjugccc2009fall
Html5 For Jjugccc2009fall
 
5.node js
5.node js5.node js
5.node js
 
Adopting F# at SBTech
Adopting F# at SBTechAdopting F# at SBTech
Adopting F# at SBTech
 

Recently uploaded

WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 

Recently uploaded (20)

WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 

Kotlin - A language to dominate them all

  • 1. Kotlin One language to dominate them all
  • 2. About us Sergio Casero Hernández Daniel Llanos Muñoz @sergioch23 sergio.casero@worldline.com @Dany4794 daniel.llanos@worldline.com
  • 5. Thanks @Kotlin team, take a look to KotlinConf app: https://github.com/JetBrains/kotlinconf-app @MarcinMoskala, He has 2 multiplatform repos that are really helpful: https://github.com/MarcinMoskala @wiyarmir, he has also a multiplatform project: https://github.com/wiyarmir @victorfriasv for the Votlin logo! Looks really nice! :) https://www.linkedin.com/in/victorfriasv @JacoboCL, moral support!! https://github.com/JacoboCL
  • 7. Kotlin - Born in 2012 - Created by JetBrains - 100% interoperability with Java programming Language - Compiles to Bytecode, assembler, LLVM, JS… - Official Android Language since May of 2017 - Kotlin version: v1.2.71 - Kotlin Native version: v0.9.3
  • 8. Kotlin features ● Data classes ● Singletons ● Extension functions ● Lambdas ● Null safety ● Inmutable ● High order functions ● Smart casting ● Named parameters ● When Multiplatform!! data class Rate(val id: Int, val value: Int) object EmptyResultException fun ImageView.load(drawableId: Int) { Glide.with(this) .load(drawableId) .into(this) }
  • 11. Dependencies org.gradle.parallel=true # kotlin kotlin_version=1.3.0-rc-131 kotlin_native_version=0.9.2-dev-3973 kotlin.incremental.multiplatform=true # kotlin libraries coroutines_version=0.30.2-eap13 serialization_version=0.7.3-eap-13 serialization_plugin=1.3.0-rc-26 # android INCLUDE_ANDROID=true gradle_android_version=3.1.3 anko_version=0.10.5 # backend squash_version=0.2.3 ktor_version=1.0.0-beta-1 # Arrow arrow_version=0.7.3
  • 12. settings.gradle rootProject.name = 'votlin-app' enableFeaturePreview('GRADLE_METADATA') include 'backend' include 'common' include 'frontend' include 'ios' if (INCLUDE_ANDROID == "true") { include 'android', 'android:app' }
  • 13. Common dependencies apply plugin: 'kotlin-platform-common' apply plugin: 'kotlinx-serialization' repositories { mavenCentral() } dependencies { implementation 'org.jetbrains.kotlin:kotlin-stdlib' implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime- common:$serialization_version" implementation "io.ktor:ktor-client-core:$ktor_version" implementation "io.ktor:ktor-client-json:$ktor_version" testCompile "org.jetbrains.kotlin:kotlin-test-common:$kotlin_version" } Plugins Kotlin mandatory libs Ktor client
  • 15. Client Architecture Splash View Home View Detail View Splash Presenter List Presenter Detail Presenter Platform Splash View Platform Home View Pltaform Detail View Repositories Use Cases Local DataSource Remote DataSource Common DataSource Platform Local DataSource Repositories Impl Error Handler Executor Platform Error Handler Platform Executor Models
  • 16. Sharing Models Client Backend Domain Models @Serializable data class Talk(val id: Int, val name: String, val description: String, val speakers: List<Speaker>, val track: Track, val time: Time) @Serializable data class Speaker( val twitter: String, val linkedin: String, val name: String, val bio: String, val photoUrl: String) @Serializable data class TalksResponse(val talks: List<Talk>) @Serializable data class Rate(val id: Int, val value: Int) enum class Track { BUSINESS, DEVELOPMENT, MAKER, ALL }
  • 17. Executor and Error Handler interface Executor { val main: CoroutineDispatcher } interface ErrorHandler { fun convert(error: Error): String }
  • 18. Coroutines private fun getTalks(track: Track) { GlobalScope.launch(context = executor.main) { val talks = when (track) { Track.ALL -> getAllTalks(repository) else -> getTalksByTrack(track, repository) } view.showTalks(talks) view.hideProgress() } }
  • 19. Presenter abstract class Presenter<out V : Presenter.View>(protected val errorHandler: ErrorHandler, val view: V) { abstract fun initialize() abstract fun destroy() protected fun onError(callback: (String) -> Unit): (Error) -> Unit = { view.hideProgress() callback(errorHandler.convert(it)) } interface View { fun showProgress() fun hideProgress() fun showError(error: String) fun showMessage(message: String) } }
  • 20. Presenters class DetailPresenter(private val repository: Repository, private val executor: Executor, errorHandler: ErrorHandler, view: DetailView) : Presenter<DetailView>(errorHandler, view) { override fun initialize() { view.showProgress() GlobalScope.launch(executor.main) { val talk = getTalkDetail(view.getTalkId(), repository) view.showTalk(talk) view.hideProgress() } } fun onBackClicked() { view.navigateToList() } fun onRateChange(rate: Int) { GlobalScope.launch(executor.new) { rateTalk(Rate(id = view.getTalkId(), value = rate), repository) } view.showRate(rate)
  • 21. Use Cases suspend fun getAllTalks(repository: Repository): List<Talk> = repository.getTalks() suspend fun getTalkDetail(id: Int, repository: Repository): Talk = repository.getTalk(talkId = id) suspend fun getTalksByTrack(track: Track, repository: Repository): List<Talk> = repository.getTalksByTrack(track = track) suspend fun rateTalk(rate: Rate, repository: Repository): Unit = repository.rateTalk(rate = rate) fun saveTalk(talk: Talk, repository: Repository): Unit = repository.saveTalk(talk = talk) fun getTalkRate(talkId: Int, repository: Repository): Int = repository.getRate(talkId = talkId)
  • 22. Remote data source class CommonRemoteDataSource : RemoteDataSource { private val endPoint: String = "ENDPOINT" private val client: HttpClient = HttpClient {} override suspend fun getTalks(): List<Talk> = JSON.parse<TalksResponse>(client.get { apiUrl("talk") }).talks override suspend fun getTalk(talkId: Int): Talk = JSON.parse(client.get { apiUrl("talk/$talkId") }) override suspend fun getTalksByTrack(track: String): List<Talk> = JSON.parse<TalksResponse>(client.get { apiUrl("talk/$track") }).talks override suspend fun rateTalk(rate: Rate): Unit = client.post { apiUrl("talk/rate") body = JSON.stringify(rate) } }
  • 24. Web Client - React. Dependencies apply plugin: 'kotlin-platform-jvm' apply plugin: 'kotlinx-serialization' apply plugin: 'application' apply plugin: 'com.github.johnrengelman.shadow' mainClassName = 'com.votlin.backend.ServerKt' dependencies { expectedBy project(":common") implementation "io.ktor:ktor-client-apache:$ktor_version" implementation "io.ktor:ktor-client-json-jvm:$ktor_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" implementation "io.ktor:ktor-server-netty:$ktor_version" implementation "io.ktor:ktor-gson:$ktor_version" implementation 'org.jetbrains.exposed:exposed:0.10.5' implementation "mysql:mysql-connector-java:5.1.46" } Plugins Main Class Getting common code Ktor clients (optional) Kotlin libs Server engine, gson serializer, and database libraries
  • 25. Backend. Ktor fun main(args: Array<String>) { embeddedServer(Netty, 10000) { // Database Database.connect(url = "jdbc:mysql://localhost:3306/edd", driver = "com.mysql.jdbc.Driver", user = "user", password = "pass") // Serialize json install(ContentNegotiation) { gson {} } // Modules main() }.start(wait = true) } Creating the server Database Install components
  • 26. Backend. Modules fun Application.talks() { routing { route("/talk") { //GET get { call.respond(TalksResponse(getTalks())) } get("/business") { call.respond(TalksResponse(getTrackTalks(Track.BUSINESS))) } get("/development") { call.respond(TalksResponse(getTrackTalks(Track.DEVELOPMENT))) } get("/maker") { call.respond(TalksResponse(getTrackTalks(Track.MAKER))) } get("/{id}") { call.parameters["id"]?.toIntOrNull()?.let { id -> call.respond(getTalkById(id = id)) } } // POST post("/rate") { call.respond(addTalkRating(call.receive())) } } } }
  • 27. Backend. Use cases object TalkVo : Table("talk") { val id: Column<Int> = integer("id").autoIncrement().primaryKey() val name: Column<String> = varchar("name", 100) val description: Column<String> = text("description") val track: Column<String> = varchar("track", 11) val start: Column<Long> = long("start") val end: Column<Long> = long("end") } fun getTalkById(id: Int): Talk = transaction { TalkVo.select { TalkVo.id eq id }.first() }.toTalk(getTalkSpeakers(talkId = id)) fun getTalks(): List<Talk> = transaction { TalkVo.selectAll().toList() }.map { it.toTalk(getTalkSpeakers(it[TalkVo.id])) }
  • 29. Android client. Diagram App Splash Activity Talks Activity Detail Activity Splash Presenter List Presenter Detail Presenter
  • 30. Android client. Dependencies apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-platform-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlinx-serialization' apply plugin: 'kotlin-kapt' android { compileSdkVersion 27 defaultConfig { applicationId 'com.votlin.android' minSdkVersion 16 targetSdkVersion 27 multiDexEnabled true versionCode 1 versionName '0.0.1' testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner' ... } dependencies { expectedBy project(':common') ... Plugins Android configuration Getting common code Android dependencies
  • 31. Android client. Activities class DetailActivity : RootActivity<DetailView>(), DetailView { override val layoutResourceId: Int = R.layout.activity_detail override val presenter: DetailPresenter by instance() override val activityModule: Kodein.Module = Kodein.Module { bind<DetailPresenter>() with provider { DetailPresenter( view = this@DetailActivity, errorHandler = instance(), executor = instance(), repository = instance()) } } override fun registerListeners() { rate.setOnRatingBarChangeListener { _, rate, _ -> presenter.onRateChange(rate = rate.toInt()) } } override fun getTalkId(): Int { return intent.extras.getInt(TALK_ID) } override fun showRate(value: Int) { rate.rating = value.toFloat() } ... Implement common view Common presenter instance Presenter -> DoSomething() View -> DoSomething()
  • 33. Web Client - React
  • 34. Web Client - React. Dependencies apply plugin: 'kotlin2js' apply plugin: 'kotlin-dce-js' apply plugin: 'org.jetbrains.kotlin.frontend' apply plugin: 'kotlinx-serialization' apply plugin: 'kotlin-platform-js' dependencies { expectedBy project(":common") compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version" compile "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serialization_version" compile "org.jetbrains.kotlinx:kotlinx-html-js:0.6.11" compile "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$coroutines_version" compile "org.jetbrains:kotlin-react:16.5.2-pre.56-kotlin-1.2.71" compile "org.jetbrains:kotlin-react-dom:16.5.2-pre.56-kotlin-1.2.71" compile "io.ktor:ktor-client-core-js:$ktor_version" testCompile "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version" } Plugins Getting common code Serialization and stdlib Coroutines React Ktor
  • 35. Web Client - React. LifeCycle abstract class RootScreen<P : RProps, S : ScreenState, out V : Presenter.View> : RComponent<P, S>(), Presenter.View { abstract val presenter: Presenter<V> override fun componentDidMount() { presenter.initialize() } override fun showProgress() { setState { progress = true } } override fun hideProgress() { setState { progress = false } } } interface ScreenState : RState { var progress: Boolean } class HomeScreen : RootScreen<HomeProps, HomeState, TalksListView>(), TalksListView {} Similar to onCreate() on Android Screen sample
  • 36. Web Client - React. Diagram App Splash Screen Home Screen Detail Screen Splash Presenter List Presenter Detail Presenter
  • 37. Web Client - React. Navigation abstract class App : RComponent<RProps, AppState>() { init { state = AppState() } override fun RBuilder.render() { div("app") { when (state.screen) { Screen.SPLASH -> splash { setState { screen = it } } Screen.HOME -> home { setState { talkId = it screen = Screen.DETAIL } } Screen.DETAIL -> detail(state.talkId) { setState { screen = it } } } } } }
  • 39. iOS
  • 40. iOS client. Diagram AppDelegate LaunchScreen AllVC DetailVC List Presenter Detail Presenter BusinessVC DevelopmentVC TalksListViewController
  • 41. iOS client. Dependencies apply plugin: 'kotlin-platform-native' configurations { compilerPlugin } dependencies { expectedBy project(':common') implementation "io.ktor:ktor-client-ios:$ktor_version" implementation "io.ktor:ktor-client-json-ios:$ktor_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serialization_version" compilerPlugin "org.jetbrains.kotlin:kotlin-serialization-unshaded:$serialization_plugin" } def pluginPath = configurations.compilerPlugin.files.first().canonicalPath def pluginArgument = '-Xplugin=' + pluginPath sourceSets { main { component { targets = ['ios_x64', 'ios_arm64'] outputKinds = [FRAMEWORK] extraOpts '-Xdisable=devirtualization', '-linker-options', '-iphoneos_version_min 9.0.0', pluginArgument } } } Plugins Getting common code Compile to iOS! :)
  • 43. Turn off bitcode Add common build as build phase Add framework search
  • 44. iOS Client. ViewControllers import ios class TalksListViewController: UIViewController, TalksListView { private lazy var presenter : TalksListPresenter = TalksListPresenter(view: self, errorHandler: IosErrorHandler()) override func viewDidLoad() { super.viewDidLoad() presenter.initialize() presenter.onTrackChanged(track: track) } func showTalks(talks: [Talk]) { self.talks = talks } … } Import common module Implement common view Common presenter instance Presenter -> DoSomething() View -> DoSomething()