ursus
07/13/2019, 10:42 PMflorent
07/13/2019, 10:45 PMursus
07/13/2019, 10:46 PMAl Warren
07/13/2019, 10:47 PMursus
07/13/2019, 10:48 PMAl Warren
07/13/2019, 10:48 PMursus
07/13/2019, 10:49 PMAl Warren
07/13/2019, 10:54 PMsealed class State {
object InFlight: State()
object Complete: State()
object Idle: State()
object Gone: State()
}
InFlight means the process is running, Complete means it finished, Idle means no work is occuring, and Gone means the "observable" is gone. A state object is observed by the fragment which reacts to changes.ursus
07/13/2019, 10:55 PMAl Warren
07/13/2019, 10:59 PMursus
07/13/2019, 10:59 PMAl Warren
07/13/2019, 11:00 PMursus
07/13/2019, 11:01 PMfun fetchNewPage()
= api.newPage(page + 1)
.flatMap { db.insert(it) }
Al Warren
07/13/2019, 11:02 PMursus
07/13/2019, 11:02 PMAl Warren
07/13/2019, 11:03 PMursus
07/13/2019, 11:04 PMAl Warren
07/13/2019, 11:05 PMursus
07/13/2019, 11:08 PMAl Warren
07/13/2019, 11:37 PMursus
07/13/2019, 11:43 PMAl Warren
07/13/2019, 11:44 PMursus
07/13/2019, 11:44 PMAl Warren
07/13/2019, 11:48 PMursus
07/13/2019, 11:50 PMAl Warren
07/13/2019, 11:50 PMursus
07/13/2019, 11:52 PMViewModel {
fun doSomething() {
repository.updateSomething()
val freshList = repository.querySomethings()
// somehow push the freshList to the ui
}
}
Al Warren
07/13/2019, 11:52 PMursus
07/13/2019, 11:53 PMAl Warren
07/13/2019, 11:53 PMursus
07/13/2019, 11:55 PMAl Warren
07/13/2019, 11:55 PMursus
07/13/2019, 11:56 PMAl Warren
07/13/2019, 11:57 PMursus
07/13/2019, 11:57 PMAl Warren
07/13/2019, 11:58 PMursus
07/13/2019, 11:59 PMAl Warren
07/13/2019, 11:59 PMursus
07/14/2019, 12:00 AMAl Warren
07/14/2019, 12:00 AMursus
07/14/2019, 12:00 AMAl Warren
07/14/2019, 12:01 AMursus
07/14/2019, 12:02 AMAl Warren
07/14/2019, 12:02 AMursus
07/14/2019, 12:03 AMAl Warren
07/14/2019, 12:04 AMursus
07/14/2019, 12:06 AMAl Warren
07/14/2019, 12:08 AMursus
07/14/2019, 12:09 AMAl Warren
07/14/2019, 12:09 AMursus
07/14/2019, 12:10 AMAl Warren
07/14/2019, 12:28 AMvar stateChangeListener: (T) -> Unit = { }
// when data or list changes
// set a state then
onSomeOtherListener { stateChangeListener(state) }
In your UI/Fragment/Whatever
yourAdapter.stateChangeListener = ::stateChanged
private fun stateChanged(state: State) {
// do something with state
}
Just a thought.ursus
07/14/2019, 12:43 AMAl Warren
07/14/2019, 12:45 AMursus
07/14/2019, 12:46 AMAl Warren
07/14/2019, 12:48 AMursus
07/14/2019, 12:48 AMAl Warren
07/14/2019, 12:49 AMursus
07/14/2019, 12:55 AMfun refresh() {
statusRelay.accept(Status.STARTED)
call the api
insert new data <------------ db query emits automatically here !
statusRelay.accept(Status.SUCCESS)
}
statusRelay.accept(Status.SUCCESS)
Observable.combineLatest(queryObservable, stateObservable)
Observable.combineLatest(queryObservable.filter { !queryRefreshBlocked }, stateObservable)˛
Al Warren
07/14/2019, 12:57 AMursus
07/14/2019, 12:58 AMAl Warren
07/14/2019, 12:59 AM2nd page; started <--- invalid
ursus
07/14/2019, 12:59 AMAl Warren
07/14/2019, 1:00 AMursus
07/14/2019, 1:00 AMAl Warren
07/14/2019, 1:02 AMursus
07/14/2019, 1:02 AMt0: 1st page; started
t1.000000 2nd page; started <--- invalid
t1,000001 2nd page; success
Al Warren
07/14/2019, 1:04 AMursus
07/14/2019, 1:04 AMObservable.combineLatest(
queryObservable,
paginationStateObservable
)
Al Warren
07/14/2019, 1:06 AMursus
07/14/2019, 1:07 AMAl Warren
07/14/2019, 1:09 AMEric Martori
07/14/2019, 9:29 AM{ Started, Success }
states are actually UI logic for showing/hiding the loader (if I understand correctly) this logic should be in the UI layer. If it is not possible to filter the observable to only emit values to the UI when the list actually changes this logic should be in the UI. In the UI layer you already know what items you are displaying in therefore can compare them with the data in the observable. If the received data is different from the currently displayed data the Loader should be hidden.Al Warren
07/14/2019, 12:14 PMursus
07/14/2019, 6:19 PMEric Martori
07/14/2019, 8:32 PMursus
07/14/2019, 9:39 PMdewildte
07/15/2019, 12:14 AMursus
07/15/2019, 12:28 AMAl Warren
07/15/2019, 12:21 PMursus
07/15/2019, 2:54 PM