mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-07-01 05:14:17 +00:00
add project adins
This commit is contained in:
parent
ad06ac5505
commit
f8f85d679d
5299 changed files with 625430 additions and 0 deletions
|
@ -0,0 +1,833 @@
|
|||
package com.adins.mss.foundation.oauth2;
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.NetworkOnMainThreadException;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
|
||||
import com.adins.mss.base.GlobalData;
|
||||
import com.adins.mss.base.R;
|
||||
import com.adins.mss.base.crashlytics.FireCrash;
|
||||
import com.adins.mss.base.util.GsonHelper;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.foundation.formatter.Tool;
|
||||
import com.adins.mss.foundation.http.HttpConnection;
|
||||
import com.adins.mss.foundation.http.InvalidTokenException;
|
||||
import com.adins.mss.foundation.http.net.HttpClient;
|
||||
import com.adins.mss.foundation.http.net.HttpsClient;
|
||||
import com.adins.mss.foundation.security.SAKFormatter;
|
||||
import com.squareup.okhttp.FormEncodingBuilder;
|
||||
import com.squareup.okhttp.Request;
|
||||
import com.squareup.okhttp.RequestBody;
|
||||
import com.squareup.okhttp.Response;
|
||||
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.ParseException;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.UnrecoverableKeyException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import static com.adins.mss.foundation.http.HttpConnection.HEADER_TENANT;
|
||||
|
||||
public class OAuthUtils {
|
||||
|
||||
private static final String TAG = "OAuthUtils";
|
||||
|
||||
public static String getProtectedResourceHttp(OAuth2Client client, Token token, String path) {
|
||||
|
||||
String resourceURL = client.getSite() + path;
|
||||
|
||||
HttpClient httpClient = new HttpClient();
|
||||
httpClient.setConnectionTimeout(Global.DEFAULTCONNECTIONTIMEOUT);
|
||||
|
||||
Request request = new Request.Builder().url(resourceURL)
|
||||
.addHeader(OAuthConstants.AUTHORIZATION,
|
||||
getAuthorizationHeaderForAccessToken(token
|
||||
.getAccessToken()))
|
||||
.get()
|
||||
.build();
|
||||
Response response = null;
|
||||
try {
|
||||
response = httpClient.execute(request);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String responseString = "";
|
||||
int code = -1;
|
||||
try {
|
||||
code = response.code();
|
||||
if (code >= 400) {
|
||||
throw new RuntimeException(
|
||||
"Could not access protected resource. Server returned http code: "
|
||||
+ code);
|
||||
}
|
||||
Response priorResponse = response.priorResponse();
|
||||
if (priorResponse != null && priorResponse.code() != HttpStatus.SC_OK) {
|
||||
throw new RuntimeException(priorResponse.message());
|
||||
}
|
||||
responseString = response.body().string();
|
||||
boolean decrypt = GlobalData.getSharedGlobalData().isDecrypt();
|
||||
if (decrypt) {
|
||||
responseString = SAKFormatter.decipherData(responseString);
|
||||
}
|
||||
if (Global.IS_DEV) Log.i(TAG, responseString);
|
||||
|
||||
} catch (ClientProtocolException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
response.body().close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return responseString;
|
||||
}
|
||||
|
||||
public static String getProtectedResourceHttps(OAuth2Client client, Token token, String path) {
|
||||
|
||||
String resourceURL = client.getSite() + path;
|
||||
|
||||
HttpsClient httpClient = null;
|
||||
try {
|
||||
httpClient = new HttpsClient();
|
||||
httpClient.setAcceptAllCertificate(true);
|
||||
httpClient.setBypassHostnameVerification(true);
|
||||
httpClient.setConnectionTimeout(Global.DEFAULTCONNECTIONTIMEOUT);
|
||||
httpClient.initialize();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
} catch (KeyStoreException e) {
|
||||
e.printStackTrace();
|
||||
} catch (KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
} catch (UnrecoverableKeyException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
Request request = new Request.Builder().url(resourceURL)
|
||||
.addHeader(OAuthConstants.AUTHORIZATION,
|
||||
getAuthorizationHeaderForAccessToken(token
|
||||
.getAccessToken()))
|
||||
.get()
|
||||
.build();
|
||||
Response response = null;
|
||||
try {
|
||||
response = httpClient.execute(request);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String responseString = "";
|
||||
int code = -1;
|
||||
try {
|
||||
code = response.code();
|
||||
if (code >= 400) {
|
||||
throw new RuntimeException(
|
||||
"Could not access protected resource. Server returned http code: "
|
||||
+ code);
|
||||
}
|
||||
Response priorResponse = response.priorResponse();
|
||||
if (priorResponse != null && priorResponse.code() != HttpStatus.SC_OK) {
|
||||
throw new RuntimeException(priorResponse.message());
|
||||
}
|
||||
responseString = response.body().string();
|
||||
boolean decrypt = GlobalData.getSharedGlobalData().isDecrypt();
|
||||
if (decrypt) {
|
||||
responseString = SAKFormatter.decipherData(responseString);
|
||||
}
|
||||
if (Global.IS_DEV) Log.i(TAG, responseString);
|
||||
|
||||
} catch (ClientProtocolException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
response.body().close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return responseString;
|
||||
}
|
||||
|
||||
public static Token getAccessTokenHttp(Context context, OAuth2Config oauthDetails) {
|
||||
HttpClient httpClient = new HttpClient(context);
|
||||
httpClient.setConnectionTimeout(Global.DEFAULTCONNECTIONTIMEOUT);
|
||||
|
||||
String clientId = oauthDetails.getClientId();
|
||||
String clientSecret = oauthDetails.getClientSecret();
|
||||
String scope = oauthDetails.getScope();
|
||||
|
||||
FormEncodingBuilder formEncodingBuilder = new FormEncodingBuilder();
|
||||
formEncodingBuilder.add(OAuthConstants.GRANT_TYPE,
|
||||
oauthDetails.getGrantType());
|
||||
formEncodingBuilder.add(OAuthConstants.USERNAME,
|
||||
oauthDetails.getUsername());
|
||||
formEncodingBuilder.add(OAuthConstants.PASSWORD,
|
||||
oauthDetails.getPassword());
|
||||
if (isValid(clientId)) {
|
||||
formEncodingBuilder.add(OAuthConstants.CLIENT_ID,
|
||||
clientId);
|
||||
}
|
||||
if (isValid(clientSecret)) {
|
||||
formEncodingBuilder.add(OAuthConstants.CLIENT_SECRET, clientSecret);
|
||||
}
|
||||
if (isValid(scope)) {
|
||||
formEncodingBuilder.add(OAuthConstants.SCOPE,
|
||||
scope);
|
||||
}
|
||||
formEncodingBuilder.add("application", GlobalData.getSharedGlobalData().getApplication());
|
||||
|
||||
RequestBody body = formEncodingBuilder.build();
|
||||
Request.Builder builder = new Request.Builder();
|
||||
builder.url(oauthDetails.getTokenEndPointUrl())
|
||||
.addHeader(HttpConnection.HEADER_CONTENT_TYPE_KEY, HttpConnection.HEADER_CONTENT_TYPE_URL_ENCODED);
|
||||
String loginId = oauthDetails.getUsername();
|
||||
String[] idNtenant = Tool.split(loginId, "@");
|
||||
if (idNtenant.length > 1)
|
||||
builder.addHeader(HEADER_TENANT, idNtenant[1]);
|
||||
builder.post(body);
|
||||
|
||||
|
||||
Request request = builder.build();
|
||||
|
||||
Response response = null;
|
||||
try {
|
||||
response = httpClient.execute(request);
|
||||
} catch (NetworkOnMainThreadException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Token accessToken = null;
|
||||
if (response != null) {
|
||||
int code = response.code();
|
||||
if (code >= 400) {
|
||||
OauthErrorResponse errorResponse = null;
|
||||
try {
|
||||
errorResponse = GsonHelper.fromJson(response.body().string(), OauthErrorResponse.class);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
}
|
||||
if (null != errorResponse && errorResponse.getError_description().contains("token")) {
|
||||
throw new RuntimeException(errorResponse.error_description);
|
||||
}
|
||||
if (Global.IS_DEV) Log.i(TAG, "Authorization server expects Basic authentication");
|
||||
// Add Basic Authorization header
|
||||
builder.removeHeader(OAuthConstants.AUTHORIZATION);
|
||||
builder.addHeader(
|
||||
OAuthConstants.AUTHORIZATION,
|
||||
getBasicAuthorizationHeader(oauthDetails.getUsername(),
|
||||
oauthDetails.getPassword()));
|
||||
if (Global.IS_DEV) Log.i(TAG,"Retry with login credentials");
|
||||
|
||||
try {
|
||||
response.body().close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
request = builder.build();
|
||||
try {
|
||||
response = httpClient.execute(request);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
code = response.code();
|
||||
if (code >= 400) {
|
||||
if (Global.IS_DEV) Log.i(TAG, "Retry with client credentials");
|
||||
builder.removeHeader(OAuthConstants.AUTHORIZATION);
|
||||
builder.addHeader(
|
||||
OAuthConstants.AUTHORIZATION,
|
||||
getBasicAuthorizationHeader(
|
||||
oauthDetails.getClientId(),
|
||||
oauthDetails.getClientSecret()));
|
||||
|
||||
try {
|
||||
response.body().close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
request = builder.build();
|
||||
try {
|
||||
response = httpClient.execute(request);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
code = response.code();
|
||||
if (code >= 400) {
|
||||
if (code == OAuthConstants.HTTP_BAD_REQUEST || code == OAuthConstants.HTTP_UNAUTHORIZED) {
|
||||
errorResponse = null;
|
||||
try {
|
||||
errorResponse = GsonHelper.fromJson(response.body().string(), OauthErrorResponse.class);
|
||||
throw new RuntimeException(errorResponse.error_description);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
throw new RuntimeException(
|
||||
"Could not retrieve access token for user: "
|
||||
+ oauthDetails.getUsername());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Response priorResponse = response.priorResponse();
|
||||
if (priorResponse != null && priorResponse.code() != HttpStatus.SC_OK) {
|
||||
throw new RuntimeException(priorResponse.message());
|
||||
}
|
||||
Map<String, ?> map = handleResponse(response);
|
||||
accessToken = new Token(new Long((Integer) map.get(OAuthConstants.EXPIRES_IN)), (String) map.get(OAuthConstants.TOKEN_TYPE), (String) map.get(OAuthConstants.REFRESH_TOKEN), (String) map.get(OAuthConstants.ACCESS_TOKEN));
|
||||
|
||||
} else {
|
||||
throw new RuntimeException(context.getString(R.string.connection_failed));
|
||||
}
|
||||
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
public static Token getAccessTokenHttps(Context context, OAuth2Config oauthDetails) {
|
||||
HttpsClient httpClient = null;
|
||||
try {
|
||||
httpClient = new HttpsClient(context);
|
||||
httpClient.setAcceptAllCertificate(true);
|
||||
httpClient.setBypassHostnameVerification(true);
|
||||
httpClient.setConnectionTimeout(Global.DEFAULTCONNECTIONTIMEOUT);
|
||||
httpClient.initialize();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
} catch (KeyStoreException e) {
|
||||
e.printStackTrace();
|
||||
} catch (KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
} catch (UnrecoverableKeyException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
String clientId = oauthDetails.getClientId();
|
||||
String clientSecret = oauthDetails.getClientSecret();
|
||||
String scope = oauthDetails.getScope();
|
||||
|
||||
FormEncodingBuilder formEncodingBuilder = new FormEncodingBuilder();
|
||||
formEncodingBuilder.add(OAuthConstants.GRANT_TYPE,
|
||||
oauthDetails.getGrantType());
|
||||
formEncodingBuilder.add(OAuthConstants.USERNAME,
|
||||
oauthDetails.getUsername());
|
||||
formEncodingBuilder.add(OAuthConstants.PASSWORD,
|
||||
oauthDetails.getPassword());
|
||||
if (isValid(clientId)) {
|
||||
formEncodingBuilder.add(OAuthConstants.CLIENT_ID,
|
||||
clientId);
|
||||
}
|
||||
if (isValid(clientSecret)) {
|
||||
formEncodingBuilder.add(OAuthConstants.CLIENT_SECRET, clientSecret);
|
||||
}
|
||||
if (isValid(scope)) {
|
||||
formEncodingBuilder.add(OAuthConstants.SCOPE,
|
||||
scope);
|
||||
}
|
||||
|
||||
RequestBody body = formEncodingBuilder.build();
|
||||
Request.Builder builder = new Request.Builder();
|
||||
builder.url(oauthDetails.getTokenEndPointUrl())
|
||||
.addHeader(HttpConnection.HEADER_CONTENT_TYPE_KEY, HttpConnection.HEADER_CONTENT_TYPE_URL_ENCODED);
|
||||
String loginId = oauthDetails.getUsername();
|
||||
String[] idNtenant = Tool.split(loginId, "@");
|
||||
if (idNtenant.length > 1)
|
||||
builder.addHeader(HEADER_TENANT, idNtenant[1]);
|
||||
builder.post(body);
|
||||
|
||||
Request request = builder.build();
|
||||
|
||||
Response response = null;
|
||||
try {
|
||||
response = httpClient.execute(request);
|
||||
} catch (NetworkOnMainThreadException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Token accessToken = null;
|
||||
if (response != null) {
|
||||
int code = response.code();
|
||||
if (code >= 400) {
|
||||
|
||||
if(response.code() == 500){
|
||||
OauthErrorResponse errorResponse = null;
|
||||
try {
|
||||
errorResponse = GsonHelper.fromJson(response.body().string(), OauthErrorResponse.class);
|
||||
throw new RuntimeException(errorResponse.error_description);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (Global.IS_DEV) Log.i(TAG, "Authorization server expects Basic authentication");
|
||||
// Add Basic Authorization header
|
||||
builder.removeHeader(OAuthConstants.AUTHORIZATION);
|
||||
builder.addHeader(
|
||||
OAuthConstants.AUTHORIZATION,
|
||||
getBasicAuthorizationHeader(oauthDetails.getUsername(),
|
||||
oauthDetails.getPassword()));
|
||||
if (Global.IS_DEV) Log.i(TAG, "Retry with login credentials");
|
||||
|
||||
try {
|
||||
response.body().close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
request = builder.build();
|
||||
try {
|
||||
response = httpClient.execute(request);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
code = response.code();
|
||||
if (code >= 400) {
|
||||
if (Global.IS_DEV) Log.i(TAG, "Retry with client credentials");
|
||||
builder.removeHeader(OAuthConstants.AUTHORIZATION);
|
||||
builder.addHeader(
|
||||
OAuthConstants.AUTHORIZATION,
|
||||
getBasicAuthorizationHeader(
|
||||
oauthDetails.getClientId(),
|
||||
oauthDetails.getClientSecret()));
|
||||
|
||||
try {
|
||||
response.body().close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
request = builder.build();
|
||||
try {
|
||||
response = httpClient.execute(request);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
code = response.code();
|
||||
if (code >= 400) {
|
||||
if (code == OAuthConstants.HTTP_BAD_REQUEST || code == OAuthConstants.HTTP_UNAUTHORIZED) {
|
||||
OauthErrorResponse errorResponse = null;
|
||||
try {
|
||||
errorResponse = GsonHelper.fromJson(response.body().string(), OauthErrorResponse.class);
|
||||
throw new RuntimeException(errorResponse.error_description);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
throw new RuntimeException(
|
||||
"Could not retrieve access token for user: "
|
||||
+ oauthDetails.getUsername());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Response priorResponse = response.priorResponse();
|
||||
if (priorResponse != null && priorResponse.code() != HttpStatus.SC_OK) {
|
||||
throw new RuntimeException(priorResponse.message());
|
||||
}
|
||||
Map<String, ?> map = handleResponse(response);
|
||||
accessToken = new Token(new Long((Integer) map.get(OAuthConstants.EXPIRES_IN)), (String) map.get(OAuthConstants.TOKEN_TYPE), (String) map.get(OAuthConstants.REFRESH_TOKEN), (String) map.get(OAuthConstants.ACCESS_TOKEN));
|
||||
|
||||
} else {
|
||||
throw new RuntimeException(context.getString(R.string.connection_failed));
|
||||
}
|
||||
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
public static Token refreshAccessTokenHttp(WeakReference<Activity> activity, Token token, OAuth2Config oauthDetails) {
|
||||
HttpClient httpClient = new HttpClient();
|
||||
httpClient.setConnectionTimeout(Global.DEFAULTCONNECTIONTIMEOUT);
|
||||
|
||||
String clientId = oauthDetails.getClientId();
|
||||
String clientSecret = oauthDetails.getClientSecret();
|
||||
|
||||
FormEncodingBuilder formEncodingBuilder = new FormEncodingBuilder();
|
||||
formEncodingBuilder.add(OAuthConstants.GRANT_TYPE, "refresh_token");
|
||||
formEncodingBuilder.add(OAuthConstants.REFRESH_TOKEN, token.getRefreshToken());
|
||||
|
||||
if (isValid(clientId)) {
|
||||
formEncodingBuilder.add(OAuthConstants.CLIENT_ID, clientId);
|
||||
}
|
||||
if (isValid(clientSecret)) {
|
||||
formEncodingBuilder.add(OAuthConstants.CLIENT_SECRET, clientSecret);
|
||||
}
|
||||
RequestBody body = formEncodingBuilder.build();
|
||||
Request.Builder builder = new Request.Builder();
|
||||
builder.url(oauthDetails.getTokenEndPointUrl())
|
||||
.addHeader(HttpConnection.HEADER_CONTENT_TYPE_KEY, HttpConnection.HEADER_CONTENT_TYPE_URL_ENCODED);
|
||||
String loginId = oauthDetails.getUsername();
|
||||
String[] idNtenant = Tool.split(loginId, "@");
|
||||
if (idNtenant.length > 1)
|
||||
builder.addHeader(HEADER_TENANT, idNtenant[1]);
|
||||
builder.post(body);
|
||||
|
||||
Request request = builder.build();
|
||||
|
||||
Response response = null;
|
||||
try {
|
||||
response = httpClient.execute(request);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Token accessToken = null;
|
||||
try {
|
||||
int code = response.code();
|
||||
if (code >= 400) {
|
||||
if (Global.IS_DEV) Log.i(TAG, "Retry with client credentials");
|
||||
builder.removeHeader(OAuthConstants.AUTHORIZATION);
|
||||
builder.addHeader(
|
||||
OAuthConstants.AUTHORIZATION,
|
||||
getBasicAuthorizationHeader(
|
||||
oauthDetails.getClientId(),
|
||||
oauthDetails.getClientSecret()));
|
||||
|
||||
try {
|
||||
response.body().close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
request = builder.build();
|
||||
try {
|
||||
response = httpClient.execute(request);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
code = response.code();
|
||||
if (code >= 400) {
|
||||
if (code == OAuthConstants.HTTP_BAD_REQUEST || code == OAuthConstants.HTTP_UNAUTHORIZED) {
|
||||
OauthErrorResponse errorResponse = null;
|
||||
try {
|
||||
errorResponse = GsonHelper.fromJson(response.body().string(), OauthErrorResponse.class);
|
||||
throw new InvalidTokenException(errorResponse.error_description);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
throw new InvalidTokenException(
|
||||
"Could not retrieve access token for user: "
|
||||
+ oauthDetails.getUsername());
|
||||
}
|
||||
}
|
||||
Response priorResponse = response.priorResponse();
|
||||
if (priorResponse != null && priorResponse.code() != HttpStatus.SC_OK) {
|
||||
throw new InvalidTokenException(priorResponse.message());
|
||||
}
|
||||
Map<String, ?> map = handleResponse(response);
|
||||
accessToken = new Token(new Long((Integer) map.get(OAuthConstants.EXPIRES_IN)), (String) map.get(OAuthConstants.TOKEN_TYPE), (String) map.get(OAuthConstants.REFRESH_TOKEN), (String) map.get(OAuthConstants.ACCESS_TOKEN));
|
||||
} catch (InvalidTokenException e) {
|
||||
e.printStackTrace();
|
||||
throw new InvalidTokenException(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(activity.get().getString(R.string.connection_failed));
|
||||
}
|
||||
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
public static Token refreshAccessTokenHttps(WeakReference<Activity> activity, Token token, OAuth2Config oauthDetails) {
|
||||
HttpsClient httpClient = null;
|
||||
try {
|
||||
httpClient = new HttpsClient();
|
||||
httpClient.setAcceptAllCertificate(true);
|
||||
httpClient.setBypassHostnameVerification(true);
|
||||
httpClient.setConnectionTimeout(Global.DEFAULTCONNECTIONTIMEOUT);
|
||||
httpClient.initialize();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
} catch (KeyStoreException e) {
|
||||
e.printStackTrace();
|
||||
} catch (KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
} catch (UnrecoverableKeyException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
String clientId = oauthDetails.getClientId();
|
||||
String clientSecret = oauthDetails.getClientSecret();
|
||||
|
||||
FormEncodingBuilder formEncodingBuilder = new FormEncodingBuilder();
|
||||
formEncodingBuilder.add(OAuthConstants.GRANT_TYPE,
|
||||
"refresh_token");
|
||||
formEncodingBuilder.add(OAuthConstants.REFRESH_TOKEN,
|
||||
token.getRefreshToken());
|
||||
|
||||
if (isValid(clientId)) {
|
||||
formEncodingBuilder.add(OAuthConstants.CLIENT_ID,
|
||||
clientId);
|
||||
}
|
||||
if (isValid(clientSecret)) {
|
||||
formEncodingBuilder.add(OAuthConstants.CLIENT_SECRET, clientSecret);
|
||||
}
|
||||
RequestBody body = formEncodingBuilder.build();
|
||||
Request.Builder builder = new Request.Builder();
|
||||
builder.url(oauthDetails.getTokenEndPointUrl())
|
||||
.addHeader(HttpConnection.HEADER_CONTENT_TYPE_KEY, HttpConnection.HEADER_CONTENT_TYPE_URL_ENCODED);
|
||||
String loginId = oauthDetails.getUsername();
|
||||
String[] idNtenant = Tool.split(loginId, "@");
|
||||
if (idNtenant.length > 1)
|
||||
builder.addHeader(HEADER_TENANT, idNtenant[1]);
|
||||
builder.post(body);
|
||||
|
||||
Request request = builder.build();
|
||||
|
||||
Response response = null;
|
||||
try {
|
||||
response = httpClient.execute(request);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Token accessToken = null;
|
||||
try {
|
||||
int code = response.code();
|
||||
if (code >= 400) {
|
||||
if (Global.IS_DEV) Log.i(TAG, "Retry with client credentials");
|
||||
builder.removeHeader(OAuthConstants.AUTHORIZATION);
|
||||
builder.addHeader(
|
||||
OAuthConstants.AUTHORIZATION,
|
||||
getBasicAuthorizationHeader(
|
||||
oauthDetails.getClientId(),
|
||||
oauthDetails.getClientSecret()));
|
||||
|
||||
try {
|
||||
response.body().close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
request = builder.build();
|
||||
try {
|
||||
response = httpClient.execute(request);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
code = response.code();
|
||||
if (code >= 400) {
|
||||
if (code == OAuthConstants.HTTP_BAD_REQUEST || code == OAuthConstants.HTTP_UNAUTHORIZED) {
|
||||
OauthErrorResponse errorResponse = null;
|
||||
try {
|
||||
errorResponse = GsonHelper.fromJson(response.body().string(), OauthErrorResponse.class);
|
||||
throw new InvalidTokenException(errorResponse.error_description);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
throw new InvalidTokenException(
|
||||
"Could not retrieve access token for user: "
|
||||
+ oauthDetails.getUsername());
|
||||
}
|
||||
}
|
||||
Response priorResponse = response.priorResponse();
|
||||
if (priorResponse != null && priorResponse.code() != HttpStatus.SC_OK) {
|
||||
throw new InvalidTokenException(priorResponse.message());
|
||||
}
|
||||
Map<String, ?> map = handleResponse(response);
|
||||
accessToken = new Token(new Long((Integer) map.get(OAuthConstants.EXPIRES_IN)), (String) map.get(OAuthConstants.TOKEN_TYPE), (String) map.get(OAuthConstants.REFRESH_TOKEN), (String) map.get(OAuthConstants.ACCESS_TOKEN));
|
||||
} catch (InvalidTokenException e) {
|
||||
e.printStackTrace();
|
||||
throw new InvalidTokenException(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(activity.get().getString(R.string.connection_failed));
|
||||
}
|
||||
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
public static Token handleJsonResponseServer(Response response) {
|
||||
String result = null;
|
||||
try {
|
||||
result = response.body().string();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
Token token = GsonHelper.fromJson(result, Token.class);
|
||||
return token;
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Map handleResponse(Response response) {
|
||||
String contentType = OAuthConstants.JSON_CONTENT;
|
||||
if (response.body().contentType() != null) {
|
||||
contentType = response.body().contentType().toString();
|
||||
if (Global.IS_DEV) Log.i(TAG, contentType);
|
||||
|
||||
}
|
||||
if (contentType.contains(OAuthConstants.JSON_CONTENT)) {
|
||||
return handleJsonResponse(response);
|
||||
} else if (contentType.contains(OAuthConstants.XML_CONTENT)) {
|
||||
return handleXMLResponse(response);
|
||||
} else {
|
||||
// Unsupported Content type
|
||||
throw new RuntimeException(
|
||||
"Cannot handle "
|
||||
+ contentType
|
||||
+ " content type. Supported content types include JSON, and XML");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Map handleJsonResponse(Response response) {
|
||||
JSONObject oauthLoginResponse = null;
|
||||
Map<String, Object> outMap = new HashMap<>();
|
||||
try {
|
||||
String result = response.body().string();
|
||||
oauthLoginResponse = new JSONObject(result);
|
||||
} catch (ParseException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (JSONException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
if(oauthLoginResponse == null){
|
||||
return outMap;
|
||||
}
|
||||
|
||||
Iterator<String> keysIterator = oauthLoginResponse.keys();
|
||||
while (keysIterator.hasNext()) {
|
||||
String keyStr = keysIterator.next();
|
||||
Object value = null;
|
||||
try {
|
||||
value = oauthLoginResponse.get(keyStr);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
outMap.put(keyStr, value);
|
||||
if (Global.IS_DEV) Log.i(TAG, String.format(" %s = %s", keyStr, value));
|
||||
}
|
||||
|
||||
return outMap;
|
||||
}
|
||||
|
||||
public static Map<String, String> handleXMLResponse(Response response) {
|
||||
Map<String, String> oauthResponse = new HashMap<>();
|
||||
try {
|
||||
|
||||
String xmlString = response.body().string();
|
||||
boolean decrypt = GlobalData.getSharedGlobalData().isDecrypt();
|
||||
if (decrypt) {
|
||||
xmlString = SAKFormatter.decipherData(xmlString);
|
||||
}
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory
|
||||
.newInstance();
|
||||
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
||||
factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
|
||||
factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
|
||||
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
|
||||
factory.setXIncludeAware(false);
|
||||
factory.setExpandEntityReferences(false);
|
||||
|
||||
DocumentBuilder db = factory.newDocumentBuilder();
|
||||
InputSource inStream = new InputSource();
|
||||
inStream.setCharacterStream(new StringReader(xmlString));
|
||||
Document doc = db.parse(inStream);
|
||||
|
||||
if (Global.IS_DEV) Log.i(TAG, "********** XML Response Received **********");
|
||||
parseXMLDoc(null, doc, oauthResponse);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(
|
||||
"Exception occurred while parsing XML response");
|
||||
}
|
||||
return oauthResponse;
|
||||
}
|
||||
|
||||
public static void parseXMLDoc(Element element, Document doc,
|
||||
Map<String, String> oauthResponse) {
|
||||
NodeList child = null;
|
||||
if (element == null) {
|
||||
child = doc.getChildNodes();
|
||||
|
||||
} else {
|
||||
child = element.getChildNodes();
|
||||
}
|
||||
for (int j = 0; j < child.getLength(); j++) {
|
||||
if (child.item(j).getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
|
||||
Element childElement = (Element) child
|
||||
.item(j);
|
||||
if (childElement.hasChildNodes()) {
|
||||
if (Global.IS_DEV) Log.i(TAG, childElement.getTagName() + " : " + childElement.getTextContent());
|
||||
oauthResponse.put(childElement.getTagName(),
|
||||
childElement.getTextContent());
|
||||
parseXMLDoc(childElement, null, oauthResponse);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getAuthorizationHeaderForAccessToken(String accessToken) {
|
||||
return OAuthConstants.BEARER + " " + accessToken;
|
||||
}
|
||||
|
||||
public static String getBasicAuthorizationHeader(String username,
|
||||
String password) {
|
||||
return OAuthConstants.BASIC + " "
|
||||
+ encodeCredentials(username, password);
|
||||
}
|
||||
|
||||
public static String encodeCredentials(String username, String password) {
|
||||
String cred = username + ":" + password;
|
||||
String encodedValue = null;
|
||||
byte[] encodedBytes = Base64.encode(cred.getBytes(), Base64.NO_WRAP);
|
||||
encodedValue = new String(encodedBytes);
|
||||
if (Global.IS_DEV) Log.i(TAG, "encodedBytes " + new String(encodedBytes));
|
||||
|
||||
byte[] decodedBytes = Base64.decode(encodedBytes, Base64.NO_WRAP);
|
||||
if (Global.IS_DEV) Log.i(TAG, "decodedBytes " + new String(decodedBytes));
|
||||
|
||||
return encodedValue;
|
||||
|
||||
}
|
||||
|
||||
public static boolean isValid(String str) {
|
||||
return (str != null && str.trim().length() > 0);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/dummyChartContent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dummyChartTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="30dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/monthly_point_page_title"
|
||||
android:textSize="20sp"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/dummyChartContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/dummyChartTitle">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dummyyAxisTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/y_axis_point_title"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dummyTotalPoint"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Total : 280"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<com.github.mikephil.charting.charts.BarChart
|
||||
android:id="@+id/dummyMonthlyChart"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="300dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/dummyTotalPoint" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/dummyLegendsContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginTop="20dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/dummyChartContainer">
|
||||
|
||||
<com.adins.mss.coll.loyalti.barchart.NonScrollListView
|
||||
android:id="@+id/dummyLegendPoints"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:dividerHeight="0dp"
|
||||
android:divider="@null"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintWidth_percent="0.65"
|
||||
/>
|
||||
|
||||
<com.adins.mss.coll.loyalti.barchart.NonScrollListView
|
||||
android:id="@+id/dummyLegendRanks"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:dividerHeight="0dp"
|
||||
android:divider="@null"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintWidth_percent="0.35"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -0,0 +1,207 @@
|
|||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in C:\Users\gigin.ginanjar\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the proguardFiles
|
||||
# directive in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
-optimizationpasses 5
|
||||
|
||||
#When not preverifing in a case-insensitive filing system, such as Windows. Because this tool unpacks your processed jars, you should then use:
|
||||
-dontusemixedcaseclassnames
|
||||
|
||||
#Specifies not to ignore non-public library classes. As of version 4.5, this is the default setting
|
||||
-dontskipnonpubliclibraryclasses
|
||||
|
||||
#Preverification is irrelevant for the dex compiler and the Dalvik VM, so we can switch it off with the -dontpreverify option.
|
||||
-dontpreverify
|
||||
|
||||
#Specifies to write out some more information during processing. If the program terminates with an exception, this option will print out the entire stack trace, instead of just the exception message.
|
||||
-verbose
|
||||
|
||||
#The -optimizations option disables some arithmetic simplifications that Dalvik 1.0 and 1.5 can't handle. Note that the Dalvik VM also can't handle aggressive overloading (of static fields).
|
||||
#To understand or change this check http://proguard.sourceforge.net/index.html#/manual/optimizations.html
|
||||
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
|
||||
|
||||
#To repackage classes on a single package
|
||||
-repackageclasses ''
|
||||
|
||||
#Uncomment if using annotations to keep them.
|
||||
-keepattributes *Annotation*, Override
|
||||
-keepattributes Signature
|
||||
-keepattributes EnclosingMethod
|
||||
-keepattributes InnerClasses
|
||||
|
||||
-dontwarn javax.script.**
|
||||
-dontwarn org.apache.commons.logging.**
|
||||
-dontwarn java.beans.**
|
||||
-dontwarn okio.**
|
||||
-dontwarn com.androidquery.auth.TwitterHandle
|
||||
-dontwarn org.bouncycastle.**
|
||||
|
||||
-keep class javax.** {*;}
|
||||
-keep class org.apache.commons.logging.** {*;}
|
||||
-keep class java.beans.** {*;}
|
||||
-keep class org.apache.commons.jexl2.** {*;}
|
||||
-keep class org.bouncycastle.** {*;}
|
||||
-keep class okio.** {*;}
|
||||
-keep class oauth.signpost.** {*;}
|
||||
-keep class org.apache.log4j.Logger {*;}
|
||||
-keep class java.nio.** {*;}
|
||||
-keep class junit..** {*;}
|
||||
-keep class oauth.signpost.commonshttp.** {*;}
|
||||
-keep class net.sqlcipher.** {
|
||||
*;
|
||||
}
|
||||
|
||||
#Keep classes that are referenced on the AndroidManifest
|
||||
-keep public class * extends androidx.appcompat.app.AppCompatActivity
|
||||
-keep public class * extends com.adins.mss.base.MssFragmentActivity
|
||||
-keep public class * extends androidx.fragment.app.Fragment
|
||||
-keep public class * extends androidx.fragment.app.FragmentActivity
|
||||
-keep public class * extends android.app.Activity
|
||||
-keep public class * extends android.app.Application
|
||||
-keep public class * extends android.app.Service
|
||||
-keep public class * extends android.content.BroadcastReceiver
|
||||
-keep public class * extends android.content.ContentProvider
|
||||
-keep public class * extends com.adins.mss.foundation.http.MssRequestType
|
||||
-keep public class * extends com.adins.mss.foundation.http.MssResponseType
|
||||
-keep public class com.android.vending.licensing.ILicensingService
|
||||
-keep class com.adins.**.*Request
|
||||
-keep class com.adins.**.*Response
|
||||
-keep class android.** { *; }
|
||||
-keep class com.google.** { *; }
|
||||
#To remove debug logs:
|
||||
-assumenosideeffects class android.util.Log {
|
||||
public static *** d(...);
|
||||
public static *** v(...);
|
||||
public static *** e(...);
|
||||
public static *** i(...);
|
||||
}
|
||||
|
||||
#To avoid changing names of methods invoked on layoutInflater's onClick.
|
||||
# Uncomment and add specific method names if using onClick on layouts
|
||||
-keepclassmembers class * {
|
||||
public void onClickButton(android.view.View);
|
||||
}
|
||||
|
||||
#Maintain java native methods
|
||||
-keepclasseswithmembernames class * {
|
||||
native <methods>;
|
||||
}
|
||||
|
||||
#To maintain custom components names that are used on layouts XML.
|
||||
#Uncomment if having any problem with the approach below
|
||||
#-keep public class custom.components.package.and.name.**
|
||||
|
||||
#To maintain custom components names that are used on layouts XML:
|
||||
-keep public class * extends android.view.View {
|
||||
public <init>(android.content.Context);
|
||||
public <init>(android.content.Context, android.util.AttributeSet);
|
||||
public <init>(android.content.Context, android.util.AttributeSet, int);
|
||||
public void set*(...);
|
||||
}
|
||||
|
||||
-keepclasseswithmembers class * {
|
||||
public <init>(android.content.Context, android.util.AttributeSet);
|
||||
}
|
||||
|
||||
-keepclasseswithmembers class * {
|
||||
public <init>(android.content.Context, android.util.AttributeSet, int);
|
||||
}
|
||||
|
||||
#Maintain enums
|
||||
-keepclassmembers enum * {
|
||||
public static **[] values();
|
||||
public static ** valueOf(java.lang.String);
|
||||
}
|
||||
|
||||
#To keep parcelable classes (to serialize - deserialize objects to sent through Intents)
|
||||
-keep class * implements android.os.Parcelable {
|
||||
public static final android.os.Parcelable$Creator *;
|
||||
}
|
||||
|
||||
#Keep the R
|
||||
#-keepclassmembers class **.R$* {
|
||||
# public static <fields>;
|
||||
#}
|
||||
|
||||
#Keep Interface
|
||||
-keep interface * {*;}
|
||||
-keep class sun.misc.Unsafe { *; }
|
||||
|
||||
###### ADDITIONAL OPTIONS NOT USED NORMALLY
|
||||
|
||||
#To keep callback calls. Uncomment if using any
|
||||
#http://proguard.sourceforge.net/index.html#/manual/examples.html#callback
|
||||
#-keep class mypackage.MyCallbackClass {
|
||||
# void myCallbackMethod(java.lang.String);
|
||||
#}
|
||||
|
||||
#Uncomment if using Serializable
|
||||
-keepclassmembers class * implements java.io.Serializable {
|
||||
private static final java.io.ObjectStreamField[] serialPersistentFields;
|
||||
private void writeObject(java.io.ObjectOutputStream);
|
||||
private void readObject(java.io.ObjectInputStream);
|
||||
java.lang.Object writeReplace();
|
||||
java.lang.Object readResolve();
|
||||
}
|
||||
|
||||
-keep class * implements java.io.Serializable {
|
||||
public protected <fields>;
|
||||
}
|
||||
|
||||
#Keep fields for Gson transactions
|
||||
-keep public class * extends com.adins.mss.foundation.http.MssRequestType{
|
||||
<fields>;
|
||||
}
|
||||
-keep public class * extends com.adins.mss.foundation.http.MssResponseType{
|
||||
<fields>;
|
||||
}
|
||||
-keep public class * extends com.adins.mss.foundation.http.KeyValue{
|
||||
<fields>;
|
||||
}
|
||||
|
||||
-ignorewarnings
|
||||
|
||||
|
||||
#Keep Class For MSS
|
||||
-keep class com.adins.mss.base.R$* {
|
||||
public static <fields>;
|
||||
}
|
||||
-keep class com.adins.mss.dao.** {*;}
|
||||
-keep class com.adins.mss.constant.** {*;}
|
||||
-keep class com.adins.mss.base.login.DefaultLoginModel
|
||||
-keep public class com.gadberry.** {*;}
|
||||
|
||||
-keep public class com.adins.mss.base.authentication.AuthenticationResultBean{
|
||||
<fields>;
|
||||
}
|
||||
|
||||
-keep public class com.adins.mss.foundation.formatter.DateFormatter{
|
||||
public <methods>;
|
||||
}
|
||||
|
||||
-keep public class com.adins.mss.logger.Logger{
|
||||
public <methods>;
|
||||
}
|
||||
|
||||
-keep class com.androidquery.AQuery {
|
||||
public protected <methods>;
|
||||
public protected <fields>;
|
||||
}
|
||||
|
||||
-keep class com.adins.mss.foundation.security.storepreferences.ObscuredSharedPreferences {*;}
|
||||
|
||||
-keep public class com.adins.mss.foundation.UserHelp.** {*;}
|
|
@ -0,0 +1,26 @@
|
|||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/newTaskLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/bg_grayscale">
|
||||
|
||||
<uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout
|
||||
android:id="@+id/ptr_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginRight="5dp">
|
||||
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:divider="@android:color/transparent"
|
||||
android:dividerHeight="5dp"
|
||||
android:footerDividersEnabled="true"
|
||||
android:headerDividersEnabled="true">
|
||||
</ListView>
|
||||
|
||||
</uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout>
|
||||
|
||||
</RelativeLayout>
|
|
@ -0,0 +1,42 @@
|
|||
package com.adins.mss.foundation.print;
|
||||
|
||||
import com.adins.mss.dao.PrintDate;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
/**
|
||||
* Created by angga.permadi on 3/10/2016.
|
||||
*/
|
||||
public class SubmitPrintEntity {
|
||||
private String dtm_print;
|
||||
private String uuid_task_h;
|
||||
|
||||
public SubmitPrintEntity() {
|
||||
|
||||
}
|
||||
|
||||
public SubmitPrintEntity(PrintDate task) {
|
||||
this(new SimpleDateFormat("ddMMyyyyHHmmss").format(task.getDtm_print()), task.getUuid_task_h());
|
||||
}
|
||||
|
||||
public SubmitPrintEntity(String dtm_print, String uuid_task_h) {
|
||||
this.dtm_print = dtm_print;
|
||||
this.uuid_task_h = uuid_task_h;
|
||||
}
|
||||
|
||||
public String getDtm_print() {
|
||||
return dtm_print;
|
||||
}
|
||||
|
||||
public void setDtm_print(String dtm_print) {
|
||||
this.dtm_print = dtm_print;
|
||||
}
|
||||
|
||||
public String getUuid_task_h() {
|
||||
return uuid_task_h;
|
||||
}
|
||||
|
||||
public void setUuid_task_h(String uuid_task_h) {
|
||||
this.uuid_task_h = uuid_task_h;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,314 @@
|
|||
/*
|
||||
* This class was copied from this Stackoverflow Q&A:
|
||||
* http://stackoverflow.com/questions/2253061/secure-http-post-in-android/2253280#2253280
|
||||
* Thanks go to MattC!
|
||||
*/
|
||||
package org.acra.util;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.acra.ACRA;
|
||||
import org.acra.sender.HttpSender.Method;
|
||||
import org.acra.sender.HttpSender.Type;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.StatusLine;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.HttpRequestRetryHandler;
|
||||
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.apache.http.client.params.ClientPNames;
|
||||
import org.apache.http.client.params.CookiePolicy;
|
||||
import org.apache.http.conn.ClientConnectionManager;
|
||||
import org.apache.http.conn.scheme.PlainSocketFactory;
|
||||
import org.apache.http.conn.scheme.Scheme;
|
||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
import org.apache.http.conn.scheme.SocketFactory;
|
||||
import org.apache.http.conn.ssl.SSLSocketFactory;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.auth.BasicScheme;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.impl.conn.SingleClientConnManager;
|
||||
import org.apache.http.params.BasicHttpParams;
|
||||
import org.apache.http.params.HttpConnectionParams;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.protocol.BasicHttpContext;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.UnrecoverableKeyException;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.acra.ACRA.LOG_TAG;
|
||||
|
||||
public final class HttpRequest {
|
||||
|
||||
private String login;
|
||||
private String password;
|
||||
private int connectionTimeOut = 3000;
|
||||
private int socketTimeOut = 3000;
|
||||
private int maxNrRetries = 3;
|
||||
private Map<String, String> headers;
|
||||
|
||||
/**
|
||||
* Converts a Map of parameters into a URL encoded Sting.
|
||||
*
|
||||
* @param parameters Map of parameters to convert.
|
||||
* @return URL encoded String representing the parameters.
|
||||
* @throws UnsupportedEncodingException if one of the parameters couldn't be converted to UTF-8.
|
||||
*/
|
||||
public static String getParamsAsFormString(Map<?, ?> parameters) throws UnsupportedEncodingException {
|
||||
|
||||
final StringBuilder dataBfr = new StringBuilder();
|
||||
for (final Object key : parameters.keySet()) {
|
||||
if (dataBfr.length() != 0) {
|
||||
dataBfr.append('&');
|
||||
}
|
||||
final Object preliminaryValue = parameters.get(key);
|
||||
final Object value = (preliminaryValue == null) ? "" : preliminaryValue;
|
||||
dataBfr.append(URLEncoder.encode(key.toString(), "UTF-8"));
|
||||
dataBfr.append('=');
|
||||
dataBfr.append(URLEncoder.encode(value.toString(), "UTF-8"));
|
||||
}
|
||||
|
||||
return dataBfr.toString();
|
||||
}
|
||||
|
||||
public void setLogin(String login) {
|
||||
this.login = login;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public void setConnectionTimeOut(int connectionTimeOut) {
|
||||
this.connectionTimeOut = connectionTimeOut;
|
||||
}
|
||||
|
||||
public void setSocketTimeOut(int socketTimeOut) {
|
||||
this.socketTimeOut = socketTimeOut;
|
||||
}
|
||||
|
||||
public void setHeaders(Map<String, String> headers) {
|
||||
this.headers = headers;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The default number of retries is 3.
|
||||
*
|
||||
* @param maxNrRetries Max number of times to retry Request on failure due to
|
||||
* SocketTimeOutException.
|
||||
*/
|
||||
public void setMaxNrRetries(int maxNrRetries) {
|
||||
this.maxNrRetries = maxNrRetries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Posts to a URL.
|
||||
*
|
||||
* @param context Android context for which to create the SocketFactory.
|
||||
* @param url URL to which to post.
|
||||
* @param content Map of parameters to post to a URL.
|
||||
* @throws IOException if the data cannot be posted.
|
||||
*/
|
||||
public void send(Context context, URL url, Method method, String content, Type type) throws IOException {
|
||||
|
||||
final HttpClient httpClient = getHttpClient(context);
|
||||
final HttpEntityEnclosingRequestBase httpRequest = getHttpRequest(url, method, content, type);
|
||||
|
||||
ACRA.log.d(LOG_TAG, "Sending request to " + url);
|
||||
if (ACRA.DEV_LOGGING)
|
||||
ACRA.log.d(LOG_TAG, "Http " + method.name() + " content : ");
|
||||
if (ACRA.DEV_LOGGING)
|
||||
ACRA.log.d(LOG_TAG, content);
|
||||
|
||||
HttpResponse response = null;
|
||||
try {
|
||||
response = httpClient.execute(httpRequest, new BasicHttpContext());
|
||||
if (response != null) {
|
||||
final StatusLine statusLine = response.getStatusLine();
|
||||
if (statusLine != null) {
|
||||
final String statusCode = Integer.toString(response.getStatusLine().getStatusCode());
|
||||
|
||||
if (!statusCode.equals("409") // 409 return code means that the
|
||||
// report has been received
|
||||
// already. So we can discard it.
|
||||
&& !statusCode.equals("403") // a 403 error code is an explicit data validation refusal
|
||||
// from the server. The request must not be repeated.
|
||||
// Discard it.
|
||||
&& (statusCode.startsWith("4") || statusCode.startsWith("5"))) {
|
||||
if (ACRA.DEV_LOGGING) {
|
||||
ACRA.log.d(LOG_TAG, "Could not send HttpPost : " + httpRequest);
|
||||
ACRA.log.d(LOG_TAG, "HttpResponse Status : "
|
||||
+ (statusLine != null ? statusLine.getStatusCode() : "NoStatusLine#noCode"));
|
||||
final String respContent = EntityUtils.toString(response.getEntity());
|
||||
ACRA.log.d(LOG_TAG,
|
||||
"HttpResponse Content : " + respContent.substring(0, Math.min(respContent.length(), 200)));
|
||||
}
|
||||
throw new IOException("Host returned error code " + statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
if (ACRA.DEV_LOGGING)
|
||||
ACRA.log.d(LOG_TAG, "HttpResponse Status : "
|
||||
+ (statusLine != null ? statusLine.getStatusCode() : "NoStatusLine#noCode"));
|
||||
final String respContent = EntityUtils.toString(response.getEntity());
|
||||
if (ACRA.DEV_LOGGING)
|
||||
ACRA.log.d(LOG_TAG,
|
||||
"HttpResponse Content : " + respContent.substring(0, Math.min(respContent.length(), 200)));
|
||||
|
||||
} else {
|
||||
if (ACRA.DEV_LOGGING)
|
||||
ACRA.log.d(LOG_TAG, "HTTP no Response!!");
|
||||
}
|
||||
} finally {
|
||||
if (response != null) {
|
||||
response.getEntity().consumeContent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HttpClient to use with this HttpRequest.
|
||||
*/
|
||||
private HttpClient getHttpClient(Context context) {
|
||||
final HttpParams httpParams = new BasicHttpParams();
|
||||
httpParams.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.RFC_2109);
|
||||
HttpConnectionParams.setConnectionTimeout(httpParams, connectionTimeOut);
|
||||
HttpConnectionParams.setSoTimeout(httpParams, socketTimeOut);
|
||||
HttpConnectionParams.setSocketBufferSize(httpParams, 8192);
|
||||
|
||||
final SchemeRegistry registry = new SchemeRegistry();
|
||||
registry.register(new Scheme("http", new PlainSocketFactory(), 80));
|
||||
if (ACRA.getConfig().disableSSLCertValidation()) {
|
||||
registry.register(new Scheme("https", (new FakeSocketFactory()), 443));
|
||||
} else if (ACRA.getConfig().keyStore() != null) {
|
||||
try {
|
||||
SSLSocketFactory sf = new SSLSocketFactory(ACRA.getConfig().keyStore());
|
||||
sf.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
|
||||
registry.register(new Scheme("https", sf, 443));
|
||||
} catch (KeyManagementException e) {
|
||||
registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
|
||||
} catch (UnrecoverableKeyException e) {
|
||||
registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
|
||||
} catch (KeyStoreException e) {
|
||||
registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
|
||||
}
|
||||
} else {
|
||||
final HttpsSocketFactoryFactory factory = ACRA.getConfig().getHttpSocketFactoryFactory();
|
||||
final SocketFactory socketFactory = factory.create(context);
|
||||
registry.register(new Scheme("https", socketFactory, 443));
|
||||
}
|
||||
|
||||
final ClientConnectionManager clientConnectionManager = new SingleClientConnManager(httpParams, registry);
|
||||
final DefaultHttpClient httpClient = new DefaultHttpClient(clientConnectionManager, httpParams);
|
||||
|
||||
final HttpRequestRetryHandler retryHandler = new SocketTimeOutRetryHandler(httpParams, maxNrRetries);
|
||||
httpClient.setHttpRequestRetryHandler(retryHandler);
|
||||
|
||||
return httpClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Credentials to use with this HttpRequest or null if no
|
||||
* credentials were supplied.
|
||||
*/
|
||||
private UsernamePasswordCredentials getCredentials() {
|
||||
if (login != null || password != null) {
|
||||
return new UsernamePasswordCredentials(login, password);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private HttpEntityEnclosingRequestBase getHttpRequest(URL url, Method method, String content, Type type)
|
||||
throws UnsupportedEncodingException, UnsupportedOperationException {
|
||||
|
||||
final HttpEntityEnclosingRequestBase httpRequest;
|
||||
switch (method) {
|
||||
case POST:
|
||||
httpRequest = new HttpPost(url.toString());
|
||||
break;
|
||||
case PUT:
|
||||
httpRequest = new HttpPut(url.toString());
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unknown method: " + method.name());
|
||||
}
|
||||
|
||||
final UsernamePasswordCredentials creds = getCredentials();
|
||||
if (creds != null) {
|
||||
httpRequest.addHeader(BasicScheme.authenticate(creds, "UTF-8", false));
|
||||
}
|
||||
httpRequest.setHeader("User-Agent", "Android");
|
||||
httpRequest
|
||||
.setHeader("Accept",
|
||||
"text/html,application/xml,application/json,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
|
||||
httpRequest.setHeader("Content-Type", type.getContentType());
|
||||
|
||||
if (headers != null) {
|
||||
for (final String header : headers.keySet()) {
|
||||
final String value = headers.get(header);
|
||||
httpRequest.setHeader(header, value);
|
||||
}
|
||||
}
|
||||
|
||||
httpRequest.setEntity(new StringEntity(content, "UTF-8"));
|
||||
|
||||
return httpRequest;
|
||||
}
|
||||
|
||||
private static class SocketTimeOutRetryHandler implements HttpRequestRetryHandler {
|
||||
|
||||
private final HttpParams httpParams;
|
||||
private final int maxNrRetries;
|
||||
|
||||
/**
|
||||
* @param httpParams HttpParams that will be used in the HttpRequest.
|
||||
* @param maxNrRetries Max number of times to retry Request on failure due to
|
||||
* SocketTimeOutException.
|
||||
*/
|
||||
private SocketTimeOutRetryHandler(HttpParams httpParams, int maxNrRetries) {
|
||||
this.httpParams = httpParams;
|
||||
this.maxNrRetries = maxNrRetries;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
|
||||
if (exception instanceof SocketTimeoutException) {
|
||||
if (executionCount <= maxNrRetries) {
|
||||
|
||||
if (httpParams != null) {
|
||||
final int newSocketTimeOut = HttpConnectionParams.getSoTimeout(httpParams) * 2;
|
||||
HttpConnectionParams.setSoTimeout(httpParams, newSocketTimeOut);
|
||||
ACRA.log.d(LOG_TAG, "SocketTimeOut - increasing time out to " + newSocketTimeOut
|
||||
+ " millis and trying again");
|
||||
} else {
|
||||
ACRA.log.d(LOG_TAG,
|
||||
"SocketTimeOut - no HttpParams, cannot increase time out. Trying again with current settings");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
ACRA.log.d(LOG_TAG, "SocketTimeOut but exceeded max number of retries : " + maxNrRetries);
|
||||
}
|
||||
|
||||
return false; // To change body of implemented methods use File |
|
||||
// Settings | File Templates.
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,477 @@
|
|||
package com.adins.mss.dao;
|
||||
|
||||
import java.util.List;
|
||||
import com.adins.mss.dao.DaoSession;
|
||||
import de.greenrobot.dao.DaoException;
|
||||
|
||||
import com.adins.mss.base.util.ExcludeFromGson;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit.
|
||||
/**
|
||||
* Entity mapped to table "TR_TIMELINE".
|
||||
*/
|
||||
public class Timeline {
|
||||
|
||||
/** Not-null value. */
|
||||
@SerializedName("uuid_timeline")
|
||||
private String uuid_timeline;
|
||||
@SerializedName("description")
|
||||
private String description;
|
||||
@SerializedName("latitude")
|
||||
private String latitude;
|
||||
@SerializedName("longitude")
|
||||
private String longitude;
|
||||
@SerializedName("dtm_crt_server")
|
||||
private java.util.Date dtm_crt_server;
|
||||
@SerializedName("name")
|
||||
private String name;
|
||||
@SerializedName("address")
|
||||
private String address;
|
||||
@SerializedName("agreement_no")
|
||||
private String agreement_no;
|
||||
@SerializedName("amount_due")
|
||||
private String amount_due;
|
||||
@SerializedName("overdue")
|
||||
private String overdue;
|
||||
@SerializedName("installment_no")
|
||||
private String installment_no;
|
||||
@SerializedName("attd_address")
|
||||
private String attd_address;
|
||||
@SerializedName("priority")
|
||||
private String priority;
|
||||
@SerializedName("isVerificationTask")
|
||||
private String isVerificationTask;
|
||||
@SerializedName("collResult")
|
||||
private String collResult;
|
||||
@SerializedName("account_name")
|
||||
private String account_name;
|
||||
@SerializedName("product_name")
|
||||
private String product_name;
|
||||
@SerializedName("status_code")
|
||||
private String status_code;
|
||||
@SerializedName("usr_crt")
|
||||
private String usr_crt;
|
||||
@SerializedName("dtm_crt")
|
||||
private java.util.Date dtm_crt;
|
||||
@SerializedName("uuid_task_h")
|
||||
private String uuid_task_h;
|
||||
@SerializedName("uuid_user")
|
||||
private String uuid_user;
|
||||
@SerializedName("uuid_timeline_type")
|
||||
private String uuid_timeline_type;
|
||||
@SerializedName("uuid_message")
|
||||
private String uuid_message;
|
||||
@SerializedName("byte_image")
|
||||
private byte[] byte_image;
|
||||
|
||||
/** Used to resolve relations */
|
||||
private transient DaoSession daoSession;
|
||||
|
||||
/** Used for active entity operations. */
|
||||
private transient TimelineDao myDao;
|
||||
|
||||
private User user;
|
||||
private String user__resolvedKey;
|
||||
|
||||
private TimelineType timelineType;
|
||||
private String timelineType__resolvedKey;
|
||||
|
||||
private Message message;
|
||||
private String message__resolvedKey;
|
||||
|
||||
private TaskH taskH;
|
||||
private String taskH__resolvedKey;
|
||||
|
||||
private List<Comment> commentList;
|
||||
|
||||
public Timeline() {
|
||||
}
|
||||
|
||||
public Timeline(String uuid_timeline) {
|
||||
this.uuid_timeline = uuid_timeline;
|
||||
}
|
||||
|
||||
public Timeline(String uuid_timeline, String description, String latitude, String longitude, java.util.Date dtm_crt_server, String name, String address, String agreement_no, String amount_due, String overdue, String installment_no, String attd_address, String priority, String isVerificationTask, String collResult, String account_name, String product_name, String status_code, String usr_crt, java.util.Date dtm_crt, String uuid_task_h, String uuid_user, String uuid_timeline_type, String uuid_message, byte[] byte_image) {
|
||||
this.uuid_timeline = uuid_timeline;
|
||||
this.description = description;
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
this.dtm_crt_server = dtm_crt_server;
|
||||
this.name = name;
|
||||
this.address = address;
|
||||
this.agreement_no = agreement_no;
|
||||
this.amount_due = amount_due;
|
||||
this.overdue = overdue;
|
||||
this.installment_no = installment_no;
|
||||
this.attd_address = attd_address;
|
||||
this.priority = priority;
|
||||
this.isVerificationTask = isVerificationTask;
|
||||
this.collResult = collResult;
|
||||
this.account_name = account_name;
|
||||
this.product_name = product_name;
|
||||
this.status_code = status_code;
|
||||
this.usr_crt = usr_crt;
|
||||
this.dtm_crt = dtm_crt;
|
||||
this.uuid_task_h = uuid_task_h;
|
||||
this.uuid_user = uuid_user;
|
||||
this.uuid_timeline_type = uuid_timeline_type;
|
||||
this.uuid_message = uuid_message;
|
||||
this.byte_image = byte_image;
|
||||
}
|
||||
|
||||
/** called by internal mechanisms, do not call yourself. */
|
||||
public void __setDaoSession(DaoSession daoSession) {
|
||||
this.daoSession = daoSession;
|
||||
myDao = daoSession != null ? daoSession.getTimelineDao() : null;
|
||||
}
|
||||
|
||||
/** Not-null value. */
|
||||
public String getUuid_timeline() {
|
||||
return uuid_timeline;
|
||||
}
|
||||
|
||||
/** Not-null value; ensure this value is available before it is saved to the database. */
|
||||
public void setUuid_timeline(String uuid_timeline) {
|
||||
this.uuid_timeline = uuid_timeline;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public void setLatitude(String latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
public String getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public void setLongitude(String longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
public java.util.Date getDtm_crt_server() {
|
||||
return dtm_crt_server;
|
||||
}
|
||||
|
||||
public void setDtm_crt_server(java.util.Date dtm_crt_server) {
|
||||
this.dtm_crt_server = dtm_crt_server;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getAgreement_no() {
|
||||
return agreement_no;
|
||||
}
|
||||
|
||||
public void setAgreement_no(String agreement_no) {
|
||||
this.agreement_no = agreement_no;
|
||||
}
|
||||
|
||||
public String getAmount_due() {
|
||||
return amount_due;
|
||||
}
|
||||
|
||||
public void setAmount_due(String amount_due) {
|
||||
this.amount_due = amount_due;
|
||||
}
|
||||
|
||||
public String getOverdue() {
|
||||
return overdue;
|
||||
}
|
||||
|
||||
public void setOverdue(String overdue) {
|
||||
this.overdue = overdue;
|
||||
}
|
||||
|
||||
public String getInstallment_no() {
|
||||
return installment_no;
|
||||
}
|
||||
|
||||
public void setInstallment_no(String installment_no) {
|
||||
this.installment_no = installment_no;
|
||||
}
|
||||
|
||||
public String getAttd_address() {
|
||||
return attd_address;
|
||||
}
|
||||
|
||||
public void setAttd_address(String attd_address) {
|
||||
this.attd_address = attd_address;
|
||||
}
|
||||
|
||||
public String getPriority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
public void setPriority(String priority) {
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
public String getIsVerificationTask() {
|
||||
return isVerificationTask;
|
||||
}
|
||||
|
||||
public void setIsVerificationTask(String isVerificationTask) {
|
||||
this.isVerificationTask = isVerificationTask;
|
||||
}
|
||||
|
||||
public String getCollResult() {
|
||||
return collResult;
|
||||
}
|
||||
|
||||
public void setCollResult(String collResult) {
|
||||
this.collResult = collResult;
|
||||
}
|
||||
|
||||
public String getAccount_name() {
|
||||
return account_name;
|
||||
}
|
||||
|
||||
public void setAccount_name(String account_name) {
|
||||
this.account_name = account_name;
|
||||
}
|
||||
|
||||
public String getProduct_name() {
|
||||
return product_name;
|
||||
}
|
||||
|
||||
public void setProduct_name(String product_name) {
|
||||
this.product_name = product_name;
|
||||
}
|
||||
|
||||
public String getStatus_code() {
|
||||
return status_code;
|
||||
}
|
||||
|
||||
public void setStatus_code(String status_code) {
|
||||
this.status_code = status_code;
|
||||
}
|
||||
|
||||
public String getUsr_crt() {
|
||||
return usr_crt;
|
||||
}
|
||||
|
||||
public void setUsr_crt(String usr_crt) {
|
||||
this.usr_crt = usr_crt;
|
||||
}
|
||||
|
||||
public java.util.Date getDtm_crt() {
|
||||
return dtm_crt;
|
||||
}
|
||||
|
||||
public void setDtm_crt(java.util.Date dtm_crt) {
|
||||
this.dtm_crt = dtm_crt;
|
||||
}
|
||||
|
||||
public String getUuid_task_h() {
|
||||
return uuid_task_h;
|
||||
}
|
||||
|
||||
public void setUuid_task_h(String uuid_task_h) {
|
||||
this.uuid_task_h = uuid_task_h;
|
||||
}
|
||||
|
||||
public String getUuid_user() {
|
||||
return uuid_user;
|
||||
}
|
||||
|
||||
public void setUuid_user(String uuid_user) {
|
||||
this.uuid_user = uuid_user;
|
||||
}
|
||||
|
||||
public String getUuid_timeline_type() {
|
||||
return uuid_timeline_type;
|
||||
}
|
||||
|
||||
public void setUuid_timeline_type(String uuid_timeline_type) {
|
||||
this.uuid_timeline_type = uuid_timeline_type;
|
||||
}
|
||||
|
||||
public String getUuid_message() {
|
||||
return uuid_message;
|
||||
}
|
||||
|
||||
public void setUuid_message(String uuid_message) {
|
||||
this.uuid_message = uuid_message;
|
||||
}
|
||||
|
||||
public byte[] getByte_image() {
|
||||
return byte_image;
|
||||
}
|
||||
|
||||
public void setByte_image(byte[] byte_image) {
|
||||
this.byte_image = byte_image;
|
||||
}
|
||||
|
||||
/** To-one relationship, resolved on first access. */
|
||||
public User getUser() {
|
||||
String __key = this.uuid_user;
|
||||
if (user__resolvedKey == null || user__resolvedKey != __key) {
|
||||
if (daoSession == null) {
|
||||
throw new DaoException("Entity is detached from DAO context");
|
||||
}
|
||||
UserDao targetDao = daoSession.getUserDao();
|
||||
User userNew = targetDao.load(__key);
|
||||
synchronized (this) {
|
||||
user = userNew;
|
||||
user__resolvedKey = __key;
|
||||
}
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
synchronized (this) {
|
||||
this.user = user;
|
||||
uuid_user = user == null ? null : user.getUuid_user();
|
||||
user__resolvedKey = uuid_user;
|
||||
}
|
||||
}
|
||||
|
||||
/** To-one relationship, resolved on first access. */
|
||||
public TimelineType getTimelineType() {
|
||||
String __key = this.uuid_timeline_type;
|
||||
if (timelineType__resolvedKey == null || timelineType__resolvedKey != __key) {
|
||||
if (daoSession == null) {
|
||||
throw new DaoException("Entity is detached from DAO context");
|
||||
}
|
||||
TimelineTypeDao targetDao = daoSession.getTimelineTypeDao();
|
||||
TimelineType timelineTypeNew = targetDao.load(__key);
|
||||
synchronized (this) {
|
||||
timelineType = timelineTypeNew;
|
||||
timelineType__resolvedKey = __key;
|
||||
}
|
||||
}
|
||||
return timelineType;
|
||||
}
|
||||
|
||||
public void setTimelineType(TimelineType timelineType) {
|
||||
synchronized (this) {
|
||||
this.timelineType = timelineType;
|
||||
uuid_timeline_type = timelineType == null ? null : timelineType.getUuid_timeline_type();
|
||||
timelineType__resolvedKey = uuid_timeline_type;
|
||||
}
|
||||
}
|
||||
|
||||
/** To-one relationship, resolved on first access. */
|
||||
public Message getMessage() {
|
||||
String __key = this.uuid_message;
|
||||
if (message__resolvedKey == null || message__resolvedKey != __key) {
|
||||
if (daoSession == null) {
|
||||
throw new DaoException("Entity is detached from DAO context");
|
||||
}
|
||||
MessageDao targetDao = daoSession.getMessageDao();
|
||||
Message messageNew = targetDao.load(__key);
|
||||
synchronized (this) {
|
||||
message = messageNew;
|
||||
message__resolvedKey = __key;
|
||||
}
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(Message message) {
|
||||
synchronized (this) {
|
||||
this.message = message;
|
||||
uuid_message = message == null ? null : message.getUuid_message();
|
||||
message__resolvedKey = uuid_message;
|
||||
}
|
||||
}
|
||||
|
||||
/** To-one relationship, resolved on first access. */
|
||||
public TaskH getTaskH() {
|
||||
String __key = this.uuid_task_h;
|
||||
if (taskH__resolvedKey == null || taskH__resolvedKey != __key) {
|
||||
if (daoSession == null) {
|
||||
throw new DaoException("Entity is detached from DAO context");
|
||||
}
|
||||
TaskHDao targetDao = daoSession.getTaskHDao();
|
||||
TaskH taskHNew = targetDao.load(__key);
|
||||
synchronized (this) {
|
||||
taskH = taskHNew;
|
||||
taskH__resolvedKey = __key;
|
||||
}
|
||||
}
|
||||
return taskH;
|
||||
}
|
||||
|
||||
public void setTaskH(TaskH taskH) {
|
||||
synchronized (this) {
|
||||
this.taskH = taskH;
|
||||
uuid_task_h = taskH == null ? null : taskH.getUuid_task_h();
|
||||
taskH__resolvedKey = uuid_task_h;
|
||||
}
|
||||
}
|
||||
|
||||
/** To-many relationship, resolved on first access (and after reset). Changes to to-many relations are not persisted, make changes to the target entity. */
|
||||
public List<Comment> getCommentList() {
|
||||
if (commentList == null) {
|
||||
if (daoSession == null) {
|
||||
throw new DaoException("Entity is detached from DAO context");
|
||||
}
|
||||
CommentDao targetDao = daoSession.getCommentDao();
|
||||
List<Comment> commentListNew = targetDao._queryTimeline_CommentList(uuid_timeline);
|
||||
synchronized (this) {
|
||||
if(commentList == null) {
|
||||
commentList = commentListNew;
|
||||
}
|
||||
}
|
||||
}
|
||||
return commentList;
|
||||
}
|
||||
|
||||
/** Resets a to-many relationship, making the next get call to query for a fresh result. */
|
||||
public synchronized void resetCommentList() {
|
||||
commentList = null;
|
||||
}
|
||||
|
||||
/** Convenient call for {@link AbstractDao#delete(Object)}. Entity must attached to an entity context. */
|
||||
public void delete() {
|
||||
if (myDao == null) {
|
||||
throw new DaoException("Entity is detached from DAO context");
|
||||
}
|
||||
myDao.delete(this);
|
||||
}
|
||||
|
||||
/** Convenient call for {@link AbstractDao#update(Object)}. Entity must attached to an entity context. */
|
||||
public void update() {
|
||||
if (myDao == null) {
|
||||
throw new DaoException("Entity is detached from DAO context");
|
||||
}
|
||||
myDao.update(this);
|
||||
}
|
||||
|
||||
/** Convenient call for {@link AbstractDao#refresh(Object)}. Entity must attached to an entity context. */
|
||||
public void refresh() {
|
||||
if (myDao == null) {
|
||||
throw new DaoException("Entity is detached from DAO context");
|
||||
}
|
||||
myDao.refresh(this);
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 6.2 KiB |
|
@ -0,0 +1,134 @@
|
|||
package com.adins.mss.odr.catalogue.api;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.os.AsyncTask;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.adins.mss.base.GlobalData;
|
||||
import com.adins.mss.base.util.GsonHelper;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.dao.MobileContentD;
|
||||
import com.adins.mss.dao.MobileContentH;
|
||||
import com.adins.mss.foundation.db.dataaccess.MobileContentDDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.MobileContentHDataAccess;
|
||||
import com.adins.mss.foundation.dialog.NiftyDialogBuilder;
|
||||
import com.adins.mss.foundation.formatter.Tool;
|
||||
import com.adins.mss.foundation.http.HttpConnectionResult;
|
||||
import com.adins.mss.foundation.http.HttpCryptedConnection;
|
||||
import com.adins.mss.foundation.http.MssRequestType;
|
||||
import com.adins.mss.foundation.image.Utils;
|
||||
import com.adins.mss.odr.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by olivia.dg on 11/28/2017.
|
||||
*/
|
||||
|
||||
public class GetPromo extends AsyncTask<Void, Void, List<PromoCatalogBean>> {
|
||||
private FragmentActivity activity;
|
||||
private ProgressDialog progressDialog;
|
||||
private String errMessage;
|
||||
private List<PromoCatalogBean> result = new ArrayList<PromoCatalogBean>();
|
||||
|
||||
public GetPromo(FragmentActivity activity) {
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
progressDialog = ProgressDialog.show(activity, "", activity.getString(R.string.contact_server), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<PromoCatalogBean> doInBackground(Void... params) {
|
||||
if (Tool.isInternetconnected(activity)) {
|
||||
MssRequestType request = new MssRequestType();
|
||||
request.setAudit(GlobalData.getSharedGlobalData().getAuditData());
|
||||
|
||||
String json = GsonHelper.toJson(request);
|
||||
|
||||
String url = GlobalData.getSharedGlobalData().getURL_GET_CATALOGUE_PROMO();
|
||||
boolean encrypt = GlobalData.getSharedGlobalData().isEncrypt();
|
||||
boolean decrypt = GlobalData.getSharedGlobalData().isDecrypt();
|
||||
HttpCryptedConnection httpConn = new HttpCryptedConnection(activity, encrypt, decrypt);
|
||||
HttpConnectionResult serverResult = null;
|
||||
try {
|
||||
serverResult = httpConn.requestToServer(url, json, Global.DEFAULTCONNECTIONTIMEOUT);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
GetPromoResponse response = null;
|
||||
if (serverResult != null && serverResult.isOK()) {
|
||||
try {
|
||||
String responseBody = serverResult.getResult();
|
||||
response = GsonHelper.fromJson(responseBody, GetPromoResponse.class);
|
||||
} catch (Exception e) {
|
||||
if(Global.IS_DEV) {
|
||||
e.printStackTrace();
|
||||
errMessage = e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
List<PromoCatalogBean> list = response.getListImage();
|
||||
if (list != null && list.size() != 0) {
|
||||
MobileContentDDataAccess.clean(activity);
|
||||
MobileContentHDataAccess.clean(activity);
|
||||
result = list;
|
||||
for (PromoCatalogBean bean : result) {
|
||||
String uuid = bean.getUuidMobileContentD();
|
||||
byte[] img = Utils.base64ToByte(bean.getContent());
|
||||
|
||||
MobileContentH tempHeader = new MobileContentH();
|
||||
tempHeader.setUuid_mobile_content_h(bean.getUuidMobileContentH());
|
||||
tempHeader.setContent_name(bean.getContentName());
|
||||
tempHeader.setContent_description(bean.getContentDescription());
|
||||
tempHeader.setUuid_user(GlobalData.getSharedGlobalData().getUser().getUuid_user());
|
||||
MobileContentHDataAccess.addOrReplace(activity, tempHeader);
|
||||
|
||||
MobileContentD tempData = new MobileContentD();
|
||||
tempData.setUuid_mobile_content_d(uuid);
|
||||
tempData.setContent(img);
|
||||
tempData.setUuid_mobile_content_h(bean.getUuidMobileContentH());
|
||||
MobileContentDDataAccess.addOrReplace(activity, tempData);
|
||||
}
|
||||
} else {
|
||||
errMessage = activity.getString(R.string.no_data_from_server);
|
||||
}
|
||||
} else {
|
||||
errMessage = activity.getString(R.string.server_down);
|
||||
}
|
||||
} else {
|
||||
errMessage = activity.getString(R.string.no_internet_connection);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<PromoCatalogBean> result) {
|
||||
super.onPostExecute(result);
|
||||
|
||||
if (progressDialog != null && progressDialog.isShowing()) {
|
||||
progressDialog.dismiss();
|
||||
}
|
||||
|
||||
if (errMessage != null) {
|
||||
if (errMessage.equals(activity.getString(R.string.no_data_from_server))) {
|
||||
NiftyDialogBuilder builder = NiftyDialogBuilder.getInstance(activity);
|
||||
builder.withTitle("INFO")
|
||||
.withMessage(errMessage)
|
||||
.show();
|
||||
} else {
|
||||
Toast.makeText(activity, errMessage, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
GetCatalogue task = new GetCatalogue(activity);
|
||||
task.execute();
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue