@Override protected Parcelable onSaveInstanceState() { Parcelable superState = super.onSaveInstanceState(); SavedState ss = new SavedState(superState); ss.message = message.getText().toString(); ss.refreshing = swipeRefreshLayout.isRefreshing(); ss.loading = mAdapter.isLoading(); ss.resources = new ArrayList<>(mAdapter.getResources()); return ss; }
@Override public void showFirstLoading() { if (mAdapter.getItemCount() > 0) { swipeRefreshLayout.setRefreshing(true); } else { message.setVisibility(View.VISIBLE); message.setText(R.string.loading_msg); } }
@Override protected void onRestoreInstanceState(Parcelable state) { if (!(state instanceof SavedState)) { super.onRestoreInstanceState(state); return; } SavedState ss = (SavedState) state; super.onRestoreInstanceState(ss.getSuperState()); mAdapter.setResource(ss.resources); if (ss.loading) { mAdapter.showLoading(); } swipeRefreshLayout.setRefreshing(ss.refreshing); message.setText(ss.message); mInited = true; }
@Override public void hideLoading() { swipeRefreshLayout.setRefreshing(false); message.setVisibility(View.GONE); mAdapter.hideLoading(); }
@Override public void showNextLoading() { mAdapter.showLoading(); }
@Override public void updateResource(int id) { mAdapter.notifyItemChangedById(id); }
@Override public void showError() { mAdapter.setResource(new ArrayList<Resource>()); }
@Override public void showResources(List<Resource> resources) { mAdapter.setResource(resources); }