RxJava for Android Developers

Book description

RxJava for Android Developers teaches you how to build fast, fluid, and reactive mobile apps for Android with RxJava.



About the Technology

For Android developers, writing multithreaded apps can be as challenging as it is necessary. RxJava simplifies complex threading operations, maintaining proper synchronization as you switch seamlessly from thread to thread. RxJava also brings the benefits of reactive programming to your apps—that means better real-time responsiveness, the holy grail for every Android developer.



About the Book

RxJava for Android Developers begins by inviting you to think about programming and data the reactive way. This engaging, hands-on essential reference introduces you to the central pattern of RxJava for Android, then explains the View Model before exploring highly sought-after app features like chat clients and elegant transitions. Finally, you’ll look at high-level design concerns and architectural approaches and frameworks that work well with Functional Reactive Programming (FRP) thinking.



What's Inside

  • An introduction to reactive programming
  • Easier thread management
  • Improving UI responsiveness
  • Thinking asynchronously
  • Building a working chat client


About the Reader

Readers should have some experience building Android applications. No experience with RxJava is needed.



About the Author

Timo Tuominen has used FRP and RxJava extensively while working with Futurice as an architect of a major Android project for Samsung.



Quotes
A terrific introduction to a complex topic. The examples are real enough to be useful when writing your own applications without bogging you down in extraneous detail.
- Mark Elston, Advantest America

Clear and practical, the book does an amazing job of showing the power of RxJava to build Android apps.
- Cody Sand, Sandtoken

Writing code that deals with asynchronous events properly is tricky, but this book and RxJava make it much easier.
- Burk Hufnagel, Daugherty Business Solutions

Table of contents

  1. Copyright
  2. Brief Table of Contents
  3. Table of Contents
  4. Preface
  5. Acknowledgments
  6. About this book
  7. Part 1. Core reactive programming
    1. Chapter 1. Introduction to reactive programming
      1. Perhaps you picked up this book because...
      2. Don’t read this book if...
      3. OOP, Rx, FP, and FRP
      4. Benefits of Rx
      5. What you code is what you get
      6. The reactive landscape
      7. What do you need to know before you start?
      8. About this book
      9. RxJava 2 and Android
      10. Setting up the Android environment
      11. Java 8 lambdas
      12. Deep dive into Rx: Live search
      13. Conditions for triggering search
      14. Project setup
      15. Text input as an emitter of data
      16. The publish-subscribe pattern
      17. Text input as an observable
      18. Filtering observables
      19. Bending time
      20. Bending time to your benefit
      21. Debounce: The bus stop operator
      22. Putting your code into Android
      23. Coffee break
      24. Principles of reactive programming
      25. Events and marble diagrams
      26. Summary
    2. Chapter 2. Networking with observables
      1. RxJava and event streams
      2. Subscribers
      3. RxJava 2 observable types
      4. Subscribing to and converting different observables
      5. What happens when you make a normal network request?
      6. What happens when you make a network request with an observable?
      7. Network request as an observable
      8. Example: An RSS feed aggregator
      9. The feed structure
      10. Getting the data
      11. The combineLatest operator
      12. The Rx code so far
      13. Coffee break
      14. Asynchronous data processing chains
      15. Putting the list in order
      16. The map operator
      17. Brief introduction to immutability
      18. Error handling
      19. Adding more feeds to the client
      20. Summary
    3. Chapter 3. Building data processing chains
      1. Different roles of observables
      2. Events vs. reactive state
      3. Internal state of an observable
      4. Arrow diagrams and different observable types
      5. Example: Credit card validation form
      6. First step: Expiration date
      7. Credit card number type and checksum
      8. CVC code validation
      9. Putting it all together
      10. Coffee break
      11. The abstraction level of reactive programming
      12. How RxJava works
      13. Summary
    4. Chapter 4. Connecting the user interface with networking
      1. Subscriptions explained
      2. Terminating subscriptions
      3. RxJava 2 concepts and subscription management
      4. Advanced Rx chains example: Flickr search client
      5. Setting up the Flickr client project
      6. Overview of the search chain
      7. Step 1: A simple hardcoded search
      8. Making it click
      9. Coffee break
      10. Implementing the reactive chain
      11. How switchMap works
      12. Getting thumbnail information
      13. Step 1: Expand the list into an observable
      14. Step 2: Apply operations to each item individually
      15. Step 3: Collect results
      16. The complete solution
      17. Adding a username from another API
      18. Summary
    5. Chapter 5. Advanced RxJava
      1. Observables and subjects in detail
      2. Example: File browser
      3. User flow of the File Browser app
      4. Getting the file listing for a directory
      5. Threading basics
      6. Threading in functional programming
      7. Changing the thread by using getFileListingObservable
      8. Making the file listing dynamic
      9. Making the list click
      10. Different types of subjects
      11. Using a subject as the FileObservable
      12. Coffee break
      13. Adding buttons for Previous and Root
      14. Expanded graph for Previous and Root
      15. Improved version with cleaner observables
      16. The Previous button
      17. Putting it all together
      18. The detailed graph
      19. The full code so far
      20. Saving and releasing the subscriptions
      21. A final note on subjects
      22. Summary
  8. Part 2. Architectures in RxJava
    1. Chapter 6. Reactive view models
      1. The view layer
      2. Platform containers
      3. View models
      4. The blueprint of a view model
      5. Connecting views and view models
      6. The whole picture
      7. View model lifecycle
      8. Coffee break
      9. View models and the Android lifecycles
      10. The view affinity of the code
      11. Summary
    2. Chapter 7. Reactive architectures
      1. Fundamentals of reactive architectures
      2. Model-View-View model
      3. Reactive model
      4. Retrieving data from the model
      5. Coffee break
      6. Revising the file browser
      7. Constructing the model for the file browser
      8. Using the model
      9. Rules of the model and its consumers
      10. Single source of truth
      11. Coffee break
      12. Persisting app state
      13. BehaviorSubjects and stores
      14. Simple SharedPreferencesStore
      15. Summary
    3. Chapter 8. Developing with view models
      1. View models and the view
      2. Example: Tic-tac-toe
      3. Drawing the game grid
      4. Making it interactive
      5. Events vs. reactive state
      6. Immutable data and the game grid
      7. Adding the code for interaction
      8. Coffee break
      9. Wrapping the logic into a view model
      10. Click coordinate processing
      11. Changing turns
      12. Coffee break
      13. Filtering illegal moves
      14. Winning conditions
      15. One more thing: Restarting the game
      16. Summary
    4. Chapter 9. Expanding existing Rx apps
      1. Working with existing reactive code
      2. The game of Connect Four
      3. Updating grid size and assets
      4. Checking for valid moves
      5. Coffee break
      6. Saving and loading the game
      7. Creating the model
      8. Sharing the model
      9. Loaded games activity
      10. PersistedGameStore
      11. Saving games
      12. Loading games
      13. Summary
    5. Chapter 10. Testing reactive code
      1. Reactive architectures and testing
      2. Test granularity
      3. The pyramid of dependencies
      4. Unit-testing basics
      5. Testing reactive chains
      6. TestObservable class
      7. Synchronous or asynchronous
      8. Coffee break
      9. Writing tests for view models
      10. Choosing what to test
      11. Testing the GameViewModel initial state
      12. Testing partial observable chains
      13. Testing Connect Four drop logic
      14. Summary
  9. Part 3. Advanced RxJava architectures
    1. Chapter 11. Advanced architectures: Chat client 1
      1. Chat client with WebSockets
      2. How to transfer messages
      3. WebSockets
      4. WebSockets as broadcasters
      5. Connecting to the server
      6. ChatMessage structure
      7. Sending ChatMessages
      8. Wrapping listeners into observables
      9. Coffee break
      10. Basic UI
      11. Showing messages
      12. The view model
      13. Accumulating ChatMessages
      14. Putting together message processing
      15. Consuming values from the view model
      16. View model lifecycle
      17. Making the view model lifecycle
      18. Summary
    2. Chapter 12. Advanced architectures: Chat client 2
      1. View models, stores, and the model
      2. Message pending state
      3. Handling state updates
      4. Store as an aggregator
      5. The code for the store
      6. Coffee break
      7. Implementing pending messages
      8. Replacing pending messages with confirmed ones
      9. Updated store code
      10. Pending state handling code
      11. Coffee break
      12. The model
      13. The code for the model
      14. Model lifecycle
      15. Singleton modules
      16. Android tools for production use
      17. Summary
    3. Chapter 13. Transitions with Rx
      1. Transitioning between states
      2. How it should have been
      3. Animation progress using one number
      4. Reactive parametrization
      5. Example: The fan widget
      6. Setting the transformations for the child views
      7. Coffee break
      8. Animating with RxJava and Android
      9. Code changes to FanView
      10. The view model
      11. View model logic
      12. Animating parametrized values in view models
      13. animateTo operator
      14. animateTo operator on Android
      15. Adding a dimmed background
      16. Summary
    4. Chapter 14. Making a maps client
      1. Maps example
      2. Getting started with map tiles
      3. Making an initial view model
      4. Calculating tiles based on zoom level
      5. Using the offset to move tiles
      6. Dragging the map
      7. The code so far
      8. Viewport and hiding tiles
      9. Loading map tiles
      10. Adding zoom-level controls
      11. Adding support for map coordinates
      12. Summary
  10. Appendix. Tutorial for developing on Android
    1. Developing on Android
    2. Android development environment
    3. Installing SDK components
    4. Downloading example projects
    5. Using Git to check out projects
    6. Running the project
    7. Running apps in the virtual device
    8. Android project structure
    9. Android platform components
    10. Summary
  11. Index

Product information

  • Title: RxJava for Android Developers
  • Author(s): Timo Tuominen
  • Release date: May 2019
  • Publisher(s): Manning Publications
  • ISBN: 9781617293368