From 06f3df407c8555bf6870ebf722c227b77c94ac26 Mon Sep 17 00:00:00 2001 From: ChronosX88 Date: Mon, 25 Feb 2019 16:44:57 +0400 Subject: [PATCH] Made multicolored rows (gray-white) in SearchableView --- .../ru/volgorobot/vrcatalog/MainContract.java | 2 ++ .../additional/SearchableNodeViewFactory.java | 4 ++-- .../FirstLevelNodeViewBinder.java | 17 ++++++++++++++++- .../SecondLevelNodeViewBinder.java | 17 ++++++++++++++++- .../volgorobot/vrcatalog/view/MainActivity.java | 1 + .../vrcatalog/view/SearchableActivity.java | 3 ++- 6 files changed, 39 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/MainContract.java b/app/src/main/java/ru/volgorobot/vrcatalog/MainContract.java index 14c60b6..e7d3303 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/MainContract.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/MainContract.java @@ -68,6 +68,8 @@ public interface MainContract { void setTreeViewChildren(ArrayList children); void onFailureAnswer(int errorCode); void swipeLayoutSetRefreshing(boolean state); + int incTreeNodeIndex(); + } interface ItemPresenter { diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/additional/SearchableNodeViewFactory.java b/app/src/main/java/ru/volgorobot/vrcatalog/additional/SearchableNodeViewFactory.java index baca273..04aab56 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/additional/SearchableNodeViewFactory.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/additional/SearchableNodeViewFactory.java @@ -23,9 +23,9 @@ public class SearchableNodeViewFactory extends BaseNodeViewFactory { public BaseNodeViewBinder getNodeViewBinder(View view, int level) { switch (level) { case 0: - return new FirstLevelNodeViewBinder(view); + return new FirstLevelNodeViewBinder(view, mView); case 1: - return new SecondLevelNodeViewBinder(view); + return new SecondLevelNodeViewBinder(view, mView); case 2: return new ThirdLevelNodeViewBinder(view, context, mView); default: diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/searchNodeViewBinders/FirstLevelNodeViewBinder.java b/app/src/main/java/ru/volgorobot/vrcatalog/searchNodeViewBinders/FirstLevelNodeViewBinder.java index 674cc54..2f4000c 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/searchNodeViewBinders/FirstLevelNodeViewBinder.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/searchNodeViewBinders/FirstLevelNodeViewBinder.java @@ -1,21 +1,28 @@ package ru.volgorobot.vrcatalog.searchNodeViewBinders; +import android.graphics.Color; import android.view.View; import android.widget.ImageView; +import android.widget.RelativeLayout; import android.widget.TextView; import me.texy.treeview.TreeNode; import me.texy.treeview.base.BaseNodeViewBinder; +import ru.volgorobot.vrcatalog.MainContract; import ru.volgorobot.vrcatalog.R; public class FirstLevelNodeViewBinder extends BaseNodeViewBinder { TextView textView; ImageView imageView; + RelativeLayout layout; + MainContract.MainActivityView mView; - public FirstLevelNodeViewBinder(View itemView) { + public FirstLevelNodeViewBinder(View itemView, MainContract.MainActivityView mView) { super(itemView); textView = (TextView) itemView.findViewById(R.id.node_name_view); imageView = (ImageView) itemView.findViewById(R.id.arrow_img); + layout = itemView.findViewById(R.id.parent_node_container_1); + this.mView = mView; } @Override @@ -26,6 +33,14 @@ public class FirstLevelNodeViewBinder extends BaseNodeViewBinder { @Override public void bindView(TreeNode treeNode) { textView.setText(treeNode.getValue().toString()); + imageView.setRotation(treeNode.isExpanded() ? 90 : 0); + int index = mView.incTreeNodeIndex(); + treeNode.setIndex(index); + if(index % 2 == 1) { + layout.setBackgroundColor(Color.parseColor("#FFFFFF")); + } else { + layout.setBackgroundColor(Color.parseColor("#BABABA")); + } } @Override diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/searchNodeViewBinders/SecondLevelNodeViewBinder.java b/app/src/main/java/ru/volgorobot/vrcatalog/searchNodeViewBinders/SecondLevelNodeViewBinder.java index 8718470..ebdf541 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/searchNodeViewBinders/SecondLevelNodeViewBinder.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/searchNodeViewBinders/SecondLevelNodeViewBinder.java @@ -1,21 +1,28 @@ package ru.volgorobot.vrcatalog.searchNodeViewBinders; +import android.graphics.Color; import android.view.View; import android.widget.ImageView; +import android.widget.RelativeLayout; import android.widget.TextView; import me.texy.treeview.TreeNode; import me.texy.treeview.base.BaseNodeViewBinder; +import ru.volgorobot.vrcatalog.MainContract; import ru.volgorobot.vrcatalog.R; public class SecondLevelNodeViewBinder extends BaseNodeViewBinder { TextView textView; ImageView imageView; + RelativeLayout layout; + MainContract.MainActivityView mView; - public SecondLevelNodeViewBinder(View itemView) { + public SecondLevelNodeViewBinder(View itemView, MainContract.MainActivityView mView) { super(itemView); textView = (TextView) itemView.findViewById(R.id.node_name_view); imageView = (ImageView) itemView.findViewById(R.id.arrow_img); + layout = itemView.findViewById(R.id.parent_node_container_2); + this.mView = mView; } @Override @@ -26,6 +33,14 @@ public class SecondLevelNodeViewBinder extends BaseNodeViewBinder { @Override public void bindView(TreeNode treeNode) { textView.setText(treeNode.getValue().toString()); + imageView.setRotation(treeNode.isExpanded() ? 90 : 0); + int index = mView.incTreeNodeIndex(); + treeNode.setIndex(index); + if(index % 2 == 1) { + layout.setBackgroundColor(Color.parseColor("#FFFFFF")); + } else { + layout.setBackgroundColor(Color.parseColor("#BABABA")); + } } @Override diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/view/MainActivity.java b/app/src/main/java/ru/volgorobot/vrcatalog/view/MainActivity.java index d97ed36..46e9c17 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/view/MainActivity.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/view/MainActivity.java @@ -125,6 +125,7 @@ public class MainActivity extends AppCompatActivity @Override public void onRefresh() { + treeNodeIndex = 0; mConnectionErrorImageView.setVisibility(View.INVISIBLE); mErrorTextView.setVisibility(View.INVISIBLE); mTreeViewContainer.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/view/SearchableActivity.java b/app/src/main/java/ru/volgorobot/vrcatalog/view/SearchableActivity.java index b6846bb..d1c3697 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/view/SearchableActivity.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/view/SearchableActivity.java @@ -35,6 +35,7 @@ public class SearchableActivity extends AppCompatActivity implements MainContrac private ImageView mConnectionErrorImageView; private NestedScrollView mTreeViewContainer; private TextView mErrorTextView; + private int treeNodeIndex; @Override protected void onCreate(Bundle savedInstanceState) { @@ -150,6 +151,6 @@ public class SearchableActivity extends AppCompatActivity implements MainContrac @Override public int incTreeNodeIndex() { - return 0; + return treeNodeIndex++; } }