Category : mediatorlivedata

I want to display favored items from two tables: Item and ItemMoto. Both tables share same table Favourite. Portion of files are" FavouriteListFragment.java public class FavouriteListFragment extends PSFragment implements DataBoundListAdapter.DiffUtilDispatchedInterface { private final androidx.databinding.DataBindingComponent dataBindingComponent = new FragmentDataBindingComponent(this); private FavouriteViewModel favouriteViewModel; private FavouriteMotoViewModel favouriteViewModelMoto; @VisibleForTesting private AutoClearedValue<FragmentFavouriteListBinding> binding; private AutoClearedValue<ItemVerticalListAdapter> adapter; private AutoClearedValue<ItemAutoVerticalListAdapter> adapterMoto; @Override ..

Read more

I’ve moved my mediator and mutable live data in abstract class because of the need to reuse it. Now, whenever my class, that extends my abstract class, changes dataMutable value, dataMediator.addSource() doesn’t get triggered. I’ve even written println("dataMediator.addSource()") which never gets called. When those methods where in my main class, everything worked fine. What am ..

Read more

Basically, I am fetching the products list from this API using Retrofit into a MediatorLiveData inside ProductsRepository class. But, the problem is, when I try to observe the LiveData I get null. Here is my code snippet: ProductsRepository: @MainScope class ProductsRepository @Inject constructor(private val productsApi: ProductsApi) { private val products: MediatorLiveData<ProductsResource<List<ProductsModel>>> = MediatorLiveData() fun getProducts(): ..

Read more

I’m posting my room query result using the below code _data.postValue(databaseImpl.findRepoById(id).value) But it seems the returned object is empty. I’m guessing we need to observe databaseImpl.findRepoById(id), not access it directly but since it’s in a viewmodel I don’t have a lifecycleOwner to assign to the room query livedata. databaseImpl.observe(this, Observer { //!!this is modelview and ..

Read more

I have two classes Route and Station, Route has an ArrayList<Station>, see the definitions below @Entity(foreignKeys = @ForeignKey(entity = Route.class, parentColumns = "routeId", childColumns = "routeIdForeignKey onDelete = ForeignKey.CASCADE)) public class Station { @PrimaryKey(autoGenerate = true) private Long stationId; @SerializedName("stationName") @Expose private String stationName; @SerializedName("streetName") @Expose private String streetName; @SerializedName("arrivalHour") @Expose private String arrivalHour; @SerializedName("departureHour") ..

Read more

I have two livedatas startedAt & finishedAt and want to use them in a transformation that depend on both these values…i tried combine them using mediatorliveData fun <A, B> LiveData<A>.combine(other: LiveData<B>): PairLiveData<A, B> { return PairLiveData(this, other) } class PairLiveData<A, B>(first: LiveData<A>, second: LiveData<B>) : MediatorLiveData<Pair<A?, B?>>() { init { addSource(first) { value = it ..

Read more