Added support for flattr-paymentlinks

This commit is contained in:
daniel oeh 2012-06-26 18:39:02 +02:00
parent 7ef8a7021c
commit 0d6a7580de
12 changed files with 73 additions and 12 deletions

View File

@ -10,6 +10,7 @@
<item android:id="@+id/remove_from_queue_item" android:title="@string/remove_from_queue_label" android:visible="false" android:showAsAction="collapseActionView"></item>
<item android:id="@+id/stream_item" android:title="@string/stream_label" android:visible="false" android:showAsAction="collapseActionView"></item>
<item android:id="@+id/visit_website_item" android:icon="@drawable/location_web_site" android:title="@string/visit_website_label" android:showAsAction="ifRoom|collapseActionView" android:visible="false"></item>
<item android:id="@+id/support_item" android:title="@string/support_label" android:showAsAction="collapseActionView" android:visible="false"></item>
</menu>

View File

@ -2,6 +2,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/mark_all_read_item" android:title="@string/mark_all_read_label" android:showAsAction="ifRoom|withText"></item><item android:id="@+id/show_info_item" android:icon="@drawable/action_about" android:title="@string/show_info_label" android:showAsAction="always"></item><item android:id="@+id/remove_item" android:title="@string/remove_feed_label" android:icon="@drawable/content_discard" android:visible="true" android:showAsAction="collapseActionView"></item>
<item android:id="@+id/visit_website_item" android:showAsAction="ifRoom|collapseActionView" android:icon="@drawable/location_web_site" android:title="@string/visit_website_label" android:visible="true"></item>
<item android:id="@+id/support_item" android:title="@string/support_label" android:showAsAction="collapseActionView" android:visible="false"></item>

View File

@ -61,4 +61,5 @@
<string name="position_default_label">00:00:00</string>
<string name="queue_label">Queue</string>
<string name="visit_website_label">Visit Website</string>
<string name="support_label">Support</string>
</resources>

View File

@ -61,7 +61,7 @@ public class FeedItemlistActivity extends SherlockFragmentActivity {
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
return FeedMenuHandler.onPrepareOptionsMenu(menu);
return FeedMenuHandler.onPrepareOptionsMenu(menu, feed);
}
@Override

View File

@ -19,6 +19,7 @@ public class Feed extends FeedFile {
private ArrayList<FeedItem> items;
/** Date of last refresh. */
private Date lastUpdate;
private String paymentLink;
public Feed(Date lastUpdate) {
super();
@ -97,5 +98,13 @@ public class Feed extends FeedFile {
public void setLastUpdate(Date lastUpdate) {
this.lastUpdate = lastUpdate;
}
public String getPaymentLink() {
return paymentLink;
}
public void setPaymentLink(String paymentLink) {
this.paymentLink = paymentLink;
}
}

View File

@ -9,6 +9,7 @@ import java.util.Date;
*
*/
public class FeedItem extends FeedComponent{
private String title;
private String description;
private String contentEncoded;
@ -17,6 +18,7 @@ public class FeedItem extends FeedComponent{
private FeedMedia media;
private Feed feed;
protected boolean read;
private String paymentLink;
public FeedItem() {
this.read = true;
@ -93,6 +95,14 @@ public class FeedItem extends FeedComponent{
public void setContentEncoded(String contentEncoded) {
this.contentEncoded = contentEncoded;
}
public String getPaymentLink() {
return paymentLink;
}
public void setPaymentLink(String paymentLink) {
this.paymentLink = paymentLink;
}
}

View File

@ -335,7 +335,8 @@ public class FeedManager {
}
}
Log.e(TAG, "Couldn't find FeedMedia with id " + id);
if (feed == null) Log.e(TAG, "Feed was null");
if (feed == null)
Log.e(TAG, "Feed was null");
return null;
}
@ -395,6 +396,8 @@ public class FeedManager {
.getColumnIndex(PodDBAdapter.KEY_LINK)));
feed.setDescription(feedlistCursor.getString(feedlistCursor
.getColumnIndex(PodDBAdapter.KEY_DESCRIPTION)));
feed.setPaymentLink(feedlistCursor.getString(feedlistCursor
.getColumnIndex(PodDBAdapter.KEY_PAYMENT_LINK)));
feed.setImage(adapter.getFeedImage(feedlistCursor
.getLong(feedlistCursor
.getColumnIndex(PodDBAdapter.KEY_IMAGE))));
@ -438,6 +441,8 @@ public class FeedManager {
.getColumnIndex(PodDBAdapter.KEY_CONTENT_ENCODED)));
item.setPubDate(new Date(itemlistCursor.getLong(itemlistCursor
.getColumnIndex(PodDBAdapter.KEY_PUBDATE))));
item.setPaymentLink(itemlistCursor.getString(itemlistCursor
.getColumnIndex(PodDBAdapter.KEY_PAYMENT_LINK)));
long mediaId = itemlistCursor.getLong(itemlistCursor
.getColumnIndex(PodDBAdapter.KEY_MEDIA));
if (mediaId != 0) {
@ -505,13 +510,13 @@ public class FeedManager {
.getColumnIndex(PodDBAdapter.KEY_FEED)));
if (feed != null) {
FeedItem item = getFeedItem(
cursor.getColumnIndex(PodDBAdapter.KEY_FEEDITEM), feed);
cursor.getColumnIndex(PodDBAdapter.KEY_FEEDITEM),
feed);
if (item != null) {
queue.add(index, item);
}
}
} while (cursor.moveToNext());
}
cursor.close();

View File

@ -143,7 +143,7 @@ public class FeedlistFragment extends SherlockListFragment {
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
return FeedMenuHandler.onPrepareOptionsMenu(menu, selectedFeed);
}
@Override

View File

@ -52,6 +52,7 @@ public class PodDBAdapter {
public static final String KEY_COMPLETION_DATE = "completion_date";
public static final String KEY_FEEDITEM = "feeditem";
public static final String KEY_CONTENT_ENCODED = "content_encoded";
public static final String KEY_PAYMENT_LINK = "payment_link";
// Table names
public static final String TABLE_NAME_FEEDS = "Feeds";
@ -70,14 +71,16 @@ public class PodDBAdapter {
+ " TEXT," + KEY_LINK + " TEXT," + KEY_DESCRIPTION + " TEXT,"
+ KEY_IMAGE + " INTEGER," + KEY_CATEGORY + " INTEGER,"
+ KEY_FILE_URL + " TEXT," + KEY_DOWNLOAD_URL + " TEXT,"
+ KEY_DOWNLOADED + " INTEGER," + KEY_LASTUPDATE + " TEXT)";
+ KEY_DOWNLOADED + " INTEGER," + KEY_LASTUPDATE + " TEXT,"
+ KEY_PAYMENT_LINK + " TEXT)";
private static final String CREATE_TABLE_FEED_ITEMS = "CREATE TABLE "
+ TABLE_NAME_FEED_ITEMS + " (" + TABLE_PRIMARY_KEY + KEY_TITLE
+ " TEXT," + KEY_LINK + " TEXT," + KEY_DESCRIPTION + " TEXT,"
+ KEY_CONTENT_ENCODED + " TEXT,"
+ KEY_PUBDATE + " INTEGER," + KEY_MEDIA + " INTEGER," + KEY_FEED
+ " INTEGER," + KEY_READ + " INTEGER)";
+ " INTEGER," + KEY_READ + " INTEGER,"
+ KEY_PAYMENT_LINK + " TEXT)";
private static final String CREATE_TABLE_FEED_CATEGORIES = "CREATE TABLE "
+ TABLE_NAME_FEED_CATEGORIES + " (" + TABLE_PRIMARY_KEY + KEY_NAME
@ -150,6 +153,7 @@ public class PodDBAdapter {
values.put(KEY_TITLE, feed.getTitle());
values.put(KEY_LINK, feed.getLink());
values.put(KEY_DESCRIPTION, feed.getDescription());
values.put(KEY_PAYMENT_LINK, feed.getPaymentLink());
if (feed.getImage() != null) {
if (feed.getImage().getId() == 0) {
setImage(feed.getImage());
@ -259,6 +263,7 @@ public class PodDBAdapter {
values.put(KEY_DESCRIPTION, item.getDescription());
values.put(KEY_CONTENT_ENCODED, item.getContentEncoded());
values.put(KEY_PUBDATE, item.getPubDate().getTime());
values.put(KEY_PAYMENT_LINK, item.getPaymentLink());
if (item.getMedia() != null) {
if (item.getMedia().getId() == 0) {
setMedia(item.getMedia());

View File

@ -2,6 +2,8 @@ package de.podfetcher.syndication.namespace.atom;
import org.xml.sax.Attributes;
import android.util.Log;
import de.podfetcher.feed.Feed;
import de.podfetcher.feed.FeedImage;
import de.podfetcher.feed.FeedItem;
@ -9,9 +11,11 @@ import de.podfetcher.feed.FeedMedia;
import de.podfetcher.syndication.handler.HandlerState;
import de.podfetcher.syndication.namespace.Namespace;
import de.podfetcher.syndication.namespace.SyndElement;
import de.podfetcher.syndication.namespace.rss20.NSRSS20;
import de.podfetcher.syndication.util.SyndDateUtils;
public class NSAtom extends Namespace {
private static final String TAG = "NSAtom";
public static final String NSTAG = "atom";
public static final String NSURI = "http://www.w3.org/2005/Atom";
@ -36,6 +40,7 @@ public class NSAtom extends Namespace {
// rel-values
private static final String LINK_REL_ALTERNATE = "alternate";
private static final String LINK_REL_ENCLOSURE = "enclosure";
private static final String LINK_REL_PAYMENT = "payment";
private static final String LINK_REL_RELATED = "related";
private static final String LINK_REL_SELF = "self";
@ -43,6 +48,9 @@ public class NSAtom extends Namespace {
private static final String isText = TITLE + "|" + CONTENT + "|" + "|"
+ SUBTITLE;
public static final String isFeed = FEED + "|" + NSRSS20.CHANNEL;
public static final String isFeedItem = ENTRY + "|" + NSRSS20.ITEM;
@Override
public SyndElement handleElementStart(String localName, HandlerState state,
Attributes attributes) {
@ -57,7 +65,7 @@ public class NSAtom extends Namespace {
String href = attributes.getValue(LINK_HREF);
String rel = attributes.getValue(LINK_REL);
SyndElement parent = state.getTagstack().peek();
if (parent.getName().equals(ENTRY)) {
if (parent.getName().matches(isFeedItem)) {
if (rel == null || rel.equals(LINK_REL_ALTERNATE)) {
state.getCurrentItem().setLink(href);
} else if (rel.equals(LINK_REL_ENCLOSURE)) {
@ -71,10 +79,16 @@ public class NSAtom extends Namespace {
state.getCurrentItem().setMedia(
new FeedMedia(state.getCurrentItem(), download_url,
size, type));
} else if (rel.equals(LINK_REL_PAYMENT)) {
Log.d(TAG, "Found payment item link");
state.getCurrentItem().setPaymentLink(href);
}
} else if (parent.getName().equals(FEED)) {
} else if (parent.getName().matches(isFeed)) {
if (rel == null || rel.equals(LINK_REL_ALTERNATE)) {
state.getFeed().setLink(href);
} else if (rel.equals(LINK_REL_PAYMENT)) {
Log.d(TAG, "Found payment link");
state.getFeed().setPaymentLink(href);
}
}
}

View File

@ -49,7 +49,11 @@ public class FeedItemMenuHandler {
if (selectedItem.getLink() != null) {
menu.findItem(R.id.visit_website_item).setVisible(true);
}
if (selectedItem.getPaymentLink() != null) {
menu.findItem(R.id.support_item).setVisible(true);
}
return true;
}
@ -92,6 +96,10 @@ public class FeedItemMenuHandler {
Uri uri = Uri.parse(selectedItem.getLink());
context.startActivity(new Intent(Intent.ACTION_VIEW, uri));
break;
case R.id.support_item:
Uri supportUri = Uri.parse(selectedItem.getPaymentLink());
context.startActivity(new Intent(Intent.ACTION_VIEW, supportUri));
break;
default:
return false;
}

View File

@ -22,7 +22,10 @@ public class FeedMenuHandler {
return true;
}
public static boolean onPrepareOptionsMenu(Menu menu) {
public static boolean onPrepareOptionsMenu(Menu menu, Feed selectedFeed) {
if (selectedFeed.getPaymentLink() != null) {
menu.findItem(R.id.support_item).setVisible(true);
}
return true;
}
@ -38,6 +41,10 @@ public class FeedMenuHandler {
Uri uri = Uri.parse(selectedFeed.getLink());
context.startActivity(new Intent(Intent.ACTION_VIEW, uri));
break;
case R.id.support_item:
Uri supportUri = Uri.parse(selectedFeed.getPaymentLink());
context.startActivity(new Intent(Intent.ACTION_VIEW, supportUri));
break;
default:
return false;
}