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
Android で Multiplatform Settings を使う
Search
Hiroyuki Kusu
September 10, 2021
Programming
0
880
Android で Multiplatform Settings を使う
Yumemi.apk #5 (
https://yumemi.connpass.com/event/219861/
) の資料
Hiroyuki Kusu
September 10, 2021
Tweet
Share
More Decks by Hiroyuki Kusu
See All by Hiroyuki Kusu
モノレポのプルリクエストに最近、導入したもの
hkusu
2
400
GitHub composite actions
hkusu
2
270
Android の静的解析における SARIF ファイルの活用
hkusu
0
4.1k
CI_でライブラリのバージョンの変化をレポートする.pdf
hkusu
0
280
Maestro を GitHub Actions で動かす 〜Android編〜
hkusu
0
1.2k
Android の CI(GitHub Actions)の改善で、最近やったこと
hkusu
0
540
Tauri Mobile で生成される Android のコードを見てみる
hkusu
0
1.2k
Custom GitHub Actions を作って Organization 内で共有する
hkusu
1
460
GitHub Actions でユニットテストの結果をレポートする
hkusu
0
3.2k
Other Decks in Programming
See All in Programming
みんなでプロポーザルを書いてみた
yuriko1211
0
260
Contemporary Test Cases
maaretp
0
130
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
330
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
150
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
Duckdb-Wasmでローカルダッシュボードを作ってみた
nkforwork
0
120
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
880
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1k
Ethereum_.pdf
nekomatu
0
460
Jakarta EE meets AI
ivargrimstad
0
510
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
110
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Fireside Chat
paigeccino
34
3k
A better future with KSS
kneath
238
17k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Faster Mobile Websites
deanohume
305
30k
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Ruby is Unlike a Banana
tanoku
97
11k
RailsConf 2023
tenderlove
29
900
Making Projects Easy
brettharned
115
5.9k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
410
Transcript
Android Ͱ Multiplatform Settings Λ͏ 2021.9.10 YUMEMI.apk #5 Hiroyuki Kusu
( @hkusu_ )
About me
ΈΜͳ͕ͬͯΔ͋ͷαʔϏεɺ ࣮ΏΊΈ͕࡞ͬͯ·͢ɻ શੈք5000ສMAUʹୡ͢ΔωοταʔϏεΛΦʔμʔϝΠυͰاըઃܭ͠ɺ γεςϜߏஙӡ༻͔ΒվળఏҊ·Ͱαϙʔτ͍͖ͯ͠·͢ɻ
Multiplatform Settings https://github.com/russhwolf/multiplatform-settings • key-value σʔλӬଓԽͷҝͷ Kotlin Multiplatform ϥΠϒϥϦ
• Android ͷ߹ SharedPreferences ͕෦తʹར༻͞ΕΔ
Kotlin Multiplatform ϓϩδΣΫτͰ ͳͯ͘௨ৗͷ Android ͷϓϩδΣΫτ Ͱར༻Ͱ͖ΔͷͰར༻ͯ͠ΈΔ ຊͷ
implementation("com.russhwolf:multiplatform-settings:0.7.4" ) implementation("com.russhwolf:multiplatform-settings-coroutines:0.7.4") build.gradle.kts ಋೖ ※ ݱ࣌ͷ࠷৽όʔδϣϯ 0.8 ͷΑ͏Ͱ͢
Coroutines ༻ͷ֦ு
val context: Context = .. . val sharedPreferences: SharedPreferences
= context.getSharedPreferences("main", Context.MODE_PRIVATE ) val flowSettings: FlowSettings = AndroidSettings(sharedPreferences, commit = true).toFlowSettings() FlowSettings Πϯελϯεͷ࡞
@ExperimentalSettingsAp i class AccountDao(private val settings: FlowSettings) { val
nameFlow: Flow<String?> = settings.getStringOrNullFlow(KEY_NAME ) suspend fun getName(): String? { return settings.getStringOrNull(KEY_NAME ) } suspend fun setName(name: String) { settings.putString(KEY_NAME, name ) } companion object { private const val KEY_NAME = "name " } } Dao Ϋϥεͷ༻ҙ FlowSettings ΠϯελϯεΛͦͷ··ར༻ͯ͠Α͍͕ɺςετ࣌ʹϞοΫ͍ͨ͠ͷͰϥούʔΫϥεΛ༻ҙ ʢkey Λར༻ऀ͔ΒӅṭͨ͠Γɺૢ࡞ΛநԽ͢Δͷత͋Δʣ
@ExperimentalSettingsAp i class AccountDao(private val settings: FlowSettings) { val
nameFlow: Flow<String?> = settings.getStringOrNullFlow(KEY_NAME ) suspend fun getName(): String? { return settings.getStringOrNull(KEY_NAME ) } suspend fun setName(name: String) { settings.putString(KEY_NAME, name ) } companion object { private const val KEY_NAME = "name " } } DaoΫϥεͷ༻ҙ Suspending Function ͰಡΈॻ͖
@ExperimentalSettingsAp i class AccountDao(private val settings: FlowSettings) { val
nameFlow: Flow<String?> = settings.getStringOrNullFlow(KEY_NAME ) suspend fun getName(): String? { return settings.getStringOrNull(KEY_NAME ) } suspend fun setName(name: String) { settings.putString(KEY_NAME, name ) } companion object { private const val KEY_NAME = "name " } } DaoΫϥεͷ༻ҙ σʔλʹมߋΠϕϯτΛྲྀ͢ Flow
val context: Context = .. . val sharedPreferences: SharedPreferences
= context.getSharedPreferences("main", Context.MODE_PRIVATE ) val flowSettings: FlowSettings = AndroidSettings(sharedPreferences, commit = true).toFlowSettings() FlowSettings Πϯελϯεͷ࡞ʢ࠶ܝʣ SharedPreferences ͷσʔλอଘͰ commitʢಉظʣͱ applyʢඇಉظʣͷ2ܗ͕ࣜ͋Δ͕ɺCoroutines Խ ͨ͜͠ͱʹΑΓ commit ͷσϝϦοτʢεϨουͷϒϩοΫʣ͕ബ·͍ͬͯΔͷͰ commit Λ࠾༻ 㱺 Coroutines ͷΈʹΔ͜ͱͰɺ࣮ߦॱεϨουΛؾʹͤͣσʔλͷಡΈॻ͖͕Մೳʹ
• Multiplatform ϥΠϒϥϦͰ͋Δ͕ Android ୯ମͰར༻ͯ͠ ศར • ଞʹศརͦ͏ͳ Multiplatform
ϥΠϒϥϦ͕͋ΔͷͰಋೖΛ ݕ౼ͯ͠Α͍͔ʁ • Retro fi t ͷସΘΓʹ Ktor • Room ͷସΘΓʹ SQLDelight ͳͲͳͲ.. ͓ΘΓʹ
Thank you ! @hkusu_ ฐࣾ Android ΤϯδχΞ ઈࢍืूத Ͱ͢ʂ