Search in sources :

Example 6 with MutableLiveData

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;
}
Also used : Disposable(io.reactivex.disposables.Disposable) GankIoDataBean(com.example.jingbin.cloudreader.bean.GankIoDataBean) MutableLiveData(androidx.lifecycle.MutableLiveData)

Example 7 with MutableLiveData

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);
}
Also used : MutableLiveData(androidx.lifecycle.MutableLiveData) RecordingSession(org.odk.collect.audiorecorder.recording.RecordingSession) Test(org.junit.Test)

Example 8 with MutableLiveData

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;
}
Also used : BarcodeResult(com.journeyapps.barcodescanner.BarcodeResult) BarcodeCallback(com.journeyapps.barcodescanner.BarcodeCallback) ResultPoint(com.google.zxing.ResultPoint) MutableLiveData(androidx.lifecycle.MutableLiveData)

Example 9 with MutableLiveData

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;
        }
    };
}
Also used : MutableLiveData(androidx.lifecycle.MutableLiveData) Handler(android.os.Handler)

Example 10 with MutableLiveData

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));
}
Also used : MutableLiveData(androidx.lifecycle.MutableLiveData) AudioButton(org.odk.collect.android.audio.AudioButton) AudioVideoImageTextLabel(org.odk.collect.android.formentry.questions.AudioVideoImageTextLabel) Test(org.junit.Test)

Aggregations

MutableLiveData (androidx.lifecycle.MutableLiveData)25 Disposable (io.reactivex.disposables.Disposable)14 Test (org.junit.Test)6 GankIoDataBean (com.example.jingbin.cloudreader.bean.GankIoDataBean)3 AudioButton (org.odk.collect.android.audio.AudioButton)3 AudioVideoImageTextLabel (org.odk.collect.android.formentry.questions.AudioVideoImageTextLabel)3 RecordingSession (org.odk.collect.audiorecorder.recording.RecordingSession)3 Handler (android.os.Handler)2 Pair (android.util.Pair)2 CoinBean (com.example.jingbin.cloudreader.bean.CoinBean)2 BaseResultBean (com.example.jingbin.cloudreader.bean.wanandroid.BaseResultBean)2 HomeListBean (com.example.jingbin.cloudreader.bean.wanandroid.HomeListBean)2 RequestImpl (com.example.jingbin.cloudreader.http.RequestImpl)2 File (java.io.File)2 FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)2 Intent (android.content.Intent)1 ServiceInfo (android.content.pm.ServiceInfo)1 Drawable (android.graphics.drawable.Drawable)1 AutofillServiceInfo (android.service.autofill.AutofillServiceInfo)1 AppPreference (com.android.settingslib.widget.AppPreference)1