summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--res/layout-v14/authentication_dialog.xml81
-rw-r--r--res/layout/authentication_dialog.xml62
-rw-r--r--res/layout/gpodnetauth_credentials.xml4
-rw-r--r--res/values/strings.xml10
-rw-r--r--res/xml/preferences.xml4
-rw-r--r--src/de/danoeh/antennapod/activity/PreferenceActivity.java36
-rw-r--r--src/de/danoeh/antennapod/dialog/AuthenticationDialog.java89
7 files changed, 272 insertions, 14 deletions
diff --git a/res/layout-v14/authentication_dialog.xml b/res/layout-v14/authentication_dialog.xml
new file mode 100644
index 000000000..ed05dab1c
--- /dev/null
+++ b/res/layout-v14/authentication_dialog.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical" >
+
+ <EditText
+ android:id="@+id/etxtUsername"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1"
+ android:layout_margin="16dp"
+ android:hint="@string/username_label"/>
+
+ <EditText
+ android:id="@+id/etxtPassword"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1"
+ android:layout_margin="16dp"
+ android:inputType="textPassword"
+ android:hint="@string/password_label"/>
+
+ <CheckBox
+ android:id="@+id/chkSaveUsernamePassword"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_margin="16dp"
+ android:text="@string/save_username_password_label"/>
+ </LinearLayout>
+
+ <RelativeLayout
+ android:id="@+id/footer"
+ android:layout_width="fill_parent"
+ android:layout_height="48dp" >
+
+ <View
+ android:layout_width="match_parent"
+ android:layout_height="1dip"
+ android:layout_alignParentTop="true"
+ android:background="?android:attr/dividerVertical" />
+
+ <View
+ android:id="@+id/horizontal_divider"
+ android:layout_width="1dip"
+ android:layout_height="fill_parent"
+ android:layout_alignParentTop="true"
+ android:layout_centerHorizontal="true"
+ android:layout_marginBottom="4dp"
+ android:layout_marginTop="4dp"
+ android:background="?android:attr/dividerVertical" />
+
+ <Button
+ android:id="@+id/butCancel"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentTop="true"
+ android:layout_toLeftOf="@id/horizontal_divider"
+ android:background="?android:attr/selectableItemBackground"
+ android:text="@string/cancel_label" />
+
+ <Button
+ android:id="@+id/butConfirm"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentRight="true"
+ android:layout_alignParentTop="true"
+ android:layout_toRightOf="@id/horizontal_divider"
+ android:background="?android:attr/selectableItemBackground"
+ android:text="@string/confirm_label" />
+ </RelativeLayout>
+
+</LinearLayout> \ No newline at end of file
diff --git a/res/layout/authentication_dialog.xml b/res/layout/authentication_dialog.xml
new file mode 100644
index 000000000..82260eb43
--- /dev/null
+++ b/res/layout/authentication_dialog.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <EditText
+ android:id="@+id/etxtUsername"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1"
+ android:layout_margin="16dp"
+ android:hint="@string/username_label"/>
+
+ <EditText
+ android:id="@+id/etxtPassword"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1"
+ android:layout_margin="16dp"
+ android:inputType="textPassword"
+ android:hint="@string/password_label"/>
+
+ <CheckBox
+ android:id="@+id/chkSaveUsernamePassword"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_margin="16dp"
+ android:text="@string/save_username_password_label"/>
+
+
+ </LinearLayout>
+
+ <LinearLayout
+ style="@android:style/ButtonBar"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+
+ <Button
+ android:id="@+id/butConfirm"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_marginRight="8dp"
+ android:text="@string/confirm_label"
+ android:layout_weight="1"/>
+
+ <Button
+ android:id="@+id/butCancel"
+ android:text="@string/cancel_label"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"/>
+ </LinearLayout>
+
+</LinearLayout> \ No newline at end of file
diff --git a/res/layout/gpodnetauth_credentials.xml b/res/layout/gpodnetauth_credentials.xml
index 43268d291..8d32a5e2b 100644
--- a/res/layout/gpodnetauth_credentials.xml
+++ b/res/layout/gpodnetauth_credentials.xml
@@ -29,7 +29,7 @@
android:id="@+id/etxtUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:hint="@string/gpodnet_username_label"
+ android:hint="@string/username_label"
android:layout_below="@id/txtvDescription"
android:layout_margin="8dp"/>
@@ -37,7 +37,7 @@
android:id="@+id/etxtPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:hint="@string/gpodnet_password_label"
+ android:hint="@string/password_label"
android:layout_below="@id/etxtUsername"
android:inputType="textPassword"
android:layout_margin="8dp"/>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 2aa08296f..6f11049c4 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -49,6 +49,7 @@
<string name="processing_label">Processing</string>
<string name="loading_label">Loading...</string>
<string name="image_of_prefix">Image of:\u0020</string>
+ <string name="save_username_password_label">Save username and password</string>
<!-- 'Add Feed' Activity labels -->
<string name="feedurl_label">Feed URL</string>
@@ -197,7 +198,10 @@
<string name="pref_gpodnet_authenticate_sum">Login with your gpodder.net account in order to sync your subscriptions.</string>
<string name="pref_gpodnet_logout_title">Logout</string>
<string name="pref_gpodnet_logout_toast">Logout was successful</string>
-
+ <string name="pref_gpodnet_setlogin_information_title">Change login information</string>
+ <string name="pref_gpodnet_setlogin_information_sum">Change the login information for your gpodder.net account.</string>
+
+
<!-- Search -->
<string name="search_hint">Search for Feeds or Episodes</string>
@@ -253,8 +257,8 @@
<string name="gpodnetauth_login_descr">Welcome to the gpodder.net login process. First, type in your login information:</string>
<string name="gpodnetauth_login_butLabel">Login</string>
<string name="gpodnetauth_login_register">If you do not have an account yet, you can create one here:\nhttps://gpodder.net/register/</string>
- <string name="gpodnet_username_label">Username</string>
- <string name="gpodnet_password_label">Password</string>
+ <string name="username_label">Username</string>
+ <string name="password_label">Password</string>
<string name="gpodnetauth_device_title">Device Selection</string>
<string name="gpodnetauth_device_descr">Create a new device to use for your gpodder.net account or choose an existing one:</string>
<string name="gpodnetauth_device_deviceID">Device ID</string>
diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml
index ac3160028..53754178d 100644
--- a/res/xml/preferences.xml
+++ b/res/xml/preferences.xml
@@ -93,6 +93,10 @@
<intent android:action=".activity.gpoddernet.GpodnetAuthenticationActivity"/>
</PreferenceScreen>
<Preference
+ android:key="pref_gpodnet_setlogin_information"
+ android:title="@string/pref_gpodnet_setlogin_information_title"
+ android:summary="@string/pref_gpodnet_setlogin_information_sum"/>
+ <Preference
android:key="pref_gpodnet_logout"
android:title="@string/pref_gpodnet_logout_title"/>
</PreferenceScreen>
diff --git a/src/de/danoeh/antennapod/activity/PreferenceActivity.java b/src/de/danoeh/antennapod/activity/PreferenceActivity.java
index 411a10257..517e71158 100644
--- a/src/de/danoeh/antennapod/activity/PreferenceActivity.java
+++ b/src/de/danoeh/antennapod/activity/PreferenceActivity.java
@@ -1,10 +1,5 @@
package de.danoeh.antennapod.activity;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources.Theme;
@@ -18,7 +13,6 @@ import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceScreen;
import android.util.Log;
-
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
@@ -26,10 +20,16 @@ import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.asynctask.FlattrClickWorker;
import de.danoeh.antennapod.asynctask.OpmlExportWorker;
+import de.danoeh.antennapod.dialog.AuthenticationDialog;
import de.danoeh.antennapod.preferences.GpodnetPreferences;
import de.danoeh.antennapod.preferences.UserPreferences;
import de.danoeh.antennapod.util.flattr.FlattrUtils;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
/**
* The main preference activity
*/
@@ -44,6 +44,7 @@ public class PreferenceActivity extends android.preference.PreferenceActivity {
private static final String PREF_CHOOSE_DATA_DIR = "prefChooseDataDir";
private static final String AUTO_DL_PREF_SCREEN = "prefAutoDownloadSettings";
private static final String PREF_GPODNET_LOGIN = "pref_gpodnet_authenticate";
+ private static final String PREF_GPODNET_SETLOGIN_INFORMATION = "pref_gpodnet_setlogin_information";
private static final String PREF_GPODNET_LOGOUT = "pref_gpodnet_logout";
private CheckBoxPreference[] selectedNetworks;
@@ -58,9 +59,9 @@ public class PreferenceActivity extends android.preference.PreferenceActivity {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
- addPreferencesFromResource(R.xml.preferences);
- findPreference(PREF_FLATTR_THIS_APP).setOnPreferenceClickListener(
- new OnPreferenceClickListener() {
+ addPreferencesFromResource(R.xml.preferences);
+ findPreference(PREF_FLATTR_THIS_APP).setOnPreferenceClickListener(
+ new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
@@ -160,6 +161,22 @@ public class PreferenceActivity extends android.preference.PreferenceActivity {
return true;
}
});
+ findPreference(PREF_GPODNET_SETLOGIN_INFORMATION).setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ AuthenticationDialog dialog = new AuthenticationDialog(PreferenceActivity.this,
+ R.string.pref_gpodnet_setlogin_information_title, false, false, GpodnetPreferences.getUsername(),
+ null) {
+
+ @Override
+ protected void onConfirmed(String username, String password, boolean saveUsernamePassword) {
+ GpodnetPreferences.setPassword(password);
+ }
+ };
+ dialog.show();
+ return true;
+ }
+ });
findPreference(PREF_GPODNET_LOGOUT).setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
@@ -182,6 +199,7 @@ public class PreferenceActivity extends android.preference.PreferenceActivity {
private void updateGpodnetPreferenceScreen() {
final boolean loggedIn = GpodnetPreferences.loggedIn();
findPreference(PREF_GPODNET_LOGIN).setEnabled(!loggedIn);
+ findPreference(PREF_GPODNET_SETLOGIN_INFORMATION).setEnabled(loggedIn);
findPreference(PREF_GPODNET_LOGOUT).setEnabled(loggedIn);
}
diff --git a/src/de/danoeh/antennapod/dialog/AuthenticationDialog.java b/src/de/danoeh/antennapod/dialog/AuthenticationDialog.java
new file mode 100644
index 000000000..bdb2d68ba
--- /dev/null
+++ b/src/de/danoeh/antennapod/dialog/AuthenticationDialog.java
@@ -0,0 +1,89 @@
+package de.danoeh.antennapod.dialog;
+
+import android.app.Dialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.view.View;
+import android.view.Window;
+import android.widget.Button;
+import android.widget.CheckBox;
+import android.widget.EditText;
+import de.danoeh.antennapod.R;
+
+/**
+ * Displays a dialog with a username and password text field and an optional checkbox to save username and preferences.
+ */
+public abstract class AuthenticationDialog extends Dialog {
+
+ private final int titleRes;
+ private final boolean enableUsernameField;
+ private final boolean showSaveCredentialsCheckbox;
+ private final String usernameInitialValue;
+ private final String passwordInitialValue;
+
+ public AuthenticationDialog(Context context, int titleRes, boolean enableUsernameField, boolean showSaveCredentialsCheckbox, String usernameInitialValue, String passwordInitialValue) {
+ super(context);
+ this.titleRes = titleRes;
+ this.enableUsernameField = enableUsernameField;
+ this.showSaveCredentialsCheckbox = showSaveCredentialsCheckbox;
+ this.usernameInitialValue = usernameInitialValue;
+ this.passwordInitialValue = passwordInitialValue;
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.authentication_dialog);
+ final EditText etxtUsername = (EditText) findViewById(R.id.etxtUsername);
+ final EditText etxtPassword = (EditText) findViewById(R.id.etxtPassword);
+ final CheckBox saveUsernamePassword = (CheckBox) findViewById(R.id.chkSaveUsernamePassword);
+ final Button butConfirm = (Button) findViewById(R.id.butConfirm);
+ final Button butCancel = (Button) findViewById(R.id.butCancel);
+
+ if (titleRes != 0) {
+ setTitle(titleRes);
+ } else {
+ requestWindowFeature(Window.FEATURE_NO_TITLE);
+ }
+ etxtUsername.setEnabled(enableUsernameField);
+ if (showSaveCredentialsCheckbox) {
+ saveUsernamePassword.setVisibility(View.VISIBLE);
+ } else {
+ saveUsernamePassword.setVisibility(View.GONE);
+ }
+ if (usernameInitialValue != null) {
+ etxtUsername.setText(usernameInitialValue);
+ }
+ if (passwordInitialValue != null) {
+ etxtPassword.setText(passwordInitialValue);
+ }
+ setOnCancelListener(new OnCancelListener() {
+ @Override
+ public void onCancel(DialogInterface dialog) {
+ onCancelled();
+ }
+ });
+ butCancel.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ cancel();
+ }
+ });
+ butConfirm.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ onConfirmed(etxtUsername.getText().toString(),
+ etxtPassword.getText().toString(),
+ showSaveCredentialsCheckbox && saveUsernamePassword.isChecked());
+ dismiss();
+ }
+ });
+ }
+
+ protected void onCancelled() {
+
+ }
+
+ protected abstract void onConfirmed(String username, String password, boolean saveUsernamePassword);
+}