Сделал проверку на очистку дерева (и модели), сделал спиннер при загрузке.
This commit is contained in:
parent
8c8927489d
commit
2d823ac11c
@ -59,17 +59,19 @@ public class MainActivity extends AppCompatActivity
|
|||||||
mSwipeRefreshLayout.setOnRefreshListener(MainActivity.this);
|
mSwipeRefreshLayout.setOnRefreshListener(MainActivity.this);
|
||||||
mSwipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary);
|
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{
|
try{
|
||||||
refreshTree();
|
refreshTree(false);
|
||||||
} catch (IllegalStateException e) {
|
} 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
|
@Override
|
||||||
@ -111,10 +113,12 @@ public class MainActivity extends AppCompatActivity
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillFirstLevelNodes() {
|
private void fillRootNode() {
|
||||||
for (int i = 0; i < firstLevelObjects.size(); i++) {
|
for (int i = 0; i < firstLevelObjects.size(); i++) {
|
||||||
firstLevelNodes.add(new TreeNode(firstLevelObjects.get(i).getName()));
|
firstLevelNodes.add(new TreeNode(firstLevelObjects.get(i).getName()));
|
||||||
}
|
}
|
||||||
|
SwipeRefreshLayout mSwipeRefreshLayout = findViewById(R.id.swipeRefreshLayout);
|
||||||
|
mSwipeRefreshLayout.setRefreshing(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -123,7 +127,7 @@ public class MainActivity extends AppCompatActivity
|
|||||||
mSwipeRefreshLayout.setRefreshing(true);
|
mSwipeRefreshLayout.setRefreshing(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
refreshTree();
|
refreshTree(true);
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
@ -137,12 +141,22 @@ public class MainActivity extends AppCompatActivity
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshTree() throws IllegalStateException {
|
private void refreshTree(boolean clean) throws IllegalStateException {
|
||||||
|
|
||||||
|
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++) {
|
for (int i = 0; i < firstLevelNodes.size(); i++) {
|
||||||
root.deleteChild(firstLevelNodes.get(i));
|
|
||||||
firstLevelNodes.remove(i);
|
firstLevelNodes.remove(i);
|
||||||
}
|
}
|
||||||
|
for (int i = 0; i < firstLevelObjects.size(); i++) {
|
||||||
|
firstLevelObjects.remove(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
String baseURL = sharedPreferences.getString("addressOfServer", "");
|
String baseURL = sharedPreferences.getString("addressOfServer", "");
|
||||||
@ -163,7 +177,7 @@ public class MainActivity extends AppCompatActivity
|
|||||||
Toast.makeText(MainActivity.this, "Ответ от сервера неверен! Перепроверьте данные подключения!", Toast.LENGTH_LONG).show();
|
Toast.makeText(MainActivity.this, "Ответ от сервера неверен! Перепроверьте данные подключения!", Toast.LENGTH_LONG).show();
|
||||||
Log.e("ERROR", "Answer of server is wrong! Re-check your connection credentials! Error: " + response.message());
|
Log.e("ERROR", "Answer of server is wrong! Re-check your connection credentials! Error: " + response.message());
|
||||||
}
|
}
|
||||||
fillFirstLevelNodes();
|
fillRootNode();
|
||||||
} else {
|
} else {
|
||||||
Log.e("ERROR", "Что-то пошло не так...");
|
Log.e("ERROR", "Что-то пошло не так...");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user