Skip to content

Instantly share code, notes, and snippets.

@erfanegtfi
Created April 16, 2020 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erfanegtfi/08e16e519d6faa12b006ee9f46ecc951 to your computer and use it in GitHub Desktop.
Save erfanegtfi/08e16e519d6faa12b006ee9f46ecc951 to your computer and use it in GitHub Desktop.
observe on list events add, remove ...
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