Skip to content

Commit

Permalink
code update
Browse files Browse the repository at this point in the history
  • Loading branch information
darkengine committed Sep 8, 2024
1 parent af9d585 commit 5865941
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 13 deletions.
12 changes: 7 additions & 5 deletions app/src/main/java/com/dark/androidbox/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.dark.androidbox.codeView.Editor;
import com.dark.androidbox.databinding.ActivityMainBinding;
import com.dark.androidbox.model.NodeData;
import com.dark.androidbox.nodes.BaseNode;
import com.dark.androidbox.nodes.ClassNode;
import com.dark.androidbox.types.NodeTypes;
import com.github.javaparser.ast.body.FieldDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
Expand Down Expand Up @@ -72,9 +74,9 @@ protected void onCreate(Bundle savedInstanceState) {
private void loadNodes() {

//Create NODES
NodeModel<NodeData> root = createNode(new NodeData(lexer.getClasses().get(0).getNameAsString(), lexer.getClasses().get(0).toString(), NodeTypes.CLASSES));
NodeModel<NodeData> var = createNode(new NodeData("Var", "", NodeTypes.VARIABLES));
NodeModel<NodeData> methods = createNode(new NodeData("Methods", "", NodeTypes.METHODS));
NodeModel<NodeData> root = createNode(new NodeData(lexer.getClasses().get(0).getNameAsString(), lexer.getClasses().get(0).toString(), NodeTypes.CLASSES, new ClassNode(this)));
NodeModel<NodeData> var = createNode(new NodeData("Var", "", NodeTypes.VARIABLES, new BaseNode(this)));
NodeModel<NodeData> methods = createNode(new NodeData("Methods", "", NodeTypes.METHODS, new BaseNode(this)));

//LOAD ROOT-NODE in TREE-MODEL
TreeModel<NodeData> treeModel = new TreeModel<>(root);
Expand All @@ -85,12 +87,12 @@ private void loadNodes() {
//LOAD Var-NODES in TREE-MODEL
for (FieldDeclaration declaration : lexer.getFields()) {
treeModel.addNode(var,
createNode(new NodeData(declaration.getVariables().get(0).getNameAsString(), declaration.getVariables().get(0).getTypeAsString(), NodeTypes.VARIABLES)));
createNode(new NodeData(declaration.getVariables().get(0).getNameAsString(), declaration.getVariables().get(0).getTypeAsString(), NodeTypes.VARIABLES, new BaseNode(this))));
}
//LOAD Methods-NODES in TREE-MODEL
for (MethodDeclaration declaration : lexer.getMethods()) {
treeModel.addNode(methods,
createNode(new NodeData(declaration.getNameAsString(), declaration.toString(), NodeTypes.METHODS)));
createNode(new NodeData(declaration.getNameAsString(), declaration.toString(), NodeTypes.METHODS, new BaseNode(this))));
}

//LOAD TREE-MODEL IN ADAPTER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public void onBindViewHolder(@NonNull TreeViewHolder<NodeData> holder) {
NodeModel<NodeData> data = holder.getNode();
NodeviewBinding binding = NodeviewBinding.bind(root);

binding.txt.setText(data.value.title);
binding.root.removeAllViews();
binding.root.addView(data.value.node);
//binding.txt.setText(data.value.title);
}

@Override
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/com/dark/androidbox/model/NodeData.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dark.androidbox.model;

import com.dark.androidbox.nodes.BaseNode;
import com.dark.androidbox.types.NodeTypes;

public class NodeData {
Expand All @@ -8,12 +9,14 @@ public class NodeData {
public String title;
public String code;
public NodeTypes types;
public BaseNode node;


public NodeData(String title, String code, NodeTypes types) {
public NodeData(String title, String code, NodeTypes types, BaseNode node) {
this.title = title;
this.code = code;
this.types = types;
this.node = node;
}


Expand Down
41 changes: 41 additions & 0 deletions app/src/main/java/com/dark/androidbox/nodes/BaseNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.dark.androidbox.nodes;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;

import androidx.annotation.Nullable;

import com.dark.androidbox.databinding.BaseNodeBinding;

public class BaseNode extends FrameLayout {

BaseNodeBinding binding;

public BaseNode(Context context) {
super(context);
init();
}

public BaseNode(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init();
}

public BaseNode(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}

public BaseNode(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
}

public void init() {
binding = BaseNodeBinding.inflate(LayoutInflater.from(getContext()), this, true);
setBackgroundColor(Color.WHITE);
}
}
37 changes: 37 additions & 0 deletions app/src/main/java/com/dark/androidbox/nodes/ClassNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.dark.androidbox.nodes;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.dark.androidbox.R;

public class ClassNode extends BaseNode{

public ClassNode(Context context) {
super(context);
}

public ClassNode(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}

public ClassNode(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

public ClassNode(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}

@Override
public void init() {
super.init();
setBackgroundColor(Color.GREEN);
}
}
12 changes: 12 additions & 0 deletions app/src/main/res/layout/base_node.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:layout_centerInParent="true"/>

</RelativeLayout>
13 changes: 7 additions & 6 deletions app/src/main/res/layout/nodeview.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="12dp"
android:layout_gravity="center"
android:background="@drawable/bg_node_view">

<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="18sp" />
<!-- <TextView-->
<!-- android:id="@+id/txt"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_centerInParent="true"-->
<!-- android:textSize="18sp" />-->

</RelativeLayout>

0 comments on commit 5865941

Please sign in to comment.