Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

Hello!!

Slide 3

Slide 3 text

BYJU’S The Learning app @iamBedant

Slide 4

Slide 4 text

Gojek The Super app @_jitinsharma

Slide 5

Slide 5 text

Multiplatform A tale of @iamBedant | @_jitinsharma HISTORY KOTLIN MP KOTLIN ANDROID & IOS SAMPLE APP VALUE PROPOSITION ADVANTAGES DISADVANTAGES RESOURCES

Slide 6

Slide 6 text

History of Platforms

Slide 7

Slide 7 text

A Long time ago…

Slide 8

Slide 8 text

System A we have

Slide 9

Slide 9 text

O 1 System A

Slide 10

Slide 10 text

0 1 1 0 0 0 O 1 1 1 0 0 1 0 1 1 0 1 1 0 0 0 O 1 0 0 1 0 1 0 O 1

Slide 11

Slide 11 text

START: MOV AX,DATA MOV DS,AX LEA DX,MSG1 MOV AH,9 INT 21H MOV AH,1 INT 21H SUB AL,30H MOV NUM1,AL LEA DX,MSG2 MOV AH,9 INT 21H MOV AH,1

Slide 12

Slide 12 text

START: MOV AX,DATA MOV DS,AX LEA DX,MSG1 MOV AH,9 INT 21H MOV AH,1 INT 21H SUB AL,30H MOV NUM1,AL LEA DX,MSG2 MOV AH,9 INT 21H MOV AH,1 0 1 0 1 0 0 1 0 1 1 1 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 1 1 1 0

Slide 13

Slide 13 text

0 1 0 1 0 0 1 0 1 1 1 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 1 1 1 0

Slide 14

Slide 14 text

0 1 0 1 0 0 1 0 1 1 1 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 1 1 1 0

Slide 15

Slide 15 text

0 1 0 1 0 0 1 0 1 1 1 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 1 1 1 0

Slide 16

Slide 16 text

START: MOV AX,DATA MOV DS,AX LEA DX,MSG1 MOV AH,9 INT 21H MOV AH,1 INT 21H SUB AL,30H MOV NUM1,AL LEA DX,MSG2 MOV AH,9 INT 21H MOV AH,1 0 1 0 1 0 0 1 0 1 1 1 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 1 1 1 0 Code 1

Slide 17

Slide 17 text

START: MOV AX,DATA MOV DS,AX LEA DX,MSG1 MOV AH,9 INT 21H MOV AH,1 INT 21H SUB AL,30H MOV NUM1,AL LEA DX,MSG2 MOV AH,9 INT 21H MOV AH,1 START: MOV AX,DATA MOV DS,AX LEA DX,MSG1 MOV AH,9 MOV AH,1 INT 21H SUB AL,30H MOV NUM1,AL LEA DX,MSG2 MOV AH,9 INT 21H LEA DX,MSG3 Code 1 Code 2

Slide 18

Slide 18 text

START: MOV AX,DATA MOV DS,AX LEA DX,MSG1 MOV AH,9 INT 21H MOV AH,1 INT 21H SUB AL,30H MOV NUM1,AL LEA DX,MSG2 MOV AH,9 INT 21H MOV AH,1 0 1 0 1 0 0 1 0 1 1 1 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 1 1 1 0 0 1 0 1 0 0 1 0 1 1 1 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 1 1 1 0 START: MOV AX,DATA MOV DS,AX LEA DX,MSG1 MOV AH,9 MOV AH,1 INT 21H SUB AL,30H MOV NUM1,AL LEA DX,MSG2 MOV AH,9 INT 21H LEA DX,MSG3 Code 1 Code 2

Slide 19

Slide 19 text

0 1 0 1 0 0 1 0 1 1 1 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 1 1 1 0 0 1 0 1 0 0 1 0 1 1 1 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 1 1 1 0

Slide 20

Slide 20 text

C / C++

Slide 21

Slide 21 text

#include int main() { !" printf() displays the string inside quotation printf("Hello, World!"); return 0; } C / C++

Slide 22

Slide 22 text

#include int main() { !" printf() displays the string inside quotation printf("Hello, World!"); return 0; } 0 1 0 1 0 0 1 0 1 1 1 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 1 1 1 0

Slide 23

Slide 23 text

#include int main() { !" printf() displays the string inside quotation printf("Hello, World!"); return 0; } 0 1 0 1 0 0 1 0 1 1 1 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 1 1 1 0 0 1 0 1 0 0 1 0 1 1 1 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 1 1 1 0

Slide 24

Slide 24 text

J V M HISTORY KOTLIN MP KOTLIN ANDROID & IOS SAMPLE APP VALUE PROPOSITION ADVANTAGES DISADVANTAGES RESOURCES

Slide 25

Slide 25 text

class HelloWorld { public static void main(String args[]) { System.out.println("Hello, World"); } }

Slide 26

Slide 26 text

class HelloWorld { public static void main(String args[]) { System.out.println("Hello, World"); } } HISTORY KOTLIN MP KOTLIN ANDROID & IOS SAMPLE APP VALUE PROPOSITION ADVANTAGES DISADVANTAGES RESOURCES

Slide 27

Slide 27 text

JVM JVM HISTORY KOTLIN MP KOTLIN ANDROID & IOS SAMPLE APP VALUE PROPOSITION ADVANTAGES DISADVANTAGES RESOURCES

Slide 28

Slide 28 text

JVM JVM HISTORY KOTLIN MP KOTLIN ANDROID & IOS SAMPLE APP VALUE PROPOSITION ADVANTAGES DISADVANTAGES RESOURCES

Slide 29

Slide 29 text

JVM JVM HISTORY KOTLIN MP KOTLIN ANDROID & IOS SAMPLE APP VALUE PROPOSITION ADVANTAGES DISADVANTAGES RESOURCES

Slide 30

Slide 30 text

W E B

Slide 31

Slide 31 text

Before the script...

alert( 'Hello, world!' );

...After the script.

Slide 32

Slide 32 text

Before the script...

alert( 'Hello, world!' );

...After the script.

0 1 0 1 0 0 1 0 1 1 1 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 1 1 1 0

Slide 33

Slide 33 text

Multiplatform HISTORY KOTLIN MP KOTLIN ANDROID & IOS SAMPLE APP VALUE PROPOSITION ADVANTAGES DISADVANTAGES RESOURCES

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

Byte Code JavaScript Native Binary objective c

Slide 36

Slide 36 text

Byte Code JavaScript Native Binary objective c kotlinc kotlinc-js LLVM

Slide 37

Slide 37 text

LLVM

Slide 38

Slide 38 text

IR LLVM

Slide 39

Slide 39 text

IR LLVM

Slide 40

Slide 40 text

IR LLVM

Slide 41

Slide 41 text

IR LLVM

Slide 42

Slide 42 text

LLVM

Slide 43

Slide 43 text

LLVM

Slide 44

Slide 44 text

LLVM Konan

Slide 45

Slide 45 text

Byte Code JavaScript Native Binary .framework kotlinc kotlinc-js LLVM

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

.jar

Slide 49

Slide 49 text

.jar .js

Slide 50

Slide 50 text

.jar .js .framework

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

HISTORY KOTLIN MP KOTLIN ANDROID & IOS SAMPLE APP VALUE PROPOSITION ADVANTAGES DISADVANTAGES RESOURCES

Slide 53

Slide 53 text

▸ Create UI. ▸ Create Models. ▸ Call Api. ▸ Parse Response. ▸ Add Business Logic. ▸ Store in DB Task

Slide 54

Slide 54 text

Task ▸ Create UI. ▸ Create Models. ▸ Call Api. ▸ Parse Response. ▸ Add Business Logic. ▸ Store in DB

Slide 55

Slide 55 text

Task ▸ Create UI. ▸ Create Models. ▸ Call Api. ▸ Parse Response. ▸ Add Business Logic. ▸ Store in DB

Slide 56

Slide 56 text

Task ▸ Create UI. ▸ Create Models. ▸ Call Api. ▸ Parse Response. ▸ Add Business Logic. ▸ Store in DB

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

Task ▸ Create UI. ▸ Create Models. ▸ Call Api. ▸ Parse Response. ▸ Add Business Logic. ▸ Store in DB

Slide 59

Slide 59 text

Task ▸ Create UI. ▸ Create Models. ▸ Call Api. ▸ Parse Response. ▸ Add Business Logic. ▸ Store in DB

Slide 60

Slide 60 text

▸ Create Models. ▸ Parse Response. ▸ Add Business Logic. ▸ Call Api. ▸ Store in DB ▸ Create UI.

Slide 61

Slide 61 text

Network Call

Slide 62

Slide 62 text

HTTP - GET - POST - PUT - host - contentType - headers - Serialize - Threading

Slide 63

Slide 63 text

ktor

Slide 64

Slide 64 text

private val httpClient = HttpClient { install(JsonFeature){ serializer = KotlinxSerializer().apply { setMapper(AllData#$class, AllData.serializer()) } } install(ExpectSuccess) } Ktor

Slide 65

Slide 65 text

private val httpClient = HttpClient { install(JsonFeature){ serializer = KotlinxSerializer().apply { setMapper(AllData#$class, AllData.serializer()) } } install(ExpectSuccess) } Ktor

Slide 66

Slide 66 text

Ktor fun getAll(userId: String, callback: (String) %& Unit) { GlobalScope.launch(NetworkDispatcher) { val result: String = client.get { protocol = URLProtocol.HTTPS host = "api.github.com" encodedPath = "users/$userId" } callback(result) } }

Slide 67

Slide 67 text

Ktor fun getAll(callback: (String) %& Unit) { GlobalScope.launch(NetworkDispatcher) { val result: String = client.get { protocol = URLProtocol.HTTPS host = "newsapi.org/v2" encodedPath = "top-headlines?country=us" } callback(result) } }

Slide 68

Slide 68 text

Ktor fun getAll(callback: (String) %& Unit) { GlobalScope.launch(NetworkDispatcher) { val result: String = client.get { protocol = URLProtocol.HTTPS host = "newsapi.org/v2" encodedPath = "top-headlines?country=us" } callback(result) } }

Slide 69

Slide 69 text

Ktor internal expect val NetworkDispatcher: CoroutineDispatcher

Slide 70

Slide 70 text

Ktor internal expect val NetworkDispatcher: CoroutineDispatcher internal actual val NetworkDispatcher = Dispatchers.Default Android

Slide 71

Slide 71 text

import platform.darwin.dispatch_async import platform.darwin.dispatch_get_main_queue import platform.darwin.dispatch_queue_t internal class NsQueueDispatcher(private val dispatchQueue: dispatch_queue_t) : CoroutineDispatcher() { override fun dispatch(context: CoroutineContext, block: Runnable) { dispatch_async(dispatchQueue) { block.run() } } }

Slide 72

Slide 72 text

import platform.darwin.dispatch_async import platform.darwin.dispatch_get_main_queue import platform.darwin.dispatch_queue_t internal class NsQueueDispatcher(private val dispatchQueue: dispatch_queue_t) : CoroutineDispatcher() { override fun dispatch(context: CoroutineContext, block: Runnable) { dispatch_async(dispatchQueue) { block.run() } } }

Slide 73

Slide 73 text

import platform.darwin.dispatch_async import platform.darwin.dispatch_get_main_queue import platform.darwin.dispatch_queue_t internal class NsQueueDispatcher(private val dispatchQueue: dispatch_queue_t) : CoroutineDispatcher() { override fun dispatch(context: CoroutineContext, block: Runnable) { dispatch_async(dispatchQueue) { block.run() } } }

Slide 74

Slide 74 text

Ktor internal expect val NetworkDispatcher: CoroutineDispatcher iOS internal actual val NetworkDispatcher = NsQueueDispatcher(dispatch_get_main_queue())

Slide 75

Slide 75 text

Storage

Slide 76

Slide 76 text

Sqlite

Slide 77

Slide 77 text

Sqlite - Queries - Transactions - host - contentType - headers - Serialize - Threading

Slide 78

Slide 78 text

sqldelight

Slide 79

Slide 79 text

CREATE TABLE BookmarkedArticle ( author TEXT NOT NULL, content TEXT NOT NULL, ); insert: INSERT INTO BookmarkedArticle (author, content) VALUES (?,?); getAll: SELECT * FROM BookmarkedArticle; BookmarkedArticle.sq

Slide 80

Slide 80 text

CREATE TABLE BookmarkedArticle ( author TEXT NOT NULL, content TEXT NOT NULL, ); insert: INSERT INTO BookmarkedArticle (author, content) VALUES (?,?); getAll: SELECT * FROM BookmarkedArticle; BookmarkedArticle.sq

Slide 81

Slide 81 text

CREATE TABLE BookmarkedArticle ( author TEXT NOT NULL, content TEXT NOT NULL, ); insert: INSERT INTO BookmarkedArticle (author, content) VALUES (?,?); getAll: SELECT * FROM BookmarkedArticle; BookmarkedArticle.sq

Slide 82

Slide 82 text

SqlDelight var newsDatabase = Database(driver)

Slide 83

Slide 83 text

AndroidSqliteDriver(Database.Schema, context, “article.db") NativeSqliteDriver(Database.Schema, "article.db") var newsDatabase = Database(driver) iOS Android SqlDelight

Slide 84

Slide 84 text

newsDatabase.bookmarkedArticleQueries.insert(...) newsDatabase.bookmarkedArticleQueries.getAll().executeAsList()

Slide 85

Slide 85 text

newsDatabase.bookmarkedArticleQueries.insert(...) newsDatabase.bookmarkedArticleQueries.getAll().executeAsList() insert: INSERT INTO BookmarkedArticle (author, content) VALUES (?,?); getAll: SELECT * FROM BookmarkedArticle;

Slide 86

Slide 86 text

Architecture

Slide 87

Slide 87 text

- Repository - Presenter - Storage/Network - Activity - ViewController

Slide 88

Slide 88 text

No content

Slide 89

Slide 89 text

No content

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

No content

Slide 92

Slide 92 text

No content

Slide 93

Slide 93 text

No content

Slide 94

Slide 94 text

No content

Slide 95

Slide 95 text

No content

Slide 96

Slide 96 text

No content

Slide 97

Slide 97 text

No content

Slide 98

Slide 98 text

No content

Slide 99

Slide 99 text

class MainPresenter(private val view: MainView, private val dataRepository: DataRepository) { fun loadData() { view.showLoader() dataRepository.getTopHeadLines { view.displayHeadLines(it.mapToNewsArticleList()) view.hideLoader() } } fun storeArticle(newsArticle: NewsArticle) { dataRepository.saveArticle(newsArticle) } }

Slide 100

Slide 100 text

class MainPresenter(private val view: MainView, private val dataRepository: DataRepository) { fun loadData() { view.showLoader() dataRepository.getTopHeadLines { view.displayHeadLines(it.mapToNewsArticleList()) view.hideLoader() } } fun storeArticle(newsArticle: NewsArticle) { dataRepository.saveArticle(newsArticle) } }

Slide 101

Slide 101 text

class MainPresenter(private val view: MainView, private val dataRepository: DataRepository) { fun loadData() { view.showLoader() dataRepository.getTopHeadLines { view.displayHeadLines(it.mapToNewsArticleList()) view.hideLoader() } } fun storeArticle(newsArticle: NewsArticle) { dataRepository.saveArticle(newsArticle) } }

Slide 102

Slide 102 text

interface MainView : BaseView { fun showLoader() fun hideLoader() fun displayHeadLines(headlines: List) fun displayBookmarkedHeadLines(headlines: List) }

Slide 103

Slide 103 text

class MainActivity : AppCompatActivity(), MainView { override fun displayHeadLines(headlines: List) {...} override fun showLoader() {...} override fun hideLoader() {...} override fun showError(error: String) {...} private val mainPresenter by lazy { inject() } override fun onCreate(savedInstanceState: Bundle?) { mainPresenter.loadData() } }

Slide 104

Slide 104 text

class MainActivity : AppCompatActivity(), MainView { override fun displayHeadLines(headlines: List) {...} override fun showLoader() {...} override fun hideLoader() {...} override fun showError(error: String) {...} private val mainPresenter by lazy { inject() } override fun onCreate(savedInstanceState: Bundle?) { mainPresenter.loadData() } }

Slide 105

Slide 105 text

class MainActivity : AppCompatActivity(), MainView { override fun displayHeadLines(headlines: List) {...} override fun showLoader() {...} override fun hideLoader() {...} override fun showError(error: String) {...} private val mainPresenter by lazy { inject() } override fun onCreate(savedInstanceState: Bundle?) { mainPresenter.loadData() } }

Slide 106

Slide 106 text

class ViewController: UIViewController , MainView { func displayHeadLines(headlines: [NewsArticle]) {...} func showError(error: String) {...} func showLoader() {...} func hideLoader() {...} lazy var presenter : MainPresenter = { IOSInjectorKt.injectMainPresenter() }() override func viewDidLoad() { super.viewDidLoad() presenter.loadData() } }

Slide 107

Slide 107 text

class ViewController: UIViewController , MainView { func displayHeadLines(headlines: [NewsArticle]) {...} func showError(error: String) {...} func showLoader() {...} func hideLoader() {...} lazy var presenter : MainPresenter = { IOSInjectorKt.injectMainPresenter() }() override func viewDidLoad() { super.viewDidLoad() presenter.loadData() } }

Slide 108

Slide 108 text

class ViewController: UIViewController , MainView { func displayHeadLines(headlines: [NewsArticle]) {...} func showError(error: String) {...} func showLoader() {...} func hideLoader() {...} lazy var presenter : MainPresenter = { IOSInjectorKt.injectMainPresenter() }() override func viewDidLoad() { super.viewDidLoad() presenter.loadData() } }

Slide 109

Slide 109 text

HISTORY KOTLIN MP KOTLIN ANDROID & IOS SAMPLE APP VALUE PROPOSITION ADVANTAGES DISADVANTAGES RESOURCES ios Android web WhatÊs great

Slide 110

Slide 110 text

- Kotlin language - No custom runtime - Platform specific libraries with common kotlin code HISTORY KOTLIN MP KOTLIN ANDROID & IOS SAMPLE APP VALUE PROPOSITION ADVANTAGES DISADVANTAGES RESOURCES WhatÊs great

Slide 111

Slide 111 text

WhatÊs not great - Dependency on multiplatform libs for better code sharing - Still experimental HISTORY KOTLIN MP KOTLIN ANDROID & IOS SAMPLE APP VALUE PROPOSITION ADVANTAGES DISADVANTAGES RESOURCES RESOURCES

Slide 112

Slide 112 text

Resources - https://kotlinlang.org/docs/reference/multiplatform.html - https://github.com/Kotlin/kotlinx.coroutines - https://github.com/square/sqldelight - https://github.com/Kotlin/kotlinx.serialization - https://ktor.io/clients/http-client/multiplatform.html - https://github.com/iamBedant/Multiplatform-Sample HISTORY KOTLIN MP KOTLIN ANDROID & IOS SAMPLE APP VALUE PROPOSITION ADVANTAGES DISADVANTAGES RESOURCES

Slide 113

Slide 113 text

Thank you!! @iamBedant @_jitinsharma