<commit_before>package com.ddiehl.android.htn.presenter;

import com.ddiehl.android.htn.R;
import com.ddiehl.android.htn.view.ListingsView;
import com.ddiehl.android.htn.view.MainView;
import com.ddiehl.reddit.identity.UserIdentity;
import com.ddiehl.reddit.listings.Link;
import com.ddiehl.reddit.listings.ListingResponse;
import com.ddiehl.reddit.listings.Subreddit;

import rx.functions.Action0;
import rx.functions.Action1;

public class SubredditPresenter extends AbsListingsPresenter {
  private Subreddit mSubredditInfo;

  public SubredditPresenter(
      MainView main, ListingsView view, String subreddit, String sort, String timespan) {
    super(main, view, null, null, subreddit, sort, timespan);
  }

  @Override
  public void requestData() {
    if (mSubreddit == null || mSubreddit.equals("all") || mSubredditInfo != null) {
      mAnalytics.logLoadSubreddit(mSubreddit, mSort, mTimespan);
      mRedditService.loadLinks(mSubreddit, mSort, mTimespan, mNextPageListingId)
          .doOnTerminate(onGetDataCompleted())
          .subscribe(onListingsLoaded(),
              e -> mMainView.showError(e, R.string.error_get_links));
    } else {
      mListingsRequested = false;
      mRedditService.getSubredditInfo(mSubreddit)
          .doOnTerminate(onGetDataCompleted())
          .subscribe(onSubredditInfoLoaded(),
              e -> mMainView.showError(e, R.string.error_get_subreddit_info));
    }
  }

  private Action0 onGetDataCompleted() {
    return () -> {
      mMainView.dismissSpinner();
      mListingsRequested = false;
    };
  }

  private Action1<Subreddit> onSubredditInfoLoaded() {
    return subreddit -> {
      mSubredditInfo = subreddit;
      UserIdentity user = getAuthorizedUser();
      if ((mSubredditInfo != null && mSubredditInfo.isOver18())
          && (user == null || !user.isOver18())) {
        mMainView.showNsfwWarningDialog();
      } else {
        requestData();
      }
      mMainView.loadImageIntoDrawerHeader(subreddit.getHeaderImageUrl());
    };
  }

  @Override
  protected Action1<ListingResponse> onListingsLoaded() {
    return (response) -> {
      super.onListingsLoaded().call(response);
      if (mSubreddit != null && mSubreddit.equals("random")) {
        mSubreddit = ((Link) mListings.get(0)).getSubreddit();
      }
    };
  }
}<commit_msg>Correcting drawer header image when navigating to from SubredditFragment<commit_after>package com.ddiehl.android.htn.presenter;

import com.ddiehl.android.htn.R;
import com.ddiehl.android.htn.view.ListingsView;
import com.ddiehl.android.htn.view.MainView;
import com.ddiehl.reddit.identity.UserIdentity;
import com.ddiehl.reddit.listings.Link;
import com.ddiehl.reddit.listings.ListingResponse;
import com.ddiehl.reddit.listings.Subreddit;

import rx.functions.Action0;
import rx.functions.Action1;

public class SubredditPresenter extends AbsListingsPresenter {
  private Subreddit mSubredditInfo;

  public SubredditPresenter(
      MainView main, ListingsView view, String subreddit, String sort, String timespan) {
    super(main, view, null, null, subreddit, sort, timespan);
    mMainView.loadImageIntoDrawerHeader(null);
  }

  @Override
  public void onResume() {
    super.onResume();
    loadHeaderImage();
  }

  @Override
  public void onPause() {
    super.onPause();
    mMainView.loadImageIntoDrawerHeader(null);
  }

  @Override
  public void requestData() {
    if (mSubreddit == null || mSubreddit.equals("all") || mSubredditInfo != null) {
      mAnalytics.logLoadSubreddit(mSubreddit, mSort, mTimespan);
      mRedditService.loadLinks(mSubreddit, mSort, mTimespan, mNextPageListingId)
          .doOnTerminate(onGetDataCompleted())
          .subscribe(onListingsLoaded(),
              e -> mMainView.showError(e, R.string.error_get_links));
    } else {
      mListingsRequested = false;
      mRedditService.getSubredditInfo(mSubreddit)
          .doOnTerminate(onGetDataCompleted())
          .subscribe(onSubredditInfoLoaded(),
              e -> mMainView.showError(e, R.string.error_get_subreddit_info));
    }
  }

  private Action0 onGetDataCompleted() {
    return () -> {
      mMainView.dismissSpinner();
      mListingsRequested = false;
    };
  }

  private Action1<Subreddit> onSubredditInfoLoaded() {
    return info -> {
      mSubredditInfo = info;
      UserIdentity user = getAuthorizedUser();
      if ((mSubredditInfo != null && mSubredditInfo.isOver18())
          && (user == null || !user.isOver18())) {
        mMainView.showNsfwWarningDialog();
      } else {
        requestData();
      }
      loadHeaderImage();
    };
  }

  @Override
  protected Action1<ListingResponse> onListingsLoaded() {
    return (response) -> {
      super.onListingsLoaded().call(response);
      if (mSubreddit != null && mSubreddit.equals("random")) {
        mSubreddit = ((Link) mListings.get(0)).getSubreddit();
      }
    };
  }

  private void loadHeaderImage() {
    if (mSubredditInfo != null) {
      mMainView.loadImageIntoDrawerHeader(mSubredditInfo.getHeaderImageUrl());
    }
  }
}
{'fraction_non_alphanumeric': 0.11657414750198256, 'fraction_numerical': 0.003965107057890563, 'mean_word_length': 3.5327942497753817, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1221219', 'n_tokens_mistral': 1604, 'n_tokens_neox': 1647, 'n_words': 268}