You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to combine this with RxPreferences. I have a List stored as shared preferences and every time this pref object gets updated I want the recycler view (using this library) to be updated as well. Think of Whatsapp chats example where when a new message comes it updated the list but all data it stored internally (shared prefs in this example).
I'm currently using this code to solve my problem (which kinda works perfectly):
val chatsPref = rxSharedPreferences.getObject("chats", emptyList(), ChatsPreferenceAdapter(gson))
val chats = chatsPref.get()
val rxDataSource = RxDataSource<ChatItemBinding, Chat>(R.layout.chat_item, chats)
disposables.add(
rxDataSource.asObservable()
.subscribe {
val item = it.item!!
val binding = it.viewDataBinding!!
binding.tvMessage.text = item.message
}
)
disposables.add(chatsPref.asObservable()
.subscribe {
rxDataSource.updateDataSet(it).updateAdapter()
}
)
You can see that in this, I'm first extracting the initial value of chats using chatsPref.get() and then initializing my RxDataSource object using that and then in the last few lines, using the observable stream of the preference item to let the data source update. Is there a way I can cut down the lines to directly pass chatsPref.asObservable() into RxDataSource during initialization to avoid all these extra steps?
The text was updated successfully, but these errors were encountered:
mohsin
changed the title
[Question] How to pass a Rx stream as dataset instead?
[Question] How to pass a Rx stream as the dataset instead?
Jan 15, 2020
mohsin
changed the title
[Question] How to pass a Rx stream as the dataset instead?
[Question] How to pass an Rx obserable as the dataset instead?
Jan 15, 2020
I'm trying to combine this with RxPreferences. I have a List stored as shared preferences and every time this pref object gets updated I want the recycler view (using this library) to be updated as well. Think of Whatsapp chats example where when a new message comes it updated the list but all data it stored internally (shared prefs in this example).
I'm currently using this code to solve my problem (which kinda works perfectly):
You can see that in this, I'm first extracting the initial value of chats using chatsPref.get() and then initializing my RxDataSource object using that and then in the last few lines, using the observable stream of the preference item to let the data source update. Is there a way I can cut down the lines to directly pass chatsPref.asObservable() into RxDataSource during initialization to avoid all these extra steps?
The text was updated successfully, but these errors were encountered: