Created
April 16, 2020 20:57
-
-
Save erfanegtfi/08e16e519d6faa12b006ee9f46ecc951 to your computer and use it in GitHub Desktop.
observe on list events add, remove ...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LiveDataList<T> extends LiveData<List<T>> { | |
public void addAll(List<T> items) { | |
if (getValue() != null && items != null) { | |
getValue().addAll(items); | |
setValue(getValue()); | |
} | |
} | |
public void clear() { | |
if (getValue() != null) { | |
getValue().clear(); | |
setValue(getValue()); | |
} | |
} | |
@Override | |
public void setValue(List<T> value) { | |
super.setValue(value); | |
} | |
public void removeValue(T value) { | |
if (getValue() != null) { | |
getValue().remove(value); | |
} | |
} | |
public void addValue(T value) { | |
if (getValue() != null) { | |
getValue().add(value); | |
} | |
} | |
@Nullable | |
@Override | |
public List<T> getValue() { | |
return super.getValue(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment