Search in sources :

Example 86 with Feed

use of de.danoeh.antennapod.model.feed.Feed in project AntennaPod by AntennaPod.

the class SyncService method syncSubscriptions.

private void syncSubscriptions(ISyncService syncServiceImpl) throws SyncServiceException {
    final long lastSync = SynchronizationSettings.getLastSubscriptionSynchronizationTimestamp();
    EventBus.getDefault().postSticky(new SyncServiceEvent(R.string.sync_status_subscriptions));
    final List<String> localSubscriptions = DBReader.getFeedListDownloadUrls();
    SubscriptionChanges subscriptionChanges = syncServiceImpl.getSubscriptionChanges(lastSync);
    long newTimeStamp = subscriptionChanges.getTimestamp();
    List<String> queuedRemovedFeeds = synchronizationQueueStorage.getQueuedRemovedFeeds();
    List<String> queuedAddedFeeds = synchronizationQueueStorage.getQueuedAddedFeeds();
    Log.d(TAG, "Downloaded subscription changes: " + subscriptionChanges);
    for (String downloadUrl : subscriptionChanges.getAdded()) {
        if (!URLChecker.containsUrl(localSubscriptions, downloadUrl) && !queuedRemovedFeeds.contains(downloadUrl)) {
            Feed feed = new Feed(downloadUrl, null);
            DownloadRequest.Builder builder = DownloadRequestCreator.create(feed);
            DownloadService.download(getApplicationContext(), false, builder.build());
        }
    }
    // remove subscription if not just subscribed (again)
    for (String downloadUrl : subscriptionChanges.getRemoved()) {
        if (!queuedAddedFeeds.contains(downloadUrl)) {
            DBTasks.removeFeedWithDownloadUrl(getApplicationContext(), downloadUrl);
        }
    }
    if (lastSync == 0) {
        Log.d(TAG, "First sync. Adding all local subscriptions.");
        queuedAddedFeeds = localSubscriptions;
        queuedAddedFeeds.removeAll(subscriptionChanges.getAdded());
        queuedRemovedFeeds.removeAll(subscriptionChanges.getRemoved());
    }
    if (queuedAddedFeeds.size() > 0 || queuedRemovedFeeds.size() > 0) {
        Log.d(TAG, "Added: " + StringUtils.join(queuedAddedFeeds, ", "));
        Log.d(TAG, "Removed: " + StringUtils.join(queuedRemovedFeeds, ", "));
        LockingAsyncExecutor.lock.lock();
        try {
            UploadChangesResponse uploadResponse = syncServiceImpl.uploadSubscriptionChanges(queuedAddedFeeds, queuedRemovedFeeds);
            synchronizationQueueStorage.clearFeedQueues();
            newTimeStamp = uploadResponse.timestamp;
        } finally {
            LockingAsyncExecutor.lock.unlock();
        }
    }
    SynchronizationSettings.setLastSubscriptionSynchronizationAttemptTimestamp(newTimeStamp);
}
Also used : DownloadRequest(de.danoeh.antennapod.core.service.download.DownloadRequest) SubscriptionChanges(de.danoeh.antennapod.net.sync.model.SubscriptionChanges) SyncServiceEvent(de.danoeh.antennapod.event.SyncServiceEvent) UploadChangesResponse(de.danoeh.antennapod.net.sync.model.UploadChangesResponse) Feed(de.danoeh.antennapod.model.feed.Feed)

Example 87 with Feed

use of de.danoeh.antennapod.model.feed.Feed in project AntennaPod by AntennaPod.

the class SubscriptionsFilter method filter.

/**
 * Run a list of feed items through the filter.
 */
public List<Feed> filter(List<Feed> items, LongIntMap feedCounters) {
    if (properties.length == 0) {
        return items;
    }
    List<Feed> result = new ArrayList<>();
    for (Feed item : items) {
        FeedPreferences itemPreferences = item.getPreferences();
        // If the item does not meet a requirement, skip it.
        if (showAutoDownloadEnabled && !itemPreferences.getAutoDownload()) {
            continue;
        } else if (showAutoDownloadDisabled && itemPreferences.getAutoDownload()) {
            continue;
        }
        if (showUpdatedEnabled && !itemPreferences.getKeepUpdated()) {
            continue;
        } else if (showUpdatedDisabled && itemPreferences.getKeepUpdated()) {
            continue;
        }
        if (showEpisodeNotificationEnabled && !itemPreferences.getShowEpisodeNotification()) {
            continue;
        } else if (showEpisodeNotificationDisabled && itemPreferences.getShowEpisodeNotification()) {
            continue;
        }
        // If the item reaches here, it meets all criteria (except counter > 0)
        result.add(item);
    }
    if (showIfCounterGreaterZero) {
        for (int i = result.size() - 1; i >= 0; i--) {
            if (feedCounters.get(result.get(i).getId()) <= 0) {
                result.remove(i);
            }
        }
    }
    return result;
}
Also used : FeedPreferences(de.danoeh.antennapod.model.feed.FeedPreferences) ArrayList(java.util.ArrayList) Feed(de.danoeh.antennapod.model.feed.Feed)

Example 88 with Feed

use of de.danoeh.antennapod.model.feed.Feed in project AntennaPod by AntennaPod.

the class DownloadLogAdapter method bind.

private void bind(DownloadLogItemViewHolder holder, DownloadStatus status, int position) {
    String statusText = "";
    if (status.getFeedfileType() == Feed.FEEDFILETYPE_FEED) {
        statusText += context.getString(R.string.download_type_feed);
    } else if (status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
        statusText += context.getString(R.string.download_type_media);
    }
    statusText += " ยท ";
    statusText += DateUtils.getRelativeTimeSpanString(status.getCompletionDate().getTime(), System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, 0);
    holder.status.setText(statusText);
    if (status.getTitle() != null) {
        holder.title.setText(status.getTitle());
    } else {
        holder.title.setText(R.string.download_log_title_unknown);
    }
    if (status.isSuccessful()) {
        holder.icon.setTextColor(ContextCompat.getColor(context, R.color.download_success_green));
        holder.icon.setText("{fa-check-circle}");
        holder.icon.setContentDescription(context.getString(R.string.download_successful));
        holder.secondaryActionButton.setVisibility(View.INVISIBLE);
        holder.reason.setVisibility(View.GONE);
        holder.tapForDetails.setVisibility(View.GONE);
    } else {
        if (status.getReason() == DownloadError.ERROR_PARSER_EXCEPTION_DUPLICATE) {
            holder.icon.setTextColor(ContextCompat.getColor(context, R.color.download_warning_yellow));
            holder.icon.setText("{fa-exclamation-circle}");
        } else {
            holder.icon.setTextColor(ContextCompat.getColor(context, R.color.download_failed_red));
            holder.icon.setText("{fa-times-circle}");
        }
        holder.icon.setContentDescription(context.getString(R.string.error_label));
        holder.reason.setText(status.getReason().getErrorString(context));
        holder.reason.setVisibility(View.VISIBLE);
        holder.tapForDetails.setVisibility(View.VISIBLE);
        if (newerWasSuccessful(position - runningDownloads.size(), status.getFeedfileType(), status.getFeedfileId())) {
            holder.secondaryActionButton.setVisibility(View.INVISIBLE);
            holder.secondaryActionButton.setOnClickListener(null);
            holder.secondaryActionButton.setTag(null);
        } else {
            holder.secondaryActionIcon.setImageResource(R.drawable.ic_refresh);
            holder.secondaryActionButton.setVisibility(View.VISIBLE);
            if (status.getFeedfileType() == Feed.FEEDFILETYPE_FEED) {
                holder.secondaryActionButton.setOnClickListener(v -> {
                    holder.secondaryActionButton.setVisibility(View.INVISIBLE);
                    Feed feed = DBReader.getFeed(status.getFeedfileId());
                    if (feed == null) {
                        Log.e(TAG, "Could not find feed for feed id: " + status.getFeedfileId());
                        return;
                    }
                    DBTasks.forceRefreshFeed(context, feed, true);
                });
            } else if (status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
                holder.secondaryActionButton.setOnClickListener(v -> {
                    holder.secondaryActionButton.setVisibility(View.INVISIBLE);
                    FeedMedia media = DBReader.getFeedMedia(status.getFeedfileId());
                    if (media == null) {
                        Log.e(TAG, "Could not find feed media for feed id: " + status.getFeedfileId());
                        return;
                    }
                    DownloadService.download(context, true, DownloadRequestCreator.create(media).build());
                    ((MainActivity) context).showSnackbarAbovePlayer(R.string.status_downloading_label, Toast.LENGTH_SHORT);
                });
            }
        }
    }
}
Also used : DateUtils(android.text.format.DateUtils) DownloadRequestCreator(de.danoeh.antennapod.core.service.download.DownloadRequestCreator) ArrayList(java.util.ArrayList) DownloadRequest(de.danoeh.antennapod.core.service.download.DownloadRequest) Toast(android.widget.Toast) View(android.view.View) DownloadLogItemViewHolder(de.danoeh.antennapod.view.viewholder.DownloadLogItemViewHolder) ContextCompat(androidx.core.content.ContextCompat) DownloadStatus(de.danoeh.antennapod.core.service.download.DownloadStatus) Log(android.util.Log) Feed(de.danoeh.antennapod.model.feed.Feed) Formatter(android.text.format.Formatter) Downloader(de.danoeh.antennapod.core.service.download.Downloader) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) ThemeUtils(de.danoeh.antennapod.ui.common.ThemeUtils) R(de.danoeh.antennapod.R) DownloadError(de.danoeh.antennapod.core.util.DownloadError) ViewGroup(android.view.ViewGroup) MainActivity(de.danoeh.antennapod.activity.MainActivity) List(java.util.List) BaseAdapter(android.widget.BaseAdapter) DBReader(de.danoeh.antennapod.core.storage.DBReader) ListFragment(androidx.fragment.app.ListFragment) Activity(android.app.Activity) DownloadService(de.danoeh.antennapod.core.service.download.DownloadService) DBTasks(de.danoeh.antennapod.core.storage.DBTasks) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Feed(de.danoeh.antennapod.model.feed.Feed)

Example 89 with Feed

use of de.danoeh.antennapod.model.feed.Feed in project AntennaPod by AntennaPod.

the class FeedSearchResultAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull Holder holder, int position) {
    final Feed podcast = data.get(position);
    holder.imageView.setContentDescription(podcast.getTitle());
    holder.imageView.setOnClickListener(v -> mainActivityRef.get().loadChildFragment(FeedItemlistFragment.newInstance(podcast.getId())));
    Glide.with(mainActivityRef.get()).load(podcast.getImageUrl()).apply(new RequestOptions().placeholder(R.color.light_gray).fitCenter().dontAnimate()).into(holder.imageView);
}
Also used : RequestOptions(com.bumptech.glide.request.RequestOptions) Feed(de.danoeh.antennapod.model.feed.Feed)

Example 90 with Feed

use of de.danoeh.antennapod.model.feed.Feed in project AntennaPod by AntennaPod.

the class NavListAdapter method bindFeedView.

private void bindFeedView(NavDrawerData.FeedDrawerItem drawerItem, FeedHolder holder) {
    Feed feed = drawerItem.feed;
    Activity context = activity.get();
    if (context == null) {
        return;
    }
    Glide.with(context).load(feed.getImageUrl()).apply(new RequestOptions().placeholder(R.color.light_gray).error(R.color.light_gray).diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY).fitCenter().dontAnimate()).into(holder.image);
    if (feed.hasLastUpdateFailed()) {
        RelativeLayout.LayoutParams p = (RelativeLayout.LayoutParams) holder.title.getLayoutParams();
        p.addRule(RelativeLayout.LEFT_OF, R.id.itxtvFailure);
        holder.failure.setVisibility(View.VISIBLE);
    } else {
        RelativeLayout.LayoutParams p = (RelativeLayout.LayoutParams) holder.title.getLayoutParams();
        p.addRule(RelativeLayout.LEFT_OF, R.id.txtvCount);
        holder.failure.setVisibility(View.GONE);
    }
}
Also used : RequestOptions(com.bumptech.glide.request.RequestOptions) RelativeLayout(android.widget.RelativeLayout) PreferenceActivity(de.danoeh.antennapod.activity.PreferenceActivity) Activity(android.app.Activity) Feed(de.danoeh.antennapod.model.feed.Feed)

Aggregations

Feed (de.danoeh.antennapod.model.feed.Feed)125 FeedItem (de.danoeh.antennapod.model.feed.FeedItem)75 Test (org.junit.Test)61 ArrayList (java.util.ArrayList)43 Date (java.util.Date)37 File (java.io.File)31 FeedMedia (de.danoeh.antennapod.model.feed.FeedMedia)27 Cursor (android.database.Cursor)15 FeedPreferences (de.danoeh.antennapod.model.feed.FeedPreferences)12 NonNull (androidx.annotation.NonNull)10 Nullable (androidx.annotation.Nullable)8 View (android.view.View)7 DownloadStatus (de.danoeh.antennapod.core.service.download.DownloadStatus)7 Log (android.util.Log)6 R (de.danoeh.antennapod.R)6 DownloadRequest (de.danoeh.antennapod.core.service.download.DownloadRequest)6 List (java.util.List)6 ViewGroup (android.view.ViewGroup)5 AlertDialog (androidx.appcompat.app.AlertDialog)5 RequestOptions (com.bumptech.glide.request.RequestOptions)5