Search in sources :

Example 1 with SelectItemClickListener

use of org.odk.collect.android.listeners.SelectItemClickListener in project collect by opendatakit.

the class ChoicesRecyclerViewTest method whenChangingAnswer_shouldHasAnswerChangedReturnCorrectValue.

@Test
public void whenChangingAnswer_shouldHasAnswerChangedReturnCorrectValue() {
    List<SelectChoice> items = getTestChoices();
    setUpFormEntryPrompt(items, "");
    SelectItemClickListener listener = mock(SelectItemClickListener.class);
    List<Selection> selectedItems = new ArrayList<>();
    selectedItems.add(items.get(0).selection());
    SelectMultipleListAdapter adapter = new SelectMultipleListAdapter(selectedItems, listener, activityController.get(), items, formEntryPrompt, null, null, 0, 1, false, mock(MediaUtils.class));
    initRecyclerView(adapter, false);
    // Select BBB
    clickChoice(1);
    assertThat(adapter.hasAnswerChanged(), is(true));
    // Unselect AAA
    clickChoice(0);
    assertThat(adapter.hasAnswerChanged(), is(true));
    // Unselect BBB
    clickChoice(1);
    assertThat(adapter.hasAnswerChanged(), is(true));
    // Select AAA
    clickChoice(0);
    assertThat(adapter.hasAnswerChanged(), is(false));
}
Also used : SelectChoice(org.javarosa.core.model.SelectChoice) Selection(org.javarosa.core.model.data.helper.Selection) SelectMultipleListAdapter(org.odk.collect.android.adapters.SelectMultipleListAdapter) ArrayList(java.util.ArrayList) MediaUtils(org.odk.collect.android.utilities.MediaUtils) SelectItemClickListener(org.odk.collect.android.listeners.SelectItemClickListener) Test(org.junit.Test)

Example 2 with SelectItemClickListener

use of org.odk.collect.android.listeners.SelectItemClickListener in project collect by opendatakit.

the class ChoicesRecyclerViewTest method whenClickOneOption_shouldPreviouslySelectedOptionRemainSelectedInSelectMultiNoButtonsMode.

@Test
public void whenClickOneOption_shouldPreviouslySelectedOptionRemainSelectedInSelectMultiNoButtonsMode() {
    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 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 3 with SelectItemClickListener

use of org.odk.collect.android.listeners.SelectItemClickListener in project collect by opendatakit.

the class ChoicesRecyclerViewTest method whenClickOneOption_shouldPreviouslySelectedOptionBeUnselectedInSelectOneNoButtonsMode.

@Test
public void whenClickOneOption_shouldPreviouslySelectedOptionBeUnselectedInSelectOneNoButtonsMode() {
    List<SelectChoice> items = getTestChoices();
    setUpFormEntryPrompt(items, "no-buttons");
    SelectItemClickListener listener = mock(SelectItemClickListener.class);
    SelectOneListAdapter adapter = new SelectOneListAdapter(null, 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 BBB
    clickChoice(1);
    assertThat(isItemSelected(0), is(false));
    assertThat(isItemSelected(1), is(true));
}
Also used : SelectChoice(org.javarosa.core.model.SelectChoice) MediaUtils(org.odk.collect.android.utilities.MediaUtils) SelectItemClickListener(org.odk.collect.android.listeners.SelectItemClickListener) SelectOneListAdapter(org.odk.collect.android.adapters.SelectOneListAdapter) Test(org.junit.Test)

Example 4 with SelectItemClickListener

use of org.odk.collect.android.listeners.SelectItemClickListener in project collect by opendatakit.

the class ChoicesRecyclerViewTest method whenChoiceSelectedInSelectOneNoButtonsMode_shouldTryToPlayAudio.

@Test
public void whenChoiceSelectedInSelectOneNoButtonsMode_shouldTryToPlayAudio() {
    List<SelectChoice> items = getTestChoices();
    setUpFormEntryPrompt(items, "no-buttons");
    SelectItemClickListener listener = mock(SelectItemClickListener.class);
    AudioHelper audioHelper = mock(AudioHelper.class);
    SelectOneListAdapter adapter = spy(new SelectOneListAdapter(null, listener, activityController.get(), items, formEntryPrompt, null, audioHelper, 0, 1, true, mock(MediaUtils.class)));
    initRecyclerView(adapter, false);
    // Select AAA
    clickChoice(0);
    verify(adapter).playAudio(any());
}
Also used : SelectChoice(org.javarosa.core.model.SelectChoice) SelectItemClickListener(org.odk.collect.android.listeners.SelectItemClickListener) SelectOneListAdapter(org.odk.collect.android.adapters.SelectOneListAdapter) AudioHelper(org.odk.collect.android.audio.AudioHelper) Test(org.junit.Test)

Example 5 with SelectItemClickListener

use of org.odk.collect.android.listeners.SelectItemClickListener in project collect by opendatakit.

the class ChoicesRecyclerViewTest method whenClickOneOption_shouldPreviouslySelectedOptionBeUnselectedInSelectOneButtonsMode.

@Test
public void whenClickOneOption_shouldPreviouslySelectedOptionBeUnselectedInSelectOneButtonsMode() {
    List<SelectChoice> items = getTestChoices();
    setUpFormEntryPrompt(items, "");
    SelectItemClickListener listener = mock(SelectItemClickListener.class);
    SelectOneListAdapter adapter = new SelectOneListAdapter(null, 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(false));
    assertThat(isItemSelected(1), is(true));
}
Also used : SelectChoice(org.javarosa.core.model.SelectChoice) MediaUtils(org.odk.collect.android.utilities.MediaUtils) SelectItemClickListener(org.odk.collect.android.listeners.SelectItemClickListener) SelectOneListAdapter(org.odk.collect.android.adapters.SelectOneListAdapter) Test(org.junit.Test)

Aggregations

SelectChoice (org.javarosa.core.model.SelectChoice)15 Test (org.junit.Test)15 SelectItemClickListener (org.odk.collect.android.listeners.SelectItemClickListener)15 MediaUtils (org.odk.collect.android.utilities.MediaUtils)11 SelectMultipleListAdapter (org.odk.collect.android.adapters.SelectMultipleListAdapter)10 SelectOneListAdapter (org.odk.collect.android.adapters.SelectOneListAdapter)5 ArrayList (java.util.ArrayList)4 AudioHelper (org.odk.collect.android.audio.AudioHelper)3 Selection (org.javarosa.core.model.data.helper.Selection)2 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