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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
Why Laravel apps break—Mastering the fundamentals to keep them maintainable
kentaroutakeda
1
350
スマートグラスで並列バイブコーディング
hyshu
0
120
「なぜそう決めたのか」を残し続ける仕組み ― Notion AI カスタムエージェント × Slack連携による設計判断の自動記録 - NIKKEI Tech Talk #47
niftycorp
PRO
0
110
dRuby over BLE
makicamel
2
330
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
260
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
190
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
540
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
120
The Arts and Crafts of Work in the AI Era — Toward Mastery in Software Development
kuranuki
1
750
Claspは野良GASの夢をみるか
takter00
0
180
エージェンティックRAGにAWSで入門しよう!
har1101
8
1.4k
Make SRE Operations Easier with Azure SRE Agent
kkamegawa
0
5.3k
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
200
Making Projects Easy
brettharned
120
6.7k
Utilizing Notion as your number one productivity tool
mfonobong
4
320
Why Our Code Smells
bkeepers
PRO
340
58k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
570
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
410
Test your architecture with Archunit
thirion
1
2.3k
Optimizing for Happiness
mojombo
378
71k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
140
Exploring anti-patterns in Rails
aemeredith
3
400
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
940
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