use of androidx.lifecycle.MutableLiveData in project CloudReader by youlookwhat.
the class SearchViewModel method loadGankData.
public MutableLiveData<GankIoDataBean> loadGankData(String keyWord) {
final MutableLiveData<GankIoDataBean> data = new MutableLiveData<>();
Disposable subscribe = HttpClient.Builder.getGankIOServer().searchGank(gankPage, mType, keyWord).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<GankIoDataBean>() {
@Override
public void accept(GankIoDataBean bean) throws Exception {
if (bean == null || bean.getResults() == null || bean.getResults().size() <= 0) {
data.setValue(null);
} else {
data.setValue(bean);
}
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
if (mPage > 1) {
mPage--;
}
data.setValue(null);
}
});
addDisposable(subscribe);
return data;
}
use of androidx.lifecycle.MutableLiveData in project collect by opendatakit.
the class AudioRecorderRecordingStatusHandlerTest method onIsRecordingChangedBlocked_listensToCurrentSession.
@Test
public void onIsRecordingChangedBlocked_listensToCurrentSession() {
MutableLiveData<RecordingSession> liveData = new MutableLiveData<>(null);
when(audioRecorder.getCurrentSession()).thenReturn(liveData);
Consumer<Boolean> listener = mock(Consumer.class);
provider.onBlockedStatusChange(listener);
verify(listener).accept(false);
liveData.setValue(new RecordingSession("blah", null, 0, 0, false));
verify(listener).accept(true);
}
use of androidx.lifecycle.MutableLiveData in project collect by opendatakit.
the class BarcodeViewDecoder method waitForBarcode.
public LiveData<BarcodeResult> waitForBarcode(DecoratedBarcodeView view) {
MutableLiveData<BarcodeResult> liveData = new MutableLiveData<>();
view.decodeContinuous(new BarcodeCallback() {
@Override
public void barcodeResult(BarcodeResult result) {
liveData.setValue(result);
}
@Override
public void possibleResultPoints(List<ResultPoint> resultPoints) {
}
});
return liveData;
}
use of androidx.lifecycle.MutableLiveData in project Signal-Android by WhisperSystems.
the class LiveDataUtil method delay.
/**
* After {@param delay} ms after observation, emits a single Object, {@param value}.
*/
public static <T> LiveData<T> delay(long delay, T value) {
return new MutableLiveData<T>() {
boolean emittedValue;
@Override
protected void onActive() {
if (emittedValue)
return;
new Handler(Looper.getMainLooper()).postDelayed(() -> setValue(value), delay);
emittedValue = true;
}
};
}
use of androidx.lifecycle.MutableLiveData in project collect by opendatakit.
the class AudioVideoImageTextLabelTest method withText_andAudio_playingAudio_highlightsText.
@Test
public void withText_andAudio_playingAudio_highlightsText() {
MutableLiveData<Boolean> isPlaying = new MutableLiveData<>();
when(audioHelper.setAudio(any(AudioButton.class), any())).thenReturn(isPlaying);
AudioVideoImageTextLabel audioVideoImageTextLabel = new AudioVideoImageTextLabel(activity);
audioVideoImageTextLabel.setText("blah", false, 16);
audioVideoImageTextLabel.setAudio("file://audio.mp3", audioHelper);
int originalTextColor = audioVideoImageTextLabel.getLabelTextView().getCurrentTextColor();
isPlaying.setValue(true);
int textColor = audioVideoImageTextLabel.getLabelTextView().getCurrentTextColor();
assertThat(textColor, not(equalTo(originalTextColor)));
isPlaying.setValue(false);
textColor = audioVideoImageTextLabel.getLabelTextView().getCurrentTextColor();
assertThat(textColor, equalTo(originalTextColor));
}
Aggregations