private void updatePostsWithTag( final String tagName, final ReaderActions.RequestDataAction updateAction, RefreshType refreshType) { if (TextUtils.isEmpty(tagName)) return; unscheduleAutoUpdate(); if (!NetworkUtils.isNetworkAvailable(getActivity())) { AppLog.i(T.READER, "network unavailable, rescheduling reader update"); scheduleAutoUpdate(); return; } setIsUpdating(true, updateAction); setEmptyTitleAndDecriptionForCurrentTag(); // if this is "Posts I Like" or "Blogs I Follow" and it's a manual refresh (user tapped refresh // icon), // refresh the posts so posts that were unliked/unfollowed no longer appear if (refreshType == RefreshType.MANUAL && isCurrentTagName(tagName)) { if (tagName.equals(ReaderTag.TAG_NAME_LIKED) || tagName.equals(ReaderTag.TAG_NAME_FOLLOWING)) refreshPosts(); } ReaderPostActions.updatePostsWithTag( tagName, updateAction, new ReaderActions.UpdateResultAndCountListener() { @Override public void onUpdateResult(ReaderActions.UpdateResult result, int numNewPosts) { if (!hasActivity()) { AppLog.w(T.READER, "volley response when fragment has no activity"); // this fragment is no longer valid, so send a broadcast that tells the host // ReaderActivity that it needs to refresh the list of posts - this // situation occurs when the user rotates the device while the update is // still in progress if (numNewPosts > 0) LocalBroadcastManager.getInstance(WordPress.getContext()) .sendBroadcast(new Intent(ReaderActivity.ACTION_REFRESH_POSTS)); return; } setIsUpdating(false, updateAction); if (result == ReaderActions.UpdateResult.CHANGED && numNewPosts > 0 && isCurrentTagName(tagName)) { // if we loaded new posts and posts are already displayed, show the "new posts" // bar rather than immediately refreshing the list if (!isPostAdapterEmpty() && updateAction == ReaderActions.RequestDataAction.LOAD_NEWER) { showNewPostsBar(numNewPosts); } else { refreshPosts(); } } else { // update empty view title and description if the the post list is empty setEmptyTitleAndDecriptionForCurrentTag(); } // schedule the next update in this tag if (result != ReaderActions.UpdateResult.FAILED) scheduleAutoUpdate(); } }); }