Search in sources :

Example 11 with MutableLiveData

use of androidx.lifecycle.MutableLiveData in project collect by opendatakit.

the class AudioVideoImageTextLabelTest method withText_andAudio_showsTextAndAudioButton.

@Test
public void withText_andAudio_showsTextAndAudioButton() {
    MutableLiveData<Boolean> isPlaying = new MutableLiveData<>(false);
    when(audioHelper.setAudio(any(AudioButton.class), any())).thenReturn(isPlaying);
    AudioVideoImageTextLabel label = new AudioVideoImageTextLabel(activity);
    label.setText("blah", false, 16);
    label.setAudio("file://audio.mp3", audioHelper);
    assertThat(label.getLabelTextView().getVisibility(), equalTo(VISIBLE));
    assertThat(label.getLabelTextView().getText().toString(), equalTo("blah"));
    assertThat(label.findViewById(R.id.audioButton).getVisibility(), equalTo(VISIBLE));
}
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)

Example 12 with MutableLiveData

use of androidx.lifecycle.MutableLiveData in project collect by opendatakit.

the class ChoicesRecyclerViewTest method whenButtonsModeIsUsed_shouldViewAndItsElementsBeLongClickableToSupportRemovingAnswers.

@Test
public void whenButtonsModeIsUsed_shouldViewAndItsElementsBeLongClickableToSupportRemovingAnswers() {
    List<SelectChoice> items = getTestChoices();
    setUpFormEntryPrompt(items, "");
    SelectItemClickListener listener = mock(SelectItemClickListener.class);
    SelectMultipleListAdapter adapter = new SelectMultipleListAdapter(new ArrayList<>(), listener, activityController.get(), items, formEntryPrompt, null, null, 0, 1, false, mock(MediaUtils.class));
    initRecyclerView(adapter, false);
    AudioVideoImageTextLabel view = (AudioVideoImageTextLabel) getChoiceView(0);
    File file = mock(File.class);
    when(file.exists()).thenReturn(true);
    view.setImage(file, mock(ImageLoader.class));
    view.setVideo(file);
    AudioHelper audioHelper = mock(AudioHelper.class);
    MutableLiveData<Boolean> isPlaying = new MutableLiveData<>(false);
    when(audioHelper.setAudio(any(AudioButton.class), any())).thenReturn(isPlaying);
    view.setAudio("file://audio.mp3", audioHelper);
    assertThat(view.isLongClickable(), is(true));
    assertThat(view.getImageView().isLongClickable(), is(true));
    assertThat(view.getVideoButton().isLongClickable(), is(true));
    assertThat(view.getAudioButton().isLongClickable(), is(true));
    assertThat(view.getLabelTextView().isLongClickable(), is(true));
}
Also used : SelectChoice(org.javarosa.core.model.SelectChoice) MediaUtils(org.odk.collect.android.utilities.MediaUtils) SelectItemClickListener(org.odk.collect.android.listeners.SelectItemClickListener) AudioHelper(org.odk.collect.android.audio.AudioHelper) SelectMultipleListAdapter(org.odk.collect.android.adapters.SelectMultipleListAdapter) MutableLiveData(androidx.lifecycle.MutableLiveData) AudioButton(org.odk.collect.android.audio.AudioButton) AudioVideoImageTextLabel(org.odk.collect.android.formentry.questions.AudioVideoImageTextLabel) ImageLoader(org.odk.collect.imageloader.ImageLoader) File(java.io.File) Test(org.junit.Test)

Example 13 with MutableLiveData

use of androidx.lifecycle.MutableLiveData in project collect by opendatakit.

the class AudioRecorderRecordingStatusHandlerTest method whenViewModelSessionUpdates_callsInProgressListener.

@Test
public void whenViewModelSessionUpdates_callsInProgressListener() {
    FormEntryPrompt prompt = promptWithAnswer(null);
    MutableLiveData<RecordingSession> sessionLiveData = new MutableLiveData<>(null);
    when(audioRecorder.getCurrentSession()).thenReturn(sessionLiveData);
    Consumer<Pair<Long, Integer>> listener = mock(Consumer.class);
    provider.onRecordingStatusChange(prompt, listener);
    verify(listener).accept(null);
    sessionLiveData.setValue(new RecordingSession(prompt.getIndex(), null, 1200L, 25, false));
    verify(listener).accept(new Pair<>(1200L, 25));
}
Also used : FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) MutableLiveData(androidx.lifecycle.MutableLiveData) RecordingSession(org.odk.collect.audiorecorder.recording.RecordingSession) Pair(android.util.Pair) Test(org.junit.Test)

Example 14 with MutableLiveData

use of androidx.lifecycle.MutableLiveData in project collect by opendatakit.

the class AudioRecorderRecordingStatusHandlerTest method whenViewModelSessionUpdates_forDifferentSession_callsInProgressListenerWithNull.

@Test
public void whenViewModelSessionUpdates_forDifferentSession_callsInProgressListenerWithNull() {
    FormEntryPrompt prompt = promptWithAnswer(null);
    MutableLiveData<RecordingSession> sessionLiveData = new MutableLiveData<>(null);
    when(audioRecorder.getCurrentSession()).thenReturn(sessionLiveData);
    Consumer<Pair<Long, Integer>> listener = mock(Consumer.class);
    provider.onRecordingStatusChange(prompt, listener);
    verify(listener).accept(null);
    sessionLiveData.setValue(new RecordingSession("something else", null, 1200L, 0, false));
    verify(listener, times(2)).accept(null);
}
Also used : FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) MutableLiveData(androidx.lifecycle.MutableLiveData) RecordingSession(org.odk.collect.audiorecorder.recording.RecordingSession) Pair(android.util.Pair) Test(org.junit.Test)

Example 15 with MutableLiveData

use of androidx.lifecycle.MutableLiveData in project collect by opendatakit.

the class FormSaveViewModel method createAnswerFile.

@Override
public LiveData<Result<File>> createAnswerFile(File file) {
    MutableLiveData<Result<File>> liveData = new MutableLiveData<>(null);
    isSavingAnswerFile.setValue(true);
    scheduler.immediate(() -> {
        String newFileHash = Md5.getMd5Hash(file);
        String instanceDir = formController.getInstanceFile().getParent();
        File[] answerFiles = new File(instanceDir).listFiles();
        for (File answerFile : answerFiles) {
            if (Md5.getMd5Hash(answerFile).equals(newFileHash)) {
                return answerFile;
            }
        }
        String fileName = file.getName();
        String extension = fileName.substring(fileName.lastIndexOf('.') + 1);
        String newFileName = System.currentTimeMillis() + "." + extension;
        String newFilePath = instanceDir + File.separator + newFileName;
        try (InputStream inputStream = new FileInputStream(file)) {
            try (OutputStream outputStream = new FileOutputStream(newFilePath)) {
                IOUtils.copy(inputStream, outputStream);
            }
        } catch (IOException e) {
            Timber.e(e);
            return null;
        }
        return new File(newFilePath);
    }, answerFile -> {
        liveData.setValue(new Result<>(answerFile));
        isSavingAnswerFile.setValue(false);
        if (answerFile == null) {
            answerFileError.setValue(file.getAbsolutePath());
        }
    });
    return liveData;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) MutableLiveData(androidx.lifecycle.MutableLiveData) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) Result(org.odk.collect.utilities.Result) SaveToDiskResult(org.odk.collect.android.tasks.SaveToDiskResult)

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