Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static AlertDialog makerNetworkAlertDialogError(final Context context, VolleyError error)
- {
- final AlertDialog.Builder builder = new AlertDialog.Builder(context);
- builder.setTitle(R.string.network_error);
- NetworkResponse networkResponse = error.networkResponse;
- if (networkResponse == null || networkResponse.data == null)
- {
- builder.setMessage(R.string.joinServer);
- builder.setPositiveButton(R.string.Ok, new DialogInterface.OnClickListener()
- {
- @Override
- public void onClick(DialogInterface dialog, int which)
- {
- ApiClient.getInstance().signOut(context);
- Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage("com.jplsystemes.cariatmatthieu.dictee_vocale");
- launchIntent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_NEW_TASK);
- context.startActivity(launchIntent);
- Toast.makeText(context, "The network is available, please log in.", Toast.LENGTH_LONG).show();
- ApiClient.getInstance().offLine = false;
- }
- });
- return builder.create();
- }
- if (checkConnection(context) == false)
- {
- builder.setMessage(R.string.no_network);
- } else if (networkResponse != null && networkResponse.data != null)
- {
- try
- {
- JSONObject jsonObject = new JSONObject(new String(networkResponse.data));
- builder.setMessage(jsonObject.getString("content"));
- } catch (JSONException e)
- {
- e.printStackTrace();
- builder.setMessage(R.string.internal_error);
- }
- } else
- {
- builder.setMessage(R.string.internal_error);
- return builder.create();
- }
- if (!(context instanceof LoginActivity) && networkResponse != null && networkResponse.statusCode == HttpStatus.SC_UNAUTHORIZED)
- {
- builder.setPositiveButton(R.string.Ok, new DialogInterface.OnClickListener()
- {
- @Override
- public void onClick(DialogInterface dialog, int which)
- {
- ApiClient.getInstance().signOut(context);
- Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage("com.jplsystemes.cariatmatthieu.dictee_vocale");
- launchIntent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_NEW_TASK);
- context.startActivity(launchIntent);
- Toast.makeText(context, "The network is available, please log in.", Toast.LENGTH_LONG).show();
- ApiClient.getInstance().offLine = false;
- }
- });
- } else
- {
- try
- {
- JSONObject jsonObject = new JSONObject(new String(networkResponse.data));
- JSONArray jsonErrors = jsonObject.getJSONArray("errors");
- String finalString = "";
- for (int i = 0; i < jsonErrors.length(); i++)
- {
- finalString += jsonErrors.getString(i) + "\n";
- }
- builder.setMessage(finalString);
- } catch (JSONException e)
- {
- e.printStackTrace();
- builder.setMessage(R.string.internal_error);
- }
- builder.setPositiveButton(R.string.Ok, new DialogInterface.OnClickListener()
- {
- @Override
- public void onClick(DialogInterface dialog, int which)
- {
- dialog.cancel();
- }
- });
- }
- return builder.create();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement