diff options
author | Daniel Oeh <daniel@danielpc.(none)> | 2012-05-28 13:22:23 +0200 |
---|---|---|
committer | Daniel Oeh <daniel@danielpc.(none)> | 2012-05-28 13:22:23 +0200 |
commit | 0cecd8255082ef32908dc9b1440b15218aca3e66 (patch) | |
tree | 7cdd0ef24ddf44b50ff53da21f4c021dd048ab9e /src/de/podfetcher/activity | |
parent | 4caa46e03f16a3dcbc8e8fe383c4d64ed533980a (diff) | |
download | AntennaPod-0cecd8255082ef32908dc9b1440b15218aca3e66.zip |
Implemented FeedMedia Download
Diffstat (limited to 'src/de/podfetcher/activity')
-rw-r--r-- | src/de/podfetcher/activity/ItemviewActivity.java | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/de/podfetcher/activity/ItemviewActivity.java b/src/de/podfetcher/activity/ItemviewActivity.java index c2d1a5564..b3c42397b 100644 --- a/src/de/podfetcher/activity/ItemviewActivity.java +++ b/src/de/podfetcher/activity/ItemviewActivity.java @@ -1,6 +1,7 @@ package de.podfetcher.activity; import java.io.File; +import java.util.concurrent.Callable; import android.net.Uri; import android.graphics.BitmapFactory; import com.actionbarsherlock.app.SherlockActivity; @@ -10,16 +11,20 @@ import android.os.Bundle; import de.podfetcher.feed.*; import android.util.Log; import android.content.Intent; +import android.content.Context; import android.widget.Button; import android.widget.TextView; import android.widget.ImageView; import de.podfetcher.R; +import de.podfetcher.service.DownloadObserver; +import de.podfetcher.storage.DownloadRequester; /** Displays a single FeedItem and provides various actions */ public class ItemviewActivity extends SherlockActivity { private static final String TAG = "ItemviewActivity"; private FeedManager manager; + private DownloadRequester requester; private FeedItem item; // Widgets @@ -36,6 +41,16 @@ public class ItemviewActivity extends SherlockActivity { manager = FeedManager.getInstance(); extractFeeditem(); populateUI(); + getDownloadStatus(); + + butDownload.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + requester = DownloadRequester.getInstance(); + requester.downloadMedia(v.getContext(), item.getMedia()); + getDownloadStatus(); + } + }); } /** Extracts FeedItem object the activity is supposed to display */ @@ -68,6 +83,41 @@ public class ItemviewActivity extends SherlockActivity { imgvImage.setImageBitmap(item.getFeed().getImage().getImageBitmap()); } } + + private void getDownloadStatus() { + if(item.getMedia().getFile_url() == null) { + butPlay.setEnabled(false); + butDownload.setEnabled(true); + butRemove.setEnabled(false); + } else { + final DownloadObserver observer = new DownloadObserver( + item.getMedia().getDownloadId(), this); + + final Callable client = new Callable() { + public Object call() { + runOnUiThread(new Runnable() { + public void run() { + if(observer.getDone() && + // Download successful + observer.getResult() == R.string.download_successful) { + butDownload.setEnabled(false); + butPlay.setEnabled(true); + butRemove.setEnabled(true); + } else { + // Download running + butDownload.setEnabled(false); + butPlay.setEnabled(false); + butRemove.setEnabled(false); + } + } + }); + return null; + } + }; + observer.setClient(client); + observer.start(); + } + } } |