diff options
Diffstat (limited to 'WordPress/src/main/java/org/wordpress/android/widgets/AuthErrorDialogFragment.java')
-rw-r--r-- | WordPress/src/main/java/org/wordpress/android/widgets/AuthErrorDialogFragment.java | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/WordPress/src/main/java/org/wordpress/android/widgets/AuthErrorDialogFragment.java b/WordPress/src/main/java/org/wordpress/android/widgets/AuthErrorDialogFragment.java new file mode 100644 index 000000000..65d677c42 --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/widgets/AuthErrorDialogFragment.java @@ -0,0 +1,63 @@ +package org.wordpress.android.widgets; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.app.DialogFragment; +import android.content.DialogInterface; +import android.os.Bundle; + +import org.wordpress.android.R; +import org.wordpress.android.WordPress; +import org.wordpress.android.ui.ActivityLauncher; + +/** + * An alert dialog fragment for XML-RPC authentication failures + */ +public class AuthErrorDialogFragment extends DialogFragment { + public static int DEFAULT_RESOURCE_ID = -1; + + private int mMessageId = R.string.incorrect_credentials; + private int mTitleId = R.string.connection_error; + + public void setWPComTitleMessage(int titleResourceId, int messageResourceId) { + if (titleResourceId != DEFAULT_RESOURCE_ID) { + mTitleId = titleResourceId; + } else { + mTitleId = R.string.connection_error; + } + + if (messageResourceId != DEFAULT_RESOURCE_ID) { + mMessageId = messageResourceId; + } else { + mMessageId = R.string.incorrect_credentials; + } + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + this.setCancelable(true); + int style = DialogFragment.STYLE_NORMAL, theme = 0; + setStyle(style, theme); + } + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + AlertDialog.Builder b = new AlertDialog.Builder(getActivity()); + b.setTitle(mTitleId); + b.setMessage(mMessageId); + b.setCancelable(true); + b.setPositiveButton(R.string.settings, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + ActivityLauncher.viewBlogSettingsForResult(getActivity(), WordPress.getCurrentBlog()); + } + }); + b.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + } + }); + return b.create(); + } +}
\ No newline at end of file |