summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2014-04-27 01:42:48 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2014-04-27 01:42:48 +0200
commitc881b7982c41a3d668ad1e651352029d9e378126 (patch)
treef3b66c1c45779dfe0d77476d2244c057e16a3ad5
parenta0ef9f5a8798e59b5ec40508bc990424d0013ebe (diff)
downloadAntennaPod-c881b7982c41a3d668ad1e651352029d9e378126.zip
Allow modification of feed username and password, propagate credentials to episodes. fixes #395
-rw-r--r--res/layout/feedinfo.xml68
-rw-r--r--res/values/strings.xml4
-rw-r--r--src/de/danoeh/antennapod/activity/FeedInfoActivity.java52
-rw-r--r--src/de/danoeh/antennapod/storage/DBWriter.java1
-rw-r--r--src/de/danoeh/antennapod/storage/DownloadRequester.java12
5 files changed, 132 insertions, 5 deletions
diff --git a/res/layout/feedinfo.xml b/res/layout/feedinfo.xml
index d975ef549..90f213e11 100644
--- a/res/layout/feedinfo.xml
+++ b/res/layout/feedinfo.xml
@@ -6,6 +6,8 @@
<RelativeLayout
android:id="@+id/header"
+ android:focusable="true"
+ android:focusableInTouchMode="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
@@ -119,6 +121,72 @@
android:textColor="?android:attr/textColorPrimary"/>
<TextView
+ android:id="@+id/txtvAuthentication"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_margin="8dp"
+ android:text="@string/authentication_label"
+ android:textSize="@dimen/text_size_medium"
+ android:textColor="?android:attr/textColorPrimary"
+ android:layout_marginLeft="8dp"
+ android:layout_marginBottom="8dp"
+ android:layout_marginTop="24dp"/>
+
+ <TextView
+ android:id="@+id/txtvAuthenticationDescr"
+ android:text="@string/authentication_descr"
+ android:textSize="@dimen/text_size_small"
+ android:textColor="?android:attr/textColorPrimary"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_margin="8dp"/>
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_margin="8dp">
+
+ <TextView
+ android:id="@+id/txtvUsername"
+ android:layout_width="0dp"
+ android:layout_weight="1"
+ android:layout_height="wrap_content"
+ android:layout_margin="8dp"
+ android:text="@string/username_label"
+ android:textColor="?android:attr/textColorPrimary"/>
+
+ <EditText
+ android:id="@+id/etxtUsername"
+ android:layout_width="0dp"
+ android:layout_weight="2"
+ android:layout_height="wrap_content"
+ android:hint="@string/username_label"/>
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_margin="8dp">
+
+ <TextView
+ android:id="@+id/txtvPassword"
+ android:layout_width="0dp"
+ android:layout_weight="1"
+ android:layout_height="wrap_content"
+ android:layout_margin="8dp"
+ android:text="@string/password_label"
+ android:textColor="?android:attr/textColorPrimary"/>
+
+ <EditText
+ android:id="@+id/etxtPassword"
+ android:layout_width="0dp"
+ android:layout_weight="2"
+ android:layout_height="wrap_content"
+ android:hint="@string/password_label"
+ android:inputType="textPassword"/>
+ </LinearLayout>
+
+ <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 7784c49f6..2eaf611f2 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -357,6 +357,10 @@
<string name="new_episodes_count_label">Number of new episodes</string>
<string name="in_progress_episodes_count_label">Number of episodes you have started listening to</string>
+ <!-- Feed information screen -->
+ <string name="authentication_label">Authentication</string>
+ <string name="authentication_descr">Change your username and password for this podcast and its episodes.</string>
+
<!-- OPML backup -->
<string name="backup_restored">"Restored feed subscriptions from backup"</string>
diff --git a/src/de/danoeh/antennapod/activity/FeedInfoActivity.java b/src/de/danoeh/antennapod/activity/FeedInfoActivity.java
index db0755ccd..f00ce13e8 100644
--- a/src/de/danoeh/antennapod/activity/FeedInfoActivity.java
+++ b/src/de/danoeh/antennapod/activity/FeedInfoActivity.java
@@ -3,21 +3,22 @@ package de.danoeh.antennapod.activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
+import android.text.Editable;
+import android.text.TextWatcher;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
-import android.widget.CheckBox;
-import android.widget.CompoundButton;
-import android.widget.ImageView;
-import android.widget.TextView;
+import android.widget.*;
import de.danoeh.antennapod.BuildConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.asynctask.ImageLoader;
import de.danoeh.antennapod.dialog.DownloadRequestErrorDialogCreator;
import de.danoeh.antennapod.feed.Feed;
+import de.danoeh.antennapod.feed.FeedPreferences;
import de.danoeh.antennapod.preferences.UserPreferences;
import de.danoeh.antennapod.storage.DBReader;
+import de.danoeh.antennapod.storage.DBWriter;
import de.danoeh.antennapod.storage.DownloadRequestException;
import de.danoeh.antennapod.util.LangUtils;
import de.danoeh.antennapod.util.menuhandler.FeedMenuHandler;
@@ -37,6 +38,8 @@ public class FeedInfoActivity extends ActionBarActivity {
private TextView txtvDescription;
private TextView txtvLanguage;
private TextView txtvAuthor;
+ private EditText etxtUsername;
+ private EditText etxtPassword;
private CheckBox cbxAutoDownload;
@Override
@@ -53,6 +56,8 @@ public class FeedInfoActivity extends ActionBarActivity {
txtvLanguage = (TextView) findViewById(R.id.txtvLanguage);
txtvAuthor = (TextView) findViewById(R.id.txtvAuthor);
cbxAutoDownload = (CheckBox) findViewById(R.id.cbxAutoDownload);
+ etxtUsername = (EditText) findViewById(R.id.etxtUsername);
+ etxtPassword = (EditText) findViewById(R.id.etxtPassword);
AsyncTask<Long, Void, Feed> loadTask = new AsyncTask<Long, Void, Feed>() {
@@ -98,6 +103,12 @@ public class FeedInfoActivity extends ActionBarActivity {
}
});
+ etxtUsername.setText(feed.getPreferences().getUsername());
+ etxtPassword.setText(feed.getPreferences().getPassword());
+
+ etxtUsername.addTextChangedListener(authTextWatcher);
+ etxtPassword.addTextChangedListener(authTextWatcher);
+
supportInvalidateOptionsMenu();
} else {
@@ -108,6 +119,39 @@ public class FeedInfoActivity extends ActionBarActivity {
loadTask.execute(feedId);
}
+
+ private boolean authInfoChanged = false;
+
+ private TextWatcher authTextWatcher = new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ authInfoChanged = true;
+ }
+ };
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ if (feed != null && authInfoChanged) {
+ Log.d(TAG, "Auth info changed, saving credentials");
+ FeedPreferences prefs = feed.getPreferences();
+ prefs.setUsername(etxtUsername.getText().toString());
+ prefs.setPassword(etxtPassword.getText().toString());
+ DBWriter.setFeedPreferences(this, prefs);
+ authInfoChanged = false;
+ }
+ }
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
diff --git a/src/de/danoeh/antennapod/storage/DBWriter.java b/src/de/danoeh/antennapod/storage/DBWriter.java
index f2586cdcb..248594a79 100644
--- a/src/de/danoeh/antennapod/storage/DBWriter.java
+++ b/src/de/danoeh/antennapod/storage/DBWriter.java
@@ -837,6 +837,7 @@ public class DBWriter {
adapter.open();
adapter.setFeedPreferences(preferences);
adapter.close();
+ EventDistributor.getInstance().sendFeedUpdateBroadcast();
}
});
}
diff --git a/src/de/danoeh/antennapod/storage/DownloadRequester.java b/src/de/danoeh/antennapod/storage/DownloadRequester.java
index 0a1747253..34d0ebe9a 100644
--- a/src/de/danoeh/antennapod/storage/DownloadRequester.java
+++ b/src/de/danoeh/antennapod/storage/DownloadRequester.java
@@ -164,9 +164,19 @@ public class DownloadRequester {
public void downloadMedia(Context context, FeedMedia feedmedia)
throws DownloadRequestException {
if (feedFileValid(feedmedia)) {
+ Feed feed = feedmedia.getItem().getFeed();
+ String username;
+ String password;
+ if (feed != null && feed.getPreferences() != null) {
+ username = feed.getPreferences().getUsername();
+ password = feed.getPreferences().getPassword();
+ } else {
+ username = null;
+ password = null;
+ }
download(context, feedmedia,
new File(getMediafilePath(context, feedmedia),
- getMediafilename(feedmedia)), false, null, null
+ getMediafilename(feedmedia)), false, username, password
);
}
}