Skip to content

Commit

Permalink
Add Alert Dialog for error messages. Changed HTTP Error String for 40…
Browse files Browse the repository at this point in the history
…4 and 401
  • Loading branch information
sh-hilden committed Oct 25, 2018
1 parent aa905fe commit 4745669
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 17 deletions.
16 changes: 8 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
buildToolsVersion "27.0.3"

defaultConfig {
applicationId "com.drobisch.partkeeprscannrapp"
Expand All @@ -20,13 +20,13 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.+'
compile 'com.android.support:design:23.+'
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:23.4.0'
implementation 'com.android.support:design:23.4.0'

compile 'com.journeyapps:zxing-android-embedded:3.4.0'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.3.1'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'

}
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>
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.android.tools.build:gradle:3.1.4'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down

0 comments on commit 4745669

Please sign in to comment.