Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
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
890
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
280
Android の静的解析における SARIF ファイルの活用
hkusu
0
4.4k
CI_でライブラリのバージョンの変化をレポートする.pdf
hkusu
0
290
Maestro を GitHub Actions で動かす 〜Android編〜
hkusu
0
1.2k
Android の CI(GitHub Actions)の改善で、最近やったこと
hkusu
0
540
Tauri Mobile で生成される Android のコードを見てみる
hkusu
0
1.3k
Custom GitHub Actions を作って Organization 内で共有する
hkusu
1
470
GitHub Actions でユニットテストの結果をレポートする
hkusu
0
3.2k
Other Decks in Programming
See All in Programming
Full stack testing :: basic to basic
up1
1
870
新規学習のハードルを下げる方法とは?/ How to Make Learning Something New Easier?
nobuoooo
1
130
社内活動の取り組み紹介 ~ スリーシェイクでこんな取り組みしてます ~
bells17
0
390
.NET Conf 2024の振り返り
tomokusaba
0
200
似たもの同士のPerlとPHP
uzulla
1
110
macOS なしで iOS アプリを開発する(※ただし xxx に限る)
mitsuharu
1
170
TypeScript でバックもやるって実際どう? 実運用で困ったこと3選
yuichiro_serita
17
7.6k
PipeCDの歩き方
kuro_kurorrr
4
140
DevTools extensions で 独自の DevTool を開発する | FlutterKaigi 2024
kokiyoshida
0
440
talk-with-local-llm-with-web-streams-api
kbaba1001
0
150
AWS認定資格を勉強した先に何があったか
satoshi256kbyte
2
180
Java 23の概要とJava Web Frameworkの現状 / Java 23 and Java web framework
kishida
2
380
Featured
See All Featured
Speed Design
sergeychernyshev
25
650
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Visualization
eitanlees
145
15k
Facilitating Awesome Meetings
lara
50
6.1k
KATA
mclloyd
29
14k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Embracing the Ebb and Flow
colly
84
4.5k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
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 ΤϯδχΞ ઈࢍืूத Ͱ͢ʂ