android-livedata

How to implement a Room LiveData filter

那年仲夏 提交于 2021-02-18 19:34:22
问题 I do not know how to implement a filter query properly inside the Repository and the ViewModel to use it to display the filtered string in a Textview or anything else really. My Entity, Dao, Repository, and ViewModel are as follows: User.kt @Entity(tableName = "user_data") data class User ( @PrimaryKey(autoGenerate = true) val id: Int, @ColumnInfo(name = "name") val name: String ) UserDao.kt @Dao interface UserDao { @Insert fun addUser(user: User) @Query("SELECT name FROM user_data WHERE name

Listening socket.io events and updating LiveData (a class of android.arch.lifecycle)in application class android

主宰稳场 提交于 2021-02-18 19:10:28
问题 I am working on a chat application and Currently I am listening and emitting socket events in an Activity. Now i want to listen all the socket events even when chat activity is not in foreground as i want to store all the messages from different users in the local DB at the same time i want to update LiveData to update UI. In order to achieve this I am listening socket events in the Application class as following: public class ChatApplication extends Application { public Socket mSocket;

Listening socket.io events and updating LiveData (a class of android.arch.lifecycle)in application class android

只谈情不闲聊 提交于 2021-02-18 19:09:57
问题 I am working on a chat application and Currently I am listening and emitting socket events in an Activity. Now i want to listen all the socket events even when chat activity is not in foreground as i want to store all the messages from different users in the local DB at the same time i want to update LiveData to update UI. In order to achieve this I am listening socket events in the Application class as following: public class ChatApplication extends Application { public Socket mSocket;

Listening socket.io events and updating LiveData (a class of android.arch.lifecycle)in application class android

早过忘川 提交于 2021-02-18 19:08:53
问题 I am working on a chat application and Currently I am listening and emitting socket events in an Activity. Now i want to listen all the socket events even when chat activity is not in foreground as i want to store all the messages from different users in the local DB at the same time i want to update LiveData to update UI. In order to achieve this I am listening socket events in the Application class as following: public class ChatApplication extends Application { public Socket mSocket;

Android LiveData: Transformation switchMap: Apply filter on the original list and show the filtered data

泪湿孤枕 提交于 2021-02-11 16:51:27
问题 public class FlightViewModel extends BaseViewModel { private FlightRepository flightRepository; private MediatorLiveData<Resource<FlightSearchMainOuterModel>> mSearchFlights = new MediatorLiveData<>(); private MediatorLiveData<Resource<FlightSearchMainOuterModel>> mOriginalList = new MediatorLiveData<>(); private MediatorLiveData<Resource<FlightSearchMainOuterModel>> mSortedSearchFlights = new MediatorLiveData<>(); public FlightViewModel(@NonNull Application application) { super(application);

Parcelable Model reinstatiates, MVVM Room LiveData

落花浮王杯 提交于 2021-02-11 14:01:17
问题 Here is my problem, I am using mvvm to load profile data from Dao, which was earlier updated when user logs in. Or if a new user an empty model loads. see my BasicProfileFragment and ViewModel. I am using LiveData to update fragment from Dao initially. Next, I want to edit/update the fields in different ways. keyboard input and updating data by Navigating to other fragments. Where data loaded as list from server. For eg. clicking the Gender strip and Navigate to Gender Fragment, Data

Observing MediatorLiveData Issue

穿精又带淫゛_ 提交于 2021-02-11 12:32:23
问题 I have the following LiveData variables in my ViewModel (simplified example): val currentUser : LiveData<UserObject> val allSites : LiveData<ArrayList<SiteObject>> val filterSitesForUser : LiveData<Boolean> val orderSitesByField : LiveData<String> val orderSitesDirection : LiveData<Query.Direction> val searchFilterSitesText : LiveData<String> I'm trying to use MediatorLiveData to have one 'stream' of data connecting to my RecyclerView . I therefore also have the following code in the

Room - LiveData not triggered

喜夏-厌秋 提交于 2021-02-08 10:07:52
问题 I'm trying to work with Room database & LiveData. I have ViewModels which holds LiveData they got from dao. If I update a Transaction , then LiveData<List<Transaction>> is observed ok, but LiveData<Transaction> is not observed at all. How is that possible? What am i doing wrong? public abstract class Dao { @Query("SELECT * FROM transact WHERE deleted = :value") public abstract LiveData<List<Transaction>> allTransactions(boolean value); @Query("SELECT * FROM transact WHERE guid = :guid AND

Room - LiveData not triggered

▼魔方 西西 提交于 2021-02-08 10:05:42
问题 I'm trying to work with Room database & LiveData. I have ViewModels which holds LiveData they got from dao. If I update a Transaction , then LiveData<List<Transaction>> is observed ok, but LiveData<Transaction> is not observed at all. How is that possible? What am i doing wrong? public abstract class Dao { @Query("SELECT * FROM transact WHERE deleted = :value") public abstract LiveData<List<Transaction>> allTransactions(boolean value); @Query("SELECT * FROM transact WHERE guid = :guid AND

How to databind livedata object (android)

感情迁移 提交于 2021-02-08 09:56:50
问题 Today I've some question about mvvm and databinding on android, I'm trying to bind object properties on view. I've an Object (Model) with some properties, by example : public String name; public String title; public int value; I've a ViewModel with livedata like this : MutableLiveData<Object> _obj = new MutableLiveData<>(); public LiveData<Object> obj = _obj; And, at last, I've a view like this : <layout> <data> <variable name="viewModel"> type="com.sample.app.viewmodels.MainViewModel" /> <