Code Conventions

This commit is contained in:
m_broelemann 2021-01-06 08:52:43 +01:00
parent a423d4a037
commit 70124761bf

View File

@ -113,12 +113,14 @@ public class Communicator {
xmlFile, xmlFile,
response -> { response -> {
try { try {
JSONObject jsonObject = new JSONObject(response.toString()); JSONObject jsonObject =
new JSONObject(response.toString());
if (!jsonObject.getString("error").equals("")) { if (!jsonObject.getString("error").equals("")) {
makeToast(jsonObject.getString("error")); makeToast(jsonObject.getString("error"));
} }
} catch (JSONException e) { } catch (JSONException e) {
Log.e("Communicator","JSON error on response during UPLOAD: " + e.getMessage()); Log.e("Communicator", "JSON error on response"
+ " during UPLOAD: " + e.getMessage());
} }
}, },
error -> handleError(error, "UPLOAD XML") error -> handleError(error, "UPLOAD XML")
@ -155,26 +157,30 @@ public class Communicator {
+ e.getMessage()); + e.getMessage());
} }
}, },
error -> handleError(error,"XML DOWNLOAD") error -> handleError(error, "XML DOWNLOAD")
); );
requestQueue.add(request); requestQueue.add(request);
} }
private void handleError(VolleyError error, String method){ private void handleError(final VolleyError error, final String method) {
if (error instanceof ServerError){ if (error instanceof ServerError) {
Log.e("Communicator","server error during " + method + ": " + error.getMessage()); Log.e("Communicator", "server error during " + method
+ ": " + error.getMessage());
} else if (error instanceof NoConnectionError) { } else if (error instanceof NoConnectionError) {
makeToast("NO CONNECTION"); makeToast("NO CONNECTION");
} else if (error instanceof TimeoutError) { } else if (error instanceof TimeoutError) {
makeToast("CONNECTION TIMEOUT"); makeToast("CONNECTION TIMEOUT");
} else { } else {
Log.e("Communicator","error during " + method + ": " + error.getMessage()); Log.e("Communicator", "error during " + method + ": "
+ error.getMessage());
} }
} }
private void makeToast(String message){ private void makeToast(final String message) {
Toast toast = new Toast(mainActivity); Toast toast = new Toast(mainActivity);
View toastView = mainActivity.getLayoutInflater().inflate(R.layout.volley_toast, (ViewGroup) mainActivity.findViewById(R.id.volleyToastContainer)); View toastView = mainActivity.getLayoutInflater().inflate(R.layout.
volley_toast, (ViewGroup) mainActivity.findViewById(R.id.
volleyToastContainer));
TextView textView = toastView.findViewById(R.id.text); TextView textView = toastView.findViewById(R.id.text);
textView.setText(message); textView.setText(message);
toast.setDuration(Toast.LENGTH_LONG); toast.setDuration(Toast.LENGTH_LONG);