From f29121ac7c7e98e8997306bc24b283cec55e0984 Mon Sep 17 00:00:00 2001 From: ChronosX88 Date: Mon, 25 Feb 2019 18:20:18 +0400 Subject: [PATCH] Removed multicolored rows (as a result of testing, this is terrible) --- .../ru/volgorobot/vrcatalog/MainContract.java | 3 - .../FirstLevelNodeViewBinder.java | 11 ---- .../SecondLevelNodeViewBinder.java | 11 ---- .../ThirdLevelNodeViewBinder.java | 11 ---- .../presenters/ViewBinderPresenter.java | 55 ++++++++++--------- .../FirstLevelNodeViewBinder.java | 11 ---- .../SecondLevelNodeViewBinder.java | 11 ---- .../vrcatalog/view/MainActivity.java | 7 --- .../vrcatalog/view/SearchableActivity.java | 6 -- 9 files changed, 29 insertions(+), 97 deletions(-) diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/MainContract.java b/app/src/main/java/ru/volgorobot/vrcatalog/MainContract.java index e7d3303..991ebef 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/MainContract.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/MainContract.java @@ -20,7 +20,6 @@ public interface MainContract { void onFailureAnswer(int errorCode); void refreshTree(); void startActivityByIntent(Intent intent); - int incTreeNodeIndex(); } interface Presenter { @@ -68,8 +67,6 @@ 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/nodeViewBinders/FirstLevelNodeViewBinder.java b/app/src/main/java/ru/volgorobot/vrcatalog/nodeViewBinders/FirstLevelNodeViewBinder.java index 7f55e80..acad9cb 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/nodeViewBinders/FirstLevelNodeViewBinder.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/nodeViewBinders/FirstLevelNodeViewBinder.java @@ -18,16 +18,12 @@ import ru.volgorobot.vrcatalog.model.FirstLevelModel; public class FirstLevelNodeViewBinder extends BaseNodeViewBinder implements MainContract.ViewBinder { TextView textView; ImageView imageView; - RelativeLayout layout; ViewBinderPresenter viewBinderPresenter; - private MainContract.MainActivityView mView; public FirstLevelNodeViewBinder(View itemView, MainContract.MainActivityView mView, Context context) { 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; viewBinderPresenter = new ViewBinderPresenter(mView, this, context); } @@ -40,13 +36,6 @@ public class FirstLevelNodeViewBinder extends BaseNodeViewBinder implements Main 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/nodeViewBinders/SecondLevelNodeViewBinder.java b/app/src/main/java/ru/volgorobot/vrcatalog/nodeViewBinders/SecondLevelNodeViewBinder.java index 04c114f..026cf46 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/nodeViewBinders/SecondLevelNodeViewBinder.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/nodeViewBinders/SecondLevelNodeViewBinder.java @@ -17,8 +17,6 @@ import ru.volgorobot.vrcatalog.model.SecondLevelModel; public class SecondLevelNodeViewBinder extends BaseNodeViewBinder implements MainContract.ViewBinder { TextView textView; ImageView imageView; - RelativeLayout layout; - private MainContract.MainActivityView mView; MainContract.LevelLoaderPresenter viewBinderPresenter; @@ -26,8 +24,6 @@ public class SecondLevelNodeViewBinder extends BaseNodeViewBinder implements Mai 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; viewBinderPresenter = new ViewBinderPresenter(mView, this, context); } @@ -40,13 +36,6 @@ public class SecondLevelNodeViewBinder extends BaseNodeViewBinder implements Mai public void bindView(final 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/nodeViewBinders/ThirdLevelNodeViewBinder.java b/app/src/main/java/ru/volgorobot/vrcatalog/nodeViewBinders/ThirdLevelNodeViewBinder.java index 6d39968..0c7529a 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/nodeViewBinders/ThirdLevelNodeViewBinder.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/nodeViewBinders/ThirdLevelNodeViewBinder.java @@ -15,16 +15,12 @@ import ru.volgorobot.vrcatalog.model.ThirdLevelModel; public class ThirdLevelNodeViewBinder extends BaseNodeViewBinder implements MainContract.ViewBinder { TextView textView; - RelativeLayout layout; - private MainContract.MainActivityView mView; MainContract.LevelLoaderPresenter viewBinderPresenter; public ThirdLevelNodeViewBinder(View itemView, Context context, MainContract.MainActivityView mView) { super(itemView); viewBinderPresenter = new ViewBinderPresenter(mView, this, context); textView = itemView.findViewById(R.id.node_name_view); - layout = itemView.findViewById(R.id.parent_node_container_3); - this.mView = mView; } @Override @@ -35,13 +31,6 @@ public class ThirdLevelNodeViewBinder extends BaseNodeViewBinder implements Main @Override public void bindView(final TreeNode treeNode) { textView.setText(treeNode.getValue().toString()); - 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/presenters/ViewBinderPresenter.java b/app/src/main/java/ru/volgorobot/vrcatalog/presenters/ViewBinderPresenter.java index 0c26546..a4a08e2 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/presenters/ViewBinderPresenter.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/presenters/ViewBinderPresenter.java @@ -32,7 +32,7 @@ public class ViewBinderPresenter implements MainContract.LevelLoaderPresenter { @Override public void fetchSecondLevel(FirstLevelModel firstLevelModel, TreeNode treeNode) { - new AsyncTask>>() { + new AsyncTask>>() { @Override protected void onPreExecute() { super.onPreExecute(); @@ -40,31 +40,32 @@ public class ViewBinderPresenter implements MainContract.LevelLoaderPresenter { } @Override - protected ResultWithErrorCode> doInBackground(FirstLevelModel... firstLevelModel) { + protected ResultWithErrorCode> doInBackground(FirstLevelModel... firstLevelModel) { ArrayList secondLevelModels = null; + ArrayList treeNodes = new ArrayList<>(); try { secondLevelModels = coreModel.fetchSecondLevelByParentID(firstLevelModel[0].getID()); } catch (NetworkErrorException networkErrorException) { - return new ResultWithErrorCode<>(secondLevelModels, networkErrorException.getErrorCode()); + return new ResultWithErrorCode<>(null, networkErrorException.getErrorCode()); } catch (NullPointerException nullPointerException) { - return new ResultWithErrorCode<>(secondLevelModels, 3); + return new ResultWithErrorCode<>(null, 3); } - return new ResultWithErrorCode<>(secondLevelModels, 0); + for (int i = 0; i < secondLevelModels.size(); i++) { + TreeNode treeNode = new TreeNode(secondLevelModels.get(i)); + treeNode.setLevel(1); + treeNodes.add(treeNode); + } + + return new ResultWithErrorCode<>(treeNodes, 0); } @Override - protected void onPostExecute(ResultWithErrorCode> result) { + protected void onPostExecute(ResultWithErrorCode> result) { super.onPostExecute(result); switch (result.getErrorCode()) { case 0: { - ArrayList treeNodes = new ArrayList<>(); - for (int i = 0; i < result.getData().size(); i++) { - TreeNode treeNode1 = new TreeNode(result.getData().get(i)); - treeNode1.setLevel(1); - treeNodes.add(treeNode1); - } - treeNode.setChildren(treeNodes); + treeNode.setChildren(result.getData()); mView.refreshTree(); viewBinder.rotateImageView(); break; @@ -89,7 +90,7 @@ public class ViewBinderPresenter implements MainContract.LevelLoaderPresenter { @Override public void fetchThirdLevel(SecondLevelModel secondLevelModel, TreeNode treeNode) { - new AsyncTask>>() { + new AsyncTask>>() { @Override protected void onPreExecute() { super.onPreExecute(); @@ -97,30 +98,32 @@ public class ViewBinderPresenter implements MainContract.LevelLoaderPresenter { } @Override - protected ResultWithErrorCode> doInBackground(SecondLevelModel... secondLevelModel) { + protected ResultWithErrorCode> doInBackground(SecondLevelModel... secondLevelModel) { ArrayList thirdLevelModels = null; + ArrayList treeNodes = new ArrayList<>(); try { thirdLevelModels = coreModel.fetchThirdLevelByParentID(secondLevelModel[0].getID()); } catch (NetworkErrorException networkErrorException) { - return new ResultWithErrorCode<>(thirdLevelModels, networkErrorException.getErrorCode()); + return new ResultWithErrorCode<>(null, networkErrorException.getErrorCode()); } catch (NullPointerException nullPointerException) { - return new ResultWithErrorCode<>(thirdLevelModels, 3); + return new ResultWithErrorCode<>(null, 3); } - return new ResultWithErrorCode<>(thirdLevelModels, 0); + + for (int i = 0; i < thirdLevelModels.size(); i++) { + TreeNode treeNode1 = new TreeNode(thirdLevelModels.get(i)); + treeNode1.setLevel(2); + treeNodes.add(treeNode1); + } + + return new ResultWithErrorCode<>(treeNodes, 0); } @Override - protected void onPostExecute(ResultWithErrorCode> result) { + protected void onPostExecute(ResultWithErrorCode> result) { super.onPostExecute(result); switch (result.getErrorCode()) { case 0: { - ArrayList treeNodes = new ArrayList<>(); - for (int i = 0; i < result.getData().size(); i++) { - TreeNode treeNode1 = new TreeNode(result.getData().get(i)); - treeNode1.setLevel(2); - treeNodes.add(treeNode1); - } - treeNode.setChildren(treeNodes); + treeNode.setChildren(result.getData()); mView.refreshTree(); viewBinder.rotateImageView(); break; 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 2f4000c..86acbac 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/searchNodeViewBinders/FirstLevelNodeViewBinder.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/searchNodeViewBinders/FirstLevelNodeViewBinder.java @@ -14,15 +14,11 @@ import ru.volgorobot.vrcatalog.R; public class FirstLevelNodeViewBinder extends BaseNodeViewBinder { TextView textView; ImageView imageView; - RelativeLayout layout; - MainContract.MainActivityView mView; 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 @@ -34,13 +30,6 @@ public class FirstLevelNodeViewBinder extends BaseNodeViewBinder { 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 ebdf541..b474415 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/searchNodeViewBinders/SecondLevelNodeViewBinder.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/searchNodeViewBinders/SecondLevelNodeViewBinder.java @@ -14,15 +14,11 @@ import ru.volgorobot.vrcatalog.R; public class SecondLevelNodeViewBinder extends BaseNodeViewBinder { TextView textView; ImageView imageView; - RelativeLayout layout; - MainContract.MainActivityView mView; 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 @@ -34,13 +30,6 @@ public class SecondLevelNodeViewBinder extends BaseNodeViewBinder { 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 46e9c17..6095e37 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/view/MainActivity.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/view/MainActivity.java @@ -45,7 +45,6 @@ public class MainActivity extends AppCompatActivity private ImageView mConnectionErrorImageView; private ViewGroup mTreeViewContainer; private TextView mErrorTextView; - private int treeNodeIndex; @Override protected void onCreate(Bundle savedInstanceState) { @@ -125,7 +124,6 @@ public class MainActivity extends AppCompatActivity @Override public void onRefresh() { - treeNodeIndex = 0; mConnectionErrorImageView.setVisibility(View.INVISIBLE); mErrorTextView.setVisibility(View.INVISIBLE); mTreeViewContainer.setVisibility(View.VISIBLE); @@ -207,11 +205,6 @@ public class MainActivity extends AppCompatActivity search.setQueryHint("Имя детали"); return true; } - - @Override - public int incTreeNodeIndex() { - return treeNodeIndex++; - } } 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 d1c3697..f411fcd 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/view/SearchableActivity.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/view/SearchableActivity.java @@ -35,7 +35,6 @@ 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) { @@ -148,9 +147,4 @@ public class SearchableActivity extends AppCompatActivity implements MainContrac } return super.onOptionsItemSelected(item); } - - @Override - public int incTreeNodeIndex() { - return treeNodeIndex++; - } }