Commit c602fb53 authored by Christian Dresen's avatar Christian Dresen
Browse files

Verbesserung der Fehlermeldungen

parent 6e4b8937
package ms.warpzone.warppay.dialogs;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Handler;
import ms.warpzone.warppay.R;
public class NotificationDialog {
AlertDialog.Builder builder;
AlertDialog dialog;
private String message;
public NotificationDialog(Context context, String title, String message) {
this.builder = new AlertDialog.Builder(context);
this.builder.setTitle(title);
this.builder.setMessage(message);
}
public NotificationDialog(Context context) {
this.builder = new AlertDialog.Builder(context);
}
public AlertDialog.Builder getBuilder() {
return this.builder;
}
public void show() {
this.show(0);
}
public void setWarning() {
this.builder.setIcon(R.drawable.ic_dialog_alert_holo_light);
this.builder.setCancelable(false);
this.builder.setTitle("WARNING");
}
public void show(int timeout) {
this.dialog = this.builder.create();
this.dialog.show();
if(timeout > 0) {
this.enableAutoDismiss(timeout);
}
}
public void enableAutoDismiss(int time){
final Handler handler = new Handler();
final Runnable runnable = new Runnable() {
@Override
public void run() {
AlertDialog alertDialog = NotificationDialog.this.dialog;
if (alertDialog != null && alertDialog.isShowing()) {
alertDialog.dismiss();
}
}
};
this.dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
handler.removeCallbacks(runnable);
}
});
handler.postDelayed(runnable, time);
}
public void setMessage(String message) {
this.builder.setMessage(message);
}
public void dismiss() {
if(this.dialog != null) {
this.dialog.dismiss();
}
}
public AlertDialog getDialog() {
return dialog;
}
}
package ms.warpzone.warppay.manager;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Handler;
......@@ -41,6 +42,7 @@ import ms.warpzone.warppay.data.models.rest.RestCategory;
import ms.warpzone.warppay.data.models.rest.RestProduct;
import ms.warpzone.warppay.data.models.rest.RestTransaction;
import ms.warpzone.warppay.data.models.rest.RestUser;
import ms.warpzone.warppay.dialogs.NotificationDialog;
import ms.warpzone.warppay.dialogs.NyanCatDialog;
import ms.warpzone.warppay.dialogs.PinCodesDialog;
import ms.warpzone.warppay.orderList.Order;
......@@ -61,6 +63,9 @@ public class MainManager {
private Timer timer;
private Timer screenSaverTimer;
public AlertDialog alertAmount;
private ProgressDialog pdRefresh = null;
private NotificationDialog ndRefreshError = null;
public static MainManager getInstance() {
return instance;
}
......@@ -129,6 +134,13 @@ public class MainManager {
}
public void refreshData() {
if(this.ndRefreshError != null)
this.ndRefreshError.dismiss();
this.ndRefreshError = null;
this.pdRefresh = ProgressDialog.show(this.mainActivity, "Refreshing...", "Loading...");
this.restService.getAllUser().enqueue(new Callback<List<RestUser>>() {
@Override
public void onResponse(Response<List<RestUser>> response, Retrofit retrofit) {
......@@ -142,6 +154,7 @@ public class MainManager {
@Override
public void onFailure(Throwable t) {
Log.d("REST", t.getMessage());
MainManager.getInstance().showRefreshError();
}
});
......@@ -152,12 +165,12 @@ public class MainManager {
if (categoryList != null) {
MainManager.getInstance().uiManager.showCategoryButtons();
}
Toast.makeText(MainManager.getInstance().mainActivity, "Refresh successful", Toast.LENGTH_LONG).show();
}
@Override
public void onFailure(Throwable t) {
Log.d("REST", t.getMessage());
MainManager.getInstance().showRefreshError();
}
});
......@@ -168,16 +181,53 @@ public class MainManager {
if (productList != null) {
MainManager.getInstance().uiManager.refreshProductData(productList);
}
MainManager.this.pdRefresh.dismiss();
}
@Override
public void onFailure(Throwable t) {
Log.d("REST", t.getMessage());
MainManager.getInstance().showRefreshError();
}
});
}
private void showRefreshError() {
if(ndRefreshError == null) {
if(pdRefresh != null)
pdRefresh.dismiss();
ndRefreshError = new NotificationDialog(this.mainActivity,"WARNING","Refresh failed. Please retry!");
ndRefreshError.setWarning();
ndRefreshError.getBuilder().setNeutralButton("Refresh", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
MainManager.getInstance().refreshData();
}
});
ndRefreshError.show();
final Handler handler = new Handler();
final Runnable runnable = new Runnable() {
@Override
public void run() {
MainManager.getInstance().refreshData();
}
};
ndRefreshError.getDialog().setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
handler.removeCallbacks(runnable);
}
});
handler.postDelayed(runnable, 10000);
}
}
public void setCurrentUser(User user) {
this.setCurrentUser(user,false);
}
......@@ -294,6 +344,10 @@ public class MainManager {
@Override
public void onFailure(Throwable t) {
NotificationDialog ndTransfer = new NotificationDialog(MainManager.getInstance().getMainActivity());
ndTransfer.setWarning();
ndTransfer.setMessage("Error Charging your account");
ndTransfer.show(4000);
Log.d("REST", t.getMessage());
}
});
......@@ -321,34 +375,18 @@ public class MainManager {
if (DataManager.getInstance().getCurrentUser().getCredit()>=totalAmount || cash){
DataManager.getInstance().performPayment(cash);
if(!cash) {
AlertDialog.Builder builder = new AlertDialog.Builder(this.mainActivity);
builder.setMessage("Neues Guthaben: " + this.getCurrentUser().getCredit() + " Euro");
alertAmount = builder.create();
alertAmount.show();
final Handler handler = new Handler();
final Runnable runnable = new Runnable() {
@Override
public void run() {
if (MainManager.getInstance().alertAmount.isShowing()) {
alertAmount.dismiss();
}
}
};
alertAmount.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
handler.removeCallbacks(runnable);
}
});
handler.postDelayed(runnable, 2500);
NotificationDialog n = new NotificationDialog(this.mainActivity);
n.setMessage("Neues Guthaben: " + this.getCurrentUser().getCredit() + " Euro");
n.show(2500);
}
MainManager.getInstance().clearCurrentUser();
} else {
Toast.makeText(mainActivity, mainActivity.getResources().getString(R.string.please_charge), Toast.LENGTH_LONG).show();
NotificationDialog ndPlsCharge = new NotificationDialog(MainManager.getInstance().getMainActivity());
ndPlsCharge.setWarning();
ndPlsCharge.setMessage(mainActivity.getResources().getString(R.string.please_charge));
ndPlsCharge.show(2000);
}
}
}
......@@ -358,14 +396,8 @@ public class MainManager {
return mainActivity;
}
public void setMainActivity(MainActivity mainActivity) {
this.mainActivity = mainActivity;
}
public RestService getRestService() { return restService; }
public void saveCardId() {
final String card_id = this.dataManager.getLastCardId();
......
......@@ -25,6 +25,7 @@ import ms.warpzone.warppay.data.models.local.Product;
import ms.warpzone.warppay.data.models.local.User;
import ms.warpzone.warppay.dialogs.ChargeCustomDialog;
import ms.warpzone.warppay.dialogs.ChargeDialog;
import ms.warpzone.warppay.dialogs.NotificationDialog;
import ms.warpzone.warppay.dialogs.PayChoiceDialog;
import ms.warpzone.warppay.dialogs.PinCodesDialog;
import ms.warpzone.warppay.dialogs.ProductDialog;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment