diff --git a/.idea/assetWizardSettings.xml b/.idea/assetWizardSettings.xml new file mode 100644 index 0000000..e64e3f9 --- /dev/null +++ b/.idea/assetWizardSettings.xml @@ -0,0 +1,46 @@ + + + + + + \ No newline at end of file diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index b985abc..ef96a85 100644 Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ diff --git a/.idea/misc.xml b/.idea/misc.xml index 37a7509..e0d5b93 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,34 @@ + + + + diff --git a/app/build.gradle b/app/build.gradle index f39c78e..3d8f62f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/MainActivity.java b/app/src/main/java/ru/volgorobot/vrcatalog/MainActivity.java index 5213dcb..1f71f27 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/MainActivity.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/MainActivity.java @@ -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 firstLevelObjects = new ArrayList<>(); private List 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> 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); } }); diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/additional/NodeViewFactory.java b/app/src/main/java/ru/volgorobot/vrcatalog/additional/NodeViewFactory.java new file mode 100644 index 0000000..caba708 --- /dev/null +++ b/app/src/main/java/ru/volgorobot/vrcatalog/additional/NodeViewFactory.java @@ -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; + } + } +} diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/nodeViewBinders/FirstLevelNodeViewBinder.java b/app/src/main/java/ru/volgorobot/vrcatalog/nodeViewBinders/FirstLevelNodeViewBinder.java new file mode 100644 index 0000000..edc69ec --- /dev/null +++ b/app/src/main/java/ru/volgorobot/vrcatalog/nodeViewBinders/FirstLevelNodeViewBinder.java @@ -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(); + } + } +} diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/nodeViewBinders/SecondLevelNodeViewBinder.java b/app/src/main/java/ru/volgorobot/vrcatalog/nodeViewBinders/SecondLevelNodeViewBinder.java new file mode 100644 index 0000000..2b55270 --- /dev/null +++ b/app/src/main/java/ru/volgorobot/vrcatalog/nodeViewBinders/SecondLevelNodeViewBinder.java @@ -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(); + } + } +} diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/nodeViewBinders/ThirdLevelNodeViewBinder.java b/app/src/main/java/ru/volgorobot/vrcatalog/nodeViewBinders/ThirdLevelNodeViewBinder.java new file mode 100644 index 0000000..238cabe --- /dev/null +++ b/app/src/main/java/ru/volgorobot/vrcatalog/nodeViewBinders/ThirdLevelNodeViewBinder.java @@ -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()); + } +} diff --git a/app/src/main/res/drawable/ic_keyboard_arrow_right_black_24dp.xml b/app/src/main/res/drawable/ic_keyboard_arrow_right_black_24dp.xml new file mode 100644 index 0000000..a3d1622 --- /dev/null +++ b/app/src/main/res/drawable/ic_keyboard_arrow_right_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/first_level_item.xml b/app/src/main/res/layout/first_level_item.xml new file mode 100644 index 0000000..f53dc6d --- /dev/null +++ b/app/src/main/res/layout/first_level_item.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/second_level_item.xml b/app/src/main/res/layout/second_level_item.xml new file mode 100644 index 0000000..f2d1388 --- /dev/null +++ b/app/src/main/res/layout/second_level_item.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/third_level_item.xml b/app/src/main/res/layout/third_level_item.xml new file mode 100644 index 0000000..879bd0e --- /dev/null +++ b/app/src/main/res/layout/third_level_item.xml @@ -0,0 +1,26 @@ + + + + + + + + + + \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2b05c88..3f0f9be 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,3 @@ -#Fri Nov 16 14:50:11 MSK 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME