Ignore invalid chapters

This commit is contained in:
daniel oeh 2012-11-06 22:28:42 +01:00
parent 08349087ca
commit 8297d03ef8
2 changed files with 40 additions and 2 deletions

View File

@ -140,7 +140,7 @@ public class AudioplayerActivity extends MediaplayerActivity {
};
sCChapterFragment.setListAdapter(new ChapterListAdapter(
activity, 0, media.getItem().getChapters()));
activity, 0, media.getItem().getChapters(), media));
return sCChapterFragment;
default:

View File

@ -21,15 +21,21 @@ import android.widget.ArrayAdapter;
import android.widget.TextView;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.feed.Chapter;
import de.danoeh.antennapod.feed.FeedMedia;
import de.danoeh.antennapod.util.Converter;
public class ChapterListAdapter extends ArrayAdapter<Chapter> {
private static final String TAG = "ChapterListAdapter";
private List<Chapter> chapters;
private FeedMedia media;
public ChapterListAdapter(Context context, int textViewResourceId,
List<Chapter> objects) {
List<Chapter> objects, FeedMedia media) {
super(context, textViewResourceId, objects);
this.chapters = objects;
this.media = media;
}
@Override
@ -181,4 +187,36 @@ public class ChapterListAdapter extends ArrayAdapter<Chapter> {
}
};
@Override
public int getCount() {
// ignore invalid chapters
int counter = 0;
for (Chapter chapter : chapters) {
if (!ignoreChapter(chapter)) {
counter++;
}
}
return counter;
}
private boolean ignoreChapter(Chapter c) {
return media.getDuration() > 0 && media.getDuration() < c.getStart();
}
@Override
public Chapter getItem(int position) {
int i = 0;
for (Chapter chapter : chapters) {
if (!ignoreChapter(chapter)) {
if (i == position) {
return chapter;
} else {
i++;
}
}
}
return super.getItem(position);
}
}