summaryrefslogtreecommitdiff
path: root/src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java')
-rw-r--r--src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java55
1 files changed, 50 insertions, 5 deletions
diff --git a/src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java b/src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java
index 3af4bee7c..4a70a558a 100644
--- a/src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java
+++ b/src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java
@@ -1,6 +1,8 @@
package de.danoeh.antennapod.activity;
import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.os.Bundle;
@@ -12,7 +14,9 @@ import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
+import de.danoeh.antennapod.dialog.AuthenticationDialog;
import de.danoeh.antennapod.feed.Feed;
+import de.danoeh.antennapod.feed.FeedPreferences;
import de.danoeh.antennapod.preferences.UserPreferences;
import de.danoeh.antennapod.service.download.DownloadRequest;
import de.danoeh.antennapod.service.download.DownloadStatus;
@@ -52,9 +56,9 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity {
private Downloader downloader;
@Override
- protected void onCreate(Bundle arg0) {
+ protected void onCreate(Bundle savedInstanceState) {
setTheme(UserPreferences.getTheme());
- super.onCreate(arg0);
+ super.onCreate(savedInstanceState);
if (getIntent() != null && getIntent().hasExtra(ARG_TITLE)) {
getSupportActionBar().setTitle(getIntent().getStringExtra(ARG_TITLE));
@@ -69,7 +73,20 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity {
if (AppConfig.DEBUG)
Log.d(TAG, "Activity was started with url " + feedUrl);
setLoadingLayout();
- startFeedDownload(feedUrl);
+ if (savedInstanceState == null) {
+ startFeedDownload(feedUrl, null, null);
+ } else {
+ startFeedDownload(feedUrl, savedInstanceState.getString("username"), savedInstanceState.getString("password"));
+ }
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ if (feed != null && feed.getPreferences() != null) {
+ outState.putString("username", feed.getPreferences().getUsername());
+ outState.putString("password", feed.getPreferences().getPassword());
+ }
}
@Override
@@ -92,6 +109,10 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity {
if (!status.isCancelled()) {
if (status.isSuccessful()) {
parseFeed();
+ } else if (status.getReason() == DownloadError.ERROR_UNAUTHORIZED) {
+ Dialog dialog = new FeedViewAuthenticationDialog(OnlineFeedViewActivity.this,
+ R.string.authentication_notification_title, downloader.getDownloadRequest().getSource());
+ dialog.show();
} else {
String errorMsg = status.getReason().getErrorString(
OnlineFeedViewActivity.this);
@@ -113,17 +134,20 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity {
}
- private void startFeedDownload(String url) {
+ private void startFeedDownload(String url, String username, String password) {
if (AppConfig.DEBUG)
Log.d(TAG, "Starting feed download");
url = URLChecker.prepareURL(url);
feed = new Feed(url, new Date());
+ if (username != null && password != null) {
+ feed.setPreferences(new FeedPreferences(0, true, username, password));
+ }
String fileUrl = new File(getExternalCacheDir(),
FileNameGenerator.generateFileName(feed.getDownload_url()))
.toString();
feed.setFile_url(fileUrl);
final DownloadRequest request = new DownloadRequest(feed.getFile_url(),
- feed.getDownload_url(), "OnlineFeed", 0, Feed.FEEDFILETYPE_FEED);
+ feed.getDownload_url(), "OnlineFeed", 0, Feed.FEEDFILETYPE_FEED, username, password);
downloader = new HttpDownloader(
request);
new Thread() {
@@ -259,4 +283,25 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity {
builder.show();
}
+ private class FeedViewAuthenticationDialog extends AuthenticationDialog {
+
+ private String feedUrl;
+
+ public FeedViewAuthenticationDialog(Context context, int titleRes, String feedUrl) {
+ super(context, titleRes, true, false, null, null);
+ this.feedUrl = feedUrl;
+ }
+
+ @Override
+ protected void onCancelled() {
+ super.onCancelled();
+ finish();
+ }
+
+ @Override
+ protected void onConfirmed(String username, String password, boolean saveUsernamePassword) {
+ startFeedDownload(feedUrl, username, password);
+ }
+ }
+
}