Exemple #1
0
 /** Returns true if we are on a user-permitted and connected internet connection. */
 public static boolean isAllowedConnection(Context context) {
   if (UpdateSettings.isOnlyUpdateOverWifi(context)) {
     return AndroidUtils.isWifiConnected(context);
   } else {
     return AndroidUtils.isNetworkConnected(context);
   }
 }
  protected void search() {
    // nag about no connectivity
    if (!AndroidUtils.isNetworkConnected(getSherlockActivity())) {
      Toast.makeText(getSherlockActivity(), R.string.offline, Toast.LENGTH_LONG).show();
      return;
    }

    String query = mSearchBox.getText().toString().trim();
    if (query.length() == 0) {
      return;
    }
    if (mSearchTask == null || mSearchTask.getStatus() == AsyncTask.Status.FINISHED) {
      mSearchTask = new SearchTask(getActivity());
      AndroidUtils.executeAsyncTask(mSearchTask, query);
    }
  }
 @Override
 public void onLowMemory() {
   if (!AndroidUtils.isICSOrHigher()) {
     // clear the whole cache as Honeycomb and below don't support
     // onTrimMemory (used directly in our ImageProvider)
     ImageProvider.getInstance(this).clearCache();
   }
 }
 private void onLoadTraktRatings(View ratingBar, boolean isUseCachedValues) {
   if (mAdapter.getCursor() != null
       && (mTraktTask == null || mTraktTask.getStatus() != AsyncTask.Status.RUNNING)) {
     mTraktTask =
         new TraktSummaryTask(getSherlockActivity(), ratingBar, isUseCachedValues)
             .episode(mShowTvdbId, mSeasonNumber, mEpisodeNumber);
     AndroidUtils.executeAsyncTask(mTraktTask);
   }
 }
  @Override
  protected void onTraktCheckIn(String message) {
    final int season = getArguments().getInt(InitBundle.SEASON);
    final int episode = getArguments().getInt(InitBundle.EPISODE);

    AndroidUtils.executeAsyncTask(
        new TraktTask(getActivity(), mListener)
            .checkInEpisode(mShowTvdbId, season, episode, message),
        new Void[] {null});
  }
Exemple #6
0
 @TargetApi(16)
 @SuppressWarnings("deprecation")
 public static void setPosterBackground(ImageView background, String posterPath, Context context) {
   if (AndroidUtils.isJellyBeanOrHigher()) {
     background.setImageAlpha(30);
   } else {
     background.setAlpha(30);
   }
   ImageProvider.getInstance(context).loadImage(background, posterPath, false);
 }
 public void onListLoad(boolean isInitialLoad) {
   // nag about no connectivity
   if (!AndroidUtils.isNetworkConnected(getActivity())) {
     Toast.makeText(getActivity(), getString(R.string.offline), Toast.LENGTH_LONG).show();
   } else {
     // nag about a trakt account if trying to display auth-only lists
     if (isInitialLoad) {
       getLoaderManager().initLoader(MOVIES_LOADER_ID, getArguments(), this);
     } else {
       getLoaderManager().restartLoader(MOVIES_LOADER_ID, getArguments(), this);
     }
   }
 }
 @TargetApi(16)
 @Override
 public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
   Movie movie = (Movie) parent.getItemAtPosition(position);
   if (movie != null && movie.id != null) {
     // display details about this movie in a new activity
     Intent i = new Intent(getActivity(), MovieDetailsActivity.class);
     i.putExtra(MovieDetailsFragment.InitBundle.TMDBID, movie.id);
     if (AndroidUtils.isJellyBeanOrHigher()) {
       Bundle options =
           ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getWidth(), v.getHeight()).toBundle();
       getActivity().startActivity(i, options);
     } else {
       startActivity(i);
     }
   }
 }
  @TargetApi(9)
  @Override
  public boolean onNavigationItemSelected(int itemPosition, long itemId) {
    Fragment newFragment = null;
    switch (itemPosition) {
      case 0:
      default:
        // popular (TMDb)
        newFragment = MoviesFragment.newInstance(TmdbCategory.POPULAR);
        break;
      case 1:
        // top rated (TMDb)
        newFragment = MoviesFragment.newInstance(TmdbCategory.TOPRATED);
        break;
      case 2:
        // now playing (TMDb)
        newFragment = MoviesFragment.newInstance(TmdbCategory.NOWPLAYING);
        break;
      case 3:
        // upcoming (TMDb)
        newFragment = MoviesFragment.newInstance(TmdbCategory.UPCOMING);
        break;
      case 4:
        // watchlist (trakt)
        newFragment = LocalMoviesFragment.newInstance(TraktCategory.WATCHLIST);
        break;
    }
    if (newFragment != null) {
      FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
      ft.replace(R.id.fragment_list, newFragment);
      ft.commit();

      // save the selected filter back to settings
      Editor editor = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit();
      editor.putInt(AppPreferences.KEY_NAVSELECTION, itemPosition);
      if (AndroidUtils.isGingerbreadOrHigher()) {
        editor.apply();
      } else {
        editor.commit();
      }

      return true;
    } else {
      return false;
    }
  }
 private void setupViews() {
   if (AndroidUtils.isKitKatOrHigher()) {
     // fix padding with translucent status bar
     // warning: status bar not always translucent (e.g. Nexus 10)
     // (using fitsSystemWindows would not work correctly with multiple views)
     mSystemBarTintManager = new SystemBarTintManager(this);
     int insetTop = mSystemBarTintManager.getConfig().getPixelInsetTop(false);
     ViewGroup actionBarToolbar = (ViewGroup) findViewById(R.id.sgToolbar);
     ViewGroup.MarginLayoutParams layoutParams =
         (ViewGroup.MarginLayoutParams) actionBarToolbar.getLayoutParams();
     layoutParams.setMargins(
         layoutParams.leftMargin,
         layoutParams.topMargin + insetTop,
         layoutParams.rightMargin,
         layoutParams.bottomMargin);
   }
 }
 @Override
 protected void handleGetGlueToggle(boolean isChecked) {
   if (isChecked) {
     if (!GetGlueSettings.isAuthenticated(getActivity())) {
       if (!AndroidUtils.isNetworkConnected(getActivity())) {
         Toast.makeText(getActivity(), R.string.offline, Toast.LENGTH_LONG).show();
         mToggleGetGlueButton.setChecked(false);
         return;
       } else {
         // authenticate already here
         Intent i = new Intent(getSherlockActivity(), GetGlueAuthActivity.class);
         startActivity(i);
       }
     } else if (TextUtils.isEmpty(mGetGlueId)) {
       // the user has to set a GetGlue object id
       launchFixGetGlueCheckInActivity(mToggleGetGlueButton, mShowTvdbId);
     }
   }
 }
  @Override
  protected boolean onGetGlueCheckin(String title, String message) {
    boolean isAbortingCheckIn = false;

    // require GetGlue authentication
    if (!GetGlueSettings.isAuthenticated(getActivity())) {
      isAbortingCheckIn = true;
    }

    // always get the latest GetGlue id
    final Cursor show =
        getActivity()
            .getContentResolver()
            .query(
                Shows.buildShowUri(String.valueOf(mShowTvdbId)),
                new String[] {Shows._ID, Shows.GETGLUEID},
                null,
                null,
                null);
    if (show != null) {
      show.moveToFirst();
      mGetGlueId = show.getString(1);
      show.close();
    }

    // check for GetGlue id
    if (TextUtils.isEmpty(mGetGlueId)) {
      isAbortingCheckIn = true;
    }

    if (isAbortingCheckIn) {
      mToggleGetGlueButton.setChecked(false);
      mGetGlueChecked = false;
      updateCheckInButtonState();
    } else {
      // check in, use task on thread pool
      AndroidUtils.executeAsyncTask(
          new CheckInTask(mGetGlueId, message, getActivity()), new Void[] {});
    }

    return isAbortingCheckIn;
  }
  private void onLoadRemainingCounter() {
    AsyncTask<String, Void, int[]> task =
        new AsyncTask<String, Void, int[]>() {

          @Override
          protected int[] doInBackground(String... params) {
            if (isCancelled()) {
              return null;
            }

            int[] counts = new int[2];

            counts[0] = DBUtils.getUnwatchedEpisodesOfShow(getActivity(), params[0]);
            counts[1] = DBUtils.getUncollectedEpisodesOfShow(getActivity(), params[0]);

            return counts;
          }

          @Override
          protected void onPostExecute(int[] result) {
            if (isAdded()) {
              if (mTextViewRemaining != null) {
                if (result[0] == -1) {
                  mTextViewRemaining.setText(
                      getString(R.string.remaining, getString(R.string.norating)));
                } else if (result[0] == 0) {
                  mTextViewRemaining.setText(null);
                } else {
                  mTextViewRemaining.setText(getString(R.string.remaining, result[0]));
                }
              }
              if (mButtonWatchedAll != null) {
                setWatchedToggleState(result[0]);
              }
              if (mButtonCollectedAll != null) {
                setCollectedToggleState(result[1]);
              }
            }
          }
        };
    AndroidUtils.executeOnPool(task, String.valueOf(getShowId()));
  }
  @TargetApi(android.os.Build.VERSION_CODES.KITKAT)
  @Override
  protected void onHandleIntent(Intent intent) {
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    /*
     * Handle a possible delete intent.
     */
    if (handleDeleteIntent(this, intent)) {
      return;
    }

    /*
     * Unschedule notification service wake-ups for disabled notifications
     * and non-supporters.
     */
    if (!NotificationSettings.isNotificationsEnabled(this) || !Utils.hasAccessToX(this)) {
      // cancel any pending alarm
      AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
      Intent i = new Intent(this, OnAlarmReceiver.class);
      PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, 0);
      am.cancel(pi);

      resetLastEpisodeAirtime(prefs);

      return;
    }

    long wakeUpTime = 0;

    /*
     * Get pool of episodes which air from 12 hours ago until eternity which
     * match the users settings.
     */
    StringBuilder selection = new StringBuilder(SELECTION);
    final long fakeNow = Utils.getFakeCurrentTime(prefs);
    boolean isFavsOnly = NotificationSettings.isNotifyAboutFavoritesOnly(this);
    if (isFavsOnly) {
      selection.append(Shows.SELECTION_FAVORITES);
    }
    boolean isNoSpecials = DisplaySettings.isHidingSpecials(this);
    if (isNoSpecials) {
      selection.append(Episodes.SELECTION_NOSPECIALS);
    }
    final Cursor upcomingEpisodes =
        getContentResolver()
            .query(
                Episodes.CONTENT_URI_WITHSHOW,
                PROJECTION,
                selection.toString(),
                new String[] {String.valueOf(fakeNow - 12 * DateUtils.HOUR_IN_MILLIS)},
                SORTING);

    if (upcomingEpisodes != null) {
      int notificationThreshold = NotificationSettings.getLatestToIncludeTreshold(this);
      if (DEBUG) {
        // a week, for debugging (use only one show to get single
        // episode notifications)
        notificationThreshold = 10080;
        // notify again for same episodes
        resetLastEpisodeAirtime(prefs);
      }
      final long latestTimeToInclude = fakeNow + DateUtils.MINUTE_IN_MILLIS * notificationThreshold;
      final long nextTimePlanned = NotificationSettings.getNextToNotifyAbout(this);
      final long nextWakeUpPlanned =
          Utils.convertToFakeTime(nextTimePlanned, prefs, false)
              - DateUtils.MINUTE_IN_MILLIS * notificationThreshold;

      /*
       * Set to -1 as on first run nextTimePlanned will be 0. This assures
       * we still see notifications of upcoming episodes then.
       */
      int newEpisodesAvailable = -1;

      // Check if we did wake up earlier than planned
      if (System.currentTimeMillis() < nextWakeUpPlanned) {
        newEpisodesAvailable = 0;
        long latestTimeNotified = NotificationSettings.getLastNotified(this);

        // Check if there are any earlier episodes to notify about
        while (upcomingEpisodes.moveToNext()) {
          final long airtime = upcomingEpisodes.getLong(NotificationQuery.FIRSTAIREDMS);
          if (airtime < nextTimePlanned) {
            if (airtime > latestTimeNotified) {
              /**
               * This will not get new episodes which would have aired the same time as the last one
               * we notified about. Sad, but the best we can do right now.
               */
              newEpisodesAvailable = 1;
              break;
            }
          } else {
            break;
          }
        }
      }

      if (newEpisodesAvailable == 0) {
        // Go to sleep, wake up as planned
        wakeUpTime = nextWakeUpPlanned;
      } else {
        // Get episodes which are within the notification threshold
        // (user set) and not yet cleared
        int count = 0;
        final List<Integer> notifyPositions = Lists.newArrayList();
        final long latestTimeCleared = NotificationSettings.getLastCleared(this);

        upcomingEpisodes.moveToPosition(-1);
        while (upcomingEpisodes.moveToNext()) {
          final long airtime = upcomingEpisodes.getLong(NotificationQuery.FIRSTAIREDMS);
          if (airtime <= latestTimeToInclude) {
            count++;
            /*
             * Only add those after the last one the user cleared.
             * At most those of the last 24 hours (see query above).
             */
            if (airtime > latestTimeCleared) {
              notifyPositions.add(count);
            }
          } else {
            // Too far into the future, stop!
            break;
          }
        }

        // Notify if we found any episodes
        if (notifyPositions.size() > 0) {
          // store latest air time of all episodes we notified about
          upcomingEpisodes.moveToPosition(notifyPositions.get(notifyPositions.size() - 1));
          long latestAirtime = upcomingEpisodes.getLong(NotificationQuery.FIRSTAIREDMS);
          if (!AndroidUtils.isHoneycombOrHigher()) {
            /*
             * Everything below HC does not have delete intents, so
             * we just never notify about the same episode twice.
             */
            prefs.edit().putLong(NotificationSettings.KEY_LAST_CLEARED, latestAirtime).commit();
          }
          prefs.edit().putLong(NotificationSettings.KEY_LAST_NOTIFIED, latestAirtime).commit();

          onNotify(prefs, upcomingEpisodes, count, latestAirtime);
        }

        /*
         * Plan next episode to notify about, calc wake-up alarm as
         * early as user wants.
         */
        upcomingEpisodes.moveToPosition(-1);
        while (upcomingEpisodes.moveToNext()) {
          final long airtime = upcomingEpisodes.getLong(NotificationQuery.FIRSTAIREDMS);
          if (airtime > latestTimeToInclude) {
            // store next episode we plan to notify about
            prefs.edit().putLong(NotificationSettings.KEY_NEXT_TO_NOTIFY, airtime).commit();

            // convert it to actual device time for setting the
            // alarm
            wakeUpTime =
                Utils.convertToFakeTime(airtime, prefs, false)
                    - DateUtils.MINUTE_IN_MILLIS * notificationThreshold;

            break;
          }
        }
      }

      upcomingEpisodes.close();
    }

    // Set a default wake-up time if there are no future episodes for now
    if (wakeUpTime <= 0) {
      wakeUpTime = System.currentTimeMillis() + 6 * DateUtils.HOUR_IN_MILLIS;
    }

    AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    Intent i = new Intent(this, NotificationService.class);
    PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
    if (AndroidUtils.isKitKatOrHigher()) {
      am.setExact(AlarmManager.RTC_WAKEUP, wakeUpTime, pi);
    } else {
      am.set(AlarmManager.RTC_WAKEUP, wakeUpTime, pi);
    }
  }
Exemple #15
0
  @Override
  protected Response doInBackground(Void... params) {
    // we need this value in onPostExecute, so get it already here
    mAction = TraktAction.values()[mArgs.getInt(InitBundle.TRAKTACTION)];

    // check for network connection
    if (!AndroidUtils.isNetworkConnected(mContext)) {
      Response r = new Response();
      r.status = TraktStatus.FAILURE;
      r.error = mContext.getString(R.string.offline);
      return r;
    }

    // check for valid credentials
    if (!ServiceUtils.isTraktCredentialsValid(mContext)) {
      // return null so a credentials dialog is displayed
      // it will call us again with valid credentials
      return null;
    }

    // get an authenticated trakt-java ServiceManager
    ServiceManager manager = ServiceUtils.getTraktServiceManagerWithAuth(mContext, false);
    if (manager == null) {
      // password could not be decrypted
      Response r = new Response();
      r.status = TraktStatus.FAILURE;
      r.error = mContext.getString(R.string.trakt_generalerror);
      return r;
    }

    // get values used by all actions
    final int showTvdbId = mArgs.getInt(InitBundle.SHOW_TVDBID);
    final int season = mArgs.getInt(InitBundle.SEASON);
    final int episode = mArgs.getInt(InitBundle.EPISODE);

    // last chance to abort
    if (isCancelled()) {
      return null;
    }

    try {
      Response r = null;

      switch (mAction) {
        case CHECKIN_EPISODE:
          {
            final String message = mArgs.getString(InitBundle.MESSAGE);

            final CheckinBuilder checkinBuilder =
                manager.showService().checkin(showTvdbId).season(season).episode(episode);
            if (!TextUtils.isEmpty(message)) {
              checkinBuilder.message(message);
            }
            r = checkinBuilder.fire();

            if (TraktStatus.SUCCESS.equals(r.status)) {
              SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
              r.message =
                  mContext.getString(
                      R.string.checkin_success_trakt,
                      (r.show != null ? r.show.title + " " : "")
                          + Utils.getEpisodeNumber(prefs, season, episode));
            }

            break;
          }
        case CHECKIN_MOVIE:
          {
            final String imdbId = mArgs.getString(InitBundle.IMDB_ID);
            final String message = mArgs.getString(InitBundle.MESSAGE);

            final MovieService.CheckinBuilder checkinBuilder =
                manager.movieService().checkin(imdbId);
            if (!TextUtils.isEmpty(message)) {
              checkinBuilder.message(message);
            }
            r = checkinBuilder.fire();

            if (TraktStatus.SUCCESS.equals(r.status)) {
              r.message =
                  mContext.getString(
                      R.string.checkin_success_trakt, (r.movie != null ? r.movie.title + " " : ""));
            }

            break;
          }
        case RATE_EPISODE:
          {
            final Rating rating = Rating.fromValue(mArgs.getString(InitBundle.RATING));
            r =
                manager
                    .rateService()
                    .episode(showTvdbId)
                    .season(season)
                    .episode(episode)
                    .rating(rating)
                    .fire();
            break;
          }
        case RATE_SHOW:
          {
            final Rating rating = Rating.fromValue(mArgs.getString(InitBundle.RATING));
            r = manager.rateService().show(showTvdbId).rating(rating).fire();
            break;
          }
        case SHOUT:
          {
            final String shout = mArgs.getString(InitBundle.MESSAGE);
            final boolean isSpoiler = mArgs.getBoolean(InitBundle.ISSPOILER);

            if (episode == 0) {
              r =
                  manager
                      .commentService()
                      .show(showTvdbId)
                      .comment(shout)
                      .spoiler(isSpoiler)
                      .fire();
            } else {
              r =
                  manager
                      .commentService()
                      .episode(showTvdbId)
                      .season(season)
                      .episode(episode)
                      .comment(shout)
                      .spoiler(isSpoiler)
                      .fire();
            }
            break;
          }
        case WATCHLIST_MOVIE:
          {
            final int tmdbId = mArgs.getInt(InitBundle.TMDB_ID);
            manager.movieService().watchlist().movie(tmdbId).fire();
            // In case of failure this will just return an exception, so
            // we need to construct our own response
            r = new Response();
            r.status = TraktStatus.SUCCESS;
            r.message = mContext.getString(R.string.watchlist_added);
            break;
          }
        case UNWATCHLIST_MOVIE:
          {
            final int tmdbId = mArgs.getInt(InitBundle.TMDB_ID);
            manager.movieService().unwatchlist().movie(tmdbId).fire();
            // In case of failure this will just return an exception, so
            // we need to construct our own response
            r = new Response();
            r.status = TraktStatus.SUCCESS;
            r.message = mContext.getString(R.string.watchlist_removed);
            break;
          }
        default:
          break;
      }

      return r;
    } catch (TraktException e) {
      Utils.trackExceptionAndLog(mContext, TAG, e);
      Response r = new Response();
      r.status = TraktStatus.FAILURE;
      r.error = mContext.getString(R.string.trakt_generalerror);
      return r;
    } catch (ApiException e) {
      Utils.trackExceptionAndLog(mContext, TAG, e);
      Response r = new Response();
      r.status = TraktStatus.FAILURE;
      r.error = mContext.getString(R.string.trakt_generalerror);
      return r;
    }
  }
Exemple #16
0
  @Override
  protected Integer doInBackground(Void... params) {
    // Ensure external storage
    if (!AndroidUtils.isExtStorageAvailable()) {
      return ERROR_STORAGE_ACCESS;
    }

    // Ensure no large database ops are running
    TaskManager tm = TaskManager.getInstance(mContext);
    if (SgSyncAdapter.isSyncActive(mContext, false) || tm.isAddTaskRunning()) {
      return ERROR_LARGE_DB_OP;
    }

    // Ensure JSON file is available
    File path = JsonExportTask.getExportPath(false);
    File backup = new File(path, JsonExportTask.EXPORT_JSON_FILE_SHOWS);
    if (!backup.exists() || !backup.canRead()) {
      return ERROR_FILE_ACCESS;
    }

    // Clean out all existing tables
    mContext.getContentResolver().delete(Shows.CONTENT_URI, null, null);
    mContext.getContentResolver().delete(Seasons.CONTENT_URI, null, null);
    mContext.getContentResolver().delete(Episodes.CONTENT_URI, null, null);
    mContext.getContentResolver().delete(SeriesContract.Lists.CONTENT_URI, null, null);
    mContext.getContentResolver().delete(ListItems.CONTENT_URI, null, null);

    // Access JSON from backup folder to create new database
    try {
      InputStream in = new FileInputStream(backup);

      Gson gson = new Gson();

      JsonReader reader = new JsonReader(new InputStreamReader(in, "UTF-8"));
      reader.beginArray();

      while (reader.hasNext()) {
        Show show = gson.fromJson(reader, Show.class);
        addShowToDatabase(show);
      }

      reader.endArray();
      reader.close();

    } catch (IOException e) {
      return ERROR;
    }

    /*
     * Lists
     */
    File backupLists = new File(path, JsonExportTask.EXPORT_JSON_FILE_LISTS);
    if (!backupLists.exists() || !backupLists.canRead()) {
      // Skip lists if the file is not accessible
      return SUCCESS;
    }

    // Access JSON from backup folder to create new database
    try {
      InputStream in = new FileInputStream(backupLists);

      Gson gson = new Gson();

      JsonReader reader = new JsonReader(new InputStreamReader(in, "UTF-8"));
      reader.beginArray();

      while (reader.hasNext()) {
        List list = gson.fromJson(reader, List.class);
        addListToDatabase(list);
      }

      reader.endArray();
      reader.close();

    } catch (IOException e) {
      return ERROR;
    }

    // Renew search table
    mContext
        .getContentResolver()
        .query(EpisodeSearch.CONTENT_URI_RENEWFTSTABLE, null, null, null, null);

    return SUCCESS;
  }
  @TargetApi(11)
  private void fillData() {
    TextView seriesname = (TextView) findViewById(R.id.title);
    TextView overview = (TextView) findViewById(R.id.TextViewShowInfoOverview);
    TextView airstime = (TextView) findViewById(R.id.TextViewShowInfoAirtime);
    TextView network = (TextView) findViewById(R.id.TextViewShowInfoNetwork);
    TextView status = (TextView) findViewById(R.id.TextViewShowInfoStatus);

    final Series show = DBUtils.getShow(this, String.valueOf(getShowId()));
    if (show == null) {
      finish();
      return;
    }

    // Name
    seriesname.setText(show.getSeriesName());

    // Overview
    if (show.getOverview().length() == 0) {
      overview.setText("");
    } else {
      overview.setText(show.getOverview());
    }

    // Airtimes
    if (show.getAirsDayOfWeek().length() == 0 || show.getAirsTime() == -1) {
      airstime.setText(getString(R.string.show_noairtime));
    } else {
      String[] values =
          Utils.parseMillisecondsToTime(
              show.getAirsTime(), show.getAirsDayOfWeek(), getApplicationContext());
      airstime.setText(getString(R.string.show_airs) + " " + values[1] + " " + values[0]);
    }

    // Network
    if (show.getNetwork().length() == 0) {
      network.setText("");
    } else {
      network.setText(getString(R.string.show_network) + " " + show.getNetwork());
    }

    // Running state
    if (show.getStatus() == 1) {
      status.setTextColor(Color.GREEN);
      status.setText(getString(R.string.show_isalive));
    } else if (show.getStatus() == 0) {
      status.setTextColor(Color.GRAY);
      status.setText(getString(R.string.show_isnotalive));
    }

    // first airdate
    long airtime = Utils.buildEpisodeAirtime(show.getFirstAired(), show.getAirsTime());
    Utils.setValueOrPlaceholder(
        findViewById(R.id.TextViewShowInfoFirstAirdate), Utils.formatToDate(airtime, this));

    // Others
    Utils.setValueOrPlaceholder(
        findViewById(R.id.TextViewShowInfoActors), Utils.splitAndKitTVDBStrings(show.getActors()));
    Utils.setValueOrPlaceholder(
        findViewById(R.id.TextViewShowInfoContentRating), show.getContentRating());
    Utils.setValueOrPlaceholder(
        findViewById(R.id.TextViewShowInfoGenres), Utils.splitAndKitTVDBStrings(show.getGenres()));
    Utils.setValueOrPlaceholder(
        findViewById(R.id.TextViewShowInfoRuntime),
        show.getRuntime() + " " + getString(R.string.show_airtimeunit));

    // TVDb rating
    String ratingText = show.getRating();
    if (ratingText != null && ratingText.length() != 0) {
      RatingBar ratingBar = (RatingBar) findViewById(R.id.bar);
      ratingBar.setProgress((int) (Double.valueOf(ratingText) / 0.1));
      TextView rating = (TextView) findViewById(R.id.value);
      rating.setText(ratingText + "/10");
    }

    // IMDb button
    View imdbButton = (View) findViewById(R.id.buttonShowInfoIMDB);
    final String imdbid = show.getImdbId();
    if (imdbButton != null) {
      imdbButton.setOnClickListener(
          new OnClickListener() {
            public void onClick(View v) {
              fireTrackerEvent("Show IMDb page");

              if (imdbid.length() != 0) {
                Intent myIntent =
                    new Intent(Intent.ACTION_VIEW, Uri.parse("imdb:///title/" + imdbid + "/"));
                try {
                  startActivity(myIntent);
                } catch (ActivityNotFoundException e) {
                  myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(IMDB_TITLE_URL + imdbid));
                  startActivity(myIntent);
                }
              } else {
                Toast.makeText(
                        getApplicationContext(),
                        getString(R.string.show_noimdbentry),
                        Toast.LENGTH_LONG)
                    .show();
              }
            }
          });
    }

    // TVDb button
    View tvdbButton = (View) findViewById(R.id.buttonTVDB);
    final String tvdbId = show.getId();
    if (tvdbButton != null) {
      tvdbButton.setOnClickListener(
          new OnClickListener() {
            public void onClick(View v) {
              fireTrackerEvent("Show TVDb page");
              Intent i =
                  new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.TVDB_SHOW_URL + tvdbId));
              startActivity(i);
            }
          });
    }

    // Shout button
    findViewById(R.id.buttonShouts)
        .setOnClickListener(
            new OnClickListener() {
              @Override
              public void onClick(View v) {
                fireTrackerEvent("Show Trakt Shouts");
                TraktShoutsFragment newFragment =
                    TraktShoutsFragment.newInstance(show.getSeriesName(), Integer.valueOf(tvdbId));

                newFragment.show(getSupportFragmentManager(), "shouts-dialog");
              }
            });

    // Share intent
    mShareIntentBuilder =
        ShareCompat.IntentBuilder.from(this)
            .setChooserTitle(R.string.share)
            .setText(
                getString(R.string.share_checkout)
                    + " \""
                    + show.getSeriesName()
                    + "\" via @SeriesGuide "
                    + ShowInfoActivity.IMDB_TITLE_URL
                    + imdbid)
            .setType("text/plain");

    // Poster
    final ImageView poster = (ImageView) findViewById(R.id.ImageViewShowInfoPoster);
    ImageProvider.getInstance(this).loadImage(poster, show.getPoster(), false);

    // trakt ratings
    TraktSummaryTask task = new TraktSummaryTask(this, findViewById(R.id.ratingbar)).show(tvdbId);
    AndroidUtils.executeAsyncTask(task, new Void[] {null});
  }
 protected void onLoadImage(String imagePath, FrameLayout container) {
   if (mArtTask == null || mArtTask.getStatus() == AsyncTask.Status.FINISHED) {
     mArtTask = new FetchArtTask(imagePath, container, getActivity());
     AndroidUtils.executeAsyncTask(mArtTask, new Void[] {null});
   }
 }
  private void onNotify(
      final SharedPreferences prefs, final Cursor upcomingEpisodes, int count, long latestAirtime) {
    final Context context = getApplicationContext();
    CharSequence tickerText = "";
    CharSequence contentTitle = "";
    CharSequence contentText = "";
    PendingIntent contentIntent = null;

    // notification sound
    final String ringtoneUri = NotificationSettings.getNotificationsRingtone(context);
    // vibration
    final boolean isVibrating = NotificationSettings.isNotificationVibrating(context);

    if (count == 1) {
      // notify in detail about one episode
      upcomingEpisodes.moveToFirst();
      final String showTitle = upcomingEpisodes.getString(NotificationQuery.SHOW_TITLE);
      final String airs =
          Utils.formatToTimeAndDay(upcomingEpisodes.getLong(NotificationQuery.FIRSTAIREDMS), this)[
              0];
      final String network = upcomingEpisodes.getString(NotificationQuery.NETWORK);

      tickerText = getString(R.string.upcoming_show, showTitle);
      contentTitle =
          showTitle
              + " "
              + Utils.getEpisodeNumber(
                  this,
                  upcomingEpisodes.getInt(NotificationQuery.SEASON),
                  upcomingEpisodes.getInt(NotificationQuery.NUMBER));
      contentText = getString(R.string.upcoming_show_detailed, airs, network);

      Intent notificationIntent = new Intent(context, EpisodesActivity.class);
      notificationIntent.putExtra(
          EpisodesActivity.InitBundle.EPISODE_TVDBID,
          upcomingEpisodes.getInt(NotificationQuery._ID));
      notificationIntent.putExtra(KEY_EPISODE_CLEARED_TIME, latestAirtime);
      contentIntent =
          PendingIntent.getActivity(context, REQUEST_CODE_SINGLE_EPISODE, notificationIntent, 0);
    } else if (count > 1) {
      // notify about multiple episodes
      tickerText = getString(R.string.upcoming_episodes);
      contentTitle = getString(R.string.upcoming_episodes_number, count);
      contentText = getString(R.string.upcoming_display);

      Intent notificationIntent = new Intent(context, UpcomingRecentActivity.class);
      notificationIntent.putExtra(KEY_EPISODE_CLEARED_TIME, latestAirtime);
      contentIntent =
          PendingIntent.getActivity(context, REQUEST_CODE_MULTIPLE_EPISODES, notificationIntent, 0);
    }

    final NotificationCompat.Builder nb = new NotificationCompat.Builder(context);

    if (AndroidUtils.isJellyBeanOrHigher()) {
      // JELLY BEAN and above

      if (count == 1) {
        // single episode
        upcomingEpisodes.moveToFirst();
        final String imagePath = upcomingEpisodes.getString(NotificationQuery.POSTER);
        nb.setLargeIcon(ImageProvider.getInstance(context).getImage(imagePath, true));

        final String episodeTitle = upcomingEpisodes.getString(NotificationQuery.TITLE);
        final String episodeSummary = upcomingEpisodes.getString(NotificationQuery.OVERVIEW);

        final SpannableStringBuilder bigText = new SpannableStringBuilder();
        bigText.append(episodeTitle);
        bigText.setSpan(new ForegroundColorSpan(Color.WHITE), 0, bigText.length(), 0);
        bigText.append("\n");
        bigText.append(episodeSummary);

        nb.setStyle(
            new NotificationCompat.BigTextStyle().bigText(bigText).setSummaryText(contentText));

        // Action button to check in
        Intent checkInActionIntent = new Intent(context, QuickCheckInActivity.class);
        checkInActionIntent.putExtra(
            QuickCheckInActivity.InitBundle.EPISODE_TVDBID,
            upcomingEpisodes.getInt(NotificationQuery._ID));
        PendingIntent checkInIntent =
            PendingIntent.getActivity(context, REQUEST_CODE_ACTION_CHECKIN, checkInActionIntent, 0);
        nb.addAction(R.drawable.ic_action_checkin, getString(R.string.checkin), checkInIntent);
      } else {
        // multiple episodes
        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();

        // display at most the first five
        final int displayCount = Math.min(count, 5);
        for (int i = 0; i < displayCount; i++) {
          if (upcomingEpisodes.moveToPosition(i)) {
            // add show title, air time and network
            final SpannableStringBuilder lineText = new SpannableStringBuilder();
            lineText.append(upcomingEpisodes.getString(NotificationQuery.SHOW_TITLE));
            lineText.setSpan(new ForegroundColorSpan(Color.WHITE), 0, lineText.length(), 0);
            lineText.append(" ");
            String airs =
                Utils.formatToTimeAndDay(
                    upcomingEpisodes.getLong(NotificationQuery.FIRSTAIREDMS), this)[0];
            String network = upcomingEpisodes.getString(NotificationQuery.NETWORK);
            lineText.append(getString(R.string.upcoming_show_detailed, airs, network));
            inboxStyle.addLine(lineText);
          }
        }

        // tell if we could not display all episodes
        if (count > 5) {
          inboxStyle.setSummaryText(getString(R.string.more, count - 5));
        }

        nb.setStyle(inboxStyle);
        nb.setContentInfo(String.valueOf(count));
      }
    } else {
      // ICS and below

      if (count == 1) {
        // single episode
        upcomingEpisodes.moveToFirst();
        final String posterPath = upcomingEpisodes.getString(NotificationQuery.POSTER);
        nb.setLargeIcon(ImageProvider.getInstance(context).getImage(posterPath, true));
      }
    }

    // If the string is empty, the user chose silent...
    if (ringtoneUri.length() != 0) {
      // ...otherwise set the specified ringtone
      nb.setSound(Uri.parse(ringtoneUri));
    }
    if (isVibrating) {
      nb.setVibrate(VIBRATION_PATTERN);
    }
    nb.setDefaults(Notification.DEFAULT_LIGHTS);
    nb.setWhen(System.currentTimeMillis());
    nb.setAutoCancel(true);
    nb.setTicker(tickerText);
    nb.setContentTitle(contentTitle);
    nb.setContentText(contentText);
    nb.setContentIntent(contentIntent);
    nb.setSmallIcon(R.drawable.ic_notification);
    nb.setPriority(NotificationCompat.PRIORITY_DEFAULT);

    Intent i = new Intent(this, NotificationService.class);
    i.putExtra(KEY_EPISODE_CLEARED_TIME, latestAirtime);
    PendingIntent deleteIntent = PendingIntent.getService(this, 1, i, 0);
    nb.setDeleteIntent(deleteIntent);

    // build the notification
    Notification notification = nb.build();

    // use string resource id, always unique within app
    final NotificationManager nm =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(R.string.upcoming_show, notification);
  }