summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2013-08-31 14:26:54 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2013-08-31 14:26:54 +0200
commita60ff4dd36de07abf6b640caf7e0723817162286 (patch)
tree34e1da7c94e2bd45de01af1b270024641bca0210 /src
parent864a6b476b803294a89facabdb4014efb9444642 (diff)
downloadAntennaPod-a60ff4dd36de07abf6b640caf7e0723817162286.zip
Added subscribe button to online feed view
Diffstat (limited to 'src')
-rw-r--r--src/de/danoeh/antennapod/activity/DefaultOnlineFeedViewActivity.java101
-rw-r--r--src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java8
2 files changed, 108 insertions, 1 deletions
diff --git a/src/de/danoeh/antennapod/activity/DefaultOnlineFeedViewActivity.java b/src/de/danoeh/antennapod/activity/DefaultOnlineFeedViewActivity.java
index c72c777c1..0aa4c55c5 100644
--- a/src/de/danoeh/antennapod/activity/DefaultOnlineFeedViewActivity.java
+++ b/src/de/danoeh/antennapod/activity/DefaultOnlineFeedViewActivity.java
@@ -1,26 +1,50 @@
package de.danoeh.antennapod.activity;
import android.content.Context;
+import android.os.AsyncTask;
import android.view.LayoutInflater;
import android.view.View;
+import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.adapter.FeedItemlistDescriptionAdapter;
import de.danoeh.antennapod.asynctask.ImageDiskCache;
+import de.danoeh.antennapod.dialog.DownloadRequestErrorDialogCreator;
+import de.danoeh.antennapod.feed.EventDistributor;
import de.danoeh.antennapod.feed.Feed;
+import de.danoeh.antennapod.storage.DBReader;
+import de.danoeh.antennapod.storage.DownloadRequestException;
+import de.danoeh.antennapod.storage.DownloadRequester;
+
+import java.util.Date;
+import java.util.List;
/**
* Created by daniel on 24.08.13.
*/
public class DefaultOnlineFeedViewActivity extends OnlineFeedViewActivity {
+ private static final int EVENTS = EventDistributor.DOWNLOAD_HANDLED | EventDistributor.DOWNLOAD_QUEUED | EventDistributor.FEED_LIST_UPDATE;
+ private volatile List<Feed> feeds;
+ private Feed feed;
+
+ private Button subscribeButton;
+
@Override
- protected void showFeedInformation(Feed feed) {
+ protected void loadData() {
+ super.loadData();
+ feeds = DBReader.getFeedList(this);
+ }
+
+ @Override
+ protected void showFeedInformation(final Feed feed) {
super.showFeedInformation(feed);
setContentView(R.layout.listview_activity);
+ this.feed = feed;
+ EventDistributor.getInstance().register(listener);
ListView listView = (ListView) findViewById(R.id.listview);
LayoutInflater inflater = (LayoutInflater)
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@@ -31,16 +55,91 @@ public class DefaultOnlineFeedViewActivity extends OnlineFeedViewActivity {
ImageView cover = (ImageView) header.findViewById(R.id.imgvCover);
TextView title = (TextView) header.findViewById(R.id.txtvTitle);
+ TextView author = (TextView) header.findViewById(R.id.txtvAuthor);
TextView description = (TextView) header.findViewById(R.id.txtvDescription);
+ subscribeButton = (Button) header.findViewById(R.id.butSubscribe);
if (feed.getImage() != null) {
ImageDiskCache.getDefaultInstance().loadThumbnailBitmap(feed.getImage().getDownload_url(), cover, (int) getResources().getDimension(
R.dimen.thumbnail_length));
}
title.setText(feed.getTitle());
+ author.setText(feed.getAuthor());
description.setText(feed.getDescription());
+ subscribeButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ try {
+ DownloadRequester.getInstance().downloadFeed(
+ DefaultOnlineFeedViewActivity.this,
+ new Feed(feed.getDownload_url(), new Date(), feed
+ .getTitle()));
+ } catch (DownloadRequestException e) {
+ e.printStackTrace();
+ DownloadRequestErrorDialogCreator.newRequestErrorDialog(DefaultOnlineFeedViewActivity.this,
+ e.getMessage());
+ }
+ setSubscribeButtonState(feed);
+ }
+ });
+ setSubscribeButtonState(feed);
+
+ }
+
+ private boolean feedInFeedlist(Feed feed) {
+ if (feeds == null || feed == null)
+ return false;
+ for (Feed f : feeds) {
+ if (f.getIdentifyingValue().equals(feed.getIdentifyingValue())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private void setSubscribeButtonState(Feed feed) {
+ if (subscribeButton != null && feed != null) {
+ if (DownloadRequester.getInstance().isDownloadingFile(feed.getDownload_url())) {
+ subscribeButton.setEnabled(false);
+ subscribeButton.setText(R.string.downloading_label);
+ } else if (feedInFeedlist(feed)) {
+ subscribeButton.setEnabled(false);
+ subscribeButton.setText(R.string.subscribed_label);
+ } else {
+ subscribeButton.setEnabled(true);
+ subscribeButton.setText(R.string.subscribe_label);
+ }
+ }
+ }
+ EventDistributor.EventListener listener = new EventDistributor.EventListener() {
+ @Override
+ public void update(EventDistributor eventDistributor, Integer arg) {
+ if ((arg & EventDistributor.FEED_LIST_UPDATE) != 0) {
+ new AsyncTask<Void, Void, List<Feed>>() {
+ @Override
+ protected List<Feed> doInBackground(Void... params) {
+ return DBReader.getFeedList(DefaultOnlineFeedViewActivity.this);
+ }
+
+ @Override
+ protected void onPostExecute(List<Feed> feeds) {
+ super.onPostExecute(feeds);
+ DefaultOnlineFeedViewActivity.this.feeds = feeds;
+ setSubscribeButtonState(feed);
+ }
+ }.execute();
+ } else if ((arg & EVENTS) != 0) {
+ setSubscribeButtonState(feed);
+ }
+ }
+ };
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ EventDistributor.getInstance().unregister(listener);
}
}
diff --git a/src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java b/src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java
index ff2e4987e..84aa2d26b 100644
--- a/src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java
+++ b/src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java
@@ -129,6 +129,7 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity {
new Thread() {
@Override
public void run() {
+ loadData();
downloader.call();
onDownloadCompleted(downloader);
}
@@ -219,6 +220,13 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity {
}
/**
+ * Can be used to load data asynchronously.
+ * */
+ protected void loadData() {
+
+ }
+
+ /**
* Called when feed parsed successfully
*/
protected void showFeedInformation(Feed feed) {