Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
An Android Dev start to Kotlin MPP
Search
Roberto Orgiu
November 16, 2020
Programming
210
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
An Android Dev start to Kotlin MPP
Roberto Orgiu
November 16, 2020
More Decks by Roberto Orgiu
See All by Roberto Orgiu
Wellness & Droid
tiwiz
0
130
Behind the curtains
tiwiz
0
83
The Importance of Being Tested
tiwiz
0
440
Fantastic API and where to find them
tiwiz
0
95
Flipping the Koin @ GDG Dev Party
tiwiz
1
78
Flipping the Koin
tiwiz
2
180
Trip into the async world @ NYC Kotlin Meetup
tiwiz
0
130
Trip into the async world
tiwiz
1
150
GraphQL IRL (Android Makers)
tiwiz
0
160
Other Decks in Programming
See All in Programming
CSC307 Lecture 17
javiergs
PRO
0
320
軽量Java基盤の設計 DIコンテナに頼らない、長期保守と1秒起動の実現 JJUG CCC 2026 Spring
macha64
0
490
Agentic UI
manfredsteyer
PRO
0
130
Spec Driven Development | AI Summit Lisbon
danielsogl
PRO
0
180
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
4k
JJUG CCC 2026 Spring: JSpecify で実現する Kotlin フレンドリーな Java API 設計
ternbusty
1
160
肥大化するレガシーコードに立ち向かうためのインターフェース分離と依存の逆転 / JJUG CCC 2026 Spring
hirokunimaeta
0
530
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
2
620
さぁV100、メモリをお食べ・・・
nilpe
0
140
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
160
依存関係から依存物へ―Dependencyという言葉の歴史をひも解く
j_lee
0
110
Inside Stream API
skrb
1
680
Featured
See All Featured
Technical Leadership for Architectural Decision Making
baasie
3
400
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
600
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
250
YesSQL, Process and Tooling at Scale
rocio
174
15k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
830
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
580
The World Runs on Bad Software
bkeepers
PRO
72
12k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.6k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
470
Transcript
An Android Dev start to Kotlin MPP
Premises I want to reuse my knowledge I am an
Android Dev I don’t want to be x-plat
What about languages?
Or actually any other example Empire State Building Lights Calendar
App
Architecture Activity ViewModel Repository
Libraries Repository Retrofit Gson / Moshi
Libraries Repository Retrofit Gson / Moshi Ktor kotlinx.serializer
Modularization Activity ViewModel Repository Native module Shared module
Modularization Repository Shared module
None
There is an app a plugin for that. PROJECT SETUP
1
Install & Profit
Create the project
Create the project
WRITE SOME CODE 2
expect actual IDE only helps after the directories have been
created.
@Serializable data class DayLight( val image: String, val color: String,
val reason: String, val date: String ) @Serializable data class Lights( val todayColor: String, val picture: String, val calendar: List<DayLight> ) :shared
class LightRepository { private val httpClient = HttpClient { install(JsonFeature)
{ val json = Json { ignoreUnknownKeys = true } serializer = KotlinxSerializer(json) } } suspend fun getLights() : Lights = httpClient.get(LIGHTS_ENDPOINT) } :shared
:android class LightsViewModel : ViewModel() { private val repository by
lazy { LightRepository() } private val _state : MutableLiveData<Lce<Lights>> = MutableLiveData() val state : LiveData<Lce<Lights>> get() = _state fun loadLights() { _state.postValue(Lce.Loading) viewModelScope.launch { try { val lights = repository.getLights() _state.postValue(Lce.Success(lights)) } catch(e: Exception) { _state.postValue(Lce.Error(e)) } } } }
val state : LiveData<Lce<Lights>> get() = _state fun loadLights() {
_state.postValue(Lce.Loading) viewModelScope.launch { try { val lights = repository.getLights() _state.postValue(Lce.Success(lights)) } catch(e: Exception) { _state.postValue(Lce.Error(e)) } }
They will happen WEIRD ERRORS 3
None
Delete all .iml files in the project Close project and
IDE Delete .idea directory Re-import the project
None
upgrade Gradle to 6.7 (KT-43039)
None
bit.ly/KMM-Codelab
USE COROUTINES 4
None
REMEMBER You cannot use extension functions
extension ContentView { enum LoadableLights { case loading case result(Lights)
case error(String) } class ViewModel: ObservableObject { let repo : LightRepository @Published var lights = LoadableLights.loading init(repo: LightRepository){ self.repo = repo self.loadLights() } func loadLights() { self.lights = .loading repo.getLights(completionHandler: { lights, error in if let lights = lights { self.lights = .result(lights) } else { self.lights = .error(error?.localizedDescription ?? "error") } }) } } }
self.repo = repo self.loadLights() } func loadLights() { self.lights =
.loading repo.getLights(completionHandler: { lights, error in if let lights = lights { self.lights = .result(lights) } else { self.lights = .error(error?.localizedDescription ?? "e } }) }
private func listView() -> AnyView { switch viewModel.lights { case
.loading: return AnyView(Text("Loading...").multilineTextAlignment(.center)) case .result(let lodableLights): return AnyView(LightsView(lights: lodableLights)) case .error(let description): return AnyView(Text(description).multilineTextAlignment(.center)) } }
None
None
Hello! I Am Rob Follow me at @_tiwiz
Q&A