summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2012-07-23 00:28:01 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2012-07-23 00:28:01 +0200
commitea2c8e6e4b161dc2af5c5054590d70ae6178aca5 (patch)
tree6188130841847427cf69477fe3e7fbdbf05296bd
parent8fb81fa7993a80255ae8ea56842c1c2f20e49f24 (diff)
downloadAntennaPod-ea2c8e6e4b161dc2af5c5054590d70ae6178aca5.zip
Added list adapter for simple chapters
-rw-r--r--res/layout/simplechapter_item.xml22
-rw-r--r--src/de/danoeh/antennapod/adapter/SCListAdapter.java76
-rw-r--r--src/de/danoeh/antennapod/feed/FeedItem.java28
-rw-r--r--src/de/danoeh/antennapod/feed/FeedManager.java2
-rw-r--r--src/de/danoeh/antennapod/feed/SimpleChapter.java30
-rw-r--r--src/de/danoeh/antennapod/syndication/namespace/simplechapters/NSSimpleChapters.java7
6 files changed, 144 insertions, 21 deletions
diff --git a/res/layout/simplechapter_item.xml b/res/layout/simplechapter_item.xml
new file mode 100644
index 000000000..cacbc9d70
--- /dev/null
+++ b/res/layout/simplechapter_item.xml
@@ -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> \ No newline at end of file
diff --git a/src/de/danoeh/antennapod/adapter/SCListAdapter.java b/src/de/danoeh/antennapod/adapter/SCListAdapter.java
new file mode 100644
index 000000000..f0c9c0e93
--- /dev/null
+++ b/src/de/danoeh/antennapod/adapter/SCListAdapter.java
@@ -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;
+ }
+
+}
diff --git a/src/de/danoeh/antennapod/feed/FeedItem.java b/src/de/danoeh/antennapod/feed/FeedItem.java
index 732c61380..6b526ad35 100644
--- a/src/de/danoeh/antennapod/feed/FeedItem.java
+++ b/src/de/danoeh/antennapod/feed/FeedItem.java
@@ -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;
}
diff --git a/src/de/danoeh/antennapod/feed/FeedManager.java b/src/de/danoeh/antennapod/feed/FeedManager.java
index 09a10a357..79e5f8abd 100644
--- a/src/de/danoeh/antennapod/feed/FeedManager.java
+++ b/src/de/danoeh/antennapod/feed/FeedManager.java
@@ -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));
diff --git a/src/de/danoeh/antennapod/feed/SimpleChapter.java b/src/de/danoeh/antennapod/feed/SimpleChapter.java
index 5e43bfeb6..861d07eb2 100644
--- a/src/de/danoeh/antennapod/feed/SimpleChapter.java
+++ b/src/de/danoeh/antennapod/feed/SimpleChapter.java
@@ -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;
+ }
+
}
diff --git a/src/de/danoeh/antennapod/syndication/namespace/simplechapters/NSSimpleChapters.java b/src/de/danoeh/antennapod/syndication/namespace/simplechapters/NSSimpleChapters.java
index 3c7853304..338715f52 100644
--- a/src/de/danoeh/antennapod/syndication/namespace/simplechapters/NSSimpleChapters.java
+++ b/src/de/danoeh/antennapod/syndication/namespace/simplechapters/NSSimpleChapters.java
@@ -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);