Skip to content

Instantly share code, notes, and snippets.

@nazmulidris
Created December 8, 2017 16:20
Show Gist options
  • Select an option

  • Save nazmulidris/5f1f4b5e03e5583891d174263dad2f8d to your computer and use it in GitHub Desktop.

Select an option

Save nazmulidris/5f1f4b5e03e5583891d174263dad2f8d to your computer and use it in GitHub Desktop.
class CounterLiveData extends MutableLiveData<Long> {
public String toString() {
return String.format("count=%d", getValue());
}
public Long get() {
return getValue() == null ? 0L : getValue();
}
public void set(Long value) {
if (Looper.getMainLooper().equals(Looper.myLooper())) {
// UI thread
setValue(value);
} else {
// Non UI thread
postValue(value);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment