Fixed infinity refreshing (when error occured) for SwipeRefreshLayout.

This commit is contained in:
ChronosX88 2018-11-20 15:35:21 +03:00
parent 2d823ac11c
commit 0279a95ab3
2 changed files with 4 additions and 1 deletions

View File

@ -143,7 +143,7 @@ public class MainActivity extends AppCompatActivity
private void refreshTree(boolean clean) throws IllegalStateException {
SwipeRefreshLayout mSwipeRefreshLayout = findViewById(R.id.swipeRefreshLayout);
final SwipeRefreshLayout mSwipeRefreshLayout = findViewById(R.id.swipeRefreshLayout);
mSwipeRefreshLayout.setRefreshing(true);
if(clean) {
List<TreeNode> list = new ArrayList<>(root.getChildren());
@ -176,10 +176,12 @@ public class MainActivity extends AppCompatActivity
} catch(Exception e) {
Toast.makeText(MainActivity.this, "Ответ от сервера неверен! Перепроверьте данные подключения!", Toast.LENGTH_LONG).show();
Log.e("ERROR", "Answer of server is wrong! Re-check your connection credentials! Error: " + response.message());
mSwipeRefreshLayout.setRefreshing(false);
}
fillRootNode();
} else {
Log.e("ERROR", "Что-то пошло не так...");
mSwipeRefreshLayout.setRefreshing(false);
}
}
@ -188,6 +190,7 @@ public class MainActivity extends AppCompatActivity
public void onFailure(Call<List<FirstLevelModel>> call, Throwable t) {
Toast.makeText(MainActivity.this, "Ошибка сети. Проверьте подключение к сети или данные подключения к API!", Toast.LENGTH_LONG).show();
Log.e("ERROR", "getFirstLevel() failed!");
mSwipeRefreshLayout.setRefreshing(false);
}
});
}