Search in sources :

Example 31 with Feed

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

the class DBReader method getNavDrawerData.

/**
     * Returns data necessary for displaying the navigation drawer. This includes
     * the list of subscriptions, the number of items in the queue and the number of unread
     * items.
     *
     */
public static NavDrawerData getNavDrawerData() {
    Log.d(TAG, "getNavDrawerData() called with: " + "");
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    List<Feed> feeds = getFeedList(adapter);
    long[] feedIds = new long[feeds.size()];
    for (int i = 0; i < feeds.size(); i++) {
        feedIds[i] = feeds.get(i).getId();
    }
    final LongIntMap feedCounters = adapter.getFeedCounters(feedIds);
    Comparator<Feed> comparator;
    int feedOrder = UserPreferences.getFeedOrder();
    if (feedOrder == UserPreferences.FEED_ORDER_COUNTER) {
        comparator = (lhs, rhs) -> {
            long counterLhs = feedCounters.get(lhs.getId());
            long counterRhs = feedCounters.get(rhs.getId());
            if (counterLhs > counterRhs) {
                // reverse natural order: podcast with most unplayed episodes first
                return -1;
            } else if (counterLhs == counterRhs) {
                return lhs.getTitle().compareToIgnoreCase(rhs.getTitle());
            } else {
                return 1;
            }
        };
    } else if (feedOrder == UserPreferences.FEED_ORDER_ALPHABETICAL) {
        comparator = (lhs, rhs) -> {
            String t1 = lhs.getTitle();
            String t2 = rhs.getTitle();
            if (t1 == null) {
                return 1;
            } else if (t2 == null) {
                return -1;
            } else {
                return t1.compareToIgnoreCase(t2);
            }
        };
    } else {
        comparator = (lhs, rhs) -> {
            if (lhs.getItems() == null || lhs.getItems().size() == 0) {
                List<FeedItem> items = DBReader.getFeedItemList(lhs);
                lhs.setItems(items);
            }
            if (rhs.getItems() == null || rhs.getItems().size() == 0) {
                List<FeedItem> items = DBReader.getFeedItemList(rhs);
                rhs.setItems(items);
            }
            if (lhs.getMostRecentItem() == null) {
                return 1;
            } else if (rhs.getMostRecentItem() == null) {
                return -1;
            } else {
                Date d1 = lhs.getMostRecentItem().getPubDate();
                Date d2 = rhs.getMostRecentItem().getPubDate();
                return d2.compareTo(d1);
            }
        };
    }
    Collections.sort(feeds, comparator);
    int queueSize = adapter.getQueueSize();
    int numNewItems = adapter.getNumberOfNewItems();
    int numDownloadedItems = adapter.getNumberOfDownloadedEpisodes();
    NavDrawerData result = new NavDrawerData(feeds, queueSize, numNewItems, numDownloadedItems, feedCounters, UserPreferences.getEpisodeCleanupAlgorithm().getReclaimableItems());
    adapter.close();
    return result;
}
Also used : FeedItemPubdateComparator(de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator) Arrays(java.util.Arrays) SimpleChapter(de.danoeh.antennapod.core.feed.SimpleChapter) Date(java.util.Date) DownloadStatusComparator(de.danoeh.antennapod.core.util.comparator.DownloadStatusComparator) VorbisCommentChapter(de.danoeh.antennapod.core.feed.VorbisCommentChapter) LongList(de.danoeh.antennapod.core.util.LongList) ArrayList(java.util.ArrayList) UserPreferences(de.danoeh.antennapod.core.preferences.UserPreferences) FeedImage(de.danoeh.antennapod.core.feed.FeedImage) ArrayMap(android.support.v4.util.ArrayMap) Map(java.util.Map) Feed(de.danoeh.antennapod.core.feed.Feed) DownloadStatus(de.danoeh.antennapod.core.service.download.DownloadStatus) Log(android.util.Log) PlaybackCompletionDateComparator(de.danoeh.antennapod.core.util.comparator.PlaybackCompletionDateComparator) Cursor(android.database.Cursor) LongIntMap(de.danoeh.antennapod.core.util.LongIntMap) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) ID3Chapter(de.danoeh.antennapod.core.feed.ID3Chapter) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedPreferences(de.danoeh.antennapod.core.feed.FeedPreferences) List(java.util.List) Chapter(de.danoeh.antennapod.core.feed.Chapter) Comparator(java.util.Comparator) Collections(java.util.Collections) FlattrThing(de.danoeh.antennapod.core.util.flattr.FlattrThing) Date(java.util.Date) LongList(de.danoeh.antennapod.core.util.LongList) ArrayList(java.util.ArrayList) List(java.util.List) LongIntMap(de.danoeh.antennapod.core.util.LongIntMap) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 32 with Feed

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

the class DBTasks method loadNextPageOfFeed.

/**
     * Queues the next page of this Feed for download. The given Feed has to be a paged
     * Feed (isPaged()=true) and must contain a nextPageLink.
     *
     * @param context      Used for requesting the download.
     * @param feed         The feed whose next page should be loaded.
     * @param loadAllPages True if any subsequent pages should also be loaded, false otherwise.
     */
public static void loadNextPageOfFeed(final Context context, Feed feed, boolean loadAllPages) throws DownloadRequestException {
    if (feed.isPaged() && feed.getNextPageLink() != null) {
        int pageNr = feed.getPageNr() + 1;
        Feed nextFeed = new Feed(feed.getNextPageLink(), null, feed.getTitle() + "(" + pageNr + ")");
        nextFeed.setPageNr(pageNr);
        nextFeed.setPaged(true);
        nextFeed.setId(feed.getId());
        DownloadRequester.getInstance().downloadFeed(context, nextFeed, loadAllPages, false);
    } else {
        Log.e(TAG, "loadNextPageOfFeed: Feed was either not paged or contained no nextPageLink");
    }
}
Also used : Feed(de.danoeh.antennapod.core.feed.Feed)

Example 33 with Feed

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

the class DownloadRequester method downloadMedia.

public synchronized void downloadMedia(Context context, FeedMedia feedmedia) throws DownloadRequestException {
    if (feedFileValid(feedmedia)) {
        Feed feed = feedmedia.getItem().getFeed();
        String username;
        String password;
        if (feed != null && feed.getPreferences() != null) {
            username = feed.getPreferences().getUsername();
            password = feed.getPreferences().getPassword();
        } else {
            username = null;
            password = null;
        }
        File dest;
        if (feedmedia.getFile_url() != null) {
            dest = new File(feedmedia.getFile_url());
        } else {
            dest = new File(getMediafilePath(context, feedmedia), getMediafilename(feedmedia));
        }
        download(context, feedmedia, feed, dest, false, username, password, null, false, null);
    }
}
Also used : FeedFile(de.danoeh.antennapod.core.feed.FeedFile) File(java.io.File) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 34 with Feed

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

the class DBReader method extractFeedFromCursorRow.

private static Feed extractFeedFromCursorRow(PodDBAdapter adapter, Cursor cursor) {
    final FeedImage image;
    int indexImage = cursor.getColumnIndex(PodDBAdapter.KEY_IMAGE);
    long imageId = cursor.getLong(indexImage);
    if (imageId != 0) {
        image = getFeedImage(adapter, imageId);
    } else {
        image = null;
    }
    Feed feed = Feed.fromCursor(cursor);
    if (image != null) {
        feed.setImage(image);
        image.setOwner(feed);
    }
    FeedPreferences preferences = FeedPreferences.fromCursor(cursor);
    feed.setPreferences(preferences);
    return feed;
}
Also used : FeedPreferences(de.danoeh.antennapod.core.feed.FeedPreferences) FeedImage(de.danoeh.antennapod.core.feed.FeedImage) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 35 with Feed

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

the class PodDBAdapter method setImage.

/**
     * Inserts or updates an image entry
     *
     * @return the id of the entry
     */
public long setImage(FeedImage image) {
    boolean startedTransaction = false;
    try {
        if (!db.inTransaction()) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                db.beginTransactionNonExclusive();
            } else {
                db.beginTransaction();
            }
            startedTransaction = true;
        }
        ContentValues values = new ContentValues();
        values.put(KEY_TITLE, image.getTitle());
        values.put(KEY_DOWNLOAD_URL, image.getDownload_url());
        values.put(KEY_DOWNLOADED, image.isDownloaded());
        values.put(KEY_FILE_URL, image.getFile_url());
        if (image.getId() == 0) {
            image.setId(db.insert(TABLE_NAME_FEED_IMAGES, null, values));
        } else {
            db.update(TABLE_NAME_FEED_IMAGES, values, KEY_ID + "=?", new String[] { String.valueOf(image.getId()) });
        }
        final FeedComponent owner = image.getOwner();
        if (owner != null && owner.getId() != 0) {
            values.clear();
            values.put(KEY_IMAGE, image.getId());
            if (owner instanceof Feed) {
                db.update(TABLE_NAME_FEEDS, values, KEY_ID + "=?", new String[] { String.valueOf(image.getOwner().getId()) });
            }
        }
        if (startedTransaction) {
            db.setTransactionSuccessful();
        }
    } catch (SQLException e) {
        Log.e(TAG, Log.getStackTraceString(e));
    } finally {
        if (startedTransaction) {
            db.endTransaction();
        }
    }
    return image.getId();
}
Also used : ContentValues(android.content.ContentValues) SQLException(android.database.SQLException) FeedComponent(de.danoeh.antennapod.core.feed.FeedComponent) Feed(de.danoeh.antennapod.core.feed.Feed)

Aggregations

Feed (de.danoeh.antennapod.core.feed.Feed)95 FeedItem (de.danoeh.antennapod.core.feed.FeedItem)55 PodDBAdapter (de.danoeh.antennapod.core.storage.PodDBAdapter)32 ArrayList (java.util.ArrayList)30 Date (java.util.Date)30 FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)21 File (java.io.File)20 Cursor (android.database.Cursor)16 FeedImage (de.danoeh.antennapod.core.feed.FeedImage)14 Context (android.content.Context)13 FlakyTest (android.test.FlakyTest)9 DialogInterface (android.content.DialogInterface)8 Intent (android.content.Intent)8 LayoutInflater (android.view.LayoutInflater)7 AdapterView (android.widget.AdapterView)7 ConfirmationDialog (de.danoeh.antennapod.core.dialog.ConfirmationDialog)6 FeedPreferences (de.danoeh.antennapod.core.feed.FeedPreferences)6 DownloadRequestException (de.danoeh.antennapod.core.storage.DownloadRequestException)6 Log (android.util.Log)4 View (android.view.View)4