mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-17 22:43:33 +02:00
Updated AndroidX lifecycle
This commit is contained in:
@@ -38,25 +38,25 @@ import java.util.Map;
|
||||
* is called for either of them, we set a new value in {@code liveDataMerger}.
|
||||
*
|
||||
* <pre>
|
||||
* LiveData<Integer> liveData1 = ...;
|
||||
* LiveData<Integer> liveData2 = ...;
|
||||
* LiveData<Integer> liveData1 = ...;
|
||||
* LiveData<Integer> liveData2 = ...;
|
||||
*
|
||||
* MediatorLiveData<Integer> liveDataMerger = new MediatorLiveData<>();
|
||||
* liveDataMerger.addSource(liveData1, value -> liveDataMerger.setValue(value));
|
||||
* liveDataMerger.addSource(liveData2, value -> liveDataMerger.setValue(value));
|
||||
* MediatorLiveData<Integer> liveDataMerger = new MediatorLiveData<>();
|
||||
* liveDataMerger.addSource(liveData1, value -> liveDataMerger.setValue(value));
|
||||
* liveDataMerger.addSource(liveData2, value -> liveDataMerger.setValue(value));
|
||||
* </pre>
|
||||
* <p>
|
||||
* Let's consider that we only want 10 values emitted by {@code liveData1}, to be
|
||||
* merged in the {@code liveDataMerger}. Then, after 10 values, we can stop listening to {@code
|
||||
* liveData1} and remove it as a source.
|
||||
* <pre>
|
||||
* liveDataMerger.addSource(liveData1, new Observer<Integer>() {
|
||||
* liveDataMerger.addSource(liveData1, new Observer<Integer>() {
|
||||
* private int count = 1;
|
||||
*
|
||||
* {@literal @}Override public void onChanged(@Nullable Integer s) {
|
||||
* count++;
|
||||
* liveDataMerger.setValue(s);
|
||||
* if (count > 10) {
|
||||
* if (count > 10) {
|
||||
* liveDataMerger.removeSource(liveData1);
|
||||
* }
|
||||
* }
|
||||
@@ -70,8 +70,24 @@ public class MediatorLiveData<T> extends MutableLiveData<T> {
|
||||
private SafeIterableMap<LiveData<?>, Source<?>> mSources = new SafeIterableMap<>();
|
||||
|
||||
/**
|
||||
* Starts to listen the given {@code source} LiveData, {@code onChanged} observer will be called
|
||||
* when {@code source} value was changed.
|
||||
* Creates a MediatorLiveData with no value assigned to it.
|
||||
*/
|
||||
public MediatorLiveData() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a MediatorLiveData initialized with the given {@code value}.
|
||||
*
|
||||
* @param value initial value
|
||||
*/
|
||||
public MediatorLiveData(T value) {
|
||||
super(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts to listen to the given {@code source} LiveData, {@code onChanged} observer will be
|
||||
* called when {@code source} value was changed.
|
||||
* <p>
|
||||
* {@code onChanged} callback will be called only when this {@code MediatorLiveData} is active.
|
||||
* <p> If the given LiveData is already added as a source but with a different Observer,
|
||||
|
||||
Reference in New Issue
Block a user