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
140
Behind the curtains
tiwiz
0
94
The Importance of Being Tested
tiwiz
0
450
Fantastic API and where to find them
tiwiz
0
110
Flipping the Koin @ GDG Dev Party
tiwiz
1
83
Flipping the Koin
tiwiz
2
190
Trip into the async world @ NYC Kotlin Meetup
tiwiz
0
130
Trip into the async world
tiwiz
1
160
GraphQL IRL (Android Makers)
tiwiz
0
170
Other Decks in Programming
See All in Programming
週末にAI-DLCを本気で回したら$1,600溶けた
hbashimizu
0
130
LLMは4年分のCompose移行を再現できるのか?実プロダクト279件のXMLで探る自動化の境界線
makun
0
440
Webエンジニアなのにブラウザの仕組みがわからないので、Pythonで自作してみた
tatsuki12
4
1.7k
AIエージェント時代のコードレビューを設計する
nogu66
6
2.5k
Hello, Hiroshima Geospatial Data! — Exploring DoboX with Python
ra0kley
0
180
異なる設計思想のフレームワークを経験して得た学び
amekuhideki
2
1.5k
Gmail/Google DriveをトリガーにAIエージェントを動かそう! / Run AI agents with Gmail/Google Drive as triggers!
har1101
3
470
iOS開発×AI駆動開発 〜最近使って便利だったスキルの話〜
nogu66
0
140
[GoCon2026] When Goroutines Are Not Enough: Runtime Locality in High-Throughput Go
takehaya
3
460
XP祭りでしか伝わらないフリップネタ #xpjug
murabayashi
0
110
まだ間に合う!今年の夏こそSchemeのマクロ展開器を完全理解!
omasanori
0
640
go-spidermonkeyでAIエージェントのCode Modeを実装する
syumai
3
1.5k
Featured
See All Featured
A Tale of Four Properties
chriscoyier
163
24k
We Are The Robots
honzajavorek
0
350
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
How GitHub (no longer) Works
holman
316
150k
Claude Code のすすめ
schroneko
67
230k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
260
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
190
The Curse of the Amulet
leimatthew05
2
14k
The Pragmatic Product Professional
lauravandoore
37
7.4k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
Optimizing for Happiness
mojombo
378
71k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
320
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