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 5865941 commit cdb0327
Show file tree
Hide file tree
Showing 87 changed files with 2,283 additions and 2,174 deletions.
2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dependencies {

implementation libs.javaparser.core

implementation project(":nodes")
implementation project(":node")
implementation project(":codeview")

implementation (libs.android.code.view){
Expand Down
54 changes: 45 additions & 9 deletions app/src/main/java/com/dark/androidbox/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.CompoundButton;

import androidx.appcompat.app.AppCompatActivity;

import com.dark.androidbox.adapter.NodeViewAdapter;
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.nodes.MethodNode;
import com.dark.androidbox.types.NodeTypes;
import com.github.javaparser.ast.body.FieldDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
Expand All @@ -25,16 +26,14 @@

public class MainActivity extends AppCompatActivity {

public static GysoTreeView treeViewStatic;
//BINDING
private ActivityMainBinding binding;

//TREEVIEW Variables
private GysoTreeView treeView;
private TreeViewAdapter<NodeData> adapter;

//CODE EDITOR Variables
private Editor editor;

//CODE INIT Variables
private Lexer lexer;

Expand All @@ -46,6 +45,7 @@ protected void onCreate(Bundle savedInstanceState) {
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
treeView = binding.nodeView.treeview;
treeViewStatic = binding.nodeView.treeview;

//Init Essentials Objects
editor = new Editor(binding.code);
Expand All @@ -68,15 +68,40 @@ protected void onCreate(Bundle savedInstanceState) {

//Temp Click Fun to Load Nodes
loadNodes();

binding.drag.setUseMaterialThemeColors(true);
binding.drag.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
treeView.getEditor().setWantEdit(!b);
}
});
}

//LOADING NODES
private void loadNodes() {

//Create NODES
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)));
NodeModel<NodeData> root =
createNode(new NodeData(
lexer.getClasses().get(0).getNameAsString(),
lexer.getClasses().get(0).toString(),
NodeTypes.CLASSES, new ClassNode(this),
lexer.getClasses()));

NodeModel<NodeData> var =
createNode(new NodeData(
"Var", "",
NodeTypes.VARIABLES,
new ClassNode(this),
lexer.getFields()));

NodeModel<NodeData> methods =
createNode(new NodeData(
"Methods", "",
NodeTypes.METHODS,
new ClassNode(this),
lexer.getMethods()));

//LOAD ROOT-NODE in TREE-MODEL
TreeModel<NodeData> treeModel = new TreeModel<>(root);
Expand All @@ -87,12 +112,23 @@ 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, new BaseNode(this))));
createNode(
new NodeData(
declaration.getVariables().get(0).getNameAsString(),
declaration.getVariables().get(0).getTypeAsString(),
NodeTypes.VARIABLES, new ClassNode(this),
null)));
}
//LOAD Methods-NODES in TREE-MODEL
for (MethodDeclaration declaration : lexer.getMethods()) {
treeModel.addNode(methods,
createNode(new NodeData(declaration.getNameAsString(), declaration.toString(), NodeTypes.METHODS, new BaseNode(this))));
createNode(
new NodeData(
declaration.getNameAsString(),
declaration.toString(),
NodeTypes.METHODS,
new MethodNode(this),
null)));
}

//LOAD TREE-MODEL IN ADAPTER
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.dark.androidbox.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.dark.androidbox.databinding.MethodsListBinding;
import com.github.javaparser.ast.body.MethodDeclaration;

import java.util.List;

public class MethodSelectAdapter extends BaseAdapter {

private List<MethodDeclaration> data;
private Context context;
private LayoutInflater inflater;

public MethodSelectAdapter(Context context, List<MethodDeclaration> data) {
this.context = context;
this.data = data;
this.inflater = LayoutInflater.from(context);
}

@Override
public int getCount() {
return data.size();
}

@Override
public Object getItem(int i) {
return data.get(i);
}

@Override
public long getItemId(int i) {
return i;
}

@SuppressLint("ViewHolder")
@Override
public View getView(int i, View convertView, ViewGroup viewGroup) {
ViewHolder holder;
if (convertView == null) {
MethodsListBinding binding = MethodsListBinding.inflate(inflater, viewGroup, false);
holder = new ViewHolder(binding);
convertView = binding.getRoot();
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}

MethodDeclaration method = data.get(i);
holder.binding.title.setText(method.getNameAsString());

return convertView;
}

static class ViewHolder {
MethodsListBinding binding;

ViewHolder(MethodsListBinding binding) {
this.binding = binding;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void onBindViewHolder(@NonNull TreeViewHolder<NodeData> holder) {
NodeviewBinding binding = NodeviewBinding.bind(root);

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

Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/com/dark/androidbox/model/NodeData.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@
import com.dark.androidbox.nodes.BaseNode;
import com.dark.androidbox.types.NodeTypes;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class NodeData {


public String title;
public String code;
public NodeTypes types;
public BaseNode node;
public List<?> data;


public NodeData(String title, String code, NodeTypes types, BaseNode node) {
public NodeData(String title, String code, NodeTypes types, BaseNode node, List<?> data) {
this.title = title;
this.code = code;
this.types = types;
this.node = node;
this.data = data;
}


Expand Down
16 changes: 15 additions & 1 deletion app/src/main/java/com/dark/androidbox/nodes/BaseNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import androidx.annotation.Nullable;

import com.dark.androidbox.databinding.BaseNodeBinding;
import com.dark.androidbox.model.NodeData;
import com.gyso.treeview.model.NodeModel;

public class BaseNode extends FrameLayout {

BaseNodeBinding binding;
NodeModel<NodeData> data;
private BaseNodeBinding binding;

public BaseNode(Context context) {
super(context);
Expand All @@ -38,4 +42,14 @@ public void init() {
binding = BaseNodeBinding.inflate(LayoutInflater.from(getContext()), this, true);
setBackgroundColor(Color.WHITE);
}

public View getNode(NodeModel<NodeData> data) {
this.data = data;
postInit();
return this;
}

public void postInit() {

}
}
17 changes: 12 additions & 5 deletions app/src/main/java/com/dark/androidbox/nodes/ClassNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
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;
import com.dark.androidbox.databinding.ClassNodeBinding;

public class ClassNode extends BaseNode{
public class ClassNode extends BaseNode {

private ClassNodeBinding binding;

public ClassNode(Context context) {
super(context);
Expand All @@ -32,6 +32,13 @@ public ClassNode(Context context, @Nullable AttributeSet attrs, int defStyleAttr
@Override
public void init() {
super.init();
setBackgroundColor(Color.GREEN);
binding = ClassNodeBinding.inflate(LayoutInflater.from(getContext()), this, true);
setBackgroundColor(Color.WHITE);
}

@Override
public void postInit() {
super.postInit();
binding.title.setText(data.value.title);
}
}
84 changes: 84 additions & 0 deletions app/src/main/java/com/dark/androidbox/nodes/MethodNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
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.AdapterView;
import android.widget.ArrayAdapter;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatSpinner;

import com.dark.androidbox.MainActivity;
import com.dark.androidbox.adapter.MethodSelectAdapter;
import com.dark.androidbox.databinding.MethodNodeBinding;
import com.github.javaparser.ast.body.MethodDeclaration;

import java.util.ArrayList;
import java.util.List;

public class MethodNode extends BaseNode {

private MethodNodeBinding binding;

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

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

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

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

@Override
public void init() {
super.init();
binding = MethodNodeBinding.inflate(LayoutInflater.from(getContext()), this, true);
setBackgroundColor(Color.GREEN);
}

@Override
public void postInit() {
super.postInit();
binding.title.setVisibility(GONE);

setup(binding.choose);

}


void setup(AppCompatSpinner spinner) {

MethodSelectAdapter adapter = new MethodSelectAdapter(getContext(), (List<MethodDeclaration>) data.getParentNode().value.data);



// Bind the adapter to the Spinner
spinner.setAdapter(adapter);

// Set a listener to handle item selection
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String selectedItem = parent.getItemAtPosition(position).toString();
binding.title.setText(selectedItem);
MainActivity.treeViewStatic.getEditor().setWantEdit(false);
}

@Override
public void onNothingSelected(AdapterView<?> parent) {
// Handle the case where no item is selected
}
});
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/bg_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/white"/>
<corners android:radius="12dp"/>
</shape>
Loading

0 comments on commit cdb0327

Please sign in to comment.