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));
}
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));
}
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));
}
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);
}
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;
}
Aggregations