private void resetFilterIfEmpty() {

    if (mResults.isEmpty()
        && (mFilterOption == Filter.COMPLETE || mFilterOption == Filter.INCOMPLETE)) {
      mResetListener.onReset();
    }
  }
  @Override
  public int getItemCount() {

    if (!mResults.isEmpty()) {
      return mResults.size() + COUNT_FOOTER;
    } else {
      if (mFilterOption == Filter.LEAST_TIME_LEFT
          || mFilterOption == Filter.MOST_TIME_LEFT
          || mFilterOption == Filter.NONE) {
        return 0;
      } else {

        return COUNT_NO_ITEMS + COUNT_FOOTER;
      }
    }
  }
  @Override
  public int getItemViewType(int position) {

    if (!mResults.isEmpty()) {
      if (position < mResults.size()) {
        return ITEM;
      } else {
        return FOOTER;
      }
    } else {
      if (mFilterOption == Filter.COMPLETE || mFilterOption == Filter.INCOMPLETE) {

        if (position == 0) {
          return NO_ITEM;
        } else {
          return FOOTER;
        }

      } else {
        return ITEM;
      }
    }
  }
 /** Open the most recently read book when the FAB is clicked. */
 @OnClick(R.id.fab)
 void onFabClick() {
   if (books != null && books.isValid() && !books.isEmpty())
     ActionHelper.openBookUsingIntent(realm, books.first());
 }
Exemple #5
0
  public static void rebuildStats(Context context, String localId) {
    Realm realm = Realm.getInstance(Migration.getConfig(context));

    RealmResults<TrackStats> statsRes =
        realm.where(TrackStats.class).equalTo("local_id", localId).findAll();

    if (!statsRes.isEmpty()) {
      /*
      Log.d(TAG, "hi5");
      Log.d(TAG, "==================");
      Log.d(TAG, "track.getTitle(): " + track.getTitle());
      Log.d(TAG, "track.getCompletedCount(): " + track.getCompletedCount());
      Log.d(TAG, "track.getSkippedCount(): " + track.getSkippedCount());
      Log.d(TAG, "track.getLikedCount(): " + track.getLikedCount());
      Log.d(TAG, "track.getDislikedCount(): " + track.getDislikedCount());

      res.where().equalTo("type", TrackStats.SONG_SELECTED) //TODO not implemented yet
       */

      int completedCount = 0;
      int skippedCount = 0;
      int likedCount = 0;
      int dislikedCount = 0;
      int halfPlayedCount = 0;
      int selectedCount = 0;

      for (TrackStats ts : statsRes) {
        switch (ts.getType()) {
          case TrackStats.SONG_COMPLETED:
            completedCount++;
            break;
          case TrackStats.SONG_HALF_PLAYED:
            halfPlayedCount++;
            break;
          case TrackStats.SONG_SELECTED:
            selectedCount++;
            break;
          case TrackStats.SONG_SKIPPED:
            skippedCount++;
            break;
          case TrackStats.SONG_LIKED:
            likedCount++;
            break;
          case TrackStats.SONG_DISLIKED:
            dislikedCount++;
            break;
        }
      }

      Track track = realm.where(Track.class).equalTo("local_id", localId).findFirst();

      realm.beginTransaction();

      track.setCompletedCount(completedCount);
      track.setHalfPlayedCount(halfPlayedCount);
      track.setSelectedCount(selectedCount);

      track.setSkippedCount(skippedCount);

      track.setLikedCount(likedCount);
      track.setDislikedCount(dislikedCount);

      track.setStatsUpdatedAt(DateTime.now(Calendar.getInstance().getTimeZone()).toString());

      realm.commitTransaction();
    }
  }