How emmaguy/wear-notify-for-reddit works
Project Type and Purpose
• This is a multi-module Android application (“Wear Notify for Reddit”) that pushes content from Reddit to an Android phone and wearable.
• Modules:
• mobile – the phone app (settings UI, fetch‐and‐sync engine, notification sender, Wear Data Layer client)
• wear – the watch app (notification listener, UI for posts/comments/actions)
• sharedlib – common model objects (Post, Comment, Constants, drawables)
High‐Level Architectural Overview
• External services:
• Reddit REST API (authentication, listing, comments)
• Pocket API (save to Pocket)
• Local storage: Android SharedPreferences (token storage, user settings, action order)
• Dependency injection: Dagger modules (AppModule, StorageModule, SettingsModule) provide singletons throughout both mobile and wear modules.
• Synchronization: mobile periodically fetches new posts & direct messages via a background alarm (BackgroundAlarmListener → LatestPostsRetriever → RedditService). Results are converted, filtered, persisted (if needed), and then forwarded to the watch via WearableListenerService.
• Notification pipeline: mobile packages data items/notifications to the watch; wear’s NotificationListenerService listens for them and displays native watch notifications with actions (reply, upvote, view image/comments).
Main Components
• Frontend (mobile UI): SettingsActivity (subreddit picker, action reorder)
• Backend (mobile fetch engine):
– BackgroundAlarmListener → RetrieveService → Retrofit‐backed RedditAuthenticationService/RedditService
– Converters (JSON → Java models) in refresh/
– TokenRefreshInterceptor handles OAuth token lifecycle
• Local Storage (mobile): SharedPreferencesTokenStorage, UserStorage, UniqueIdentifierStorage
• Wear Data Layer Client (mobile): WearableListenerService sends DataApi messages to wearable
• Frontend (wear UI): MainActivity, CommentsActivity, ViewImageActivity, PanView, comment fragments
• Notification Listener (wear): NotificationListenerService displays rich notifications
• Shared Library: Comment, Post models + resource drawables used by both modules
Relationships and Data Flows
1. User configures settings in mobile UI → writes to SharedPreferences via SettingsModule
2. Alarm triggers BackgroundAlarmListener → calls LatestPostsRetriever → uses RedditService (Retrofit) authenticated by Token and TokenRefreshInterceptor → JSON responses → converters → Java models
3. Mobile sends DataItems/MessageEvents via WearableListenerService → Wear Data Layer → watch
4. Wear receives data → NotificationListenerService publishes notifications → user taps actions → Intents handled by wear Activities/Services → may send reply back to mobile (e.g. voice reply)
5. “Save to Pocket” action invokes PocketUtils on the phone via the phone’s Pocket app
Architectural Patterns & Principles
• Modularization: mobile vs. wear vs. sharedlib
• Separation of concerns: UI, networking, storage, DI
• Dependency Injection (Dagger) for testability (mobile/src/test covers converters, retriever, token interceptor)
• Observer/publisher (Wearable Data Layer) for inter-device comms
• Retrofit + interceptors for clean REST integration
• JSON converters (delegating converter pattern)