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.2k
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
180
khronos
hotchemi
4
2k
Other Decks in Programming
See All in Programming
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
260
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
210
AI駆動開発を妨げる技術的負債の解消アプローチ / ai-refactoring-approach
minodriven
12
6.4k
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
4.2k
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.8k
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
920
技術記事、 専門家としてのプログラマ、 言語化
mizchi
13
6.5k
トークンをケチるな、設計しろ:GitHub Copilotを賢く使うコンテキスト戦略
ochtum
0
160
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
200
「なぜそう決めたのか」を残し続ける仕組み ― Notion AI カスタムエージェント × Slack連携による設計判断の自動記録 - NIKKEI Tech Talk #47
niftycorp
PRO
0
230
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
180
依存関係から依存物へ―Dependencyという言葉の歴史をひも解く
j_lee
0
130
Featured
See All Featured
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
270
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.5k
Fireside Chat
paigeccino
42
4k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
340
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.2k
From π to Pie charts
rasagy
0
220
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
490
We Are The Robots
honzajavorek
0
250
Writing Fast Ruby
sferik
630
63k
Why Our Code Smells
bkeepers
PRO
340
58k
エンジニアに許された特別な時間の終わり
watany
107
250k
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!