Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
shalzz committed Feb 11, 2016
2 parents 16543fc + 765099f commit 21f8267
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 118 deletions.
4 changes: 2 additions & 2 deletions attendance/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.shalzz.attendance"
android:versionCode="241"
android:versionName="2.4.1" >
android:versionCode="242"
android:versionName="2.4.2" >

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand Down
20 changes: 8 additions & 12 deletions attendance/src/main/java/com/shalzz/attendance/Miscellaneous.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.security.KeyStore;
Expand Down Expand Up @@ -165,22 +166,17 @@ public static void showSnackBar(View view, String msg) {
* @return the hash of the string s
*/
public static String md5(String s) {
try {
// Create MD5 Hash
MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
digest.update(s.getBytes());
byte messageDigest[] = digest.digest();

// Create Hex String
StringBuilder hexString = new StringBuilder();
for (byte aMessageDigest : messageDigest)
hexString.append(Integer.toHexString(0xFF & aMessageDigest));
return hexString.toString();
MessageDigest m;

try {
m = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return "";
}
return "";

m.update(s.getBytes(),0,s.length());
return new BigInteger(1, m.digest()).toString(16);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,103 +1,103 @@
/*
* Copyright (c) 2013-2016 Shaleen Jain <[email protected]>
*
* This file is part of UPES Academics.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.shalzz.attendance.wrapper;

import android.content.Context;

import com.android.volley.AuthFailureError;
import com.android.volley.NetworkError;
import com.android.volley.NetworkResponse;
import com.android.volley.ServerError;
import com.android.volley.TimeoutError;
import com.android.volley.VolleyError;
import com.shalzz.attendance.R;

public class MyVolleyErrorHelper {
/**
* Returns appropriate message which is to be displayed to the user
* against the specified error object.
*
* @param error {@link Object}
* @param context {@link android.content.Context}
* @return Error Message
*/
public static String getMessage(Object error, Context context) {
if (error instanceof TimeoutError) {
return context.getResources().getString(R.string.generic_server_down);
}
else if (isServerProblem(error)) {
return handleServerError(error, context);
}
else if (isNetworkProblem(error)) {
return context.getResources().getString(R.string.no_internet);
}
return context.getResources().getString(R.string.generic_error);
}

/**
* Determines whether the error is related to network
* @param error {@link Object}
* @return True or False
*/
private static boolean isNetworkProblem(Object error) {
return error instanceof NetworkError;
}
/**
* Determines whether the error is related to server
* @param error {@link Object}
* @return True or False
*/
private static boolean isServerProblem(Object error) {
return (error instanceof ServerError) || (error instanceof AuthFailureError);
}
/**
* Handles the server error, tries to determine whether to show a stock message or to
* show a message retrieved from the server.
*
* @param err {@link Object}
* @param context {@link android.content.Context}
* @return Error Message
*/
private static String handleServerError(Object err, Context context) {
VolleyError error = (VolleyError) err;

NetworkResponse response = error.networkResponse;

if (response != null) {
switch (response.statusCode) {
case 404:
case 422:
case 401:
if(error.getMessage() != null)
return error.getMessage();
return "Unauthorized";
case 407:
return context.getResources().getString(R.string.proxy_error);

default:
return context.getResources().getString(R.string.generic_server_down);
}
}
return context.getResources().getString(R.string.generic_error);
}
}
/*
* Copyright (c) 2013-2016 Shaleen Jain <[email protected]>
*
* This file is part of UPES Academics.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.shalzz.attendance.wrapper;

import android.content.Context;

import com.android.volley.AuthFailureError;
import com.android.volley.NetworkError;
import com.android.volley.NetworkResponse;
import com.android.volley.ServerError;
import com.android.volley.TimeoutError;
import com.android.volley.VolleyError;
import com.shalzz.attendance.R;

public class MyVolleyErrorHelper {

/**
* Returns appropriate message which is to be displayed to the user
* against the specified error object.
*
* @param error {@link Object}
* @param context {@link android.content.Context}
* @return Error Message
*/
public static String getMessage(Object error, Context context) {
if (error instanceof TimeoutError) {
return context.getResources().getString(R.string.generic_server_down);
}
else if (isServerProblem(error)) {
return handleServerError(error, context);
}
else if (isNetworkProblem(error)) {
return context.getResources().getString(R.string.no_internet);
}
return context.getResources().getString(R.string.generic_error);
}

/**
* Determines whether the error is related to network
* @param error {@link Object}
* @return True or False
*/
private static boolean isNetworkProblem(Object error) {
return error instanceof NetworkError;
}

/**
* Determines whether the error is related to server
* @param error {@link Object}
* @return True or False
*/
private static boolean isServerProblem(Object error) {
return (error instanceof ServerError) || (error instanceof AuthFailureError);
}

/**
* Handles the server error, tries to determine whether to show a stock message or to
* show a message retrieved from the server.
*
* @param err {@link Object}
* @param context {@link android.content.Context}
* @return Error Message
*/
private static String handleServerError(Object err, Context context) {
VolleyError error = (VolleyError) err;

NetworkResponse response = error.networkResponse;

if (response != null) {
switch (response.statusCode) {
case 401:
if(error.getMessage() != null)
return error.getMessage();
return context.getResources().getString(R.string.auth_error);
case 404:
case 422:
case 407:
return context.getResources().getString(R.string.proxy_error);

default:
return context.getResources().getString(R.string.generic_server_down);
}
}
return context.getResources().getString(R.string.generic_error);
}
}
3 changes: 2 additions & 1 deletion attendance/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<!--Semantic versioning: MAJOR.MINOR.PATCH-->
<!-- DON'T update this for PATCH release -->
<string name="user_version" translatable="false">2.4</string>
<string name="pref_version_summary" translatable="false">v2.4.1</string>
<string name="pref_version_summary" translatable="false">v2.4.2</string>

<!--API keys-->
<string name="test_banner_ad_unit_id" translatable="false">ca-app-pub-3940256099942544/6300978111</string>
Expand Down Expand Up @@ -65,6 +65,7 @@
<string name="unavailable_timetable_error_msg">No TimeTable available at this time</string>
<string name="form_sapid_error">Invalid SAP ID</string>
<string name="form_password_error">This field is required</string>
<string name="auth_error">Incorrect SAP ID or password</string>

<!--EditText's and TextView's-->
<string name="no_classes">You don\'t have any classes on this day :)</string>
Expand Down

0 comments on commit 21f8267

Please sign in to comment.