Made multicolored rows (gray-white) in SearchableView

This commit is contained in:
ChronosX88 2019-02-25 16:44:57 +04:00
parent 4d331326b0
commit 06f3df407c
No known key found for this signature in database
GPG Key ID: 8F92E090A87804AA
6 changed files with 39 additions and 5 deletions

View File

@ -68,6 +68,8 @@ public interface MainContract {
void setTreeViewChildren(ArrayList<TreeNode> children); void setTreeViewChildren(ArrayList<TreeNode> children);
void onFailureAnswer(int errorCode); void onFailureAnswer(int errorCode);
void swipeLayoutSetRefreshing(boolean state); void swipeLayoutSetRefreshing(boolean state);
int incTreeNodeIndex();
} }
interface ItemPresenter { interface ItemPresenter {

View File

@ -23,9 +23,9 @@ public class SearchableNodeViewFactory extends BaseNodeViewFactory {
public BaseNodeViewBinder getNodeViewBinder(View view, int level) { public BaseNodeViewBinder getNodeViewBinder(View view, int level) {
switch (level) { switch (level) {
case 0: case 0:
return new FirstLevelNodeViewBinder(view); return new FirstLevelNodeViewBinder(view, mView);
case 1: case 1:
return new SecondLevelNodeViewBinder(view); return new SecondLevelNodeViewBinder(view, mView);
case 2: case 2:
return new ThirdLevelNodeViewBinder(view, context, mView); return new ThirdLevelNodeViewBinder(view, context, mView);
default: default:

View File

@ -1,21 +1,28 @@
package ru.volgorobot.vrcatalog.searchNodeViewBinders; package ru.volgorobot.vrcatalog.searchNodeViewBinders;
import android.graphics.Color;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import me.texy.treeview.TreeNode; import me.texy.treeview.TreeNode;
import me.texy.treeview.base.BaseNodeViewBinder; import me.texy.treeview.base.BaseNodeViewBinder;
import ru.volgorobot.vrcatalog.MainContract;
import ru.volgorobot.vrcatalog.R; import ru.volgorobot.vrcatalog.R;
public class FirstLevelNodeViewBinder extends BaseNodeViewBinder { public class FirstLevelNodeViewBinder extends BaseNodeViewBinder {
TextView textView; TextView textView;
ImageView imageView; ImageView imageView;
RelativeLayout layout;
MainContract.MainActivityView mView;
public FirstLevelNodeViewBinder(View itemView) { public FirstLevelNodeViewBinder(View itemView, MainContract.MainActivityView mView) {
super(itemView); super(itemView);
textView = (TextView) itemView.findViewById(R.id.node_name_view); textView = (TextView) itemView.findViewById(R.id.node_name_view);
imageView = (ImageView) itemView.findViewById(R.id.arrow_img); imageView = (ImageView) itemView.findViewById(R.id.arrow_img);
layout = itemView.findViewById(R.id.parent_node_container_1);
this.mView = mView;
} }
@Override @Override
@ -26,6 +33,14 @@ public class FirstLevelNodeViewBinder extends BaseNodeViewBinder {
@Override @Override
public void bindView(TreeNode treeNode) { public void bindView(TreeNode treeNode) {
textView.setText(treeNode.getValue().toString()); 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 @Override

View File

@ -1,21 +1,28 @@
package ru.volgorobot.vrcatalog.searchNodeViewBinders; package ru.volgorobot.vrcatalog.searchNodeViewBinders;
import android.graphics.Color;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import me.texy.treeview.TreeNode; import me.texy.treeview.TreeNode;
import me.texy.treeview.base.BaseNodeViewBinder; import me.texy.treeview.base.BaseNodeViewBinder;
import ru.volgorobot.vrcatalog.MainContract;
import ru.volgorobot.vrcatalog.R; import ru.volgorobot.vrcatalog.R;
public class SecondLevelNodeViewBinder extends BaseNodeViewBinder { public class SecondLevelNodeViewBinder extends BaseNodeViewBinder {
TextView textView; TextView textView;
ImageView imageView; ImageView imageView;
RelativeLayout layout;
MainContract.MainActivityView mView;
public SecondLevelNodeViewBinder(View itemView) { public SecondLevelNodeViewBinder(View itemView, MainContract.MainActivityView mView) {
super(itemView); super(itemView);
textView = (TextView) itemView.findViewById(R.id.node_name_view); textView = (TextView) itemView.findViewById(R.id.node_name_view);
imageView = (ImageView) itemView.findViewById(R.id.arrow_img); imageView = (ImageView) itemView.findViewById(R.id.arrow_img);
layout = itemView.findViewById(R.id.parent_node_container_2);
this.mView = mView;
} }
@Override @Override
@ -26,6 +33,14 @@ public class SecondLevelNodeViewBinder extends BaseNodeViewBinder {
@Override @Override
public void bindView(TreeNode treeNode) { public void bindView(TreeNode treeNode) {
textView.setText(treeNode.getValue().toString()); 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 @Override

View File

@ -125,6 +125,7 @@ public class MainActivity extends AppCompatActivity
@Override @Override
public void onRefresh() { public void onRefresh() {
treeNodeIndex = 0;
mConnectionErrorImageView.setVisibility(View.INVISIBLE); mConnectionErrorImageView.setVisibility(View.INVISIBLE);
mErrorTextView.setVisibility(View.INVISIBLE); mErrorTextView.setVisibility(View.INVISIBLE);
mTreeViewContainer.setVisibility(View.VISIBLE); mTreeViewContainer.setVisibility(View.VISIBLE);

View File

@ -35,6 +35,7 @@ public class SearchableActivity extends AppCompatActivity implements MainContrac
private ImageView mConnectionErrorImageView; private ImageView mConnectionErrorImageView;
private NestedScrollView mTreeViewContainer; private NestedScrollView mTreeViewContainer;
private TextView mErrorTextView; private TextView mErrorTextView;
private int treeNodeIndex;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -150,6 +151,6 @@ public class SearchableActivity extends AppCompatActivity implements MainContrac
@Override @Override
public int incTreeNodeIndex() { public int incTreeNodeIndex() {
return 0; return treeNodeIndex++;
} }
} }