@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { Log.d(LOG_TAG, "OnLoadFinished"); switch (loader.getId()) { case LOADER_PREVIEWS: mCursorRecyclerAdapter.swapCursor(cursor); int loaded = cursor.getCount(); int preloadAmount = 0; Article.Category category = PreferencesUtility.readCategory(getActivity()); Log.d(LOG_TAG, "Loaded: " + loaded); initEmptyView(loaded); if (category != Article.Category.FAVOURITES && loaded - currentState.lastLoadedAmount < ARTICLES_PER_PAGE && currentState.lastPageLoaded != currentState.currentPage) { if (isConnected()) { swipeRefreshLayout.setRefreshing(true); if (isWifi() || PreferencesUtility.readInternetType(getContext()) == NetworkManager.BOTH) { preloadAmount = PreferencesUtility.readPreloadAmount(getActivity()); } startWebLoadService(category, currentState.currentPage, preloadAmount); } else { SnackbarUtility.createErrorSnackbar( getActivity().findViewById(R.id.coordinatorLayout), getString(R.string.error_no_interent)) .show(); } } else { finishLoading(); } currentState.lastPageLoaded = currentState.currentPage; currentState.lastLoadedAmount = loaded; break; } }
@Override public void onRefresh() { if (isConnected()) { startWebLoadService( PreferencesUtility.readCategory(getContext()), 1, PreferencesUtility.readPreloadAmount(getContext())); } else { BroadcastManager.broadcastErrorMessage( getContext(), MainActivity.BROADCAST_ARTICLES_ACTIVITY_FILTER, getString(R.string.error_no_interent)); swipeRefreshLayout.setRefreshing(false); } }