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
280
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
Jakarta EE meets AI
ivargrimstad
0
610
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
24k
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
170
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
受け取る人から提供する人になるということ
little_rubyist
0
230
subpath importsで始めるモック生活
10tera
0
300
Quine, Polyglot, 良いコード
qnighy
4
640
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
2
1.1k
Macとオーディオ再生 2024/11/02
yusukeito
0
370
CSC509 Lecture 12
javiergs
PRO
0
160
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.2k
Featured
See All Featured
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
Making Projects Easy
brettharned
115
5.9k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
47
2.1k
Scaling GitHub
holman
458
140k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Optimizing for Happiness
mojombo
376
70k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
860
The Pragmatic Product Professional
lauravandoore
31
6.3k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
A designer walks into a library…
pauljervisheath
204
24k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
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 ΤϯδχΞ ઈࢍืूத Ͱ͢ʂ