summaryrefslogtreecommitdiff
path: root/src/de/danoeh
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2012-08-04 13:26:02 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2012-08-04 13:26:02 +0200
commitb91a04fc8c7289e7586a9f02ddcc81c23bb8f2de (patch)
tree2f1244049c043c407f0f22e664e3bec7eb602ad5 /src/de/danoeh
parentb712ffee8f5d42c8bf9c27a9f8a10688d4afd07b (diff)
downloadAntennaPod-b91a04fc8c7289e7586a9f02ddcc81c23bb8f2de.zip
Created Activity for displaying information about a channel
Diffstat (limited to 'src/de/danoeh')
-rw-r--r--src/de/danoeh/antennapod/activity/MiroGuideChannelViewActivity.java149
-rw-r--r--src/de/danoeh/antennapod/adapter/MiroGuideItemlistAdapter.java60
-rw-r--r--src/de/danoeh/antennapod/feed/FeedManager.java10
-rw-r--r--src/de/danoeh/antennapod/fragment/MiroGuideChannellistFragment.java18
-rw-r--r--src/de/danoeh/antennapod/storage/DownloadRequester.java10
5 files changed, 247 insertions, 0 deletions
diff --git a/src/de/danoeh/antennapod/activity/MiroGuideChannelViewActivity.java b/src/de/danoeh/antennapod/activity/MiroGuideChannelViewActivity.java
new file mode 100644
index 000000000..102dd92ca
--- /dev/null
+++ b/src/de/danoeh/antennapod/activity/MiroGuideChannelViewActivity.java
@@ -0,0 +1,149 @@
+package de.danoeh.antennapod.activity;
+
+import android.annotation.SuppressLint;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+import android.widget.ProgressBar;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+
+import com.actionbarsherlock.app.SherlockActivity;
+import com.actionbarsherlock.view.Menu;
+import com.actionbarsherlock.view.MenuInflater;
+import com.actionbarsherlock.view.MenuItem;
+
+import de.danoeh.antennapod.AppConfig;
+import de.danoeh.antennapod.R;
+import de.danoeh.antennapod.adapter.MiroGuideItemlistAdapter;
+import de.danoeh.antennapod.feed.FeedManager;
+import de.danoeh.antennapod.miroguide.con.MiroGuideException;
+import de.danoeh.antennapod.miroguide.con.MiroGuideService;
+import de.danoeh.antennapod.miroguide.model.MiroChannel;
+import de.danoeh.antennapod.miroguide.model.MiroItem;
+import de.danoeh.antennapod.storage.DownloadRequester;
+
+public class MiroGuideChannelViewActivity extends SherlockActivity {
+ private static final String TAG = "MiroGuideChannelViewActivity";
+
+ public static final String EXTRA_CHANNEL_ID = "id";
+ public static final String EXTRA_CHANNEL_URL = "url";
+
+ private RelativeLayout layoutContent;
+ private ProgressBar progLoading;
+ private TextView txtvTitle;
+ private TextView txtVDescription;
+ private ListView listEntries;
+
+ private long channelId;
+ private String channelUrl;
+ private MiroChannel channel;
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ channelLoader.cancel(true);
+ }
+
+ @SuppressLint("NewApi")
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ setContentView(R.layout.miroguide_channelview);
+
+ layoutContent = (RelativeLayout) findViewById(R.id.layout_content);
+ progLoading = (ProgressBar) findViewById(R.id.progLoading);
+ txtvTitle = (TextView) findViewById(R.id.txtvTitle);
+ txtVDescription = (TextView) findViewById(R.id.txtvDescription);
+ listEntries = (ListView) findViewById(R.id.itemlist);
+
+ channelId = getIntent().getLongExtra(EXTRA_CHANNEL_ID, -1);
+ channelUrl = getIntent().getStringExtra(EXTRA_CHANNEL_URL);
+
+ if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
+ channelLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+ } else {
+ channelLoader.execute();
+ }
+
+ }
+
+ private AsyncTask<Void, Void, Void> channelLoader = new AsyncTask<Void, Void, Void>() {
+ private static final String TAG = "ChannelLoader";
+ private Exception exception;
+
+ @Override
+ protected Void doInBackground(Void... params) {
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Starting background task");
+ MiroGuideService service = new MiroGuideService();
+ try {
+ channel = service.getChannel(channelId);
+ } catch (MiroGuideException e) {
+ e.printStackTrace();
+ exception = e;
+ }
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void result) {
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Loading finished");
+ if (exception == null) {
+ txtvTitle.setText(channel.getName());
+ txtVDescription.setText(channel.getDescription());
+ String[] entryNames = new String[channel.getItems().size()];
+ for (int i = 0; i < channel.getItems().size(); i++) {
+ entryNames[i] = channel.getItems().get(i).getName();
+ }
+ MiroGuideItemlistAdapter listAdapter = new MiroGuideItemlistAdapter(
+ MiroGuideChannelViewActivity.this, 0,
+ channel.getItems());
+ listEntries.setAdapter(listAdapter);
+ progLoading.setVisibility(View.GONE);
+ layoutContent.setVisibility(View.VISIBLE);
+ invalidateOptionsMenu();
+ } else {
+ finish();
+ }
+ }
+
+ };
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuInflater inflater = new MenuInflater(this);
+ inflater.inflate(R.menu.channelview, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onPrepareOptionsMenu(Menu menu) {
+ boolean channelLoaded = channel != null;
+ boolean notAdded = channelLoaded
+ && !((FeedManager.getInstance().feedExists(channel
+ .getDownloadUrl())) || (DownloadRequester.getInstance()
+ .isDownloadingFile(channel.getDownloadUrl())));
+ menu.findItem(R.id.add_feed).setVisible(notAdded);
+ menu.findItem(R.id.visit_website_item).setVisible(
+ channelLoaded && channel.getWebsiteUrl() != null);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ finish();
+ return true;
+ default:
+ return false;
+ }
+ }
+
+}
diff --git a/src/de/danoeh/antennapod/adapter/MiroGuideItemlistAdapter.java b/src/de/danoeh/antennapod/adapter/MiroGuideItemlistAdapter.java
new file mode 100644
index 000000000..d0d3d43a9
--- /dev/null
+++ b/src/de/danoeh/antennapod/adapter/MiroGuideItemlistAdapter.java
@@ -0,0 +1,60 @@
+package de.danoeh.antennapod.adapter;
+
+import java.text.DateFormat;
+import java.util.List;
+
+import android.content.Context;
+import android.text.format.DateUtils;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.TextView;
+import de.danoeh.antennapod.R;
+import de.danoeh.antennapod.miroguide.model.MiroItem;
+
+public class MiroGuideItemlistAdapter extends ArrayAdapter<MiroItem> {
+
+ public MiroGuideItemlistAdapter(Context context, int textViewResourceId,
+ List<MiroItem> objects) {
+ super(context, textViewResourceId, objects);
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ Holder holder;
+ MiroItem item = getItem(position);
+
+ // Inflate Layout
+ if (convertView == null) {
+ holder = new Holder();
+ LayoutInflater inflater = (LayoutInflater) getContext()
+ .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+
+ convertView = inflater.inflate(R.layout.miroguide_itemlist_item,
+ null);
+ holder.title = (TextView) convertView.findViewById(R.id.txtvTitle);
+ holder.date = (TextView) convertView.findViewById(R.id.txtvDate);
+ convertView.setTag(holder);
+ } else {
+ holder = (Holder) convertView.getTag();
+ }
+
+ holder.title.setText(item.getName());
+ if (item.getDate() != null) {
+ holder.date.setText(DateUtils.formatSameDayTime(item.getDate()
+ .getTime(), System.currentTimeMillis(), DateFormat.SHORT,
+ DateFormat.SHORT));
+ holder.date.setVisibility(View.VISIBLE);
+ } else {
+ holder.date.setVisibility(View.GONE);
+ }
+ return convertView;
+ }
+
+ static class Holder {
+ TextView title;
+ TextView date;
+ }
+
+}
diff --git a/src/de/danoeh/antennapod/feed/FeedManager.java b/src/de/danoeh/antennapod/feed/FeedManager.java
index 5c7041a8d..853890308 100644
--- a/src/de/danoeh/antennapod/feed/FeedManager.java
+++ b/src/de/danoeh/antennapod/feed/FeedManager.java
@@ -448,6 +448,16 @@ public class FeedManager {
}
return null;
}
+
+ /** Returns true if a feed with the given download link is already in the feedlist. */
+ public boolean feedExists(String downloadUrl) {
+ for (Feed feed : feeds) {
+ if (feed.getDownload_url().equals(downloadUrl)) {
+ return true;
+ }
+ }
+ return false;
+ }
/** Get a FeedItem by its identifying value. */
private FeedItem searchFeedItemByIdentifyingValue(Feed feed,
diff --git a/src/de/danoeh/antennapod/fragment/MiroGuideChannellistFragment.java b/src/de/danoeh/antennapod/fragment/MiroGuideChannellistFragment.java
index 76ecb1aa1..bb9643829 100644
--- a/src/de/danoeh/antennapod/fragment/MiroGuideChannellistFragment.java
+++ b/src/de/danoeh/antennapod/fragment/MiroGuideChannellistFragment.java
@@ -7,6 +7,7 @@ import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
@@ -14,11 +15,13 @@ import android.view.LayoutInflater;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
+import android.widget.ListView;
import com.actionbarsherlock.app.SherlockListFragment;
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
+import de.danoeh.antennapod.activity.MiroGuideChannelViewActivity;
import de.danoeh.antennapod.adapter.MiroGuideChannelListAdapter;
import de.danoeh.antennapod.asynctask.FeedImageLoader;
import de.danoeh.antennapod.miroguide.con.MiroGuideException;
@@ -153,6 +156,21 @@ public class MiroGuideChannellistFragment extends SherlockListFragment {
});
}
+ @Override
+ public void onListItemClick(ListView l, View v, int position, long id) {
+ super.onListItemClick(l, v, position, id);
+ if (listAdapter != null) {
+ MiroChannel selection = listAdapter.getItem(position);
+ Intent launchIntent = new Intent(getActivity(),
+ MiroGuideChannelViewActivity.class);
+ launchIntent.putExtra(MiroGuideChannelViewActivity.EXTRA_CHANNEL_ID,
+ selection.getId());
+ launchIntent.putExtra(MiroGuideChannelViewActivity.EXTRA_CHANNEL_URL,
+ selection.getDownloadUrl());
+ startActivity(launchIntent);
+ }
+ }
+
@SuppressLint("NewApi")
private void loadChannels() {
if (!isLoadingChannels) {
diff --git a/src/de/danoeh/antennapod/storage/DownloadRequester.java b/src/de/danoeh/antennapod/storage/DownloadRequester.java
index 90c481ebb..90891e6a5 100644
--- a/src/de/danoeh/antennapod/storage/DownloadRequester.java
+++ b/src/de/danoeh/antennapod/storage/DownloadRequester.java
@@ -180,6 +180,16 @@ public class DownloadRequester {// TODO handle externalstorage missing
}
return false;
}
+
+ /** Checks if feedfile with the given download url is in the downloads list */
+ public boolean isDownloadingFile(String downloadUrl) {
+ for (FeedFile f : downloads) {
+ if (f.getDownload_url().equals(downloadUrl)) {
+ return true;
+ }
+ }
+ return false;
+ }
public boolean hasNoDownloads() {
return downloads.isEmpty();