Android’s Architecture Components Version 0.10

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Author(s): Mark L. Murphy
Edition: 0.10
Publisher: Commonsware LLC
Year: 2018

Language: English
Pages: 425
Tags: android, commonsware, mark murphy, kotlin

Table of Contents......Page 4
How the Book Is Structured......Page 10
What’s New in Version 0.10?......Page 11
Warescription......Page 12
Source Code and Its License......Page 13
Acknowledgments......Page 14
Wrenching Relations Into Objects......Page 18
Room Requirements......Page 19
Entities......Page 20
DAO......Page 22
Database......Page 24
Get a Room......Page 26
Writing Instrumentation Tests......Page 28
Using In-Memory Databases......Page 30
Importing Starter Data......Page 31
Writing Unit Tests via Mocks......Page 32
Configuring Entities......Page 38
Auto-Generated Primary Keys......Page 39
Composite Primary Keys......Page 40
Adding Indexes......Page 41
Ignoring Fields......Page 42
Custom Table and Column Names......Page 44
Indexing......Page 47
DAOs and Queries......Page 48
Adding Parameters......Page 49
What You Can Return......Page 50
Breadth of Results......Page 51
Aggregate Functions......Page 53
Dynamic Queries......Page 54
@RawQuery......Page 55
Other DAO Operations......Page 56
Conflict Resolution......Page 57
Other Operations......Page 58
Custom Methods......Page 59
On @Query Methods......Page 60
Threads and Room......Page 61
Type Converters......Page 62
Setting Up a Type Converter......Page 63
Example: Dates and Times......Page 64
Example: Locations......Page 66
Example: Simple Collections......Page 67
Example: Locations......Page 70
Simple vs. Prefixed......Page 72
Updating the Trip Sample......Page 73
The Classic ORM Approach......Page 78
A History of Threading Mistakes......Page 79
Cascades on Updates and Deletes......Page 80
The Domain Model......Page 81
The New Entities......Page 82
The Updated DAO and Database......Page 86
Self-Referential Relations for Tree Structures......Page 89
Using @Relation......Page 91
Representing No Relation......Page 93
“Can’t You See That This is a Facade?”......Page 96
Other ORMs......Page 97
Get a Factory......Page 98
Add a Callback......Page 100
Get a Helper......Page 101
Get the Rest......Page 102
Getting a Database......Page 103
Using the Database......Page 104
What’s a Migration?......Page 108
But First, a Word About Exporting Schemas......Page 109
Writing Migrations......Page 112
Employing Migrations......Page 117
Testing Migrations......Page 119
Adding the Schemas......Page 120
Setting Up the Helper......Page 121
Creating a Database for a Schema Version......Page 122
Testing a Migration......Page 123
Migrating Under Protest......Page 124
SQLCipher for Android......Page 126
Adding the Dependency......Page 127
Passphrase Management......Page 128
More to Come!......Page 129
Lifecycle......Page 132
Adding the Lifecycle Components......Page 133
…From a FragmentActivity or a Support Fragment......Page 134
…From Anything Else......Page 135
Observing a Lifecycle......Page 136
Ordinary Activities and Fragments, and Other Objects......Page 137
Pre-Java 8......Page 139
So, What’s the Point of This?......Page 141
Observables Are the New Black......Page 142
Observer......Page 143
Implementing LiveData......Page 144
State Transitions......Page 145
Retaining the LiveData......Page 147
Event Bus......Page 150
Room......Page 151
Testing LiveData......Page 152
ViewModels, As Originally Envisioned......Page 154
…Saved Instance State......Page 155
Mommy, Where Do ViewModels Come From?......Page 156
ViewModels, Google’s Way......Page 157
Defining a ViewModel......Page 158
Using the ViewModel......Page 159
ViewModels as Simple POJOs......Page 160
Getting a ViewModel......Page 161
Scenario: Tabbed Editor......Page 163
The ViewModel......Page 164
The Layouts......Page 167
The Activity and Tabs......Page 169
The Paging......Page 175
ProcessLifecycleOwner......Page 178
Wait… Where Are LifecycleProvider and LifecycleReceiver?......Page 182
New Layout Resource Structure......Page 184
Adapters......Page 185
Binding from Code......Page 186
LiveData Updating Data Binding......Page 187
Updating Observables......Page 188
Binding to LiveData......Page 191
Handling Changes to LiveData......Page 193
The Saved Instance State Situation......Page 195
Existing Model......Page 198
New Model......Page 199
Where Should We Use WorkManager?......Page 200
WorkManager Dependencies......Page 201
Workers: They Do Work......Page 202
Work Inputs......Page 204
Constrained Work......Page 205
Tagged Work......Page 206
Getting the Status Updates......Page 207
Consuming the Status Updates… In Code......Page 208
Consuming the Status Updates… In Data Binding......Page 210
Canceling Work......Page 211
Parallel Work......Page 212
How Do We Chain Work?......Page 213
OK, Where’s the Code?......Page 214
How Complex Can This Get?......Page 218
Unique Work......Page 219
Testing Work......Page 220
Implementing a Join Entity......Page 226
Static Entity Classes......Page 227
Foreign Keys and Indices......Page 229
Adding and Removing Relations......Page 230
Fetching Via the Join......Page 231
Where’s That Good Ol’ Object Feel?......Page 232
Polymorphism With Separate Tables......Page 234
Polymorphism With a Single Table......Page 239
Polymorphism With M:N Relations......Page 243
The Bucket Brigade......Page 244
Mapping Data to Data......Page 245
Writing a Transformation......Page 247
Do We Really Want This?......Page 249
Adding RxJava......Page 252
The InstantTaskExecutorRule......Page 253
Rx Query Response Types......Page 254
What Happens… Normally?......Page 255
What Happens… When the Data is Updated?......Page 256
Single......Page 257
Maybe......Page 258
Applying This to Your UI......Page 259
@RawQuery and Reactive Responses......Page 260
The Classic Approach......Page 262
Bridging RxJava and LiveData......Page 263
From RxJava to LiveData......Page 264
From LiveData to RxJava......Page 265
The Semi-Deprecated Solution: RxLifecycle......Page 266
The Problem......Page 268
The Classic Solution: SQLiteAssetHelper......Page 269
Merging SQLiteAssetHelper with Room......Page 270
The Problem: Too Much Data......Page 274
Enter the Paging Library......Page 275
PagedListAdapter......Page 276
The Dependency......Page 277
The Entity, DAO, and Database......Page 278
The ViewModel......Page 281
The PagedListAdapter......Page 282
The CitiesFragment......Page 284
The Results......Page 285
What About RxJava?......Page 286
No Dirty Data......Page 290
Thread Safety......Page 291
Partial Immutability Problems......Page 292
Some Things Want Setters......Page 293
Garbage, To Be Collected......Page 294
Immutability via AutoValue......Page 295
AutoValue and LiveData......Page 297
AutoValue and Room......Page 298
What the Repository Does......Page 300
Normalizes Model Objects......Page 301
Isolates Rest of App from Strategy Changes......Page 302
Network + Network API Caching......Page 303
Persistence-Only......Page 304
API......Page 305
Implementation......Page 306
Managing the Observables......Page 308
Saving State......Page 310
The Factory......Page 311
The UI......Page 312
The Menu......Page 314
The Event Flow......Page 317
Blending Data Sources......Page 318
Pwned Passwords......Page 319
score()......Page 320
Integrating PwnedCheck......Page 323
Modifying the Model......Page 324
Validating the Passphrase......Page 325
GUI Architectures......Page 328
Avoiding Known Problems......Page 329
Consistency Over Time......Page 330
Atypical Apps......Page 331
No Obvious User Benefit......Page 332
A Rough Comparison of GUI Architectures......Page 333
The Basics of Model-View-Intent......Page 336
What’s a View State?......Page 337
Where Does the “Intent” Thing Show Up?......Page 338
Additional MVI Resources......Page 340
The Roster......Page 342
The Viewer......Page 348
The Editor......Page 349
MVI and the Sample App......Page 350
The Model......Page 351
The View State......Page 353
The View......Page 355
Receiving View States......Page 356
Rendering View States......Page 357
The Actions......Page 359
Publishing Actions......Page 363
The Repositories......Page 365
ToDoRepository......Page 366
FilterModeRepository......Page 369
The Controller......Page 370
Doing the Work and Publishing Results......Page 371
add()/modify()/delete()......Page 372
select()/unselect()/unselectAll()......Page 373
About Those Results......Page 374
Subscribing to Results......Page 376
Merging Results Into the ViewState......Page 377
DisplayFragment......Page 381
Summary......Page 382
Plan A: The Whole Directory......Page 386
Plan B: Just SQLite’s Files......Page 387
When You Feel Like It......Page 388
A Simple Close......Page 389
Triggering the Operation......Page 390
Our UI......Page 392
Performing the Operation......Page 395
Areas for Improvement......Page 396
Backing Up Off-Device......Page 397
What Is FTS?......Page 398
The FTS Recipe......Page 399
RawQuery the Table......Page 400
The Book......Page 401
The Data Model......Page 402
The Database......Page 404
The Searches......Page 409
The Repository......Page 411
The ViewModels......Page 412
The UI......Page 413
The Results......Page 419
When To Make Changes......Page 422
Example: Turbo Boost Mode......Page 423