Search in sources :

Example 1 with SearchResult

use of com.battlelancer.seriesguide.ui.search.SearchResult in project SeriesGuide by UweTrottmann.

the class HexagonShowSync method appendShowUpdates.

private void appendShowUpdates(List<SgShow2CloudUpdate> updates, Set<Long> toUpdate, Map<Integer, SearchResult> toAdd, List<SgCloudShow> shows, Map<Integer, Long> tmdbIdsToShowIds, boolean mergeValues) {
    for (SgCloudShow show : shows) {
        // schedule to add shows not in local database
        Integer showTmdbId = show.getTmdbId();
        // Invalid data.
        if (showTmdbId == null)
            continue;
        Long showIdOrNull = tmdbIdsToShowIds.get(showTmdbId);
        if (showIdOrNull == null) {
            // ...but do NOT add shows marked as removed
            if (show.getIsRemoved() != null && show.getIsRemoved()) {
                continue;
            }
            if (!toAdd.containsKey(showTmdbId)) {
                SearchResult item = new SearchResult();
                item.setTmdbId(showTmdbId);
                item.setLanguage(show.getLanguage());
                item.setTitle("");
                toAdd.put(showTmdbId, item);
            }
        } else if (!toUpdate.contains(showIdOrNull)) {
            // Create update if there isn't already one.
            SgShow2CloudUpdate update = SgRoomDatabase.getInstance(context).sgShow2Helper().getForCloudUpdate(showIdOrNull);
            if (update != null) {
                boolean hasUpdates = false;
                if (show.getIsFavorite() != null) {
                    // when merging, favorite shows, but never unfavorite them
                    if (!mergeValues || show.getIsFavorite()) {
                        update.setFavorite(show.getIsFavorite());
                        hasUpdates = true;
                    }
                }
                if (show.getNotify() != null) {
                    // when merging, enable notifications, but never disable them
                    if (!mergeValues || show.getNotify()) {
                        update.setNotify(show.getNotify());
                        hasUpdates = true;
                    }
                }
                if (show.getIsHidden() != null) {
                    // when merging, un-hide shows, but never hide them
                    if (!mergeValues || !show.getIsHidden()) {
                        update.setHidden(show.getIsHidden());
                        hasUpdates = true;
                    }
                }
                if (!TextUtils.isEmpty(show.getLanguage())) {
                    // always overwrite with hexagon language value
                    update.setLanguage(show.getLanguage());
                    hasUpdates = true;
                }
                if (hasUpdates) {
                    updates.add(update);
                    toUpdate.add(showIdOrNull);
                }
            }
        }
    }
}
Also used : SgCloudShow(com.uwetrottmann.seriesguide.backend.shows.model.SgCloudShow) SearchResult(com.battlelancer.seriesguide.ui.search.SearchResult) SgShow2CloudUpdate(com.battlelancer.seriesguide.provider.SgShow2CloudUpdate)

Example 2 with SearchResult

use of com.battlelancer.seriesguide.ui.search.SearchResult in project SeriesGuide by UweTrottmann.

the class TaskManager method performAddTask.

/**
 * Schedule shows to be added to the database.
 *
 * @param isSilentMode   Whether to display status toasts if a show could not be added.
 * @param isMergingShows Whether to set the Hexagon show merged flag to true if all shows were
 */
@MainThread
public synchronized void performAddTask(final Context context, final List<SearchResult> shows, final boolean isSilentMode, final boolean isMergingShows) {
    if (!isSilentMode) {
        // notify user here already
        if (shows.size() == 1) {
            // say title of show
            SearchResult show = shows.get(0);
            Toast.makeText(context, context.getString(R.string.add_started, show.getTitle()), Toast.LENGTH_SHORT).show();
        } else {
            // generic adding multiple message
            Toast.makeText(context, R.string.add_multiple, Toast.LENGTH_SHORT).show();
        }
    }
    // noinspection ConstantConditions: null check in isAddTaskRunning
    if (!isAddTaskRunning() || !addShowTask.addShows(shows, isSilentMode, isMergingShows)) {
        addShowTask = new AddShowTask(context, shows, isSilentMode, isMergingShows);
        addShowTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }
}
Also used : AddShowTask(com.battlelancer.seriesguide.ui.search.AddShowTask) SearchResult(com.battlelancer.seriesguide.ui.search.SearchResult) MainThread(androidx.annotation.MainThread)

Aggregations

SearchResult (com.battlelancer.seriesguide.ui.search.SearchResult)2 MainThread (androidx.annotation.MainThread)1 SgShow2CloudUpdate (com.battlelancer.seriesguide.provider.SgShow2CloudUpdate)1 AddShowTask (com.battlelancer.seriesguide.ui.search.AddShowTask)1 SgCloudShow (com.uwetrottmann.seriesguide.backend.shows.model.SgCloudShow)1