Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Rx and Preferences
Search
@hotchemi
November 24, 2016
Programming
200
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
300
The things we’ve learned from iOS×React Native hybrid development
hotchemi
2
5.6k
React Nativeを活用したアプリ開発体制/sapuri meetup
hotchemi
3
8.3k
Type-Safe i18n on RN
hotchemi
2
1.3k
Navigation in a hybrid app
hotchemi
3
1.4k
PermissionsDispatcher × Kotlin
hotchemi
0
3.4k
kotlin compiler plugin
hotchemi
1
840
Introducing PermissionsDispatcher
hotchemi
1
200
khronos
hotchemi
4
2k
Other Decks in Programming
See All in Programming
残高管理から台帳サービスへの進化
artoy
1
200
速習iPhone Duo対応
yuukiw00w
2
990
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
1.9k
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
27
31k
UPDATE をやめる — EF Core でマスタをバージョン管理する
panda728
PRO
0
1.2k
Kotlinの15年とServer-Side Kotlin
n_takehata
1
150
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
390
コードで差別化できない時代の ソフトウェアエンジニアリング / Software Engineering in an Era Where Code Doesn’t Differentiate
kishida
2
170
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.6k
Compiling a real-world CLI tool to native with Static Hermes
tmikov2023
0
120
wkhtmltopdfの次どうするか問題2026
willnet
2
1.9k
Agentic Software Factoryに、すごく賢いIF文を。 / super smart IF statement into the Agentic Software Factory.
rkaga
8
2.2k
Featured
See All Featured
Measuring & Analyzing Core Web Vitals
bluesmoon
9
1k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
570
Evolving SEO for Evolving Search Engines
ryanjones
0
330
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
430
Building an army of robots
kneath
307
47k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.6k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
500
The Invisible Side of Design
smashingmag
301
52k
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!