Changed library for TreeView. Now TreeView works!!!

This commit is contained in:
ChronosX88 2019-01-03 14:17:11 +04:00
parent 79a32d590b
commit c09373514b
No known key found for this signature in database
GPG Key ID: 8F92E090A87804AA
14 changed files with 320 additions and 18 deletions

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="WizardSettings">
<option name="children">
<map>
<entry key="vectorWizard">
<value>
<PersistentState>
<option name="children">
<map>
<entry key="vectorAssetStep">
<value>
<PersistentState>
<option name="children">
<map>
<entry key="clipartAsset">
<value>
<PersistentState>
<option name="values">
<map>
<entry key="url" value="jar:file:/home/chronosx/Документы/bin/Android%20Studio/plugins/android/lib/android.jar!/images/material_design_icons/hardware/ic_keyboard_arrow_right_black_24dp.xml" />
</map>
</option>
</PersistentState>
</value>
</entry>
</map>
</option>
<option name="values">
<map>
<entry key="outputName" value="ic_keyboard_arrow_right_black_24dp" />
<entry key="sourceFile" value="$USER_HOME$" />
</map>
</option>
</PersistentState>
</value>
</entry>
</map>
</option>
</PersistentState>
</value>
</entry>
</map>
</option>
</component>
</project>

View File

@ -1,5 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="7">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
<item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
<item index="6" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="6">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
<item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" />
</list>
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>

View File

@ -24,8 +24,7 @@ dependencies {
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
implementation 'com.github.bmelnychuk:atv:1.2.+'
implementation 'me.texy.treeview:treeview_lib:1.0.4'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.squareup.retrofit2:retrofit:2.1.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'

View File

@ -13,18 +13,19 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.unnamed.b.atv.model.TreeNode;
import com.unnamed.b.atv.view.AndroidTreeView;
import java.util.ArrayList;
import java.util.List;
import me.texy.treeview.TreeNode;
import me.texy.treeview.TreeView;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import ru.volgorobot.vrcatalog.additional.NodeViewFactory;
import ru.volgorobot.vrcatalog.api.Controller;
import ru.volgorobot.vrcatalog.api.VRApi;
import ru.volgorobot.vrcatalog.model.FirstLevelModel;
@ -32,9 +33,11 @@ import ru.volgorobot.vrcatalog.model.FirstLevelModel;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener, SwipeRefreshLayout.OnRefreshListener {
private TreeView treeView;
private VRApi vrApi;
private List<FirstLevelModel> firstLevelObjects = new ArrayList<>();
private List<TreeNode> firstLevelNodes = new ArrayList<>();
private TreeNode rootNode = TreeNode.root();
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -57,11 +60,15 @@ public class MainActivity extends AppCompatActivity
mSwipeRefreshLayout.setOnRefreshListener(MainActivity.this);
mSwipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary);
try{
refreshTree(false);
getTreeData(false);
} catch (IllegalStateException e) {
//
}
treeView = new TreeView(rootNode, MainActivity.this, new NodeViewFactory());
((ViewGroup) findViewById(R.id.treeViewContainer)).addView(treeView.getView());
}
@Override
@ -106,16 +113,10 @@ public class MainActivity extends AppCompatActivity
private void fillRootNode() {
for (int i = 0; i < firstLevelObjects.size(); i++) {
firstLevelNodes.add(new TreeNode(firstLevelObjects.get(i).getName()));
firstLevelNodes.get(i).setLevel(0);
}
ViewGroup containerView = findViewById(R.id.treeViewContainer);
containerView.removeAllViews();
TreeNode root = TreeNode.root();
root.addChildren(firstLevelNodes);
AndroidTreeView treeView = new AndroidTreeView(MainActivity.this, root);
treeView.setDefaultAnimation(true);
treeView.setDefaultContainerStyle(R.style.TreeNodeStyle);
containerView.addView(treeView.getView());
rootNode.setChildren(firstLevelNodes);
}
@Override
@ -124,13 +125,13 @@ public class MainActivity extends AppCompatActivity
mSwipeRefreshLayout.setRefreshing(true);
try {
refreshTree(true);
getTreeData(true);
} catch (IllegalStateException e) {
//
}
}
private void refreshTree(boolean clean) throws IllegalStateException {
private void getTreeData(boolean clean) throws IllegalStateException {
final SwipeRefreshLayout mSwipeRefreshLayout = findViewById(R.id.swipeRefreshLayout);
mSwipeRefreshLayout.setRefreshing(true);
@ -170,6 +171,7 @@ public class MainActivity extends AppCompatActivity
mSwipeRefreshLayout.setRefreshing(false);
}
fillRootNode();
treeView.refreshTreeView();
} else {
Log.e("VRCatalog", "Что-то пошло не так...");
mSwipeRefreshLayout.setRefreshing(false);
@ -180,7 +182,7 @@ public class MainActivity extends AppCompatActivity
@Override
public void onFailure(Call<List<FirstLevelModel>> call, Throwable t) {
Toast.makeText(MainActivity.this, "Ошибка сети. Проверьте подключение к сети или данные подключения к API!", Toast.LENGTH_LONG).show();
Log.e("VRCatalog", "Network Error! Re-check your connection credentials or network settings!");
Log.e("VRCatalog", "Network Error! Re-check your connection credentials or network settings! Technical information: " + t.toString());
mSwipeRefreshLayout.setRefreshing(false);
}
});

View File

@ -0,0 +1,25 @@
package ru.volgorobot.vrcatalog.additional;
import android.view.View;
import me.texy.treeview.base.BaseNodeViewBinder;
import me.texy.treeview.base.BaseNodeViewFactory;
import ru.volgorobot.vrcatalog.nodeViewBinders.FirstLevelNodeViewBinder;
import ru.volgorobot.vrcatalog.nodeViewBinders.SecondLevelNodeViewBinder;
import ru.volgorobot.vrcatalog.nodeViewBinders.ThirdLevelNodeViewBinder;
public class NodeViewFactory extends BaseNodeViewFactory {
@Override
public BaseNodeViewBinder getNodeViewBinder(View view, int level) {
switch (level) {
case 0:
return new FirstLevelNodeViewBinder(view);
case 1:
return new SecondLevelNodeViewBinder(view);
case 2:
return new ThirdLevelNodeViewBinder(view);
default:
return null;
}
}
}

View File

@ -0,0 +1,39 @@
package ru.volgorobot.vrcatalog.nodeViewBinders;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import me.texy.treeview.TreeNode;
import me.texy.treeview.base.BaseNodeViewBinder;
import ru.volgorobot.vrcatalog.R;
public class FirstLevelNodeViewBinder extends BaseNodeViewBinder {
TextView textView;
ImageView imageView;
public FirstLevelNodeViewBinder(View itemView) {
super(itemView);
textView = (TextView) itemView.findViewById(R.id.node_name_view);
imageView = (ImageView) itemView.findViewById(R.id.arrow_img);
}
@Override
public int getLayoutId() {
return R.layout.first_level_item;
}
@Override
public void bindView(TreeNode treeNode) {
textView.setText(treeNode.getValue().toString());
}
@Override
public void onNodeToggled(TreeNode treeNode, boolean expand) {
if (expand) {
imageView.animate().rotation(90).setDuration(200).start();
} else {
imageView.animate().rotation(0).setDuration(200).start();
}
}
}

View File

@ -0,0 +1,40 @@
package ru.volgorobot.vrcatalog.nodeViewBinders;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import me.texy.treeview.TreeNode;
import me.texy.treeview.base.BaseNodeViewBinder;
import ru.volgorobot.vrcatalog.R;
public class SecondLevelNodeViewBinder extends BaseNodeViewBinder {
TextView textView;
ImageView imageView;
public SecondLevelNodeViewBinder(View itemView) {
super(itemView);
textView = (TextView) itemView.findViewById(R.id.node_name_view);
imageView = (ImageView) itemView.findViewById(R.id.arrow_img);
}
@Override
public int getLayoutId() {
return R.layout.second_level_item;
}
@Override
public void bindView(final TreeNode treeNode) {
textView.setText(treeNode.getValue().toString());
imageView.setRotation(treeNode.isExpanded() ? 90 : 0);
}
@Override
public void onNodeToggled(TreeNode treeNode, boolean expand) {
if (expand) {
imageView.animate().rotation(90).setDuration(200).start();
} else {
imageView.animate().rotation(0).setDuration(200).start();
}
}
}

View File

@ -0,0 +1,27 @@
package ru.volgorobot.vrcatalog.nodeViewBinders;
import android.view.View;
import android.widget.TextView;
import me.texy.treeview.TreeNode;
import me.texy.treeview.base.BaseNodeViewBinder;
import ru.volgorobot.vrcatalog.R;
public class ThirdLevelNodeViewBinder extends BaseNodeViewBinder {
TextView textView;
public ThirdLevelNodeViewBinder(View itemView) {
super(itemView);
textView = (TextView) itemView.findViewById(R.id.node_name_view);
}
@Override
public int getLayoutId() {
return R.layout.third_level_item;
}
@Override
public void bindView(final TreeNode treeNode) {
textView.setText(treeNode.getValue().toString());
}
}

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M8.59,16.34l4.58,-4.59 -4.58,-4.59L10,5.75l6,6 -6,6z"/>
</vector>

View File

@ -0,0 +1,30 @@
<?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="80dp">
<LinearLayout
android:id="@+id/node_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/arrow_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_keyboard_arrow_right_black_24dp" />
<TextView
android:id="@+id/node_name_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="monospace"
android:textSize="15dp"
android:text="Tree Node" />
</LinearLayout>
</RelativeLayout>

View File

@ -0,0 +1,31 @@
<?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="60dp"
android:orientation="vertical">
<LinearLayout
android:id="@+id/node_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="60dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/arrow_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_keyboard_arrow_right_black_24dp" />
<TextView
android:id="@+id/node_name_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="monospace"
android:text="Tree Node"
android:textSize="15dp" />
</LinearLayout>
</RelativeLayout>

View File

@ -0,0 +1,26 @@
<?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="40dp"
android:orientation="vertical">
<LinearLayout
android:id="@+id/node_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="110dp"
android:orientation="horizontal">
<TextView
android:id="@+id/node_name_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="monospace"
android:text="Tree Node"
android:textSize="15dp" />
</LinearLayout>
</RelativeLayout>

View File

@ -1,4 +1,3 @@
#Fri Nov 16 14:50:11 MSK 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME