@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);
   }
 }
 public void switchCategory(Article.Category category) {
   PreferencesUtility.saveCategory(getContext(), category);
   currentState = new State();
   recyclerView.scrollToPosition(0);
   if (category == Article.Category.FAVOURITES) {
     mListener.removeOffsetListener();
   } else {
     mListener.restoreOffsetListener();
   }
   launchLoader(currentState.currentPage);
 }
  @Override
  public void onViewStateRestored(Bundle savedInstanceState) {
    Log.d(LOG_TAG, "OnViewStateRestored");
    //        if (savedInstanceState != null) {
    //            currentState = savedInstanceState.getParcelable(STATE);
    //            launchLoader(currentState.lastPageLoaded);
    //            mLinearLayoutManager.scrollToPosition(currentState.firstVisibleIndex);
    //            //поставить выделение selected на нужной позиции
    //
    //            if (mListener.isDualPane() && currentState.selectedId > 0) {
    //                Log.d(LOG_TAG, "Loading article");
    //                loadArticle(currentState.selectedId, currentState.selectedPosition);
    //            }
    //        } else {
    if (PreferencesUtility.readCategory(getContext()) == Article.Category.FAVOURITES) {
      mListener.removeOffsetListener();
    }
    launchLoader(1);
    //        }

    super.onViewStateRestored(savedInstanceState);
  }
 private void launchLoader(int page) {
   Bundle args = new Bundle();
   args.putInt(PAGE, page);
   args.putInt(CATEGORY, PreferencesUtility.readCategory(getActivity()).ordinal());
   getLoaderManager().restartLoader(LOADER_PREVIEWS, args, this);
 }