Source:
public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager( getResources().getInteger(R.integer.news_fragment_column_count), StaggeredGridLayoutManager.VERTICAL); getListView().setLayoutManager(layoutManager); mAdapter = new NewsAdapter(getActivity(), ((GdgActivity) getActivity()).getGoogleApiClient()); setRecyclerAdapter(mAdapter); setOnRefreshListener(this); final String plusId = getArguments().getString(Const.EXTRA_PLUS_ID); if (Utils.isOnline(getActivity())) { new Builder<>(String.class, Activities.class) .addParameter(plusId) .setOnPreExecuteListener(new CommonAsyncTask.OnPreExecuteListener() { @Override public void onPreExecute() { setIsLoading(true); } }) .setOnBackgroundExecuteListener( new CommonAsyncTask.OnBackgroundExecuteListener<String, Activities>() { @Override public Activities doInBackground(String... params) { Activities feed = (Activities) App.getInstance().getModelCache().get(Const.CACHE_KEY_NEWS + params[0]); if (feed == null) { feed = getActivityFeedSync(params[0]); } return feed; } }) .setOnPostExecuteListener(new CommonAsyncTask.OnPostExecuteListener<String, Activities>() { @Override public void onPostExecute(String[] params, Activities activityFeed) { if (activityFeed != null) { mAdapter.addAll(activityFeed.getItems()); setIsLoading(false); } } }) .buildAndExecute(); } else { App.getInstance().getModelCache().getAsync(Const.CACHE_KEY_NEWS + plusId, false, new ModelCache.CacheListener() { @Override public void onGet(Object item) { Activities feed = (Activities) item; if (isAdded()) { Snackbar snackbar = Snackbar.make(getView(), R.string.cached_content, Snackbar.LENGTH_SHORT); ColoredSnackBar.info(snackbar).show(); } mAdapter.addAll(feed.getItems()); setIsLoading(false); } @Override public void onNotFound(String key) { showError(R.string.offline_alert); } }); } }

Target:
public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager( getResources().getInteger(R.integer.news_fragment_column_count), StaggeredGridLayoutManager.VERTICAL); getListView().setLayoutManager(layoutManager); mAdapter = new NewsAdapter(getActivity(), ((GdgActivity) getActivity()).getGoogleApiClient()); setRecyclerAdapter(mAdapter); setOnRefreshListener(this); final String plusId = getArguments().getString(Const.EXTRA_PLUS_ID); if (Utils.isOnline(getActivity())) { setIsLoading(true); App.getInstance().getModelCache() .getAsync(Const.CACHE_KEY_NEWS + plusId, new ModelCache.CacheListener() { @Override public void onGet(Object item) { Activities activityFeed = (Activities) item; mAdapter.addAll(activityFeed.getItems()); setIsLoading(false); } @Override public void onNotFound(String key) { App.getInstance().getPlusApi().getActivities(plusId).enqueue( new Callback<Activities>() { @Override public void success(Activities activityFeed) { if (activityFeed != null) { mAdapter.addAll(activityFeed.getItems()); } else { } setIsLoading(false); } }); } }); } else { App.getInstance().getModelCache().getAsync(Const.CACHE_KEY_NEWS + plusId, false, new ModelCache.CacheListener() { @Override public void onGet(Object item) { Activities feed = (Activities) item; if (isAdded()) { Snackbar snackbar = Snackbar.make(getView(), R.string.cached_content, Snackbar.LENGTH_SHORT); ColoredSnackBar.info(snackbar).show(); } mAdapter.addAll(feed.getItems()); setIsLoading(false); } @Override public void onNotFound(String key) { showError(R.string.offline_alert); } }); } }