Search in sources :

Example 6 with SelectMultipleListAdapter

use of org.odk.collect.android.adapters.SelectMultipleListAdapter in project collect by opendatakit.

the class ChoicesRecyclerViewTest method whenChoicesFiltered_shouldProperValuesBeReturnedInSelectMultiNoButtonsMode.

@Test
public void whenChoicesFiltered_shouldProperValuesBeReturnedInSelectMultiNoButtonsMode() {
    List<SelectChoice> items = getTestChoices();
    setUpFormEntryPrompt(items, "no-buttons");
    SelectMultipleListAdapter adapter = new SelectMultipleListAdapter(new ArrayList<>(), null, activityController.get(), items, formEntryPrompt, null, null, 0, 1, true, mock(MediaUtils.class));
    initRecyclerView(adapter, false);
    assertVisibleItemsInNoButtonsMode("AAA", "BBB");
    filterList(adapter, "b");
    assertVisibleItemsInNoButtonsMode("BBB");
    filterList(adapter, "bc");
    assertVisibleItemsInNoButtonsMode();
    filterList(adapter, "b");
    assertVisibleItemsInNoButtonsMode("BBB");
    filterList(adapter, "");
    assertVisibleItemsInNoButtonsMode("AAA", "BBB");
}
Also used : SelectChoice(org.javarosa.core.model.SelectChoice) SelectMultipleListAdapter(org.odk.collect.android.adapters.SelectMultipleListAdapter) MediaUtils(org.odk.collect.android.utilities.MediaUtils) Test(org.junit.Test)

Example 7 with SelectMultipleListAdapter

use of org.odk.collect.android.adapters.SelectMultipleListAdapter in project collect by opendatakit.

the class ChoicesRecyclerViewTest method whenClickOneOption_shouldPreviouslySelectedOptionRemainSelectedInSelectMultiButtonsMode.

@Test
public void whenClickOneOption_shouldPreviouslySelectedOptionRemainSelectedInSelectMultiButtonsMode() {
    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);
    // Select AAA
    clickChoice(0);
    assertThat(isItemSelected(0), is(true));
    assertThat(isItemSelected(1), is(false));
    // Select BBB
    clickChoice(1);
    assertThat(isItemSelected(0), is(true));
    assertThat(isItemSelected(1), is(true));
}
Also used : SelectChoice(org.javarosa.core.model.SelectChoice) SelectMultipleListAdapter(org.odk.collect.android.adapters.SelectMultipleListAdapter) MediaUtils(org.odk.collect.android.utilities.MediaUtils) SelectItemClickListener(org.odk.collect.android.listeners.SelectItemClickListener) Test(org.junit.Test)

Example 8 with SelectMultipleListAdapter

use of org.odk.collect.android.adapters.SelectMultipleListAdapter in project collect by opendatakit.

the class ChoicesRecyclerViewTest method whenChoicesFiltered_shouldProperValuesBeReturnedInSelectMultiButtonsMode.

@Test
public void whenChoicesFiltered_shouldProperValuesBeReturnedInSelectMultiButtonsMode() {
    List<SelectChoice> items = getTestChoices();
    setUpFormEntryPrompt(items, "");
    SelectMultipleListAdapter adapter = new SelectMultipleListAdapter(new ArrayList<>(), null, activityController.get(), items, formEntryPrompt, null, null, 0, 1, false, mock(MediaUtils.class));
    initRecyclerView(adapter, false);
    assertVisibleItemsInButtonsMode("AAA", "BBB");
    filterList(adapter, "b");
    assertVisibleItemsInButtonsMode("BBB");
    filterList(adapter, "bc");
    assertVisibleItemsInButtonsMode();
    filterList(adapter, "b");
    assertVisibleItemsInButtonsMode("BBB");
    filterList(adapter, "");
    assertVisibleItemsInButtonsMode("AAA", "BBB");
}
Also used : SelectChoice(org.javarosa.core.model.SelectChoice) SelectMultipleListAdapter(org.odk.collect.android.adapters.SelectMultipleListAdapter) MediaUtils(org.odk.collect.android.utilities.MediaUtils) Test(org.junit.Test)

Example 9 with SelectMultipleListAdapter

use of org.odk.collect.android.adapters.SelectMultipleListAdapter in project collect by opendatakit.

the class ChoicesRecyclerViewTest method whenClickOneElementTwice_shouldThatElementBeUnselectedInSelectMultiNoButtonsMode.

@Test
public void whenClickOneElementTwice_shouldThatElementBeUnselectedInSelectMultiNoButtonsMode() {
    List<SelectChoice> items = getTestChoices();
    setUpFormEntryPrompt(items, "no-buttons");
    SelectItemClickListener listener = mock(SelectItemClickListener.class);
    SelectMultipleListAdapter adapter = new SelectMultipleListAdapter(new ArrayList<>(), listener, activityController.get(), items, formEntryPrompt, null, audioHelper, 0, 1, true, mock(MediaUtils.class));
    initRecyclerView(adapter, false);
    // Select AAA
    clickChoice(0);
    assertThat(isItemSelected(0), is(true));
    assertThat(isItemSelected(1), is(false));
    // Select AAA again
    clickChoice(0);
    assertThat(isItemSelected(0), is(false));
    assertThat(isItemSelected(1), is(false));
}
Also used : SelectChoice(org.javarosa.core.model.SelectChoice) SelectMultipleListAdapter(org.odk.collect.android.adapters.SelectMultipleListAdapter) MediaUtils(org.odk.collect.android.utilities.MediaUtils) SelectItemClickListener(org.odk.collect.android.listeners.SelectItemClickListener) Test(org.junit.Test)

Example 10 with SelectMultipleListAdapter

use of org.odk.collect.android.adapters.SelectMultipleListAdapter 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)

Aggregations

SelectMultipleListAdapter (org.odk.collect.android.adapters.SelectMultipleListAdapter)13 SelectChoice (org.javarosa.core.model.SelectChoice)12 Test (org.junit.Test)12 SelectItemClickListener (org.odk.collect.android.listeners.SelectItemClickListener)10 MediaUtils (org.odk.collect.android.utilities.MediaUtils)9 ArrayList (java.util.ArrayList)4 Selection (org.javarosa.core.model.data.helper.Selection)2 AudioHelper (org.odk.collect.android.audio.AudioHelper)2 SuppressLint (android.annotation.SuppressLint)1 MutableLiveData (androidx.lifecycle.MutableLiveData)1 File (java.io.File)1 AudioButton (org.odk.collect.android.audio.AudioButton)1 AudioVideoImageTextLabel (org.odk.collect.android.formentry.questions.AudioVideoImageTextLabel)1 ImageLoader (org.odk.collect.imageloader.ImageLoader)1