2019-05-29 14:04:30 +02:00
|
|
|
package lu.circl.mispbump.auxiliary;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
|
2019-05-29 14:52:00 +02:00
|
|
|
import lu.circl.mispbump.R;
|
|
|
|
|
2019-05-29 14:04:30 +02:00
|
|
|
/**
|
|
|
|
* Creates and show dialogs.
|
|
|
|
* Automatically takes care of using the UI Thread.
|
|
|
|
*/
|
|
|
|
public class DialogManager {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dialog to display a received public key.
|
2019-05-29 14:52:00 +02:00
|
|
|
*
|
2019-05-29 14:04:30 +02:00
|
|
|
* @param publicKey the public key to display
|
2019-05-29 14:52:00 +02:00
|
|
|
* @param context needed to build and show the dialog
|
|
|
|
* @param callback {@link IDialogFeedback}
|
2019-05-29 14:04:30 +02:00
|
|
|
*/
|
|
|
|
public static void publicKeyDialog(String publicKey, Context context, final IDialogFeedback callback) {
|
|
|
|
final AlertDialog.Builder adb = new AlertDialog.Builder(context);
|
|
|
|
adb.setTitle("Public Key Received");
|
|
|
|
adb.setMessage(publicKey);
|
|
|
|
adb.setPositiveButton("Accept", new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
callback.positive();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
adb.setNegativeButton("Reject", new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
callback.negative();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Activity act = (Activity) context;
|
|
|
|
|
|
|
|
act.runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
adb.create().show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dialog to ask the user if his sync partner already scanned the displayed qr code.
|
2019-05-29 14:52:00 +02:00
|
|
|
*
|
|
|
|
* @param context needed to build and show the dialog
|
2019-05-29 14:04:30 +02:00
|
|
|
* @param callback {@link IDialogFeedback}
|
|
|
|
*/
|
|
|
|
public static void confirmProceedDialog(Context context, final IDialogFeedback callback) {
|
|
|
|
final AlertDialog.Builder adb = new AlertDialog.Builder(context);
|
|
|
|
adb.setTitle("Really continue?");
|
|
|
|
adb.setMessage("Was this QR Code already scanned by your partner?");
|
|
|
|
adb.setPositiveButton("Yes, continue", new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
callback.positive();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
adb.setNegativeButton("No, show QR Code", new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
callback.negative();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Activity act = (Activity) context;
|
|
|
|
|
|
|
|
act.runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
adb.create().show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-05-29 14:52:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Dialog to provide login information.
|
|
|
|
*
|
|
|
|
* @param context needed to build and show the dialog
|
|
|
|
*/
|
|
|
|
public static void loginHelpDialog(Context context) {
|
|
|
|
final AlertDialog.Builder adb = new AlertDialog.Builder(context);
|
|
|
|
adb.setTitle(R.string.app_name);
|
|
|
|
adb.setMessage(R.string.login_help_text);
|
|
|
|
adb.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
dialog.dismiss();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Activity act = (Activity) context;
|
|
|
|
|
|
|
|
act.runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
adb.create().show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interface to give feedback about the user choice in dialogs.
|
|
|
|
*/
|
|
|
|
public interface IDialogFeedback {
|
|
|
|
void positive();
|
|
|
|
|
|
|
|
void negative();
|
|
|
|
}
|
2019-05-29 14:04:30 +02:00
|
|
|
}
|