diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/EpisodesApplyActionFragment.java b/app/src/main/java/de/danoeh/antennapod/dialog/EpisodesApplyActionFragment.java index 25d27217b..1ca5b831c 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/EpisodesApplyActionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/EpisodesApplyActionFragment.java @@ -1,6 +1,5 @@ package de.danoeh.antennapod.dialog; -import android.app.ProgressDialog; import android.content.res.TypedArray; import android.graphics.Color; import android.os.Bundle; @@ -26,7 +25,9 @@ import com.joanzapata.android.iconify.Iconify; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.List; +import java.util.Map; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator; @@ -49,6 +50,7 @@ public class EpisodesApplyActionFragment extends Fragment { private Button btnDownload; private Button btnDelete; + private final Map idMap; private final List episodes; private final List titles = new ArrayList(); private final LongList checkedIds = new LongList(); @@ -57,16 +59,17 @@ public class EpisodesApplyActionFragment extends Fragment { private int textColor; - private ProgressDialog pd; - public EpisodesApplyActionFragment(List episodes) { this.episodes = episodes; + this.idMap = new HashMap<>(episodes.size()); + for(FeedItem episode : episodes) { + this.idMap.put(episode.getId(), episode); + } } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - ActionBar bar = ((ActionBarActivity)getActivity()).getSupportActionBar(); setHasOptionsMenu(true); } @@ -278,14 +281,21 @@ public class EpisodesApplyActionFragment extends Fragment { Collections.sort(episodes, new Comparator() { @Override public int compare(FeedItem lhs, FeedItem rhs) { - int code = lhs.getMedia().getDuration() - rhs.getMedia().getDuration(); - if (reverse) { - return -1 * code; + int ordering; + if (false == lhs.hasMedia()) { + ordering = 1; + } else if (false == rhs.hasMedia()) { + ordering = -1; } else { - return code; + ordering = lhs.getMedia().getDuration() - rhs.getMedia().getDuration(); } + if(reverse) { + return -1 * ordering; + } else { + return ordering; } - }); + } + }); refreshTitles(); refreshCheckboxes(); } @@ -321,7 +331,7 @@ public class EpisodesApplyActionFragment extends Fragment { private void checkDownloaded(boolean isDownloaded) { for (FeedItem episode : episodes) { - if(episode.getMedia().isDownloaded() == isDownloaded) { + if(episode.hasMedia() && episode.getMedia().isDownloaded() == isDownloaded) { if(!checkedIds.contains(episode.getId())) { checkedIds.add(episode.getId()); } @@ -391,8 +401,10 @@ public class EpisodesApplyActionFragment extends Fragment { private void deleteChecked() { for(long id : checkedIds.toArray()) { - FeedItem episode = findById(id); - DBWriter.deleteFeedMediaOfItem(getActivity(), episode.getMedia().getId()); + FeedItem episode = idMap.get(id); + if(episode.hasMedia()) { + DBWriter.deleteFeedMediaOfItem(getActivity(), episode.getMedia().getId()); + } } close(); } @@ -401,14 +413,4 @@ public class EpisodesApplyActionFragment extends Fragment { getActivity().getSupportFragmentManager().popBackStack(); } - private FeedItem findById(long id) { - for(int i=0; i < episodes.size(); i++) { - FeedItem episode = episodes.get(i); - if(episode.getId() == id) { - return episode; - } - } - return null; - } - } diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java index 2c403d9ca..e103007e3 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java @@ -415,7 +415,7 @@ public class DBWriter { boolean addToFront = UserPreferences.enqueueAtFront(); if(addToFront){ - queue.add(0, item); + queue.add(0+i, item); } else { queue.add(item); } diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 7ee026fa2..00d7ed1bd 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -464,7 +464,7 @@ Selected unplayed Episodes Downloaded Selected downloaded Episodes - Unplayed + Not downloaded Selected not downloaded Episodes Sort by ... Title (A \u2192 Z)