Search in sources :

Example 91 with FeedItem

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

the class PodDBAdapter method setQueue.

public void setQueue(List<FeedItem> queue) {
    ContentValues values = new ContentValues();
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            db.beginTransactionNonExclusive();
        } else {
            db.beginTransaction();
        }
        db.delete(TABLE_NAME_QUEUE, null, null);
        for (int i = 0; i < queue.size(); i++) {
            FeedItem item = queue.get(i);
            values.put(KEY_ID, i);
            values.put(KEY_FEEDITEM, item.getId());
            values.put(KEY_FEED, item.getFeed().getId());
            db.insertWithOnConflict(TABLE_NAME_QUEUE, null, values, SQLiteDatabase.CONFLICT_REPLACE);
        }
        db.setTransactionSuccessful();
    } catch (SQLException e) {
        Log.e(TAG, Log.getStackTraceString(e));
    } finally {
        db.endTransaction();
    }
}
Also used : ContentValues(android.content.ContentValues) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) SQLException(android.database.SQLException)

Example 92 with FeedItem

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

the class PodDBAdapter method removeFeed.

/**
     * Remove a feed with all its FeedItems and Media entries.
     */
public void removeFeed(Feed feed) {
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            db.beginTransactionNonExclusive();
        } else {
            db.beginTransaction();
        }
        if (feed.getImage() != null) {
            removeFeedImage(feed.getImage());
        }
        if (feed.getItems() != null) {
            for (FeedItem item : feed.getItems()) {
                removeFeedItem(item);
            }
        }
        // delete download log entries for feed
        db.delete(TABLE_NAME_DOWNLOAD_LOG, KEY_FEEDFILE + "=? AND " + KEY_FEEDFILETYPE + "=?", new String[] { String.valueOf(feed.getId()), String.valueOf(Feed.FEEDFILETYPE_FEED) });
        db.delete(TABLE_NAME_FEEDS, KEY_ID + "=?", new String[] { String.valueOf(feed.getId()) });
        db.setTransactionSuccessful();
    } catch (SQLException e) {
        Log.e(TAG, Log.getStackTraceString(e));
    } finally {
        db.endTransaction();
    }
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) SQLException(android.database.SQLException)

Example 93 with FeedItem

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

the class DBWriter method deleteFeed.

/**
     * Deletes a Feed and all downloaded files of its components like images and downloaded episodes.
     *
     * @param context A context that is used for opening a database connection.
     * @param feedId  ID of the Feed that should be deleted.
     */
public static Future<?> deleteFeed(final Context context, final long feedId) {
    return dbExec.submit(() -> {
        DownloadRequester requester = DownloadRequester.getInstance();
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
        final Feed feed = DBReader.getFeed(feedId);
        if (feed != null) {
            if (PlaybackPreferences.getCurrentlyPlayingMedia() == FeedMedia.PLAYABLE_TYPE_FEEDMEDIA && PlaybackPreferences.getLastPlayedFeedId() == feed.getId()) {
                context.sendBroadcast(new Intent(PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE));
                SharedPreferences.Editor editor = prefs.edit();
                editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEED_ID, -1);
                editor.commit();
            }
            // delete image file
            if (feed.getImage() != null) {
                if (feed.getImage().isDownloaded() && feed.getImage().getFile_url() != null) {
                    File imageFile = new File(feed.getImage().getFile_url());
                    imageFile.delete();
                } else if (requester.isDownloadingFile(feed.getImage())) {
                    requester.cancelDownload(context, feed.getImage());
                }
            }
            // delete stored media files and mark them as read
            List<FeedItem> queue = DBReader.getQueue();
            List<FeedItem> removed = new ArrayList<>();
            if (feed.getItems() == null) {
                DBReader.getFeedItemList(feed);
            }
            for (FeedItem item : feed.getItems()) {
                if (queue.remove(item)) {
                    removed.add(item);
                }
                if (item.getMedia() != null && item.getMedia().isDownloaded()) {
                    File mediaFile = new File(item.getMedia().getFile_url());
                    mediaFile.delete();
                } else if (item.getMedia() != null && requester.isDownloadingFile(item.getMedia())) {
                    requester.cancelDownload(context, item.getMedia());
                }
                if (item.hasItemImage()) {
                    FeedImage image = item.getImage();
                    if (image.isDownloaded() && image.getFile_url() != null) {
                        File imgFile = new File(image.getFile_url());
                        imgFile.delete();
                    } else if (requester.isDownloadingFile(image)) {
                        requester.cancelDownload(context, item.getImage());
                    }
                }
            }
            PodDBAdapter adapter = PodDBAdapter.getInstance();
            adapter.open();
            if (removed.size() > 0) {
                adapter.setQueue(queue);
                for (FeedItem item : removed) {
                    EventBus.getDefault().post(QueueEvent.irreversibleRemoved(item));
                }
            }
            adapter.removeFeed(feed);
            adapter.close();
            if (ClientConfig.gpodnetCallbacks.gpodnetEnabled()) {
                GpodnetPreferences.addRemovedFeed(feed.getDownload_url());
            }
            EventDistributor.getInstance().sendFeedUpdateBroadcast();
            // we assume we also removed download log entries for the feed or its media files.
            // especially important if download or refresh failed, as the user should not be able
            // to retry these
            EventDistributor.getInstance().sendDownloadLogUpdateBroadcast();
            BackupManager backupManager = new BackupManager(context);
            backupManager.dataChanged();
        }
    });
}
Also used : FeedImage(de.danoeh.antennapod.core.feed.FeedImage) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) SharedPreferences(android.content.SharedPreferences) ArrayList(java.util.ArrayList) Intent(android.content.Intent) File(java.io.File) BackupManager(android.app.backup.BackupManager) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 94 with FeedItem

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

the class DBWriter method addQueueItem.

public static Future<?> addQueueItem(final Context context, final FeedItem... items) {
    LongList itemIds = new LongList(items.length);
    for (FeedItem item : items) {
        itemIds.add(item.getId());
        item.addTag(FeedItem.TAG_QUEUE);
    }
    return addQueueItem(context, false, itemIds.toArray());
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) LongList(de.danoeh.antennapod.core.util.LongList)

Example 95 with FeedItem

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

the class QueueAccess method ItemListAccess.

public static QueueAccess ItemListAccess(final List<FeedItem> items) {
    return new QueueAccess() {

        @Override
        public boolean contains(long id) {
            if (items == null) {
                return false;
            }
            for (FeedItem item : items) {
                if (item.getId() == id) {
                    return true;
                }
            }
            return false;
        }

        @Override
        public boolean remove(long id) {
            Iterator<FeedItem> it = items.iterator();
            FeedItem item;
            while (it.hasNext()) {
                item = it.next();
                if (item.getId() == id) {
                    it.remove();
                    return true;
                }
            }
            return false;
        }
    };
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem)

Aggregations

FeedItem (de.danoeh.antennapod.core.feed.FeedItem)149 Feed (de.danoeh.antennapod.core.feed.Feed)53 FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)40 Date (java.util.Date)35 ArrayList (java.util.ArrayList)33 PodDBAdapter (de.danoeh.antennapod.core.storage.PodDBAdapter)28 Cursor (android.database.Cursor)23 File (java.io.File)18 FeedImage (de.danoeh.antennapod.core.feed.FeedImage)15 Context (android.content.Context)12 FlakyTest (android.test.FlakyTest)11 View (android.view.View)10 Playable (de.danoeh.antennapod.core.util.playback.Playable)7 Intent (android.content.Intent)6 LayoutInflater (android.view.LayoutInflater)5 ListView (android.widget.ListView)5 SharedPreferences (android.content.SharedPreferences)4 Chapter (de.danoeh.antennapod.core.feed.Chapter)4 FeedFilter (de.danoeh.antennapod.core.feed.FeedFilter)4 LongList (de.danoeh.antennapod.core.util.LongList)4