Skip to content

Commit

Permalink
Merge pull request #6 from sh-hilden/change_http_error_messages
Browse files Browse the repository at this point in the history
Change the Error Reporting in Scanner. Thank you.
  • Loading branch information
mdrobisch authored Jan 2, 2019
2 parents fb82978 + 4745669 commit b5a0b4a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.drobisch.partkeeprscannrapp;

import android.app.Activity;
import android.content.DialogInterface;
import android.net.ConnectivityManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Message;
import android.support.v7.app.AlertDialog;
import android.util.Base64;
import android.util.Log;
import android.util.Pair;
Expand Down Expand Up @@ -273,6 +275,7 @@ public class ApiPartTask extends AsyncTask<Void, Void, Boolean> {
private Boolean error = false;
private String errorString;


ApiPartTask(String user, String password, String server, int partID, String command, String json) {
mUser = user;
mPassword = password;
Expand Down Expand Up @@ -316,19 +319,34 @@ protected Boolean doInBackground(Void... params) {
else
{
if(httpcon != null) {
error = true;
errorString = "Connection failed with http-code " + httpcon.getResponseCode();

switch (httpcon.getResponseCode())
{
case 401:
error = true;
errorString = getString(R.string.error_incorrect_password_user);
break;
case 404:
error = true;
errorString = getString(R.string.error_part_not_exists);
break;
default:
error = true;
errorString = getString(R.string.error_http_long);
break;
}
}
else {
error = true;
errorString = "Connection failed";
errorString = getString(R.string.error_connection_long);
}
}
}

catch (IOException e1) {
e1.printStackTrace();
error = true;
errorString = getString(R.string.error_server_connect_failed);
}

try {
Expand All @@ -353,17 +371,25 @@ protected void onPostExecute(final Boolean success) {
mPartPartID = mPartID;
if(error == true) {
mPartPartID = -1;
Toast infoToast = Toast.makeText(getApplicationContext(),errorString,Toast.LENGTH_SHORT);
//specify the toast display position exact parent layout center. no x or y offset
infoToast.setGravity(Gravity.BOTTOM,0,390);
infoToast.show();

openMessageBox("Error", errorString);
}
}

@Override
protected void onCancelled() {

}


protected void openMessageBox(String headline, String message)
{
AlertDialog.Builder builder = new AlertDialog.Builder(ContinuousCaptureActivity.this);
builder.setMessage(message).setTitle(headline);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int id) {}});
AlertDialog dialog = builder.create();
dialog.show();
}


}
}
19 changes: 19 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,27 @@
<string name="error_invalid_user">This user is invalid</string>
<string name="error_invalid_password">This password is too short</string>
<string name="error_incorrect_password">This password is incorrect</string>
<string name="error_incorrect_password_user">Wrong username or password!</string>
<string name="error_unauthorized">Unauthorized</string>
<string name="error_field_required">This field is required</string>

<string name="error_not_found">Not found</string>
<string name="error_part_not_exists">This part does not exists</string>

<string name="error_connection">Connection error</string>
<string name="error_connection_long">The connection failed!</string>

<string name="error_http">HTTP Error</string>
<string name="error_http_long">Connection failed with http-code</string>
<string name="error_server_connect_failed">Failed to connect to server</string>



<string name="permission_rationale">"Contacts permissions are needed for providing email completions."</string>
<string name="action_settings">Settings</string>
<string name="settings_activity_title">Partkeepr App - Settings</string>




</resources>

0 comments on commit b5a0b4a

Please sign in to comment.