Move "Delete Removes from Queue" logic to DBWriter

This commit is contained in:
Petar Kukolj 2018-12-02 23:17:56 +01:00
parent 90e6259331
commit b53a3c2ecf
5 changed files with 15 additions and 21 deletions

View File

@ -26,7 +26,6 @@ import java.util.Map;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.storage.DownloadRequestException;
@ -450,9 +449,6 @@ public class EpisodesApplyActionFragment extends Fragment {
FeedItem episode = idMap.get(id);
if(episode.hasMedia()) {
DBWriter.deleteFeedMediaOfItem(getActivity(), episode.getMedia().getId());
if (UserPreferences.shouldDeleteRemoveFromQueue()) {
DBWriter.removeQueueItem(getActivity(), episode, false);
}
}
}
close();

View File

@ -17,7 +17,6 @@ import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.adapter.DownloadedEpisodesListAdapter;
import de.danoeh.antennapod.core.feed.EventDistributor;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.util.FeedItemUtil;
@ -170,9 +169,6 @@ public class CompletedDownloadsFragment extends ListFragment {
@Override
public void onFeedItemSecondaryAction(FeedItem item) {
DBWriter.deleteFeedMediaOfItem(getActivity(), item.getMedia().getId());
if (UserPreferences.shouldDeleteRemoveFromQueue()) {
DBWriter.removeQueueItem(getActivity(), item, false);
}
}
};

View File

@ -248,9 +248,6 @@ public class ItemFragment extends Fragment implements OnSwipeGesture {
((MainActivity) getActivity()).dismissChildFragment();
} else {
DBWriter.deleteFeedMediaOfItem(getActivity(), media.getId());
if (UserPreferences.shouldDeleteRemoveFromQueue()) {
DBWriter.removeQueueItem(getActivity(), item, false);
}
}
} else if (item.getLink() != null) {
Uri uri = Uri.parse(item.getLink());

View File

@ -165,9 +165,6 @@ public class FeedItemMenuHandler {
break;
case R.id.remove_item:
DBWriter.deleteFeedMediaOfItem(context, selectedItem.getMedia().getId());
if (UserPreferences.shouldDeleteRemoveFromQueue()) {
DBWriter.removeQueueItem(context, selectedItem, false);
}
break;
case R.id.mark_read_item:
selectedItem.setPlayed(true);

View File

@ -74,13 +74,7 @@ public class DBWriter {
private DBWriter() {
}
/**
* Deletes a downloaded FeedMedia file from the storage device.
*
* @param context A context that is used for opening a database connection.
* @param mediaId ID of the FeedMedia object whose downloaded file should be deleted.
*/
public static Future<?> deleteFeedMediaOfItem(final Context context,
private static Future<?> doDeleteFeedMediaOfItem(final Context context,
final long mediaId) {
return dbExec.submit(() -> {
final FeedMedia media = DBReader.getFeedMedia(mediaId);
@ -136,6 +130,20 @@ public class DBWriter {
});
}
/**
* Deletes a downloaded FeedMedia file from the storage device.
*
* @param context A context that is used for opening a database connection.
* @param mediaId ID of the FeedMedia object whose downloaded file should be deleted.
*/
public static Future<?> deleteFeedMediaOfItem(final Context context,
final long mediaId) {
if (UserPreferences.shouldDeleteRemoveFromQueue()) {
DBWriter.removeQueueItem(context, DBReader.getFeedMedia(mediaId).getItem(), false);
}
return doDeleteFeedMediaOfItem(context, mediaId);
}
/**
* Deletes a Feed and all downloaded files of its components like images and downloaded episodes.
*