From 2d823ac11cfd12ae71b2312e0949f02ea287409f Mon Sep 17 00:00:00 2001 From: ChronosX88 Date: Tue, 20 Nov 2018 14:23:32 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D1=83=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BE=D1=87=D0=B8=D1=81=D1=82=D0=BA=D1=83=20=D0=B4=D0=B5=D1=80?= =?UTF-8?q?=D0=B5=D0=B2=D0=B0=20(=D0=B8=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B8),=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D1=81=D0=BF?= =?UTF-8?q?=D0=B8=D0=BD=D0=BD=D0=B5=D1=80=20=D0=BF=D1=80=D0=B8=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/volgorobot/vrcatalog/MainActivity.java | 40 +++++++++++++------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/MainActivity.java b/app/src/main/java/ru/volgorobot/vrcatalog/MainActivity.java index be58598..aeccc82 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/MainActivity.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/MainActivity.java @@ -59,17 +59,19 @@ public class MainActivity extends AppCompatActivity mSwipeRefreshLayout.setOnRefreshListener(MainActivity.this); mSwipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary); - treeView = new AndroidTreeView(MainActivity.this, root); - treeView.setDefaultAnimation(true); - ViewGroup containerView = (ViewGroup) findViewById(R.id.treeViewContainer); - containerView.addView(treeView.getView()); - try{ - refreshTree(); + refreshTree(false); } catch (IllegalStateException e) { // } + root.addChildren(firstLevelNodes); + treeView = new AndroidTreeView(MainActivity.this, root); + treeView.setDefaultAnimation(true); + ViewGroup containerView = (ViewGroup) findViewById(R.id.treeViewContainer); + + containerView.addView(treeView.getView()); + } @Override @@ -111,10 +113,12 @@ public class MainActivity extends AppCompatActivity return true; } - private void fillFirstLevelNodes() { + private void fillRootNode() { for (int i = 0; i < firstLevelObjects.size(); i++) { firstLevelNodes.add(new TreeNode(firstLevelObjects.get(i).getName())); } + SwipeRefreshLayout mSwipeRefreshLayout = findViewById(R.id.swipeRefreshLayout); + mSwipeRefreshLayout.setRefreshing(false); } @Override @@ -123,7 +127,7 @@ public class MainActivity extends AppCompatActivity mSwipeRefreshLayout.setRefreshing(true); try { - refreshTree(); + refreshTree(true); } catch (IllegalStateException e) { // } @@ -137,11 +141,21 @@ public class MainActivity extends AppCompatActivity }); } - private void refreshTree() throws IllegalStateException { + private void refreshTree(boolean clean) throws IllegalStateException { - for (int i = 0; i < firstLevelNodes.size(); i++) { - root.deleteChild(firstLevelNodes.get(i)); - firstLevelNodes.remove(i); + SwipeRefreshLayout mSwipeRefreshLayout = findViewById(R.id.swipeRefreshLayout); + mSwipeRefreshLayout.setRefreshing(true); + if(clean) { + List list = new ArrayList<>(root.getChildren()); + for (int i = 0; i < list.size(); i++) { + root.deleteChild(list.get(i)); + } + for (int i = 0; i < firstLevelNodes.size(); i++) { + firstLevelNodes.remove(i); + } + for (int i = 0; i < firstLevelObjects.size(); i++) { + firstLevelObjects.remove(i); + } } SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); @@ -163,7 +177,7 @@ public class MainActivity extends AppCompatActivity Toast.makeText(MainActivity.this, "Ответ от сервера неверен! Перепроверьте данные подключения!", Toast.LENGTH_LONG).show(); Log.e("ERROR", "Answer of server is wrong! Re-check your connection credentials! Error: " + response.message()); } - fillFirstLevelNodes(); + fillRootNode(); } else { Log.e("ERROR", "Что-то пошло не так..."); }