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
900
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
410
GitHub composite actions
hkusu
2
290
Android の静的解析における SARIF ファイルの活用
hkusu
0
4.6k
CI_でライブラリのバージョンの変化をレポートする.pdf
hkusu
0
290
Maestro を GitHub Actions で動かす 〜Android編〜
hkusu
0
1.2k
Android の CI(GitHub Actions)の改善で、最近やったこと
hkusu
0
550
Tauri Mobile で生成される Android のコードを見てみる
hkusu
0
1.3k
Custom GitHub Actions を作って Organization 内で共有する
hkusu
1
480
GitHub Actions でユニットテストの結果をレポートする
hkusu
0
3.2k
Other Decks in Programming
See All in Programming
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
Security_for_introducing_eBPF
kentatada
0
110
Refactor your code - refactor yourself
xosofox
1
260
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
210
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
250
ドメインイベント増えすぎ問題
h0r15h0
2
300
Recoilを剥がしている話
kirik
5
6.7k
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
4.1k
Zoneless Testing
rainerhahnekamp
0
120
DevFest Tokyo 2025 - Flutter のアプリアーキテクチャ現在地点
wasabeef
5
900
nekko cloudにおけるProxmox VE利用事例
irumaru
3
430
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
750
Featured
See All Featured
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Docker and Python
trallard
42
3.1k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Code Review Best Practice
trishagee
65
17k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Rails Girls Zürich Keynote
gr2m
94
13k
Navigating Team Friction
lara
183
15k
We Have a Design System, Now What?
morganepeng
51
7.3k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
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 ΤϯδχΞ ઈࢍืूத Ͱ͢ʂ