Updated the Groups module dialogs with DialogFactory methods

This commit is contained in:
Juan Miguel Boyero Corral 2013-11-08 21:19:07 +01:00
parent 72548b90a4
commit e5b347dada
8 changed files with 65 additions and 60 deletions

View File

@ -550,7 +550,7 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
} }
}; };
AlertDialog errorDialog = DialogFactory.errorDialog(this, TAG, message, ex, sendException, AlertDialog errorDialog = DialogFactory.createErrorDialog(this, TAG, message, ex, sendException,
isDebuggable, onClickListener); isDebuggable, onClickListener);
errorDialog.show(); errorDialog.show();

View File

@ -142,7 +142,7 @@ public class SWADMain extends MenuExpandableListActivity {
} }
}; };
AlertDialog alertDialog = DialogFactory.positiveNegativeDialog(this, AlertDialog alertDialog = DialogFactory.createPositiveNegativeDialog(this,
-1, -1,
R.string.initialDialogTitle, R.string.initialDialogTitle,
R.string.firstRunMsg, R.string.firstRunMsg,

View File

@ -9,6 +9,8 @@ import com.bugsense.trace.BugSenseHandler;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnClickListener;
import android.content.res.Resources; import android.content.res.Resources;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -40,12 +42,12 @@ public class DialogFactory {
/** /**
* Creates a Webview dialog with HTML content. * Creates a Webview dialog with HTML content.
*/ */
public static AlertDialog createWebViewDialog(Context context, int title, int contentResourceId) { public static AlertDialog createWebViewDialog(Context context, int titleId, int contentResourceId) {
LayoutInflater li = LayoutInflater.from(context); LayoutInflater li = LayoutInflater.from(context);
View promptsView = li.inflate(R.layout.dialog_webview, null); View promptsView = li.inflate(R.layout.dialog_webview, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setTitle(context.getString(title)); alertDialogBuilder.setTitle(context.getString(titleId));
alertDialogBuilder.setCancelable(false); alertDialogBuilder.setCancelable(false);
alertDialogBuilder.setNeutralButton(R.string.close_dialog, null); alertDialogBuilder.setNeutralButton(R.string.close_dialog, null);
@ -71,20 +73,21 @@ public class DialogFactory {
return alertDialogBuilder.create(); return alertDialogBuilder.create();
} }
public static AlertDialog neutralDialog(Context context, int title, int message) { public static AlertDialog createNeutralDialog(Context context, int titleId, int messageId, int buttonLabelId,
OnClickListener clickListener) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context) AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context)
.setTitle(title) .setTitle(titleId)
.setMessage(message) .setMessage(messageId)
.setCancelable(false) .setCancelable(false)
.setNeutralButton(R.string.close_dialog, null); .setNeutralButton(buttonLabelId, clickListener);
return alertDialogBuilder.create(); return alertDialogBuilder.create();
} }
public static AlertDialog positiveNegativeDialog(Context context, int layoutId, int titleId, int messageId, public static AlertDialog createPositiveNegativeDialog(Context context, int layoutId, int titleId,
int acceptLabel, int cancelLabel, int messageId, int acceptLabel, int cancelLabel, OnClickListener positiveListener,
DialogInterface.OnClickListener positiveListener, DialogInterface.OnClickListener negativeListener, OnClickListener negativeListener, OnCancelListener cancelListener) {
DialogInterface.OnCancelListener cancelListener) {
AlertDialog alertDialog; AlertDialog alertDialog;
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context) AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context)
@ -116,7 +119,7 @@ public class DialogFactory {
return alertDialog; return alertDialog;
} }
public static AlertDialog errorDialog(Context context, String tag, String message, Exception ex, public static AlertDialog createErrorDialog(Context context, String tag, String message, Exception ex,
boolean sendException, boolean isDebuggable, DialogInterface.OnClickListener onClickListener) { boolean sendException, boolean isDebuggable, DialogInterface.OnClickListener onClickListener) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context) AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context)

View File

@ -124,7 +124,7 @@ public class MenuActivity extends Activity {
} }
}; };
AlertDialog errorDialog = DialogFactory.errorDialog(this, TAG, message, ex, sendException, AlertDialog errorDialog = DialogFactory.createErrorDialog(this, TAG, message, ex, sendException,
isDebuggable, onClickListener); isDebuggable, onClickListener);
errorDialog.show(); errorDialog.show();
@ -134,7 +134,7 @@ public class MenuActivity extends Activity {
* Shows a dialog. * Shows a dialog.
*/ */
public void showDialog(int title, int message) { public void showDialog(int title, int message) {
AlertDialog dialog = DialogFactory.neutralDialog(this, title, message); AlertDialog dialog = DialogFactory.createNeutralDialog(this, title, message, R.string.close_dialog, null);
dialog.show(); dialog.show();
} }

View File

@ -128,7 +128,7 @@ public class MenuExpandableListActivity extends ExpandableListActivity {
} }
}; };
AlertDialog errorDialog = DialogFactory.errorDialog(this, TAG, message, ex, sendException, AlertDialog errorDialog = DialogFactory.createErrorDialog(this, TAG, message, ex, sendException,
isDebuggable, onClickListener); isDebuggable, onClickListener);
errorDialog.show(); errorDialog.show();
@ -138,7 +138,7 @@ public class MenuExpandableListActivity extends ExpandableListActivity {
* Shows a dialog. * Shows a dialog.
*/ */
public void showDialog(int title, int message) { public void showDialog(int title, int message) {
AlertDialog dialog = DialogFactory.neutralDialog(this, title, message); AlertDialog dialog = DialogFactory.createNeutralDialog(this, title, message, R.string.close_dialog, null);
dialog.show(); dialog.show();
} }

View File

@ -155,7 +155,7 @@ public class Messages extends Module {
notificationCode = getIntent().getLongExtra("notificationCode", 0); notificationCode = getIntent().getLongExtra("notificationCode", 0);
messageDialog = DialogFactory.positiveNegativeDialog(this, messageDialog = DialogFactory.createPositiveNegativeDialog(this,
R.layout.dialog_messages, R.layout.dialog_messages,
R.string.messagesModuleLabel, R.string.messagesModuleLabel,
-1, -1,

View File

@ -132,7 +132,7 @@ public class Notices extends Module {
}; };
private void launchNoticeDialog() { private void launchNoticeDialog() {
noticeDialog = DialogFactory.positiveNegativeDialog(this, noticeDialog = DialogFactory.createPositiveNegativeDialog(this,
R.layout.dialog_notice, R.layout.dialog_notice,
R.string.noticesModuleLabel, R.string.noticesModuleLabel,
-1, -1,

View File

@ -21,12 +21,14 @@ package es.ugr.swad.swadroid.modules.groups;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.*; import android.widget.*;
import es.ugr.swad.swadroid.Constants; import es.ugr.swad.swadroid.Constants;
import es.ugr.swad.swadroid.R; import es.ugr.swad.swadroid.R;
import es.ugr.swad.swadroid.gui.DialogFactory;
import es.ugr.swad.swadroid.gui.MenuExpandableListActivity; import es.ugr.swad.swadroid.gui.MenuExpandableListActivity;
import es.ugr.swad.swadroid.model.Group; import es.ugr.swad.swadroid.model.Group;
import es.ugr.swad.swadroid.model.Model; import es.ugr.swad.swadroid.model.Model;
@ -67,6 +69,11 @@ public class MyGroupsManager extends MenuExpandableListActivity {
private ImageButton updateButton; private ImageButton updateButton;
private ProgressBar progressbar; private ProgressBar progressbar;
private OnClickListener cancelClickListener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
};
@Override @Override
protected void onStart() { protected void onStart() {
@ -180,33 +187,27 @@ public class MyGroupsManager extends MenuExpandableListActivity {
/** /**
* Shows informative dialog on successful enrollment * Shows informative dialog on successful enrollment
*/ */
void showSuccessfulEnrollmentDialog() { void showSuccessfulEnrollmentDialog() {
new AlertDialog.Builder(this) AlertDialog dialog = DialogFactory.createNeutralDialog(this,
.setTitle(R.string.resultEnrollment) R.string.resultEnrollment,
.setMessage(R.string.successfullEnrollment) R.string.successfullEnrollment,
.setCancelable(false) R.string.ok,
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { cancelClickListener);
public void onClick(DialogInterface dialog, int id) {
dialog.cancel(); dialog.show();
}
})
.show();
} }
/** /**
* Shows informative dialog on failed enrollment * Shows informative dialog on failed enrollment
*/ */
void showFailedEnrollmentDialog() { void showFailedEnrollmentDialog() {
new AlertDialog.Builder(this) AlertDialog dialog = DialogFactory.createNeutralDialog(this,
.setTitle(R.string.resultEnrollment) R.string.resultEnrollment,
.setMessage(R.string.failedEnrollment) R.string.failedEnrollment,
.setCancelable(false) R.string.ok,
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { cancelClickListener);
public void onClick(DialogInterface dialog, int id) {
dialog.cancel(); dialog.show();
}
})
.show();
} }
@ -214,27 +215,28 @@ public class MyGroupsManager extends MenuExpandableListActivity {
* Shows dialog to ask for confirmation in group enrollments * Shows dialog to ask for confirmation in group enrollments
*/ */
private void showConfirmEnrollmentDialog() { private void showConfirmEnrollmentDialog() {
new AlertDialog.Builder(this) OnClickListener positiveClickListener = new DialogInterface.OnClickListener() {
.setTitle(R.string.confirmEnrollments) public void onClick(DialogInterface dialog, int id) {
.setMessage(R.string.areYouSure) dialog.cancel();
.setCancelable(false) String myGroups = ((EnrollmentExpandableListAdapter) getExpandableListView().getExpandableListAdapter()).getChosenGroupCodesAsString();
.setPositiveButton(R.string.yesMsg, new DialogInterface.OnClickListener() { Intent activity = new Intent(getBaseContext(), SendMyGroups.class);
public void onClick(DialogInterface dialog, int id) { activity.putExtra("courseCode", courseCode);
dialog.cancel(); activity.putExtra("myGroups", myGroups);
String myGroups = ((EnrollmentExpandableListAdapter) getExpandableListView().getExpandableListAdapter()).getChosenGroupCodesAsString(); startActivityForResult(activity, Constants.SENDMYGROUPS_REQUEST_CODE);
Intent activity = new Intent(getBaseContext(), SendMyGroups.class); }
activity.putExtra("courseCode", courseCode); };
activity.putExtra("myGroups", myGroups);
startActivityForResult(activity, Constants.SENDMYGROUPS_REQUEST_CODE); AlertDialog dialog = DialogFactory.createPositiveNegativeDialog(this,
} -1,
}) R.string.confirmEnrollments,
.setNegativeButton(R.string.noMsg, new DialogInterface.OnClickListener() { R.string.areYouSure,
public void onClick(DialogInterface dialog, int id) { R.string.yesMsg,
dialog.cancel(); R.string.noMsg,
} positiveClickListener,
}) cancelClickListener,
.show(); null);
dialog.show();
} }
/* private String getRequestedGroups(){ /* private String getRequestedGroups(){