Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Commit

Permalink
Fixes incorrect 'selection' and 'expansion' behaviour (#73)
Browse files Browse the repository at this point in the history
When the sections have selection/expansion mode as single and adapter has mode as multiple, then incorrect mode is set for adapter. This is discussed in this issue #72.
  • Loading branch information
DevAhamed authored May 3, 2019
1 parent 76b46dd commit 7fedd55
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ public final void notifySectionRangeRemoved(Section section, int positionStart,
}

@Override void onItemSelectionToggled(int itemPosition, @NonNull Mode selectionMode) {
Mode selectionModeToHonor = getModeToHonor(selectionMode, this.selectionMode);
Mode selectionModeToHonor =
itemPosition < getCount() && itemPosition >= 0 ? getModeToHonor(selectionMode,
this.selectionMode) : selectionMode;
for (Section section : sections) {
section.onItemSelectionToggled(itemPosition, selectionModeToHonor);
itemPosition -= section.getCount();
Expand Down Expand Up @@ -229,7 +231,9 @@ public final void notifySectionRangeRemoved(Section section, int positionStart,
}

@Override void onItemExpansionToggled(int itemPosition, @NonNull Mode expansionMode) {
Mode expansionModeToHonor = getModeToHonor(expansionMode, this.expansionMode);
Mode expansionModeToHonor =
itemPosition < getCount() && itemPosition >= 0 ? getModeToHonor(expansionMode,
this.expansionMode) : expansionMode;
for (Section section : sections) {
section.onItemExpansionToggled(itemPosition, expansionModeToHonor);
itemPosition -= section.getCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package mva2.adapter;

import mva2.adapter.util.Mode;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
Expand Down Expand Up @@ -123,9 +124,10 @@
assertTrue(adapter.isItemExpanded(1));
}

@Test public void expansionModeTest_SectionSingle() {
@Test public void selectionModeTest_SectionSingle() {
adapter.setExpansionMode(Mode.MULTIPLE);
headerSection1.setExpansionMode(Mode.SINGLE);
listSection1.setExpansionMode(Mode.SINGLE);
headerSection1.getListSection().setExpansionMode(Mode.SINGLE);
adapter.onItemExpansionToggled(1);
assertTrue(adapter.isItemExpanded(1));

Expand All @@ -135,7 +137,25 @@

adapter.onItemExpansionToggled(23);
assertTrue(adapter.isItemExpanded(23));
assertTrue(!adapter.isItemExpanded(22));
Assert.assertFalse(adapter.isItemExpanded(22));
assertTrue(adapter.isItemExpanded(1));
}

@Test public void selectionModeTest_SectionSingle_1() {
adapter.setExpansionMode(Mode.MULTIPLE);
listSection1.setExpansionMode(Mode.SINGLE);
headerSection1.getListSection().setExpansionMode(Mode.SINGLE);

adapter.onItemExpansionToggled(22);
assertTrue(adapter.isItemExpanded(22));

adapter.onItemExpansionToggled(1);
assertTrue(adapter.isItemExpanded(22));
assertTrue(adapter.isItemExpanded(1));

adapter.onItemExpansionToggled(23);
assertTrue(adapter.isItemExpanded(23));
assertFalse(adapter.isItemExpanded(22));
assertTrue(adapter.isItemExpanded(1));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.mockito.junit.MockitoJUnitRunner;

import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertFalse;

@RunWith(MockitoJUnitRunner.class) public class CoreSelectionTest extends BaseTest {

Expand Down Expand Up @@ -119,6 +120,7 @@
@Test public void selectionModeTest_SectionSingle() {
adapter.setSelectionMode(Mode.MULTIPLE);
listSection1.setSelectionMode(Mode.SINGLE);
headerSection1.getListSection().setSelectionMode(Mode.SINGLE);
adapter.onItemSelectionToggled(1);
assertTrue(adapter.isItemSelected(1));

Expand All @@ -128,7 +130,25 @@

adapter.onItemSelectionToggled(23);
assertTrue(adapter.isItemSelected(23));
assertFalse(adapter.isItemSelected(22));
assertTrue(adapter.isItemSelected(1));
}

@Test public void selectionModeTest_SectionSingle_1() {
adapter.setSelectionMode(Mode.MULTIPLE);
listSection1.setSelectionMode(Mode.SINGLE);
headerSection1.getListSection().setSelectionMode(Mode.SINGLE);

adapter.onItemSelectionToggled(22);
assertTrue(adapter.isItemSelected(22));

adapter.onItemSelectionToggled(1);
assertTrue(adapter.isItemSelected(22));
assertTrue(adapter.isItemSelected(1));

adapter.onItemSelectionToggled(23);
assertTrue(adapter.isItemSelected(23));
assertFalse(adapter.isItemSelected(22));
assertTrue(adapter.isItemSelected(1));
}

Expand Down

0 comments on commit 7fedd55

Please sign in to comment.