android.arch.lifecycle.MediatorLiveData Java Examples
The following examples show how to use
android.arch.lifecycle.MediatorLiveData.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocalUserDataSource.java From MVVM with MIT License | 7 votes |
@Override public LiveData<Lcee<User>> queryUserByUsername(String username) { final MediatorLiveData<Lcee<User>> data = new MediatorLiveData<>(); data.setValue(Lcee.<User>loading()); data.addSource(userService.queryByUsername(username), new Observer<User>() { @Override public void onChanged(@Nullable User user) { if (null == user) { data.setValue(Lcee.<User>empty()); } else { data.setValue(Lcee.content(user)); } } }); return data; }
Example #2
Source File: ReminderApi.java From EasyNLU with Apache License 2.0 | 6 votes |
private void initialize(final Context context){ executor = Executors.newSingleThreadExecutor(); busyStatus = new MutableLiveData<>(); errorMsg = new MutableLiveData<>(); reminders = new MediatorLiveData<>(); database = ReminderDatabase.buildDatabase(context); reminders.addSource(database.reminderDao().loadAllReminders(), reminders::postValue); executor.execute(() -> { busyStatus.postValue(true); nlu = new ReminderNlu(context); scheduler = new ReminderScheduler(context); busyStatus.postValue(false); Log.i(TAG, "Initialization complete"); }); }
Example #3
Source File: LocalUserDataSource.java From MVVM with MIT License | 6 votes |
@Override public LiveData<Lcee<User>> queryUserByUsername(String username) { final MediatorLiveData<Lcee<User>> data = new MediatorLiveData<>(); data.setValue(Lcee.<User>loading()); data.addSource(userService.queryByUsername(username), new Observer<User>() { @Override public void onChanged(@Nullable User user) { if (null == user) { data.setValue(Lcee.<User>empty()); } else { data.setValue(Lcee.content(user)); } } }); return data; }
Example #4
Source File: LocalProjectDataSource.java From MVVM with MIT License | 6 votes |
@Override public LiveData<Lcee<Projects>> queryProjects(int page) { final MediatorLiveData<Lcee<Projects>> data = new MediatorLiveData<>(); data.setValue(Lcee.<Projects>loading()); data.addSource(projectsService.queryProjects(page), new Observer<Projects>() { @Override public void onChanged(@Nullable Projects projects) { if (null == projects) { data.setValue(Lcee.<Projects>empty()); } else { // parse items from json projects.itemsFromJson(); data.setValue(Lcee.content(projects)); } } }); return data; }
Example #5
Source File: LocalUserDataSource.java From MVVM with MIT License | 6 votes |
@Override public LiveData<Lcee<User>> queryUserByUsername(String username) { final MediatorLiveData<Lcee<User>> data = new MediatorLiveData<>(); data.setValue(Lcee.<User>loading()); data.addSource(userService.queryByUsername(username), new Observer<User>() { @Override public void onChanged(@Nullable User user) { if (null == user) { data.setValue(Lcee.<User>empty()); } else { data.setValue(Lcee.content(user)); } } }); return data; }
Example #6
Source File: LocalUserDataSource.java From MVVM with MIT License | 6 votes |
@Override public LiveData<Lcee<User>> queryUserByUsername(String username) { final MediatorLiveData<Lcee<User>> data = new MediatorLiveData<>(); data.setValue(Lcee.<User>loading()); data.addSource(userService.queryByUsername(username), new Observer<User>() { @Override public void onChanged(@Nullable User user) { if (null == user) { data.setValue(Lcee.<User>empty()); } else { data.setValue(Lcee.content(user)); } } }); return data; }
Example #7
Source File: ReminderViewModel.java From EasyNLU with Apache License 2.0 | 5 votes |
public ReminderViewModel(@NonNull Application application) { super(application); busyStatus = new MediatorLiveData<>(); errorMsg = new MediatorLiveData<>(); reminderText = new MutableLiveData<>(); reminders = new MediatorLiveData<>(); api = ((ReminderApplication)application).getApi(); busyStatus.addSource(api.getBusyStatus(), busyStatus::setValue); reminders.addSource(api.getReminders(), reminders::setValue); errorMsg.addSource(api.getErrorMessages(), errorMsg::setValue); }
Example #8
Source File: LogcatContentRepository.java From Fairy with Apache License 2.0 | 5 votes |
static LiveData<LogcatContent> creat (int id, LiveData<LogcatContent> rawData, String grep) { /** * ${rawData}变量是Source中的MediatorLiveData */ MediatorLiveData<LogcatContent> rawMediaData = (MediatorLiveData) rawData; if (grep.equals("")) { writeClearCache(id, GrepFilter.RAW_SIGNAL); rawMediaData.setValue(clearCache); return rawData; } rawMediaData.setValue(clearCache); return GrepFilter.grepData(rawData, grep); }
Example #9
Source File: ExampleUnitTest.java From Fairy with Apache License 2.0 | 5 votes |
public Holder() { data = new MediatorLiveData<>(); data.addSource(rawData, str -> { data.setValue(str); }); transData.setValue(false); }
Example #10
Source File: MergeResource.java From Fairy with Apache License 2.0 | 4 votes |
MergeResource(AppExecutors executors) { this.executors = executors; result = new MediatorLiveData<>(); }