Itemlists were not updating their content properly if "Display only
episodes'-preference was enabled
This commit is contained in:
parent
c772471268
commit
9513099a10
|
@ -38,6 +38,8 @@ public class PodcastApp extends Application implements
|
|||
|
||||
private static PodcastApp singleton;
|
||||
|
||||
private boolean displayOnlyEpisodes;
|
||||
|
||||
public static PodcastApp getInstance() {
|
||||
return singleton;
|
||||
}
|
||||
|
@ -49,6 +51,7 @@ public class PodcastApp extends Application implements
|
|||
LOGICAL_DENSITY = getResources().getDisplayMetrics().density;
|
||||
SharedPreferences prefs = PreferenceManager
|
||||
.getDefaultSharedPreferences(this);
|
||||
displayOnlyEpisodes = prefs.getBoolean(PREF_DISPLAY_ONLY_EPISODES, false);
|
||||
createImportDirectory();
|
||||
createNoMediaFile();
|
||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||
|
@ -124,6 +127,9 @@ public class PodcastApp extends Application implements
|
|||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Automatic update was deactivated");
|
||||
}
|
||||
} else if (key.equals(PREF_DISPLAY_ONLY_EPISODES)) {
|
||||
if (AppConfig.DEBUG) Log.d(TAG, "PREF_DISPLAY_ONLY_EPISODES changed");
|
||||
displayOnlyEpisodes = sharedPreferences.getBoolean(PREF_DISPLAY_ONLY_EPISODES, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,6 +137,10 @@ public class PodcastApp extends Application implements
|
|||
return LOGICAL_DENSITY;
|
||||
}
|
||||
|
||||
public boolean displayOnlyEpisodes() {
|
||||
return displayOnlyEpisodes;
|
||||
}
|
||||
|
||||
public boolean isLargeScreen() {
|
||||
return (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE || (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE;
|
||||
|
||||
|
|
|
@ -7,7 +7,10 @@ import de.danoeh.antennapod.feed.FeedItem;
|
|||
import de.danoeh.antennapod.feed.FeedManager;
|
||||
import de.danoeh.antennapod.storage.DownloadRequester;
|
||||
import de.danoeh.antennapod.util.Converter;
|
||||
import de.danoeh.antennapod.util.EpisodeFilter;
|
||||
import de.danoeh.antennapod.PodcastApp;
|
||||
import de.danoeh.antennapod.R;
|
||||
import android.widget.Adapter;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
|
@ -27,6 +30,7 @@ public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> {
|
|||
private OnClickListener onButActionClicked;
|
||||
private boolean showFeedtitle;
|
||||
private int selectedItemIndex;
|
||||
private List<FeedItem> objects;
|
||||
|
||||
public static final int SELECTION_NONE = -1;
|
||||
|
||||
|
@ -34,6 +38,7 @@ public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> {
|
|||
List<FeedItem> objects, OnClickListener onButActionClicked,
|
||||
boolean showFeedtitle) {
|
||||
super(context, textViewResourceId, objects);
|
||||
this.objects = objects;
|
||||
this.onButActionClicked = onButActionClicked;
|
||||
this.showFeedtitle = showFeedtitle;
|
||||
this.selectedItemIndex = SELECTION_NONE;
|
||||
|
@ -75,10 +80,11 @@ public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> {
|
|||
} else {
|
||||
holder = (Holder) convertView.getTag();
|
||||
}
|
||||
|
||||
if (!(getItemViewType(position) == Adapter.IGNORE_ITEM_VIEW_TYPE)) {
|
||||
convertView.setVisibility(View.VISIBLE);
|
||||
if (position == selectedItemIndex) {
|
||||
convertView.setBackgroundColor(convertView.getResources().getColor(
|
||||
R.color.selection_background));
|
||||
convertView.setBackgroundColor(convertView.getResources()
|
||||
.getColor(R.color.selection_background));
|
||||
} else {
|
||||
convertView.setBackgroundResource(0);
|
||||
}
|
||||
|
@ -110,15 +116,17 @@ public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> {
|
|||
holder.inPlaylist.setVisibility(View.GONE);
|
||||
}
|
||||
if (item.getMedia().isDownloaded()) {
|
||||
holder.lenSize.setText(convertView.getResources().getString(
|
||||
R.string.length_prefix)
|
||||
holder.lenSize.setText(convertView.getResources()
|
||||
.getString(R.string.length_prefix)
|
||||
+ Converter.getDurationStringLong(item.getMedia()
|
||||
.getDuration()));
|
||||
holder.downloaded.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.lenSize.setText(convertView.getResources().getString(
|
||||
holder.lenSize
|
||||
.setText(convertView.getResources().getString(
|
||||
R.string.size_prefix)
|
||||
+ Converter.byteToString(item.getMedia().getSize()));
|
||||
+ Converter.byteToString(item.getMedia()
|
||||
.getSize()));
|
||||
holder.downloaded.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
|
@ -142,7 +150,9 @@ public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> {
|
|||
|
||||
holder.butAction.setFocusable(false);
|
||||
holder.butAction.setOnClickListener(onButActionClicked);
|
||||
|
||||
} else {
|
||||
convertView.setVisibility(View.GONE);
|
||||
}
|
||||
return convertView;
|
||||
|
||||
}
|
||||
|
@ -169,4 +179,22 @@ public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> {
|
|||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
if (PodcastApp.getInstance().displayOnlyEpisodes()) {
|
||||
return EpisodeFilter.countItemsWithEpisodes(objects);
|
||||
} else {
|
||||
return super.getCount();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeedItem getItem(int position) {
|
||||
if (PodcastApp.getInstance().displayOnlyEpisodes()) {
|
||||
return EpisodeFilter.accessEpisodeByIndex(objects, position);
|
||||
} else {
|
||||
return super.getItem(position);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -103,13 +103,6 @@ public class ItemlistFragment extends SherlockListFragment implements
|
|||
items = feed.getItems();
|
||||
}
|
||||
|
||||
boolean displayOnlyEpisodes = PreferenceManager
|
||||
.getDefaultSharedPreferences(PodcastApp.getInstance())
|
||||
.getBoolean(PodcastApp.PREF_DISPLAY_ONLY_EPISODES, false);
|
||||
if (displayOnlyEpisodes) {
|
||||
items = EpisodeFilter.getEpisodeList(items);
|
||||
}
|
||||
|
||||
fila = new FeedItemlistAdapter(getActivity(), 0, items,
|
||||
onButActionClicked, showFeedtitle);
|
||||
setListAdapter(fila);
|
||||
|
@ -170,16 +163,9 @@ public class ItemlistFragment extends SherlockListFragment implements
|
|||
DownloadRequester.ACTION_DOWNLOAD_QUEUED)) {
|
||||
updateProgressBarVisibility();
|
||||
} else {
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
fila.notifyDataSetChanged();
|
||||
updateProgressBarVisibility();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import de.danoeh.antennapod.feed.FeedManager;
|
|||
import de.danoeh.antennapod.R;
|
||||
|
||||
public class QueueFragment extends ItemlistFragment {
|
||||
private static final String TAG = "QueueFragment";
|
||||
|
||||
public QueueFragment() {
|
||||
super(FeedManager.getInstance().getQueue(), true);
|
||||
|
|
|
@ -20,4 +20,30 @@ public class EpisodeFilter {
|
|||
}
|
||||
return episodes;
|
||||
}
|
||||
|
||||
public static int countItemsWithEpisodes(List<FeedItem> items) {
|
||||
int count = 0;
|
||||
for (FeedItem item : items) {
|
||||
if (item.getMedia() != null) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static FeedItem accessEpisodeByIndex(List<FeedItem> items,
|
||||
int position) {
|
||||
int count = 0;
|
||||
for (FeedItem item : items) {
|
||||
|
||||
if (item.getMedia() != null) {
|
||||
if (count == position) {
|
||||
return item;
|
||||
} else {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue