use of com.battlelancer.seriesguide.provider.SgEpisode2Helper in project SeriesGuide by UweTrottmann.
the class EpisodeWatchedJob method applyDatabaseChanges.
@Override
protected boolean applyDatabaseChanges(@NonNull Context context) {
SgEpisode2Helper episodeHelper = SgRoomDatabase.getInstance(context).sgEpisode2Helper();
int flagValue = getFlagValue();
int rowsUpdated;
switch(flagValue) {
case EpisodeFlags.SKIPPED:
rowsUpdated = episodeHelper.setSkipped(episodeId);
break;
case EpisodeFlags.WATCHED:
rowsUpdated = episodeHelper.setWatchedAndAddPlay(episodeId);
break;
case EpisodeFlags.UNWATCHED:
rowsUpdated = episodeHelper.setNotWatchedAndRemovePlays(episodeId);
break;
default:
throw new IllegalArgumentException("Flag value not supported");
}
return rowsUpdated == 1;
}
use of com.battlelancer.seriesguide.provider.SgEpisode2Helper in project SeriesGuide by UweTrottmann.
the class SeasonWatchedJob method applyDatabaseChanges.
@Override
protected boolean applyDatabaseChanges(@NonNull Context context) {
SgEpisode2Helper helper = SgRoomDatabase.getInstance(context).sgEpisode2Helper();
int rowsUpdated;
switch(getFlagValue()) {
case EpisodeFlags.SKIPPED:
rowsUpdated = helper.setSeasonSkipped(seasonId, currentTimePlusOneHour);
break;
case EpisodeFlags.WATCHED:
rowsUpdated = helper.setSeasonWatchedAndAddPlay(seasonId, currentTimePlusOneHour);
break;
case EpisodeFlags.UNWATCHED:
rowsUpdated = helper.setSeasonNotWatchedAndRemovePlays(seasonId);
break;
default:
throw new IllegalArgumentException("Flag value not supported");
}
// -1 means error.
return rowsUpdated >= 0;
}
use of com.battlelancer.seriesguide.provider.SgEpisode2Helper in project SeriesGuide by UweTrottmann.
the class ShowWatchedJob method applyDatabaseChanges.
@Override
protected boolean applyDatabaseChanges(@NonNull Context context) {
SgEpisode2Helper helper = SgRoomDatabase.getInstance(context).sgEpisode2Helper();
int rowsUpdated;
switch(getFlagValue()) {
case EpisodeFlags.UNWATCHED:
rowsUpdated = helper.setShowNotWatchedAndRemovePlays(getShowId());
break;
case EpisodeFlags.WATCHED:
rowsUpdated = helper.setShowWatchedAndAddPlay(getShowId(), currentTimePlusOneHour);
break;
default:
// Note: Skip not supported for whole show.
throw new IllegalArgumentException("Flag value not supported");
}
// -1 means error.
return rowsUpdated >= 0;
}
use of com.battlelancer.seriesguide.provider.SgEpisode2Helper in project SeriesGuide by UweTrottmann.
the class EpisodeBaseJob method applyLocalChanges.
@Override
public boolean applyLocalChanges(Context context, boolean requiresNetworkJob) {
// Gather data needed for later steps.
SgEpisode2Helper helper = SgRoomDatabase.getInstance(context).sgEpisode2Helper();
SgEpisode2Numbers episode = helper.getEpisodeNumbers(episodeId);
if (episode == null) {
return false;
}
this.episode = episode;
return super.applyLocalChanges(context, requiresNetworkJob);
}
use of com.battlelancer.seriesguide.provider.SgEpisode2Helper in project SeriesGuide by UweTrottmann.
the class TraktRecentEpisodeHistoryLoader method addItems.
protected void addItems(List<NowAdapter.NowItem> items, List<HistoryEntry> history) {
SparseArrayCompat<String> tmdbIdsToPoster = SgApp.getServicesComponent(getContext()).showTools().getTmdbIdsToPoster();
SgEpisode2Helper episodeHelper = SgRoomDatabase.getInstance(getContext()).sgEpisode2Helper();
long timeDayAgo = System.currentTimeMillis() - DateUtils.DAY_IN_MILLIS;
for (int i = 0, size = history.size(); i < size; i++) {
HistoryEntry entry = history.get(i);
if (entry.episode == null || entry.show == null || entry.watched_at == null) {
// missing required values
continue;
}
// however, include at least one older episode if there are none, yet
if (TimeTools.isBeforeMillis(entry.watched_at, timeDayAgo) && items.size() > 1) {
break;
}
// look for a TVDB poster
String posterUrl;
Integer showTmdbId = entry.show.ids == null ? null : entry.show.ids.tmdb;
if (showTmdbId != null) {
// prefer poster of already added show, fall back to first uploaded poster
posterUrl = ImageTools.posterUrlOrResolve(tmdbIdsToPoster.get(showTmdbId), showTmdbId, DisplaySettings.LANGUAGE_EN, getContext());
} else {
posterUrl = null;
}
String description = (entry.episode.season == null || entry.episode.number == null) ? entry.episode.title : TextTools.getNextEpisodeString(getContext(), entry.episode.season, entry.episode.number, entry.episode.title);
Integer episodeTmdbIdOrNull = entry.episode.ids != null ? entry.episode.ids.tmdb : null;
long localEpisodeIdOrZero = episodeTmdbIdOrNull != null ? episodeHelper.getEpisodeIdByTmdbId(episodeTmdbIdOrNull) : 0;
NowAdapter.NowItem item = new NowAdapter.NowItem().displayData(entry.watched_at.toInstant().toEpochMilli(), entry.show.title, description, posterUrl).episodeIds(localEpisodeIdOrZero, showTmdbId != null ? showTmdbId : 0).recentlyWatchedTrakt(entry.action);
items.add(item);
}
}
Aggregations