定 價:¥49.00
作 者: | 李衍順 著 |
出版社: | 電子工業(yè)出版社 |
叢編項: | |
標 簽: | 暫缺 |
ISBN: | 9787121336409 | 出版時間: | 2018-03-01 | 包裝: | |
開本: | 頁數(shù): | 字數(shù): |
第1章 走進RxJava的世界 .......................................................................................................... 1
1.1 響應(yīng)式編程.......................................................................................................................... 1
1.2 什么是RxJava................................................................................................................ 4
1.3 Observable和Subscriber ............................................................................................... 5
1.3.1 Single:單個數(shù)據(jù)的生產(chǎn)者 ........................................................................................... 8
1.3.2 Completable:單個事件的生產(chǎn)者 .................................................................................. 9
1.4 在Android工程中引入RxJava .................................................................................. 11
第2章 RxJava中的操作符 ..................................................................................................... 12
2.1 創(chuàng)建Observable的操作符 .......................................................................................... 12
2.1.1 range ........................................................................................................................... 13
2.1.2 defer和just ................................................................................................................. 13
2.1.3 from ............................................................................................................................ 16
2.1.4 interval ........................................................................................................................ 17
2.1.5 repeat和timer ............................................................................................................. 19
2.2 轉(zhuǎn)化Observable的操作符 .......................................................................................... 21
2.2.1 buffer .......................................................................................................................... 21
2.2.2 flatMap ....................................................................................................................... 23
2.2.3 groupBy ...................................................................................................................... 25
2.2.4 map............................................................................................................................ 28
2.2.5 cast ............................................................................................................................. 29
2.2.6 scan ............................................................................................................................ 31
2.2.7 window ....................................................................................................................... 32
2.3 過濾操作符 .................................................................................................................. 35
2.3.1 debounce ..................................................................................................................... 35
2.3.2 distinct ........................................................................................................................ 39
2.3.3 elementAt .................................................................................................................... 40
2.3.4 filter ............................................................................................................................ 41
2.3.5 first和last ................................................................................................................... 43
2.3.6 skip和take,skipLast和takeLast ................................................................................ 45
2.3.7 sample和throttleFirst .................................................................................................. 46
2.4 組合操作符 .................................................................................................................. 48
2.4.1 combineLatest .............................................................................................................. 48
2.4.2 join和groupJoin ......................................................................................................... 51
2.4.3 merge和mergeDelayError............................................................................................ 55
2.4.4 startWith...................................................................................................................... 58
2.4.5 switch ......................................................................................................................... 59
2.4.6 zip和zipWith .............................................................................................................. 61
2.5 錯誤處理操作符 .......................................................................................................... 64
2.5.1 onErrorReturn .............................................................................................................. 64
2.5.2 onErrorResumeNext ..................................................................................................... 66
2.5.3 onExceptionResumeNext .............................................................................................. 67
2.5.4 retry ............................................................................................................................ 70
2.6 輔助操作符 .................................................................................................................. 72
2.6.1 delay ........................................................................................................................... 72
2.6.2 do ............................................................................................................................... 74
2.6.3 materialize和dematerialize .......................................................................................... 78
2.6.4 subscribeOn和observeOn ............................................................................................ 80
2.6.5 timeInterval和timeStamp ............................................................................................ 82
2.6.6 timeout ........................................................................................................................ 84
2.6.7 using ........................................................................................................................... 87
2.7 條件操作 ...................................................................................................................... 90
2.7.1 all ............................................................................................................................... 90
2.7.2 amb............................................................................................................................ 92
2.7.3 contains ....................................................................................................................... 93
2.7.4 isEmpty ....................................................................................................................... 94
2.7.5 defaultIfEmpty ............................................................................................................. 95
2.7.6 sequenceEqual ............................................................................................................. 97
2.7.7 skipUntil和skipWhile ................................................................................................. 98
2.7.8 takeUntil和takeWhile ............................................................................................... 100
2.8 聚合操作符 ................................................................................................................ 102
2.8.1 concat ....................................................................................................................... 102
2.8.2 count ......................................................................................................................... 104
2.8.3 reduce ....................................................................................................................... 105
2.8.4 collect ....................................................................................................................... 106
2.9 與Connectable Observable相關(guān)的操作符 ............................................................... 107
2.9.1 publish和connect ...................................................................................................... 108
2.9.2 refCount .................................................................................................................... 110
2.9.3 replay ........................................................................................................................ 111
2.10 自定義操作符 .......................................................................................................... 114
2.10.1 lift ........................................................................................................................... 115
2.10.2 compose .................................................................................................................. 117
第3章 使用Scheduler進行線程調(diào)度 ................................................................................. 119
3.1 什么是Scheduler ....................................................................................................... 119
3.2 Scheduler的類型 ....................................................................................................... 121
3.2.1 computation ............................................................................................................... 121
3.2.2 newThread ................................................................................................................. 122
3.2.3 io .............................................................................................................................. 122
3.2.4 immediate .................................................................................................................. 123
3.2.5 trampoline ................................................................................................................. 123
3.2.6 from .......................................................................................................................... 123
3.3 總結(jié) ............................................................................................................................ 125
第4章 RxJava的實現(xiàn)原理 ................................................................................................... 126
4.1 數(shù)據(jù)的發(fā)送和接收 .................................................................................................... 126
4.1.1 創(chuàng)建Observable的過程 ............................................................................................. 127
4.1.2 訂閱的過程 ............................................................................................................... 128
4.2 操作符的實現(xiàn) ............................................................................................................ 130
4.2.1 lift的工作原理 .......................................................................................................... 130
4.2.2 map的工作原理 ........................................................................................................ 132
4.2.3 flatMap的工作原理 ................................................................................................... 135
4.2.4 merge的工作原理 ..................................................................................................... 136
4.2.5 concat的工作原理 ..................................................................................................... 139
4.3 Scheduler的工作原理 ............................................................................................... 144
4.3.1 Scheduler源碼 .......................................................................................................... 144
4.3.2 subscribeOn的工作原理 ............................................................................................ 152
4.3.3 observeOn的工作原理 .............................................................................................. 156
第5章 RxJava的應(yīng)用實例 ................................................................................................... 161
5.1 計算π的值 ................................................................................................................ 161
5.2 圖片的三級緩存 ........................................................................................................ 165
5.2.1 內(nèi)存緩存 .................................................................................................................. 167
5.2.2 外存緩存 .................................................................................................................. 169
5.2.3 網(wǎng)絡(luò)緩存 .................................................................................................................. 172
5.2.4 緩存管理 .................................................................................................................. 173
5.2.5 封裝.......................................................................................................................... 176
5.2.6 運行測試 .................................................................................................................. 178
5.3 結(jié)合Retrofit和OkHttp訪問網(wǎng)絡(luò) ............................................................................ 181
5.3.1 卡片類的定義 ........................................................................................................... 181
5.3.2 配置OkHttp .............................................................................................................. 183
5.3.3 配置Retrofit.............................................................................................................. 186
5.4 使用RxLifecycle避免內(nèi)存泄漏 ............................................................................... 189
5.4.1 修改demo工程 .................................................................................................... 189
5.4.2 綁定其他生命周期 ................................................................................................ 191
5.5 使用RxBinding綁定各種View事件....................................................................... 193
5.5.1 綁定點擊事件 ...................................................................................................... 194
5.5.2 綁定TextWatcher .................................................................................................. 196
5.5.3 綁定OnPageChangeListener ................................................................................... 197
第6章 RxJava 2的改進 ....................................................................................................... 200
6.1 Observable和Flowable ............................................................................................. 200
6.2 null的使用 ................................................................................................................. 203
6.3 Single和Completable ................................................................................................ 205
6.4 Maybe ......................................................................................................................... 207
6.5 Subscriber ................................................................................................................... 208
6.5.1 DefaultSubscriber .................................................................................................. 209
6.5.2 ResourceSubscriber ................................................................................................ 210
6.5.3 DisposableSubscriber ............................................................................................. 211
6.6 Action和Function ..................................................................................................... 212
6.7 錯誤處理 .................................................................................................................... 214
6.8 Scheduler .................................................................................................................... 216