Added list adapter for simple chapters

This commit is contained in:
daniel oeh 2012-07-23 00:28:01 +02:00
parent 8fb81fa799
commit ea2c8e6e4b
6 changed files with 144 additions and 21 deletions

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/txtvTitle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:textStyle="bold" />
<TextView
android:id="@+id/txtvStart"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:textColor="@color/gray" />
</RelativeLayout>

View File

@ -0,0 +1,76 @@
package de.danoeh.antennapod.adapter;
import java.text.DateFormat;
import java.util.List;
import de.danoeh.antennapod.BuildConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.adapter.FeedlistAdapter.Holder;
import de.danoeh.antennapod.feed.Feed;
import de.danoeh.antennapod.feed.SimpleChapter;
import de.danoeh.antennapod.storage.DownloadRequester;
import de.danoeh.antennapod.util.Converter;
import android.content.Context;
import android.graphics.Color;
import android.text.format.DateUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class SCListAdapter extends ArrayAdapter<SimpleChapter> {
private static final String TAG = "SCListAdapter";
public SCListAdapter(Context context, int textViewResourceId,
List<SimpleChapter> objects) {
super(context, textViewResourceId, objects);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Holder holder;
SimpleChapter sc = getItem(position);
// Inflate Layout
if (convertView == null) {
holder = new Holder();
LayoutInflater inflater = (LayoutInflater) getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.simplechapter_item, null);
holder.title = (TextView) convertView.findViewById(R.id.txtvTitle);
holder.start = (TextView) convertView.findViewById(R.id.txtvStart);
convertView.setTag(holder);
} else {
holder = (Holder) convertView.getTag();
}
holder.title.setText(sc.getTitle());
holder.start.setText(Converter.getDurationStringLong((int) sc.getStart()));
SimpleChapter current = sc.getItem().getCurrentChapter();
if (current != null) {
if (current == sc) {
holder.title.setTextColor(convertView.getResources().getColor(R.color.bright_blue));
} else {
holder.title.setTextColor(Color.parseColor("black"));
}
} else {
Log.w(TAG, "Could not find out what the current chapter is.");
}
return convertView;
}
static class Holder {
TextView title;
TextView start;
}
}

View File

@ -3,13 +3,13 @@ package de.danoeh.antennapod.feed;
import java.util.ArrayList;
import java.util.Date;
/**
* Data Object for a XML message
*
* @author daniel
*
*
*/
public class FeedItem extends FeedComponent{
public class FeedItem extends FeedComponent {
private String title;
private String description;
@ -23,9 +23,9 @@ public class FeedItem extends FeedComponent{
private ArrayList<SimpleChapter> simpleChapters;
public FeedItem() {
this.read = true;
this.read = true;
}
public FeedItem(String title, String description, String link,
Date pubDate, FeedMedia media, Feed feed) {
super();
@ -38,6 +38,20 @@ public class FeedItem extends FeedComponent{
this.read = true;
}
public SimpleChapter getCurrentChapter() {
if (simpleChapters != null) {
SimpleChapter current = simpleChapters.get(0);
for (SimpleChapter sc : simpleChapters) {
if (media.getPosition() > current.getStart() &&
media.getPosition() <= sc.getStart()) {
return current;
}
current = sc;
}
}
return null;
}
public String getTitle() {
return title;
}
@ -89,7 +103,7 @@ public class FeedItem extends FeedComponent{
public boolean isRead() {
return read;
}
public String getContentEncoded() {
return contentEncoded;
}
@ -97,7 +111,7 @@ public class FeedItem extends FeedComponent{
public void setContentEncoded(String contentEncoded) {
this.contentEncoded = contentEncoded;
}
public String getPaymentLink() {
return paymentLink;
}

View File

@ -632,7 +632,7 @@ public class FeedManager {
if (chapterCursor.moveToFirst()) {
item.setSimpleChapters(new ArrayList<SimpleChapter>());
do {
SimpleChapter chapter = new SimpleChapter(
SimpleChapter chapter = new SimpleChapter(item,
chapterCursor
.getLong(PodDBAdapter.KEY_SC_START_INDEX),
chapterCursor.getString(PodDBAdapter.KEY_TITLE_INDEX));

View File

@ -1,12 +1,14 @@
package de.danoeh.antennapod.feed;
public class SimpleChapter extends FeedComponent {
public long getStart() {
return start;
}
public SimpleChapter(long start, String title) {
/** Defines starting point in milliseconds. */
private long start;
private String title;
private FeedItem item;
public SimpleChapter(FeedItem item, long start, String title) {
super();
this.item = item;
this.start = start;
this.title = title;
}
@ -14,9 +16,17 @@ public class SimpleChapter extends FeedComponent {
public String getTitle() {
return title;
}
/** Defines starting point in milliseconds. */
private long start;
private String title;
public FeedItem getItem() {
return item;
}
public long getStart() {
return start;
}
public void setItem(FeedItem item) {
this.item = item;
}
}

View File

@ -28,9 +28,10 @@ public class NSSimpleChapters extends Namespace {
} else if (localName.equals(CHAPTER)) {
state.getCurrentItem()
.getSimpleChapters()
.add(new SimpleChapter(SyndDateUtils
.parseTimeString(attributes.getValue(START)),
attributes.getValue(TITLE)));
.add(new SimpleChapter(state.getCurrentItem(),
SyndDateUtils.parseTimeString(attributes
.getValue(START)), attributes
.getValue(TITLE)));
}
return new SyndElement(localName, this);