Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import static androidx.test.espresso.matcher.ViewMatchers.isChecked;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.isEnabled;
import static androidx.test.espresso.matcher.ViewMatchers.isNotChecked;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;

Expand Down Expand Up @@ -129,7 +130,74 @@ public void testSelectWholeScript() {
.check(matches(not(isChecked())));
}
}
@Test
public void testSelectWholeScriptByClickingOnTheBrick() {
openContextualActionModeOverflowMenu();
onView(withText(R.string.copy)).perform(click());

int brickIndex = 0;
onBrickAtPosition(brickIndex).performClick();

getCheckbox(brickIndex).check(matches(isChecked()));

for (brickIndex++; brickIndex <= firstScriptEndIndex; brickIndex++) {
getCheckbox(brickIndex)
.check(matches(not(isEnabled())))
.check(matches(isChecked()));
}
for (; brickIndex <= secondScriptEndIndex; brickIndex++) {
getCheckbox(brickIndex)
.check(matches(not(isEnabled())))
.check(matches(not(isChecked())));
}
}
@Test
public void testIfCheckboxSetAfterClickingOnBrick() {
openContextualActionModeOverflowMenu();
onView(withText(R.string.copy)).perform(click());

int brickIndex = 0;
onBrickAtPosition(brickIndex).performClick();
getCheckbox(brickIndex).check(matches(isChecked()));
onBrickAtPosition(brickIndex).performClick();
getCheckbox(brickIndex).check(matches(isNotChecked()));

for (++brickIndex; brickIndex <= firstScriptEndIndex; brickIndex++) {
if (brickIndex == 3) {
onBrickAtPosition(brickIndex).performClick();
getCheckbox(brickIndex).check(matches(isChecked()));
onBrickAtPosition(brickIndex - 2).performClick();
getCheckbox(brickIndex).check(matches(isNotChecked()));
continue;
}
onBrickAtPosition(brickIndex).performClick();
getCheckbox(brickIndex).check(matches(isChecked()));
onBrickAtPosition(brickIndex).performClick();
getCheckbox(brickIndex).check(matches(isNotChecked()));
}
}
@Test
public void testIfDisabledBricksNotClickable() {
openContextualActionModeOverflowMenu();
onView(withText(R.string.copy)).perform(click());

int brickIndex = 0;
onBrickAtPosition(brickIndex).performClick();

getCheckbox(brickIndex).check(matches(isChecked()));

for (++brickIndex; brickIndex <= firstScriptEndIndex; brickIndex++) {
getCheckbox(brickIndex).check(matches(not(isEnabled())))
.check(matches(isChecked()));
}

brickIndex = 0;
for (++brickIndex; brickIndex <= firstScriptEndIndex; brickIndex++) {
onBrickAtPosition(brickIndex).performClick();
getCheckbox(brickIndex).check(matches(not(isEnabled())))
.check(matches(isChecked()));
}
}
@Test
public void testSelectSingleBrick() {
openContextualActionModeOverflowMenu();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,27 @@ class BrickAdapter(private val sprite: Sprite) :
} else {
background.clearColorFilter()
}

checkBoxClickListener(item, itemView, position)
if (checkBoxMode != NONE) {
checkBoxClickListener(item, itemView, position)
} else {
if (item is FormulaBrick) {
item.setClickListeners()
} else if (item is ListSelectorBrick) {
item.setClickListeners()
}
}
item.checkBox.isChecked = selectionManager.isPositionSelected(position)
item.checkBox.isEnabled = viewStateManager.isEnabled(position)
return itemView
}

private fun checkBoxClickListener(item: Brick, itemView: ViewGroup, position: Int) {
item.checkBox.setOnClickListener { onCheckBoxClick(position) }
if (viewStateManager.isEnabled(position)) {
itemView.setOnClickListener { onCheckBoxClick(position) }
} else {
itemView.setOnClickListener(null)
}
when (checkBoxMode) {
NONE -> handleCheckBoxModeNone(item)
CONNECTED_ONLY -> handleCheckBoxModeConnectedOnly(item, itemView, position)
Expand Down