Created
December 8, 2017 16:20
-
-
Save nazmulidris/5f1f4b5e03e5583891d174263dad2f8d to your computer and use it in GitHub Desktop.
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
| 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