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
Rx and Preferences
Search
@hotchemi
November 24, 2016
Programming
180
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Rx and Preferences
http://www.meetup.com/Tokyo-Android-Meetup/events/235119373
@hotchemi
November 24, 2016
More Decks by @hotchemi
See All by @hotchemi
kompile-testing internal
hotchemi
0
290
The things we’ve learned from iOS×React Native hybrid development
hotchemi
2
5.5k
React Nativeを活用したアプリ開発体制/sapuri meetup
hotchemi
3
8.3k
Type-Safe i18n on RN
hotchemi
2
1.2k
Navigation in a hybrid app
hotchemi
3
1.4k
PermissionsDispatcher × Kotlin
hotchemi
0
3.4k
kotlin compiler plugin
hotchemi
1
820
Introducing PermissionsDispatcher
hotchemi
1
190
khronos
hotchemi
4
2k
Other Decks in Programming
See All in Programming
The Bowling Game- From Imperative to Functional Programming - Part 1
philipschwarz
PRO
0
330
Laravelで学ぶ Webアプリケーションチューニング入門/web_application_tuning_101
hanhan1978
4
680
音楽のための関数型プログラミング言語mimiumにおける多段階計算の活用
tomoyanonymous
1
330
AIを活用したE2Eテスト実装効率化のあゆみ / ebisu-mobile-14-kotetu
kotetuco
0
170
Claude Team Plan導入・ガイド
tk3fftk
0
210
SREの積み重ねがAI駆動開発のガードレールになった ― 7つの実践/SRE Guardrails The 7
tomoyakitaura
8
4.4k
初めてのKubernetes 本番運用でハマった話
oku053
0
130
광주소프트웨어마이스터고등학교 DevFest 특강 - 바이브 코딩 시대에서 주니어 개발자로 살아남는 방법
utilforever
1
140
Claude Opus 4.6以後の受託開発エンジニアの変化(Claude Code開発ノウハウ大公開スペシャルbyクラスメソッド)
iidatakuma
1
780
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
380
ルールを書いて終わらせないハーネスエンジニアリング
yug1224
3
1.5k
ソフトウェア設計に溶けるインフラ ― AWS CDK のインフラ認識論
konokenj
2
540
Featured
See All Featured
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
530
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
370
Un-Boring Meetings
codingconduct
0
350
Prompt Engineering for Job Search
mfonobong
0
380
Into the Great Unknown - MozCon
thekraken
41
2.6k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Test your architecture with Archunit
thirion
1
2.3k
From π to Pie charts
rasagy
0
240
What's in a price? How to price your products and services
michaelherold
247
13k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
870
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
970
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
290
Transcript
Rx and Preferences Shintaro Katafuchi/hotchemi
• Shared Preferences • Just a XML based KVS •
boolean,String,float,int,long,Set<String> • Tend to be messy to manage keys
public class PreferenceManager { private static final String KEY_USER_ID
= "user_id"; public putUserId(int userId) { prefs.edit().putInt(KEY_USER_ID, userId).apply(); } public int getUserId() { return prefs.getUserId(KEY_USER_ID, -1); } public boolean hasUserId() { return prefs.contains(KEY_USER_ID); } public void removeUserId() { prefs.edit().remove(KEY_USER_ID).apply(); } }
private static final String SHARED_PREFS_NAME = "HogeActivity"; private static
final String LAST_UPDATE_TICK_KEY = "lastUpdateTick"; private static final String LAST_DAILY_TASK_TICK_KEY = "lastDailyTaskTick"; private static final String LAST_SPLASH_EVENT_KEY = "lastSplashEventTick"; private static final String FCM_TOKEN_KEY = "fcmToken"; private static final String GCM_REGISTRATION_ID_KEY = "gcmRegistrationId"; private static final String GCM_APP_VERSION_KEY = "gcmAppVersion"; private static final String INVALIDATED_COUNT_KEY = "invalidatedCount"; private static final String LAUNCH_COUNT_KEY = "launchCount"; private static final String FIRST_BOOT_TICK_KEY = "firstBootTick"; private static final String RATING_DIALOG_KEY = "ratingDialogKey";
• Rx and Preferences • Deal with every “data” as
Observable • We need a subscription mechanism • Yes, RxJava! • Compound with other Rx libraries
Android Application Architecture https://labs.ribot.co.uk/android-application-architecture-8b6e34acda65#.74al8nhsz
None
None
• What I wanna do… • manage keys easily •
subscribe a data with Rx
hotchemi/tiamat https://github.com/hotchemi/tiamat
apply plugin: 'android-apt' dependencies { compile ‘com.github.hotchemi:tiamat:0.8.1’ provided ‘com.github.hotchemi:tiamat-compiler:0.8.1’ }
Install
@Pref("sample") class Sample { @Key(name = "long_value") long longValue =
false; // you can define default value like stringValue @Key(name = "string_value") String stringValue = "default_value"; @Key(name = "boolean_value") boolean booleanValue; @Key(name = "int_value") int intValue; @Key(name = "float_value") float floatValue; @Key(name = "set_string") Set<String> setStringValue; } Define a model
RxPreferences preferences = new SampleSharedPreferences(context); preferences.putStringValue(string); preferences.putStringValue(string, defaultValue); preferences.getStringValue(); preferences.hasStringValue();
preferences.removeStringValue(); Generate codes
// as primitive boolean value = preferences.getBooleanValue().asValue(); // as Observable
Observable<Boolean> value = preferences.getBooleanValue().asObservable(); // as Action Action1<? super Boolean> value = preferences.getBooleanValue().asAction(); As RxJava
subscriptions.add(preference.asObservable() .observeOn(AndroidSchedulers.mainThread()) .subscribe(RxCompoundButton.checked(checkBox))); subscriptions.add(RxCompoundButton.checkedChanges(checkBox) .skip(1) .subscribe(preference.asAction())); With Rx libraries
None
Everything is a stream!