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
Full stack testing :: basic to basic
up1
1
930
42 best practices for Symfony, a decade later
tucksaun
1
180
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
2
3.6k
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
Discord Bot with AI -for English learners-
xin9le
1
120
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
200
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
2
460
fs2-io を試してたらバグを見つけて直した話
chencmd
0
220
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
3
920
暇に任せてProxmoxコンソール 作ってみました
karugamo
1
710
14 Years of iOS: Lessons and Key Points
seyfoyun
1
770
あれやってみてー駆動から成長を加速させる / areyattemite-driven
nashiusagi
1
200
Featured
See All Featured
Being A Developer After 40
akosma
87
590k
Building an army of robots
kneath
302
44k
Into the Great Unknown - MozCon
thekraken
33
1.5k
Building Adaptive Systems
keathley
38
2.3k
How to Ace a Technical Interview
jacobian
276
23k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
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 ΤϯδχΞ ઈࢍืूத Ͱ͢ʂ