From 3cd2c6bc48202ce33d401a47729569dc66c23560 Mon Sep 17 00:00:00 2001 From: DevKumar00001 Date: Fri, 29 Dec 2023 08:16:19 +0530 Subject: [PATCH] refactor: Saparate developer tools blockholder and some blocks --- .../java/builtin/blocks/BuiltInBlocks.java | 54 +----------- .../builtin/blocks/holder/OperatorBlocks.java | 83 +++++++++++++++++++ 2 files changed, 87 insertions(+), 50 deletions(-) create mode 100644 app/src/main/java/builtin/blocks/holder/OperatorBlocks.java diff --git a/app/src/main/java/builtin/blocks/BuiltInBlocks.java b/app/src/main/java/builtin/blocks/BuiltInBlocks.java index 95e8ef5..831f93c 100644 --- a/app/src/main/java/builtin/blocks/BuiltInBlocks.java +++ b/app/src/main/java/builtin/blocks/BuiltInBlocks.java @@ -3,6 +3,7 @@ import android.graphics.Color; import android.util.Log; import android.widget.Toast; +import builtin.blocks.holder.OperatorBlocks; import com.dragon.ide.objects.Block; import com.dragon.ide.objects.BlockContent; import com.dragon.ide.objects.BlocksHolder; @@ -19,33 +20,11 @@ public static ArrayList getBuiltInBlocksHolder() { ArrayList blocksHolder = new ArrayList(); BlocksHolder holder1 = new BlocksHolder(); holder1.setColor("#009900"); - holder1.setName("Operators"); - holder1.setTags( - new String[] { - "developer", "developerOnly" - }); + holder1.setName("Developer tools"); + holder1.setTags(new String[] {"developer", "developerOnly"}); ArrayList blockList = new ArrayList(); - Block blockInHolder1 = new Block(); - blockInHolder1.setColor("#009900"); - blockInHolder1.setBlockType(Block.BlockType.defaultBlock); - blockInHolder1.setName("addSource"); - blockInHolder1.setRawCode("DevKumar DragonIDE parameter DevKumar"); - blockInHolder1.setTags(new String[] {"developer", "developerOnly"}); - - ArrayList block1ContentList = new ArrayList(); - - BlockContent block1Content1 = new BlockContent(); - block1Content1.setText("add source"); - block1ContentList.add(block1Content1); - - SourceContent block1Content2 = new SourceContent(); - block1Content2.setId("parameter"); - block1ContentList.add(block1Content2); - - blockInHolder1.setBlockContent(block1ContentList); - Block blockInHolder2 = new Block(); blockInHolder2.setColor("#ff0000"); blockInHolder2.setBlockType(Block.BlockType.sideAttachableBlock); @@ -66,30 +45,6 @@ public static ArrayList getBuiltInBlocksHolder() { blockInHolder2.setBlockContent(block2ContentList); - ComplexBlock blockInHolder3 = new ComplexBlock(); - blockInHolder3.setColor("#009900"); - blockInHolder3.setBlockType(Block.BlockType.complexBlock); - blockInHolder3.setName("if"); - StringBuilder blockInHolder3StringBuilder = new StringBuilder(); - blockInHolder3StringBuilder.append("if ("); - blockInHolder3StringBuilder.append(CodeReplacer.getReplacer("condition")); - blockInHolder3StringBuilder.append(") {\n\t"); - blockInHolder3StringBuilder.append(CodeReplacer.getReplacer("complexBlockContent")); - blockInHolder3StringBuilder.append("\n}"); - blockInHolder3.setRawCode(blockInHolder3StringBuilder.toString()); - blockInHolder3.setTags(new String[] {"developer", "developerOnly"}); - - ArrayList block3ContentList = new ArrayList(); - - BlockContent block3Content1 = new BlockContent(); - block3Content1.setText("if"); - block3ContentList.add(block3Content1); - - BooleanContent block3Content2 = new BooleanContent(); - block3Content2.setId("condition"); - block3ContentList.add(block3Content2); - blockInHolder3.setBlockContent(block3ContentList); - Block blockInHolder4 = new Block(); blockInHolder4.setColor("#009900"); blockInHolder4.setBlockType(Block.BlockType.returnWithTypeBoolean); @@ -142,9 +97,7 @@ public static ArrayList getBuiltInBlocksHolder() { blockInHolder6.setBlockContent(block6ContentList); - blockList.add(blockInHolder1); blockList.add(blockInHolder2); - blockList.add(blockInHolder3); blockList.add(blockInHolder4); blockList.add(blockInHolder5); blockList.add(blockInHolder6); @@ -152,6 +105,7 @@ public static ArrayList getBuiltInBlocksHolder() { holder1.setBlocks(blockList); blocksHolder.add(holder1); + blocksHolder.add(OperatorBlocks.getBlockHolder()); return blocksHolder; } diff --git a/app/src/main/java/builtin/blocks/holder/OperatorBlocks.java b/app/src/main/java/builtin/blocks/holder/OperatorBlocks.java new file mode 100644 index 0000000..316b2d8 --- /dev/null +++ b/app/src/main/java/builtin/blocks/holder/OperatorBlocks.java @@ -0,0 +1,83 @@ +package builtin.blocks.holder; + +import com.dragon.ide.objects.Block; +import com.dragon.ide.objects.BlockContent; +import com.dragon.ide.objects.BlocksHolder; +import com.dragon.ide.objects.ComplexBlock; +import com.dragon.ide.objects.blockcontent.BooleanContent; +import com.dragon.ide.objects.blockcontent.SourceContent; +import com.dragon.ide.utils.CodeReplacer; +import editor.tsd.tools.Language; +import java.util.ArrayList; + +public class OperatorBlocks { + public static BlocksHolder getBlockHolder() { + BlocksHolder blocksHolder = new BlocksHolder(); + blocksHolder.setColor("#009900"); + blocksHolder.setName("Operators"); + blocksHolder.setTags(new String[] {Language.HTML, Language.CSS, Language.JavaScript}); + + ArrayList blocksList = new ArrayList(); + + blocksList.add(getIfBlock()); + blocksList.add(getAddSourceBlock()); + + blocksHolder.setBlocks(blocksList); + return blocksHolder; + } + + public static Block getAddSourceBlock() { + Block addSource = new Block(); + addSource.setColor("#009900"); + addSource.setBlockType(Block.BlockType.defaultBlock); + addSource.setName("addSource"); + addSource.setRawCode(CodeReplacer.getReplacer("parameter")); + addSource.setTags(new String[] {Language.HTML, Language.CSS, Language.JavaScript}); + + ArrayList addSourceContentList = new ArrayList(); + + BlockContent addSourceBlockContent1 = new BlockContent(); + addSourceBlockContent1.setText("add source"); + addSourceContentList.add(addSourceBlockContent1); + + SourceContent addSourceBlockContent2 = new SourceContent(); + addSourceBlockContent2.setId("parameter"); + addSourceContentList.add(addSourceBlockContent2); + + addSource.setBlockContent(addSourceContentList); + + return addSource; + } + + public static Block getIfBlock() { + ComplexBlock ifBlock = new ComplexBlock(); + ifBlock.setColor("#009900"); + ifBlock.setBlockType(Block.BlockType.complexBlock); + ifBlock.setName("if"); + + StringBuilder ifBlockStringBuilder = new StringBuilder(); + ifBlockStringBuilder.append("if ("); + ifBlockStringBuilder.append(CodeReplacer.getReplacer("condition")); + ifBlockStringBuilder.append(") {\n\t"); + ifBlockStringBuilder.append(CodeReplacer.getReplacer("complexBlockContent")); + ifBlockStringBuilder.append("\n}"); + + ifBlock.setRawCode(ifBlockStringBuilder.toString()); + + ifBlock.setTags(new String[] {Language.JavaScript}); + + ArrayList ifBlockContentList = new ArrayList(); + + BlockContent ifBlockBlockContent1 = new BlockContent(); + ifBlockBlockContent1.setText("if"); + ifBlockContentList.add(ifBlockBlockContent1); + + BooleanContent ifBlockBlockContent2 = new BooleanContent(); + ifBlockBlockContent2.setId("condition"); + ifBlockContentList.add(ifBlockBlockContent2); + + ifBlock.setBlockContent(ifBlockContentList); + + return ifBlock; + } +}