Сделал проверку на очистку дерева (и модели), сделал спиннер при загрузке.

This commit is contained in:
ChronosX88 2018-11-20 14:23:32 +04:00
parent 8c8927489d
commit 2d823ac11c

View File

@ -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<TreeNode> 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", "Что-то пошло не так...");
}