diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-07-15 18:10:07 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-07-15 18:10:07 -0700 |
commit | 9e33865a18d55ac1cb4a5b6c2445221d762d990d (patch) | |
tree | 4415f7693bf85d8ae50e3e7e183a41e6670b2989 | |
parent | f851f1421a9fbeec065df4ee06042e7513eb30b8 (diff) | |
download | dsub-9e33865a18d55ac1cb4a5b6c2445221d762d990d.tar.gz dsub-9e33865a18d55ac1cb4a5b6c2445221d762d990d.tar.bz2 dsub-9e33865a18d55ac1cb4a5b6c2445221d762d990d.zip |
Don't close dialog on input errors
-rw-r--r-- | src/github/daneren2005/dsub/util/UserUtil.java | 266 |
1 files changed, 139 insertions, 127 deletions
diff --git a/src/github/daneren2005/dsub/util/UserUtil.java b/src/github/daneren2005/dsub/util/UserUtil.java index 77e07f6b..5c57b422 100644 --- a/src/github/daneren2005/dsub/util/UserUtil.java +++ b/src/github/daneren2005/dsub/util/UserUtil.java @@ -191,48 +191,52 @@ public final class UserUtil { AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.admin_change_password)
.setView(layout)
- .setPositiveButton(R.string.common_save, new DialogInterface.OnClickListener() {
+ .setPositiveButton(R.string.common_save, null)
+ .setNegativeButton(R.string.common_cancel, null)
+ .setCancelable(true);
+
+ final AlertDialog dialog = builder.create();
+ dialog.show();
+
+ dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ final String password = passwordView.getText().toString();
+ // Don't allow blank passwords
+ if ("".equals(password)) {
+ Util.toast(context, R.string.admin_change_password_invalid);
+ return;
+ }
+
+ new SilentBackgroundTask<Void>(context) {
@Override
- public void onClick(DialogInterface dialog, int id) {
- final String password = passwordView.getText().toString();
- // Don't allow blank passwords
- if ("".equals(password)) {
- Util.toast(context, R.string.admin_change_password_invalid);
- return;
+ protected Void doInBackground() throws Throwable {
+ MusicService musicService = MusicServiceFactory.getMusicService(context);
+ musicService.changePassword(user.getUsername(), password, context, null);
+ return null;
+ }
+
+ @Override
+ protected void done(Void v) {
+ Util.toast(context, context.getResources().getString(R.string.admin_change_password_success, user.getUsername()));
+ }
+
+ @Override
+ protected void error(Throwable error) {
+ String msg;
+ if (error instanceof OfflineException || error instanceof ServerTooOldException) {
+ msg = getErrorMessage(error);
+ } else {
+ msg = context.getResources().getString(R.string.admin_change_password_error, user.getUsername());
}
- new SilentBackgroundTask<Void>(context) {
- @Override
- protected Void doInBackground() throws Throwable {
- MusicService musicService = MusicServiceFactory.getMusicService(context);
- musicService.changePassword(user.getUsername(), password, context, null);
- return null;
- }
-
- @Override
- protected void done(Void v) {
- Util.toast(context, context.getResources().getString(R.string.admin_change_password_success, user.getUsername()));
- }
-
- @Override
- protected void error(Throwable error) {
- String msg;
- if (error instanceof OfflineException || error instanceof ServerTooOldException) {
- msg = getErrorMessage(error);
- } else {
- msg = context.getResources().getString(R.string.admin_change_password_error, user.getUsername());
- }
-
- Util.toast(context, msg);
- }
- }.execute();
+ Util.toast(context, msg);
}
- })
- .setNegativeButton(R.string.common_cancel, null)
- .setCancelable(true);
+ }.execute();
- AlertDialog dialog = builder.create();
- dialog.show();
+ dialog.dismiss();
+ }
+ });
}
public static void updateSettings(final Context context, final User user) {
@@ -270,48 +274,52 @@ public final class UserUtil { AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.admin_change_email)
.setView(layout)
- .setPositiveButton(R.string.common_save, new DialogInterface.OnClickListener() {
+ .setPositiveButton(R.string.common_save, null)
+ .setNegativeButton(R.string.common_cancel, null)
+ .setCancelable(true);
+
+ final AlertDialog dialog = builder.create();
+ dialog.show();
+
+ dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ final String email = emailView.getText().toString();
+ // Don't allow blank emails
+ if ("".equals(email)) {
+ Util.toast(context, R.string.admin_change_email_invalid);
+ return;
+ }
+
+ new SilentBackgroundTask<Void>(context) {
@Override
- public void onClick(DialogInterface dialog, int id) {
- final String email = emailView.getText().toString();
- // Don't allow blank emails
- if ("".equals(email)) {
- Util.toast(context, R.string.admin_change_email_invalid);
- return;
+ protected Void doInBackground() throws Throwable {
+ MusicService musicService = MusicServiceFactory.getMusicService(context);
+ musicService.changeEmail(user.getUsername(), email, context, null);
+ return null;
+ }
+
+ @Override
+ protected void done(Void v) {
+ Util.toast(context, context.getResources().getString(R.string.admin_change_email_success, user.getUsername()));
+ }
+
+ @Override
+ protected void error(Throwable error) {
+ String msg;
+ if (error instanceof OfflineException || error instanceof ServerTooOldException) {
+ msg = getErrorMessage(error);
+ } else {
+ msg = context.getResources().getString(R.string.admin_change_email_error, user.getUsername());
}
- new SilentBackgroundTask<Void>(context) {
- @Override
- protected Void doInBackground() throws Throwable {
- MusicService musicService = MusicServiceFactory.getMusicService(context);
- musicService.changeEmail(user.getUsername(), email, context, null);
- return null;
- }
-
- @Override
- protected void done(Void v) {
- Util.toast(context, context.getResources().getString(R.string.admin_change_email_success, user.getUsername()));
- }
-
- @Override
- protected void error(Throwable error) {
- String msg;
- if (error instanceof OfflineException || error instanceof ServerTooOldException) {
- msg = getErrorMessage(error);
- } else {
- msg = context.getResources().getString(R.string.admin_change_email_error, user.getUsername());
- }
-
- Util.toast(context, msg);
- }
- }.execute();
+ Util.toast(context, msg);
}
- })
- .setNegativeButton(R.string.common_cancel, null)
- .setCancelable(true);
+ }.execute();
- AlertDialog dialog = builder.create();
- dialog.show();
+ dialog.dismiss();
+ }
+ });
}
public static void deleteUser(final Context context, final User user, final ArrayAdapter adapter) {
@@ -372,65 +380,69 @@ public final class UserUtil { AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.menu_add_user)
.setView(layout)
- .setPositiveButton(R.string.common_save, new DialogInterface.OnClickListener() {
+ .setPositiveButton(R.string.common_save, null)
+ .setNegativeButton(R.string.common_cancel, null)
+ .setCancelable(true);
+
+ final AlertDialog dialog = builder.create();
+ dialog.show();
+
+ dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ final String username = usernameView.getText().toString();
+ // Don't allow blank emails
+ if ("".equals(username)) {
+ Util.toast(context, R.string.admin_change_username_invalid);
+ return;
+ }
+
+ final String email = emailView.getText().toString();
+ // Don't allow blank emails
+ if ("".equals(email)) {
+ Util.toast(context, R.string.admin_change_email_invalid);
+ return;
+ }
+
+ final String password = passwordView.getText().toString();
+ if ("".equals(password)) {
+ Util.toast(context, R.string.admin_change_password_invalid);
+ return;
+ }
+
+ user.setUsername(username);
+ user.setEmail(email);
+ user.setPassword(password);
+
+ new SilentBackgroundTask<Void>(context) {
@Override
- public void onClick(DialogInterface dialog, int id) {
- final String username = usernameView.getText().toString();
- // Don't allow blank emails
- if ("".equals(username)) {
- Util.toast(context, R.string.admin_change_username_invalid);
- return;
- }
+ protected Void doInBackground() throws Throwable {
+ MusicService musicService = MusicServiceFactory.getMusicService(context);
+ musicService.createUser(user, context, null);
+ return null;
+ }
- final String email = emailView.getText().toString();
- // Don't allow blank emails
- if ("".equals(email)) {
- Util.toast(context, R.string.admin_change_email_invalid);
- return;
- }
+ @Override
+ protected void done(Void v) {
+ fragment.onRefresh();
+ Util.toast(context, context.getResources().getString(R.string.admin_create_user_success));
+ }
- final String password = passwordView.getText().toString();
- if ("".equals(password)) {
- Util.toast(context, R.string.admin_change_password_invalid);
- return;
+ @Override
+ protected void error(Throwable error) {
+ String msg;
+ if (error instanceof OfflineException || error instanceof ServerTooOldException) {
+ msg = getErrorMessage(error);
+ } else {
+ msg = context.getResources().getString(R.string.admin_create_user_error);
}
- user.setUsername(username);
- user.setEmail(email);
- user.setPassword(password);
-
- new SilentBackgroundTask<Void>(context) {
- @Override
- protected Void doInBackground() throws Throwable {
- MusicService musicService = MusicServiceFactory.getMusicService(context);
- musicService.createUser(user, context, null);
- return null;
- }
-
- @Override
- protected void done(Void v) {
- fragment.onRefresh();
- Util.toast(context, context.getResources().getString(R.string.admin_create_user_success));
- }
-
- @Override
- protected void error(Throwable error) {
- String msg;
- if (error instanceof OfflineException || error instanceof ServerTooOldException) {
- msg = getErrorMessage(error);
- } else {
- msg = context.getResources().getString(R.string.admin_create_user_error);
- }
-
- Util.toast(context, msg);
- }
- }.execute();
+ Util.toast(context, msg);
}
- })
- .setNegativeButton(R.string.common_cancel, null)
- .setCancelable(true);
+ }.execute();
- AlertDialog dialog = builder.create();
- dialog.show();
+ dialog.dismiss();
+ }
+ });
}
}
|