private List<Submission> clearSeenPosts(boolean forever) { if (adapter.dataSet.posts != null) { List<Submission> originalDataSetPosts = adapter.dataSet.posts; OfflineSubreddit o = OfflineSubreddit.getSubreddit(id.toLowerCase()); for (int i = adapter.dataSet.posts.size(); i > -1; i--) { try { if (HasSeen.getSeen(adapter.dataSet.posts.get(i))) { if (forever) { Hidden.setHidden(adapter.dataSet.posts.get(i)); } o.clearPost(adapter.dataSet.posts.get(i)); adapter.dataSet.posts.remove(i); if (adapter.dataSet.posts.size() == 0) { adapter.notifyDataSetChanged(); } else { rv.setItemAnimator(new FadeInAnimator()); adapter.notifyItemRemoved(i + 1); } } } catch (IndexOutOfBoundsException e) { // Let the loop reset itself } } o.writeToMemory(); rv.setItemAnimator(new SlideInUpAnimator(new AccelerateDecelerateInterpolator())); return originalDataSetPosts; } return null; }
@Override public void updateError() { if (getActivity() instanceof MainActivity) { if (((MainActivity) getActivity()).runAfterLoad != null) { new Handler().post(((MainActivity) getActivity()).runAfterLoad); } } mSwipeRefreshLayout.setRefreshing(false); adapter.setError(true); }
@Override public void updateOffline(List<Submission> submissions, final long cacheTime) { if (getActivity() instanceof MainActivity) { if (((MainActivity) getActivity()).runAfterLoad != null) { new Handler().post(((MainActivity) getActivity()).runAfterLoad); } } if (this.isAdded()) { if (mSwipeRefreshLayout != null) { mSwipeRefreshLayout.setRefreshing(false); Toast.makeText( mSwipeRefreshLayout.getContext(), getString( R.string.offline_last_update, TimeUtils.getTimeAgo(cacheTime, mSwipeRefreshLayout.getContext())), Toast.LENGTH_SHORT) .show(); } adapter.notifyDataSetChanged(); } }