<commit_before>/*
 * Copyright (C) 2013 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.simonvt.cathode.ui;

import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.v4.app.Fragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.DrawerLayout;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewPropertyAnimator;
import android.widget.ProgressBar;
import butterknife.ButterKnife;
import butterknife.InjectView;
import com.squareup.otto.Bus;
import com.squareup.otto.Subscribe;
import javax.inject.Inject;
import net.simonvt.cathode.CathodeApp;
import net.simonvt.cathode.R;
import net.simonvt.cathode.event.LogoutEvent;
import net.simonvt.cathode.event.MessageEvent;
import net.simonvt.cathode.jobqueue.SyncEvent;
import net.simonvt.cathode.provider.DatabaseContract;
import net.simonvt.cathode.provider.DatabaseSchematic;
import net.simonvt.cathode.provider.ProviderSchematic;
import net.simonvt.cathode.settings.Settings;
import net.simonvt.cathode.ui.dialog.LogoutDialog;
import net.simonvt.cathode.ui.fragment.EpisodeFragment;
import net.simonvt.cathode.ui.fragment.MovieCollectionFragment;
import net.simonvt.cathode.ui.fragment.MovieFragment;
import net.simonvt.cathode.ui.fragment.MovieRecommendationsFragment;
import net.simonvt.cathode.ui.fragment.MovieWatchlistFragment;
import net.simonvt.cathode.ui.fragment.NavigationFragment;
import net.simonvt.cathode.ui.fragment.SearchMovieFragment;
import net.simonvt.cathode.ui.fragment.SearchShowFragment;
import net.simonvt.cathode.ui.fragment.SeasonFragment;
import net.simonvt.cathode.ui.fragment.ShowFragment;
import net.simonvt.cathode.ui.fragment.ShowRecommendationsFragment;
import net.simonvt.cathode.ui.fragment.ShowsCollectionFragment;
import net.simonvt.cathode.ui.fragment.ShowsWatchlistFragment;
import net.simonvt.cathode.ui.fragment.TrendingMoviesFragment;
import net.simonvt.cathode.ui.fragment.TrendingShowsFragment;
import net.simonvt.cathode.ui.fragment.UpcomingShowsFragment;
import net.simonvt.cathode.ui.fragment.WatchedMoviesFragment;
import net.simonvt.cathode.ui.fragment.WatchedShowsFragment;
import net.simonvt.cathode.util.FragmentStack;
import net.simonvt.cathode.widget.WatchingView;
import net.simonvt.cathode.widget.WatchingView.WatchingViewListener;
import net.simonvt.messagebar.MessageBar;
import timber.log.Timber;

public class HomeActivity extends BaseActivity
    implements NavigationFragment.OnMenuClickListener, ShowsNavigationListener,
    MoviesNavigationListener {

  static final String FRAGMENT_NAVIGATION =
      "net.simonvt.cathode.ui.HomeActivity.navigationFragment";
  static final String FRAGMENT_SHOWS = "net.simonvt.cathode.ui.HomeActivity.showsFragment";
  static final String FRAGMENT_SHOWS_UPCOMING =
      "net.simonvt.cathode.ui.HomeActivity.upcomingShowsFragment";
  static final String FRAGMENT_SHOWS_COLLECTION =
      "net.simonvt.cathode.ui.HomeActivity.collectionShowsFragment";
  static final String FRAGMENT_SHOWS_TRENDING =
      "net.simonvt.cathode.ui.HomeActivity.trendingShowsFragment";
  static final String FRAGMENT_SHOWS_RECOMMENDATIONS =
      "net.simonvt.cathode.ui.HomeActivity.showRecommendationsFragment";
  static final String FRAGMENT_SHOW = "net.simonvt.cathode.ui.HomeActivity.showFragment";
  static final String FRAGMENT_SEASON = "net.simonvt.cathode.ui.HomeActivity.seasonFragment";
  static final String FRAGMENT_EPISODE = "net.simonvt.cathode.ui.HomeActivity.episodeFragment";
  static final String FRAGMENT_SHOWS_WATCHLIST =
      "net.simonvt.cathode.ui.HomeActivity.showsWatchlistFragment";
  static final String FRAGMENT_SEARCH_SHOW =
      "net.simonvt.cathode.ui.HomeActivity.searchShowFragment";
  static final String FRAGMENT_MOVIES_WATCHED =
      "net.simonvt.cathode.ui.HomeActivity.moviesWatchedFragment";
  static final String FRAGMENT_MOVIES_COLLECTION =
      "net.simonvt.cathode.ui.HomeActivity.moviesCollectionFragment";
  static final String FRAGMENT_MOVIES_WATCHLIST =
      "net.simonvt.cathode.ui.HomeActivity.moviesWatchlistFragment";
  static final String FRAGMENT_MOVIES_TRENDING =
      "net.simonvt.cathode.ui.HomeActivity.moviesTrendingFragment";
  static final String FRAGMENT_MOVIES_RECOMMENDATIONS =
      "net.simonvt.cathode.ui.HomeActivity.movieRecommendationsFragment";
  static final String FRAGMENT_SEARCH_MOVIE =
      "net.simonvt.cathode.ui.HomeActivity.searchMovieFragment";
  static final String FRAGMENT_MOVIE = "net.simonvt.cathode.ui.HomeActivity.movieFragment";

  private static final String STATE_STACK = "net.simonvt.cathode.ui.HomeActivity.stack";

  public static final String ACTION_LOGIN = "net.simonvt.cathode.intent.action.LOGIN";
  public static final String DIALOG_LOGOUT = "net.simonvt.cathode.ui.HomeActivity.logoutDialog";

  @Inject Bus bus;

  protected MessageBar messageBar;

  @InjectView(R.id.progress_top) ProgressBar progressTop;
  private ViewPropertyAnimator progressAnimator;

  private FragmentStack stack;

  @InjectView(R.id.drawer) DrawerLayout drawer;
  private int drawerState = DrawerLayout.STATE_IDLE;
  private NavigationFragment navigation;

  @InjectView(R.id.watching_parent) ViewGroup watchingParent;
  @InjectView(R.id.watchingView) WatchingView watchingView;

  private Cursor watchingShow;
  private Cursor watchingMovie;

  private boolean isTablet;

  @Override protected void onCreate(Bundle inState) {
    super.onCreate(inState);
    Timber.d("onCreate");
    CathodeApp.inject(this);

    setContentView(R.layout.activity_home);

    ButterKnife.inject(this);

    isTablet = getResources().getBoolean(R.bool.isTablet);

    navigation =
        (NavigationFragment) getSupportFragmentManager().findFragmentByTag(FRAGMENT_NAVIGATION);

    stack = FragmentStack.forContainer(this, R.id.content, new FragmentStack.Callback() {
      @Override public void onStackChanged(int stackSize, Fragment topFragment) {
        Timber.d("onStackChanged: %s", topFragment.getTag());
      }
    });
    stack.setDefaultAnimation(R.anim.fade_in_front, R.anim.fade_out_back, R.anim.fade_in_back,
        R.anim.fade_out_front);
    if (inState != null) {
      stack.restoreState(inState.getBundle(STATE_STACK));
    }
    if (stack.size() == 0) {
      stack.replace(UpcomingShowsFragment.class, FRAGMENT_SHOWS_UPCOMING);
      stack.commit();
    }

    getSupportLoaderManager().initLoader(BaseActivity.LOADER_SHOW_WATCHING, null,
        watchingShowCallback);
    getSupportLoaderManager().initLoader(BaseActivity.LOADER_MOVIE_WATCHING, null,
        watchingMovieCallback);

    messageBar = new MessageBar(this);

    drawer.setDrawerListener(new DrawerLayout.DrawerListener() {<commit_msg>Remember to set watching listener.<commit_after>/*
 * Copyright (C) 2013 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.simonvt.cathode.ui;

import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.v4.app.Fragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.DrawerLayout;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewPropertyAnimator;
import android.widget.ProgressBar;
import butterknife.ButterKnife;
import butterknife.InjectView;
import com.squareup.otto.Bus;
import com.squareup.otto.Subscribe;
import javax.inject.Inject;
import net.simonvt.cathode.CathodeApp;
import net.simonvt.cathode.R;
import net.simonvt.cathode.event.LogoutEvent;
import net.simonvt.cathode.event.MessageEvent;
import net.simonvt.cathode.jobqueue.SyncEvent;
import net.simonvt.cathode.provider.DatabaseContract;
import net.simonvt.cathode.provider.DatabaseSchematic;
import net.simonvt.cathode.provider.ProviderSchematic;
import net.simonvt.cathode.settings.Settings;
import net.simonvt.cathode.ui.dialog.LogoutDialog;
import net.simonvt.cathode.ui.fragment.EpisodeFragment;
import net.simonvt.cathode.ui.fragment.MovieCollectionFragment;
import net.simonvt.cathode.ui.fragment.MovieFragment;
import net.simonvt.cathode.ui.fragment.MovieRecommendationsFragment;
import net.simonvt.cathode.ui.fragment.MovieWatchlistFragment;
import net.simonvt.cathode.ui.fragment.NavigationFragment;
import net.simonvt.cathode.ui.fragment.SearchMovieFragment;
import net.simonvt.cathode.ui.fragment.SearchShowFragment;
import net.simonvt.cathode.ui.fragment.SeasonFragment;
import net.simonvt.cathode.ui.fragment.ShowFragment;
import net.simonvt.cathode.ui.fragment.ShowRecommendationsFragment;
import net.simonvt.cathode.ui.fragment.ShowsCollectionFragment;
import net.simonvt.cathode.ui.fragment.ShowsWatchlistFragment;
import net.simonvt.cathode.ui.fragment.TrendingMoviesFragment;
import net.simonvt.cathode.ui.fragment.TrendingShowsFragment;
import net.simonvt.cathode.ui.fragment.UpcomingShowsFragment;
import net.simonvt.cathode.ui.fragment.WatchedMoviesFragment;
import net.simonvt.cathode.ui.fragment.WatchedShowsFragment;
import net.simonvt.cathode.util.FragmentStack;
import net.simonvt.cathode.widget.WatchingView;
import net.simonvt.cathode.widget.WatchingView.WatchingViewListener;
import net.simonvt.messagebar.MessageBar;
import timber.log.Timber;

public class HomeActivity extends BaseActivity
    implements NavigationFragment.OnMenuClickListener, ShowsNavigationListener,
    MoviesNavigationListener {

  static final String FRAGMENT_NAVIGATION =
      "net.simonvt.cathode.ui.HomeActivity.navigationFragment";
  static final String FRAGMENT_SHOWS = "net.simonvt.cathode.ui.HomeActivity.showsFragment";
  static final String FRAGMENT_SHOWS_UPCOMING =
      "net.simonvt.cathode.ui.HomeActivity.upcomingShowsFragment";
  static final String FRAGMENT_SHOWS_COLLECTION =
      "net.simonvt.cathode.ui.HomeActivity.collectionShowsFragment";
  static final String FRAGMENT_SHOWS_TRENDING =
      "net.simonvt.cathode.ui.HomeActivity.trendingShowsFragment";
  static final String FRAGMENT_SHOWS_RECOMMENDATIONS =
      "net.simonvt.cathode.ui.HomeActivity.showRecommendationsFragment";
  static final String FRAGMENT_SHOW = "net.simonvt.cathode.ui.HomeActivity.showFragment";
  static final String FRAGMENT_SEASON = "net.simonvt.cathode.ui.HomeActivity.seasonFragment";
  static final String FRAGMENT_EPISODE = "net.simonvt.cathode.ui.HomeActivity.episodeFragment";
  static final String FRAGMENT_SHOWS_WATCHLIST =
      "net.simonvt.cathode.ui.HomeActivity.showsWatchlistFragment";
  static final String FRAGMENT_SEARCH_SHOW =
      "net.simonvt.cathode.ui.HomeActivity.searchShowFragment";
  static final String FRAGMENT_MOVIES_WATCHED =
      "net.simonvt.cathode.ui.HomeActivity.moviesWatchedFragment";
  static final String FRAGMENT_MOVIES_COLLECTION =
      "net.simonvt.cathode.ui.HomeActivity.moviesCollectionFragment";
  static final String FRAGMENT_MOVIES_WATCHLIST =
      "net.simonvt.cathode.ui.HomeActivity.moviesWatchlistFragment";
  static final String FRAGMENT_MOVIES_TRENDING =
      "net.simonvt.cathode.ui.HomeActivity.moviesTrendingFragment";
  static final String FRAGMENT_MOVIES_RECOMMENDATIONS =
      "net.simonvt.cathode.ui.HomeActivity.movieRecommendationsFragment";
  static final String FRAGMENT_SEARCH_MOVIE =
      "net.simonvt.cathode.ui.HomeActivity.searchMovieFragment";
  static final String FRAGMENT_MOVIE = "net.simonvt.cathode.ui.HomeActivity.movieFragment";

  private static final String STATE_STACK = "net.simonvt.cathode.ui.HomeActivity.stack";

  public static final String ACTION_LOGIN = "net.simonvt.cathode.intent.action.LOGIN";
  public static final String DIALOG_LOGOUT = "net.simonvt.cathode.ui.HomeActivity.logoutDialog";

  @Inject Bus bus;

  protected MessageBar messageBar;

  @InjectView(R.id.progress_top) ProgressBar progressTop;
  private ViewPropertyAnimator progressAnimator;

  private FragmentStack stack;

  @InjectView(R.id.drawer) DrawerLayout drawer;
  private int drawerState = DrawerLayout.STATE_IDLE;
  private NavigationFragment navigation;

  @InjectView(R.id.watching_parent) ViewGroup watchingParent;
  @InjectView(R.id.watchingView) WatchingView watchingView;

  private Cursor watchingShow;
  private Cursor watchingMovie;

  private boolean isTablet;

  @Override protected void onCreate(Bundle inState) {
    super.onCreate(inState);
    Timber.d("onCreate");
    CathodeApp.inject(this);

    setContentView(R.layout.activity_home);

    ButterKnife.inject(this);

    isTablet = getResources().getBoolean(R.bool.isTablet);

    navigation =
        (NavigationFragment) getSupportFragmentManager().findFragmentByTag(FRAGMENT_NAVIGATION);

    watchingView.setWatchingViewListener(watchingListener);

    stack = FragmentStack.forContainer(this, R.id.content, new FragmentStack.Callback() {
      @Override public void onStackChanged(int stackSize, Fragment topFragment) {
        Timber.d("onStackChanged: %s", topFragment.getTag());
      }
    });
    stack.setDefaultAnimation(R.anim.fade_in_front, R.anim.fade_out_back, R.anim.fade_in_back,
        R.anim.fade_out_front);
    if (inState != null) {
      stack.restoreState(inState.getBundle(STATE_STACK));
    }
    if (stack.size() == 0) {
      stack.replace(UpcomingShowsFragment.class, FRAGMENT_SHOWS_UPCOMING);
      stack.commit();
    }

    getSupportLoaderManager().initLoader(BaseActivity.LOADER_SHOW_WATCHING, null,
        watchingShowCallback);
    getSupportLoaderManager().initLoader(BaseActivity.LOADER_MOVIE_WATCHING, null,
        watchingMovieCallback);

    messageBar = new MessageBar(this);

    drawer.setDrawerListener(new DrawerLayout.DrawerListener() {
{'fraction_non_alphanumeric': 0.0916744001060586, 'fraction_numerical': 0.00185602545406337, 'mean_word_length': 5.433688699360341, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3833625', 'n_tokens_mistral': 4932, 'n_tokens_neox': 4798, 'n_words': 819}