Skip to content

Commit

Permalink
fix: dereferencing methods were not removing last block and some impr…
Browse files Browse the repository at this point in the history
…ovement
  • Loading branch information
SyntaxGalaxy committed Dec 29, 2024
1 parent 82cfe9a commit 221a11c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,13 @@ public void removeOldReferences() {
if (parent == null)
return;

int index = 0;
if (parent instanceof MainActionBlockDropZoneView mainChain) {
index = mainChain.indexOfChild(actionBlockBeanView) - 1;
int index = mainChain.indexOfChild(actionBlockBeanView);
mainChain.getChildAt(index).setOnTouchListener(null);
mainChain.removeViews(index, mainChain.getChildCount() - index);
mainChain.dereferenceActionBlocks(index);
mainChain.dereferenceActionBlocks(index - 1);
} else if (parent instanceof ActionBlockDropZoneView regularChain) {
index = regularChain.indexOfChild(actionBlockBeanView);
int index = regularChain.indexOfChild(actionBlockBeanView);
regularChain.getChildAt(index).setOnTouchListener(null);
regularChain.removeViews(index, regularChain.getBlocksSize() - index);
regularChain.dereferenceActionBlocks(index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public boolean isTerminated() {
}

public void dereferenceActionBlocks(int index) {
for (int i = index; i < blockBeans.size(); ++i) {
for (int i = index; i <= blockBeans.size(); ++i) {
blockBeans.remove(index);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public boolean isTerminated() {
}

public void dereferenceActionBlocks(int index) {
for (int i = index; i < blockBeans.size(); ++i) {
for (int i = index; i <= blockBeans.size(); ++i) {
blockBeans.remove(index);
}
}
Expand Down Expand Up @@ -277,8 +277,8 @@ private void addBlockBeans(ArrayList<ActionBlockBean> actionBlocks, int index) {
continue;

addView(
actionBlockBeanView, index +
i + (eventDefinationBlockView.getParent() == null ? 0 : 1));
actionBlockBeanView,
index + i + (eventDefinationBlockView.getParent() == null ? 0 : 1));

LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ public void run() {
blocksList = mainChain.getBlockBeans();
int index = mainChain.indexOfChild(actionBlockBeanView) - 1;
for (int i = index; i < mainChain.getBlocksSize(); ++i) {
draggingBlocks.add(blocksList.get(i));
actionBlockDropZone
.getChildAt(i)
.getChildAt(i + 1)
.setVisibility(View.GONE);
draggingBlocks.add(blocksList.get(i - 1));
}
} else if (actionBlockDropZone instanceof ActionBlockDropZoneView regularChain) {
int index = regularChain.indexOfChild(actionBlockBeanView);
Expand Down

0 comments on commit 221a11c

Please sign in to comment.