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);
}
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;
}
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);
});
}
}
}
}
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);
}
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);
}
}
Aggregations