mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-06-30 21:04:16 +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,772 @@
|
|||
package com.adins.mss.base.authentication;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.adins.mss.base.AppContext;
|
||||
import com.adins.mss.base.GlobalData;
|
||||
import com.adins.mss.base.NewMainActivity;
|
||||
import com.adins.mss.base.R;
|
||||
import com.adins.mss.base.crashlytics.FireCrash;
|
||||
import com.adins.mss.base.dynamictheme.DynamicTheme;
|
||||
import com.adins.mss.base.dynamictheme.ThemeLoader;
|
||||
import com.adins.mss.base.timeline.TimelineManager;
|
||||
import com.adins.mss.base.util.GenericAsyncTask;
|
||||
import com.adins.mss.base.util.GenericAsyncTask.GenericTaskInterface;
|
||||
import com.adins.mss.base.util.GsonHelper;
|
||||
import com.adins.mss.base.util.LocaleHelper;
|
||||
import com.adins.mss.base.util.UserSession;
|
||||
import com.adins.mss.base.util.Utility;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.dao.GeneralParameter;
|
||||
import com.adins.mss.dao.Menu;
|
||||
import com.adins.mss.dao.Timeline;
|
||||
import com.adins.mss.dao.User;
|
||||
import com.adins.mss.foundation.UserHelp.UserHelp;
|
||||
import com.adins.mss.foundation.db.dataaccess.GeneralParameterDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.MenuDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.TimelineDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.UserDataAccess;
|
||||
import com.adins.mss.foundation.formatter.Formatter;
|
||||
import com.adins.mss.foundation.formatter.Tool;
|
||||
import com.adins.mss.foundation.http.AuditDataType;
|
||||
import com.adins.mss.foundation.http.AuditDataTypeGenerator;
|
||||
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.http.MssResponseType;
|
||||
import com.adins.mss.foundation.http.MssResponseType.Status;
|
||||
import com.adins.mss.foundation.security.storepreferences.ObscuredSharedPreferences;
|
||||
import com.google.firebase.perf.FirebasePerformance;
|
||||
import com.google.firebase.perf.metrics.HttpMetric;
|
||||
|
||||
import org.acra.ACRA;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p> Used to authenticate user, using HttpCryptedConnection to send user credential to server, and receive server response
|
||||
*
|
||||
* @author glen.iglesias
|
||||
*/
|
||||
public class Authentication implements GenericTaskInterface {
|
||||
|
||||
public static final String LOGIN_PREFERENCES = "login_preferences";
|
||||
public static final String LOGIN_PREFERENCES_APPLICATION_CLEANSING = "login_preferences.APPLICATION_CLEANSING";
|
||||
public static final String SHARED_PREF = "sharedPreferencesAuthentication";
|
||||
public static final String SHARED_PREF_KEY_FRESH_INSTALL = "sharedPreferencesKey_freshInstall";
|
||||
public static final String SHARED_PREF_KEY_DB_SAVED = "sharedPreferencesKey_dbsaved";
|
||||
private static final int LOGIN_SUCCESS = 1;
|
||||
private static final int FORCE_UPDATE = 2;
|
||||
private static final int FORCE_CLEANSING = 3;
|
||||
private static final int LOGIN_FAIL = 0;
|
||||
private static final String TASK_OBJ_KEY_CONN = "task_object_key_connection";
|
||||
private static final String TASK_OBJ_KEY_URL = "task_object_key_url";
|
||||
private static final String TASK_OBJ_KEY_JSON = "task_object_key_json";
|
||||
private static final String TASK_OBJ_KEY_DELEGATE = "task_object_key_delegate";
|
||||
private static final String TASK_OBJ_KEY_CONTEXT = "task_object_key_context";
|
||||
private static final String TASK_OBJ_KEY_RESULT = "task_object_key_result";
|
||||
private static final String TASK_OBJ_KEY_BUILD_NUMBER = "task_object_key_build_number";
|
||||
private static final String TASK_OBJ_KEY_LOGIN_ID = "task_object_key_login_id";
|
||||
//Debug
|
||||
public static boolean enableSimulatedResult = false;
|
||||
public static int simulatedResult = 1;
|
||||
protected static String temp_loginID;
|
||||
protected static String temp_password;
|
||||
private String url;
|
||||
private AuthenticationHandler handler;
|
||||
private boolean encrypt;
|
||||
private boolean decrypt;
|
||||
|
||||
/**
|
||||
* Default constructor. Will fetch data from GlobalData if any
|
||||
*/
|
||||
public Authentication() {
|
||||
GlobalData globData = GlobalData.getSharedGlobalData();
|
||||
url = globData.getURL_LOGIN();
|
||||
encrypt = globData.isEncrypt();
|
||||
decrypt = globData.isDecrypt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send user credential over HTTP to server. Will replace stored AuditDataType in GlobalData with newly
|
||||
* generated one. Will also store successfully logged in user data in GlobalData
|
||||
* <br>Connection will run on async task
|
||||
*
|
||||
* @param context
|
||||
* @param url target URL
|
||||
* @param username username to be authenticated
|
||||
* @param password password to be authenticated
|
||||
* @param encrypt flag to encrypt sent data to server
|
||||
* @param decrypt flag to decrypt server response message
|
||||
*/
|
||||
public static void authenticateOnBackground(Context context, String url, String username, String password, boolean encrypt, boolean decrypt, int buildNumber, AuthenticationHandler handler) {
|
||||
|
||||
Map<String, String> listImei = AuditDataTypeGenerator.getListImeiFromDevice(context);
|
||||
GlobalData.getSharedGlobalData().setImei(listImei.get(MssRequestType.UN_KEY_IMEI));
|
||||
if (listImei.get(MssRequestType.UN_KEY_IMEI2) != null) {
|
||||
GlobalData.getSharedGlobalData().setImei2(listImei.get(MssRequestType.UN_KEY_IMEI2));
|
||||
}
|
||||
|
||||
//generate and store new AuditDataType
|
||||
String language = LocaleHelper.getLanguage(context);
|
||||
LocaleHelper.setLocale(context,language);
|
||||
GlobalData.getSharedGlobalData().setLocale(language);
|
||||
|
||||
AuditDataType auditDataType = AuditDataTypeGenerator.generateAuditDataType(username);
|
||||
storeAuditData(auditDataType);
|
||||
|
||||
//freshInstall
|
||||
boolean needUpdateVersion = UserSession.needUpdateVersion();
|
||||
boolean isFresh = isFreshInstall(context);
|
||||
boolean isFreshInstall = needUpdateVersion || isFresh;
|
||||
|
||||
HttpCryptedConnection httpConn = new HttpCryptedConnection(context, encrypt, decrypt);
|
||||
|
||||
temp_loginID = username;
|
||||
temp_password = password;
|
||||
String json = getStringForSending(username, password, isFreshInstall);
|
||||
if (Global.IS_DEV)
|
||||
System.out.println(json);
|
||||
|
||||
//use asynctask instead
|
||||
HashMap<String, Object> params = new HashMap<>();
|
||||
params.put(TASK_OBJ_KEY_CONN, httpConn);
|
||||
params.put(TASK_OBJ_KEY_URL, url);
|
||||
params.put(TASK_OBJ_KEY_JSON, json);
|
||||
params.put(TASK_OBJ_KEY_DELEGATE, handler);
|
||||
params.put(TASK_OBJ_KEY_CONTEXT, context);
|
||||
params.put(TASK_OBJ_KEY_BUILD_NUMBER, buildNumber);
|
||||
params.put(TASK_OBJ_KEY_LOGIN_ID, username);
|
||||
|
||||
GenericAsyncTask task = new GenericAsyncTask(new Authentication());
|
||||
task.setAdditionalObject(params);
|
||||
task.execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send user credential over HTTP to server using GlobalData settings, like url, encryption, and decryption
|
||||
* <br>Connection will run on async task
|
||||
*
|
||||
* @param username username to be authenticated
|
||||
* @param password password to be authenticated
|
||||
*/
|
||||
public static void authenticateOnBackground(Context context, String username, String password, int buildNumber, AuthenticationHandler handler) {
|
||||
GlobalData globData = GlobalData.getSharedGlobalData();
|
||||
|
||||
String url = globData.getURL_LOGIN();
|
||||
boolean enc = globData.isEncrypt();
|
||||
boolean dec = globData.isDecrypt();
|
||||
|
||||
authenticateOnBackground(context, url, username, password, enc, dec, buildNumber, handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define a way to interpret server response and translate into AuthenticationResultBean
|
||||
* <p>Should you choose a different way, override this method
|
||||
*
|
||||
* @param result a string received from server
|
||||
* @return an AuthenticationResultBean as standard result
|
||||
*/
|
||||
protected static AuthenticationResultBean mapResultToBean(String result, String login_id_tenant) {
|
||||
//Default, treat result as JSON with format of LoginUserResponse
|
||||
LoginUserResponse responseBean;
|
||||
try {
|
||||
responseBean = GsonHelper.fromJson(result, LoginUserResponse.class);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
if (Global.IS_DEV)
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
Status resultStatus = responseBean.getStatus();
|
||||
|
||||
List<GeneralParameter> generalParameterss = responseBean.getListGeneralParameter();
|
||||
|
||||
//add tenant id to general parameters
|
||||
GeneralParameter gP = new GeneralParameter();
|
||||
if (!generalParameterss.isEmpty()) {
|
||||
gP.setUuid_general_parameter(Tool.getUUID());
|
||||
gP.setGs_code(Global.GS_TENANT_ID);
|
||||
gP.setGs_value(login_id_tenant);
|
||||
generalParameterss.add(0, gP);
|
||||
}
|
||||
|
||||
|
||||
//20 Jan 2015, adapt to backend system
|
||||
AuthenticationResultBean resultBean = new AuthenticationResultBean();
|
||||
|
||||
if (resultStatus.getCode() == 0) { //success login
|
||||
User user = responseBean.getUser();
|
||||
|
||||
resultBean.setActiveUser(true);
|
||||
String loginGenParam = getGeneralParameter(Global.GS_VERS_LOGIN, generalParameterss);
|
||||
if(loginGenParam != null && loginGenParam.equals("1")){
|
||||
resultBean.setForceUpdate(true);
|
||||
}
|
||||
resultBean.setGeneralParameters(responseBean.getListGeneralParameter());
|
||||
resultBean.setListMenu(responseBean.getListMenu());
|
||||
resultBean.setLastUpdateVersion(getGeneralParameter(Global.GS_BUILD_NUMBER, generalParameterss));
|
||||
resultBean.setLoginResult(LOGIN_SUCCESS);
|
||||
resultBean.setNeedUpdatePassword(user.getChg_pwd().equals(Global.TRUE_STRING));
|
||||
resultBean.setOtaLink(getGeneralParameter(Global.GS_URL_DOWNLOAD, generalParameterss));
|
||||
resultBean.setUserInfo(user);
|
||||
} else { //login failed
|
||||
resultBean.setLoginResult(LOGIN_FAIL);
|
||||
resultBean.setMessage(resultStatus.getMessage());
|
||||
}
|
||||
return resultBean;
|
||||
}
|
||||
|
||||
private static String getGeneralParameter(String name, List<GeneralParameter> generalParameterss) {
|
||||
for (GeneralParameter param : generalParameterss) {
|
||||
if (param.getGs_code().equals(name)) {
|
||||
return param.getGs_value();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to implement different method of storing AuditData
|
||||
*
|
||||
* @param auditData
|
||||
*/
|
||||
protected static void storeAuditData(AuditDataType auditData) {
|
||||
GlobalData.getSharedGlobalData().setAuditData(auditData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this method to provide other format of String to send to server
|
||||
* <p>Default is using AuthenticationModel as the format
|
||||
*
|
||||
* @param username username the user input
|
||||
* @param password password the user input
|
||||
* @param isFreshInstall true if this application never had any user login yet
|
||||
* @return string of data (JSON or not) to send to server
|
||||
* @see MssRequestType
|
||||
*/
|
||||
protected static String getStringForSending(String username, String password, boolean isFreshInstall) {
|
||||
//Initiate audit data
|
||||
AuditDataType audit = AuditDataTypeGenerator.generateActiveUserAuditData();
|
||||
GlobalData.getSharedGlobalData().setAuditData(audit);
|
||||
|
||||
String strFlagFreshInstall = isFreshInstall ? "1" : "0";
|
||||
|
||||
//Create LoginUserRequest
|
||||
LoginUserRequest data = new LoginUserRequest();
|
||||
data.setAudit(audit);
|
||||
data.setUsername(username);
|
||||
data.setPassword(password);
|
||||
data.setFlagFreshInstall(strFlagFreshInstall);
|
||||
data.setFcmTokenId(Global.Token);
|
||||
|
||||
//GlobalData.imei were set from method authenticate
|
||||
data.addImeiAndroidIdToUnstructured();
|
||||
|
||||
String json = Formatter.getJsonFromObject(data);
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set as no longer a fresh install to application preferences. On next call to authenticate(), method would give
|
||||
* false to isFreshInstall
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
public static void setAsNonFreshInstall(Context context) {
|
||||
ObscuredSharedPreferences pref = ObscuredSharedPreferences.getPrefs(context, SHARED_PREF, Context.MODE_PRIVATE);
|
||||
pref.edit().putString(SHARED_PREF_KEY_FRESH_INSTALL, "false").apply();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set as a fresh install to application preferences. On next call to authenticate(), method would give
|
||||
* true to isFreshInstall
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
public static void setAsFreshInstall(Context context) {
|
||||
ObscuredSharedPreferences pref = ObscuredSharedPreferences.getPrefs(context, SHARED_PREF, Context.MODE_PRIVATE);
|
||||
pref.edit().putString(SHARED_PREF_KEY_FRESH_INSTALL, "true").apply();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method to check if application is first-time running after installation and has device's IMEI not registered yet
|
||||
* based on whether the sharedPreference exist or not.
|
||||
* <p/>
|
||||
* Override this method to implement other method of determining if it's a fresh install
|
||||
*
|
||||
* @param context
|
||||
* @return true if it is a fresh install application, false if it is not
|
||||
*/
|
||||
public static boolean isFreshInstall(Context context) {
|
||||
ObscuredSharedPreferences pref = ObscuredSharedPreferences.getPrefs(context, SHARED_PREF, Context.MODE_PRIVATE);
|
||||
String isFreshInstall = pref.getString(SHARED_PREF_KEY_FRESH_INSTALL, "true"); //if no preference exist, meaning it's a new install
|
||||
return Boolean.parseBoolean(isFreshInstall);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this method and pass parameters object to save it to database
|
||||
* <p/>
|
||||
* <p>Override this method to change how application save the parameters
|
||||
*/
|
||||
protected static void saveServerParameters(Context context, List<GeneralParameter> generalParameters) {
|
||||
|
||||
|
||||
for (GeneralParameter gp : generalParameters) {
|
||||
String temp_uuid_user = gp.getUuid_user();
|
||||
User user = UserDataAccess.getOne(context, temp_uuid_user);
|
||||
gp.setUser(user);
|
||||
GeneralParameterDataAccess.addOrReplace(context, gp);
|
||||
}
|
||||
|
||||
//save to GlobalData
|
||||
GlobalData.getSharedGlobalData().loadGeneralParameters(generalParameters);
|
||||
}
|
||||
|
||||
protected static void saveUserInfo(Context context, User authenticatedUser) {
|
||||
String temp_uuid_user = authenticatedUser.getUuid_user();
|
||||
User user = UserDataAccess.getOne(context, temp_uuid_user);
|
||||
if (user != null) {
|
||||
user.setLogin_id(temp_loginID);
|
||||
user.setPassword(temp_password);
|
||||
if (Global.IS_LOGIN) {
|
||||
user.setBranch_name(authenticatedUser.getBranch_name());
|
||||
Global.IS_LOGIN = false;
|
||||
}
|
||||
|
||||
//olivia : update jam start dan end tracking
|
||||
user.setIs_tracking(authenticatedUser.getIs_tracking());
|
||||
if (authenticatedUser.getIs_tracking() != null && authenticatedUser.getIs_tracking().equals("1")) {
|
||||
user.setStart_time(authenticatedUser.getStart_time());
|
||||
user.setEnd_time(authenticatedUser.getEnd_time());
|
||||
}
|
||||
if(authenticatedUser.getTracking_days() != null && !authenticatedUser.getTracking_days().equals("")){
|
||||
user.setTracking_days(authenticatedUser.getTracking_days());
|
||||
}
|
||||
|
||||
user.setCash_on_hand(authenticatedUser.getCash_on_hand());
|
||||
user.setCash_limit(authenticatedUser.getCash_limit());
|
||||
|
||||
UserDataAccess.addOrReplace(context, user);
|
||||
// save to GlobalData
|
||||
GlobalData.getSharedGlobalData().setUser(user);
|
||||
Global.user = user;
|
||||
} else {
|
||||
authenticatedUser.setLogin_id(temp_loginID);
|
||||
authenticatedUser.setPassword(temp_password);
|
||||
UserDataAccess.addOrReplace(context, authenticatedUser);
|
||||
// save to GlobalData
|
||||
GlobalData.getSharedGlobalData().setUser(authenticatedUser);
|
||||
Global.user = authenticatedUser;
|
||||
}
|
||||
}
|
||||
|
||||
protected static void saveMenu(Context context, List<Menu> listMenu) {
|
||||
for (Menu menu : listMenu) {
|
||||
String temp_uuid_user = menu.getUuid_user();
|
||||
User user = UserDataAccess.getOne(context, temp_uuid_user);
|
||||
menu.setUser(user);
|
||||
MenuDataAccess.addOrReplace(context, menu);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void updateTimeline(Context context) {
|
||||
// 2017/10/09 | olivia : hapus timeline yang sudah lebih dari range di general parameter
|
||||
int range = GlobalData.getSharedGlobalData().getKeepTimelineInDays();
|
||||
List<Timeline> timelines = TimelineManager.getAllTimeline(context);
|
||||
for (Timeline timeline : timelines) {
|
||||
if (timeline.getDtm_crt().before(Tool.getIncrementDate(-range)))
|
||||
TimelineDataAccess.delete(context, timeline);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send user credential over HTTP to server
|
||||
* <br>Will run connection on background thread
|
||||
*
|
||||
* @param context
|
||||
* @param username
|
||||
* @param password
|
||||
*/
|
||||
public void authenticateOnBackground(Context context, String username, String password, int buildNumber) {
|
||||
authenticateOnBackground(context, url, username, password, encrypt, decrypt, buildNumber, handler);
|
||||
}
|
||||
|
||||
//=== Generic Task Interface Callbacks ===//
|
||||
|
||||
@Override
|
||||
public void onPreExecute(GenericAsyncTask task) {
|
||||
Log.d("Log","OnPreExecute");//must override this
|
||||
}
|
||||
|
||||
@Override
|
||||
public String doInBackground(GenericAsyncTask task, String... args) {
|
||||
|
||||
HttpCryptedConnection httpConn = (HttpCryptedConnection) task.getAdditionalObject().get(TASK_OBJ_KEY_CONN);
|
||||
String json = (String) task.getAdditionalObject().get(TASK_OBJ_KEY_JSON);
|
||||
String url = (String) task.getAdditionalObject().get(TASK_OBJ_KEY_URL);
|
||||
HttpConnectionResult result = null;
|
||||
|
||||
//Firebase Performance Trace HTTP Request
|
||||
HttpMetric networkMetric =
|
||||
FirebasePerformance.getInstance().newHttpMetric(url, FirebasePerformance.HttpMethod.POST);
|
||||
Utility.metricStart(networkMetric, json);
|
||||
|
||||
try {
|
||||
result = httpConn.requestToServer(url, json, Global.DEFAULTCONNECTIONTIMEOUT);
|
||||
Utility.metricStop(networkMetric, result);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
if (Global.IS_DEV)
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (result != null) task.getAdditionalObject().put(TASK_OBJ_KEY_RESULT, result);
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPostExecute(GenericAsyncTask task, String result,
|
||||
String errMsg) {
|
||||
|
||||
HttpConnectionResult connResult = (HttpConnectionResult) task.getAdditionalObject().get(TASK_OBJ_KEY_RESULT);
|
||||
AuthenticationHandler handler = (AuthenticationHandler) task.getAdditionalObject().get(TASK_OBJ_KEY_DELEGATE);
|
||||
Context context = (Context) task.getAdditionalObject().get(TASK_OBJ_KEY_CONTEXT);
|
||||
String loginId = (String) task.getAdditionalObject().get(TASK_OBJ_KEY_LOGIN_ID);
|
||||
|
||||
if (handler != null) {
|
||||
if (connResult != null && connResult.isOK()) {
|
||||
//success
|
||||
|
||||
//convert to bean
|
||||
AuthenticationResultBean authResultBean = mapResultToBean(connResult.getResult(), loginId);
|
||||
|
||||
//bong 30 mar 15 - penjagaan jika belum log in di router tapi sudah dapat ip
|
||||
try {
|
||||
if (authResultBean == null) {
|
||||
String error = context.getString(R.string.request_error) + ".\n" + context.getString(R.string.connection_failed_wifi);
|
||||
connResult.setResult(error);
|
||||
handler.onConnectionFail(null, connResult);
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
if (Global.IS_DEV)
|
||||
e.printStackTrace();
|
||||
handler.onConnectionFail(null, connResult);
|
||||
return;
|
||||
}
|
||||
|
||||
MssResponseType responseFromServer = GsonHelper.fromJson(connResult.getResult(), MssResponseType.class);
|
||||
|
||||
if (responseFromServer.getStatus().getCode() == Global.STATUS_CODE_APPL_CLEANSING) {
|
||||
NewMainActivity.Force_Uninstall = true;
|
||||
handler.onInactiveUser(null);
|
||||
|
||||
ObscuredSharedPreferences.Editor editor = ObscuredSharedPreferences.getPrefs(context, LOGIN_PREFERENCES, Context.MODE_PRIVATE).edit();
|
||||
editor.putString(LOGIN_PREFERENCES_APPLICATION_CLEANSING, "uninstall");
|
||||
editor.apply();
|
||||
return;
|
||||
} else {
|
||||
try {
|
||||
ObscuredSharedPreferences.Editor editor = ObscuredSharedPreferences.getPrefs(context, LOGIN_PREFERENCES, Context.MODE_PRIVATE).edit();
|
||||
editor.remove(LOGIN_PREFERENCES_APPLICATION_CLEANSING);
|
||||
editor.apply();
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String message = authResultBean.getMessage();
|
||||
String otaLink = authResultBean.getOtaLink();
|
||||
|
||||
//get login status
|
||||
int status = 0;
|
||||
status = authResultBean.getLoginResult();
|
||||
|
||||
//debug
|
||||
if (enableSimulatedResult) {
|
||||
status = simulatedResult;
|
||||
}
|
||||
|
||||
if (status != LOGIN_FAIL) { //Login authorized
|
||||
boolean needUpdatePassword = authResultBean.needUpdatePassword();
|
||||
boolean pwdExp = "1".equals(authResultBean.getUserInfo().getPwd_exp());
|
||||
boolean forceUpdate = authResultBean.isForceUpdate();
|
||||
boolean isActiveUser = authResultBean.isActiveUser();
|
||||
List<GeneralParameter> generalParameters = authResultBean.getGeneralParameters();
|
||||
List<Menu> listMenu = authResultBean.getListMenu();
|
||||
User authenticatedUser = authResultBean.getUserInfo();
|
||||
|
||||
// bong - 30 jan 15 need set uuid_user to general parameter
|
||||
for (GeneralParameter generalParameter : generalParameters) {
|
||||
if (generalParameter.getUuid_user() == null || "".equals(generalParameter.getUuid_user()))
|
||||
generalParameter.setUuid_user(authResultBean.getUserInfo().getUuid_user());
|
||||
}
|
||||
|
||||
for (Menu menu : listMenu) {
|
||||
if (menu.getUuid_user() == null || "".equals(menu.getUuid_user()))
|
||||
menu.setUuid_user(authResultBean.getUserInfo().getUuid_user());
|
||||
}
|
||||
|
||||
boolean softUpdate = false;
|
||||
|
||||
String listVersion = authResultBean.getLastUpdateVersion();
|
||||
String[] versions = Tool.split(listVersion, Global.DELIMETER_DATA);
|
||||
String thisVersion = Tool.split(Global.APP_VERSION, "-")[0];
|
||||
String lastVersionFromServer = null;
|
||||
for (int i = 0; i < versions.length; i++) {
|
||||
lastVersionFromServer = versions[i];
|
||||
if (thisVersion.equals(lastVersionFromServer)) {
|
||||
softUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!softUpdate) {
|
||||
forceUpdate = true;
|
||||
} else {
|
||||
if (thisVersion.equals(lastVersionFromServer))
|
||||
softUpdate = false;
|
||||
}
|
||||
|
||||
GeneralParameterDataAccess.clean(context);
|
||||
MenuDataAccess.clean(context);
|
||||
|
||||
saveUserInfo(context, authenticatedUser);
|
||||
saveServerParameters(context, generalParameters);
|
||||
saveMenu(context, listMenu);
|
||||
|
||||
updateTimeline(context);
|
||||
|
||||
//GIGIN ~ SAVE USER INFO TO ACRA
|
||||
ACRA.getErrorReporter().putCustomData("UUID_USER", GlobalData.getSharedGlobalData().getUser().getUuid_user());
|
||||
ACRA.getErrorReporter().putCustomData("LOGIN_ID", GlobalData.getSharedGlobalData().getUser().getLogin_id());
|
||||
ACRA.getErrorReporter().putCustomData("JOB_DESCRIPTION", GlobalData.getSharedGlobalData().getUser().getJob_description());
|
||||
ACRA.getErrorReporter().putCustomData("BRANCH_NAME", GlobalData.getSharedGlobalData().getUser().getBranch_name());
|
||||
ACRA.getErrorReporter().putCustomData("TENANT_ID", GlobalData.getSharedGlobalData().getTenant());
|
||||
|
||||
// bong 11 march 15 - stored callerId in audit
|
||||
GlobalData.getSharedGlobalData().getAuditData().setCallerId(authResultBean.getUserInfo().getUuid_user());
|
||||
if (!isActiveUser) {
|
||||
status = FORCE_CLEANSING;
|
||||
} else if (forceUpdate /*&& latestVersion > buildNumber*/) {
|
||||
status = FORCE_UPDATE;
|
||||
}
|
||||
|
||||
//proceed with status
|
||||
if (status == LOGIN_SUCCESS) {
|
||||
//Set as non fresh install
|
||||
setAsNonFreshInstall(context);
|
||||
|
||||
// simpan app version ketika sukses auth
|
||||
UserSession.setAppVersion(AppContext.getInstance().getVersionCode());
|
||||
|
||||
//Store successfully logged in user's data to GlobalData
|
||||
authenticatedUser.setLogin_id(temp_loginID);
|
||||
authenticatedUser.setPassword(temp_password);
|
||||
String temp_uuid_user = authenticatedUser.getUuid_user();
|
||||
User user = UserDataAccess.getOne(context, temp_uuid_user);
|
||||
if (user != null) {
|
||||
user.setLogin_id(temp_loginID);
|
||||
user.setPassword(temp_password);
|
||||
GlobalData.getSharedGlobalData().setUser(user);
|
||||
} else {
|
||||
GlobalData.getSharedGlobalData().setUser(authenticatedUser);
|
||||
}
|
||||
checkIsEnableLoyalty(generalParameters);
|
||||
if(Global.ENABLE_USER_HELP) {
|
||||
fetchUserHelp(context, generalParameters);
|
||||
}
|
||||
//load theme
|
||||
fetchTheme(context,generalParameters,handler,null, otaLink,
|
||||
needUpdatePassword, pwdExp, softUpdate,
|
||||
message, GlobalData.getSharedGlobalData().getUser());
|
||||
|
||||
} else if (status == FORCE_UPDATE) {
|
||||
handler.onForceUpdate(null, message, otaLink);
|
||||
} else if (status == FORCE_CLEANSING) {
|
||||
handler.onInactiveUser(null);
|
||||
}
|
||||
} else { //login unauthorized
|
||||
handler.onLoginFail(null, message);
|
||||
}
|
||||
|
||||
} else { //fail
|
||||
handler.onConnectionFail(null, connResult);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void fetchTheme(Context context, List<GeneralParameter> generalParameters,
|
||||
final AuthenticationHandler handler, final Authentication auth, final String otaLink,
|
||||
final boolean needUpdatePassword, final boolean pwdExp,
|
||||
final boolean softUpdate, final String message, final User user) {
|
||||
String themeConfigUrl = null;
|
||||
if(GlobalData.getSharedGlobalData().getApplication().equalsIgnoreCase(Global.APPLICATION_SURVEY)){
|
||||
themeConfigUrl = getGeneralParameter(Global.GS_THEME_CONFIG_SURVEY,generalParameters);
|
||||
}
|
||||
else if(GlobalData.getSharedGlobalData().getApplication().equalsIgnoreCase(Global.APPLICATION_COLLECTION)){
|
||||
themeConfigUrl = getGeneralParameter(Global.GS_THEME_CONFIG_COLLECTION,generalParameters);
|
||||
}
|
||||
else if(GlobalData.getSharedGlobalData().getApplication().equalsIgnoreCase(Global.APPLICATION_ORDER)){
|
||||
themeConfigUrl = getGeneralParameter(Global.GS_THEME_CONFIG_ORDER,generalParameters);
|
||||
}
|
||||
ThemeLoader themeLoader = new ThemeLoader(context);
|
||||
themeLoader.loadThemeFromUrl(themeConfigUrl, new ThemeLoader.ColorSetLoaderCallback() {
|
||||
@Override
|
||||
public void onHasLoaded(DynamicTheme dynamicTheme) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHasLoaded(DynamicTheme dynamicTheme, boolean needUpdate) {
|
||||
handler.onLoginSuccess(auth, otaLink, needUpdatePassword, pwdExp, softUpdate, message, user);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void fetchUserHelp(Context context, List<GeneralParameter> generalParameters){
|
||||
String userHelpUrl = null;
|
||||
String commonUserHelpUrl = getGeneralParameter(Global.GS_COMMON_USERHELP_LINK, generalParameters);
|
||||
if(GlobalData.getSharedGlobalData().getApplication().equalsIgnoreCase(Global.APPLICATION_SURVEY)){
|
||||
userHelpUrl = getGeneralParameter(Global.GS_MS_USERHELP_LINK,generalParameters);
|
||||
}
|
||||
else if(GlobalData.getSharedGlobalData().getApplication().equalsIgnoreCase(Global.APPLICATION_COLLECTION)){
|
||||
userHelpUrl = getGeneralParameter(Global.GS_MC_USERHELP_LINK,generalParameters);
|
||||
}
|
||||
else if(GlobalData.getSharedGlobalData().getApplication().equalsIgnoreCase(Global.APPLICATION_ORDER)){
|
||||
userHelpUrl = getGeneralParameter(Global.GS_MO_USERHELP_LINK,generalParameters);
|
||||
}
|
||||
UserHelp.initializeUserHelp(context, commonUserHelpUrl, userHelpUrl);
|
||||
}
|
||||
|
||||
private void checkIsEnableLoyalty(List<GeneralParameter> generalParameters){
|
||||
String gsCode = null;
|
||||
String svyJob = null;
|
||||
if(GlobalData.getSharedGlobalData().getApplication().equalsIgnoreCase(Global.APPLICATION_SURVEY)){
|
||||
gsCode = Global.GS_MS_LOYALTY_ENABLED;
|
||||
svyJob = getGeneralParameter("MS_JOBSVY",generalParameters);
|
||||
}
|
||||
else if(GlobalData.getSharedGlobalData().getApplication().equalsIgnoreCase(Global.APPLICATION_COLLECTION)){
|
||||
gsCode = Global.GS_MC_LOYALTY_ENABLED;
|
||||
}
|
||||
String value = getGeneralParameter(gsCode,generalParameters);
|
||||
if(value == null){
|
||||
Global.LOYALTI_ENABLED = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if(value.equals("1")){
|
||||
Global.LOYALTI_ENABLED = true;
|
||||
if(svyJob != null && !svyJob.isEmpty()){
|
||||
svyJob = svyJob.trim();
|
||||
String[] svyJobParts = svyJob.split(";");
|
||||
Global.SLA_LOYALTI_JOB = svyJobParts[0].split(",");
|
||||
}
|
||||
}
|
||||
else {
|
||||
Global.LOYALTI_ENABLED = false;
|
||||
}
|
||||
}
|
||||
|
||||
//=== Setter and Getter ===//
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public AuthenticationHandler getHandler() {
|
||||
return handler;
|
||||
}
|
||||
|
||||
public void setHandler(AuthenticationHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public boolean isEncrypt() {
|
||||
return encrypt;
|
||||
}
|
||||
|
||||
public void setEncrypt(boolean encrypt) {
|
||||
this.encrypt = encrypt;
|
||||
}
|
||||
|
||||
public boolean isDecrypt() {
|
||||
return decrypt;
|
||||
}
|
||||
|
||||
public void setDecrypt(boolean decrypt) {
|
||||
this.decrypt = decrypt;
|
||||
}
|
||||
|
||||
public static String getTemp_loginID() {
|
||||
return temp_loginID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback interface to handle authentication result. When authentication is done, user info need to be registered
|
||||
* to GlobalData manually
|
||||
*
|
||||
* @author glen.iglesias
|
||||
*/
|
||||
public interface AuthenticationHandler {
|
||||
|
||||
/**
|
||||
* Called when connection fail
|
||||
*
|
||||
* @param auth
|
||||
* @param result HttpConnectionResult containing error code and reason phrase
|
||||
*/
|
||||
void onConnectionFail(Authentication auth, HttpConnectionResult result);
|
||||
|
||||
/**
|
||||
* Called when server reject credential sent by application
|
||||
*
|
||||
* @param auth
|
||||
* @param message message returned by the server
|
||||
*/
|
||||
void onLoginFail(Authentication auth, String message);
|
||||
|
||||
/**
|
||||
* Called when server force application update
|
||||
*
|
||||
* @param auth
|
||||
* @param message message returned by the server
|
||||
* @param otaLink OTA link to download update
|
||||
*/
|
||||
void onForceUpdate(Authentication auth, String message, String otaLink);
|
||||
|
||||
/**
|
||||
* Called when server report sent credential belong to inactive user
|
||||
*
|
||||
* @param auth
|
||||
*/
|
||||
void onInactiveUser(Authentication auth);
|
||||
|
||||
/**
|
||||
* Called when server has successfully authenticate credential.
|
||||
* Authenticated user need to be registered to GlobalData manually
|
||||
*
|
||||
* @param auth
|
||||
* @param otaLink OTA link to download update, or null if no update needed
|
||||
* @param needUpdatePassword flag if password change is needed
|
||||
* @param message message returned by the server
|
||||
* @param authenticatedUser user info which successfully authenticated with server
|
||||
*/
|
||||
void onLoginSuccess(Authentication auth, String otaLink, boolean needUpdatePassword, boolean pwdExp, boolean needUpdateApplication, String message, User authenticatedUser);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,215 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/bgColor">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?android:attr/actionBarSize"
|
||||
app:titleTextAppearance="?android:attr/textAppearanceSmall"
|
||||
android:titleTextColor="@color/fontColorWhite"
|
||||
android:background="@drawable/header" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/toolbar"
|
||||
android:orientation="vertical"
|
||||
android:layout_above="@id/buttonContainer">
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/depositReportContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:cardCornerRadius="10dp"
|
||||
app:contentPadding="7dp"
|
||||
app:cardElevation="@dimen/card_shadow"
|
||||
android:layout_margin="@dimen/card_margin"
|
||||
app:cardBackgroundColor="@color/fontColorWhite">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/selectAction"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/gradient_end"
|
||||
android:paddingBottom="10dp"/>
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<androidx.appcompat.widget.AppCompatSpinner
|
||||
android:id="@+id/spinnerAction"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="5dp"
|
||||
android:spinnerMode="dropdown"
|
||||
android:background="@drawable/dropdown_background"
|
||||
android:padding="5dp"/>
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_expand"
|
||||
android:layout_alignRight="@+id/spinnerAction"
|
||||
android:layout_alignBottom="@+id/spinnerAction"
|
||||
android:layout_alignTop="@+id/spinnerAction"
|
||||
android:layout_marginRight="10dp"
|
||||
android:tint="@color/gradient_end"/>
|
||||
</RelativeLayout>
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/scrollView1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="5dp">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
<LinearLayout
|
||||
android:id="@+id/surveyorLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone">
|
||||
<TextView
|
||||
android:id="@+id/lblSvyList"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Surveyor List :"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:drawableLeft="@drawable/ic_person_color"
|
||||
android:drawablePadding="5dp"/>
|
||||
<RadioGroup
|
||||
android:id="@+id/radioAction"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="5dp" >
|
||||
</RadioGroup>
|
||||
</LinearLayout>
|
||||
<TextView
|
||||
android:id="@+id/lblNotes"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/customer_notes_hint"
|
||||
android:drawableLeft="@drawable/ic_form_color"
|
||||
android:drawablePadding="5dp"
|
||||
android:paddingTop="5dp"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/txtNotes"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="15dp"
|
||||
android:hint="@string/requiredField"
|
||||
android:minLines="3"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textColor="@drawable/edit_text_selector" />
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
</LinearLayout>
|
||||
</androidx.cardview.widget.CardView>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/buttonContainer"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:padding="5dp"
|
||||
android:weightSum="1"
|
||||
android:background="@drawable/bottomnav_background"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/btnBackLayout"
|
||||
android:orientation="vertical"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_width="75dp"
|
||||
android:layout_height="wrap_content">
|
||||
<ImageButton
|
||||
android:id="@+id/btnBack"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="30dp"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:src="@drawable/icon_back"
|
||||
android:scaleType="center"
|
||||
android:background="@drawable/button_bg" />
|
||||
<TextView
|
||||
android:id="@+id/textView1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/fontColor"
|
||||
android:gravity="center"
|
||||
android:text="@string/btnBack"
|
||||
android:textSize="10dp" />
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:id="@+id/btnSaveLayout"
|
||||
android:orientation="vertical"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_width="75dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone">
|
||||
<ImageButton
|
||||
android:id="@+id/btnSave"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="30dp"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:src="@drawable/ic_save_draft"
|
||||
android:scaleType="center"
|
||||
android:background="@drawable/button_bg" />
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/fontColor"
|
||||
android:gravity="center"
|
||||
android:text="@string/btnSave"
|
||||
android:textSize="10dp" />
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:id="@+id/btnSendLayout"
|
||||
android:orientation="vertical"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_width="75dp"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/btnSend"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="30dp"
|
||||
android:background="@drawable/button_bg"
|
||||
android:clickable="false"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/icon_send" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/fontColor"
|
||||
android:gravity="center"
|
||||
android:text="@string/btnSend"
|
||||
android:textSize="10dp" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="30dp"
|
||||
android:height="30dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="@color/fontColor"
|
||||
android:pathData="M17,3L5,3c-1.11,0 -2,0.9 -2,2v14c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,7l-4,-4zM12,19c-1.66,0 -3,-1.34 -3,-3s1.34,-3 3,-3 3,1.34 3,3 -1.34,3 -3,3zM15,9L5,9L5,5h10v4z"/>
|
||||
</vector>
|
|
@ -0,0 +1,459 @@
|
|||
/*
|
||||
* Copyright 2013 Chris Banes
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package uk.co.senab.actionbarpulltorefresh.library;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.AnimatorSet;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.drawable.ClipDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.ShapeDrawable;
|
||||
import android.graphics.drawable.shapes.RectShape;
|
||||
import android.os.Build;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.AccelerateInterpolator;
|
||||
import android.view.animation.Interpolator;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.adins.mss.base.R;
|
||||
|
||||
import fr.castorflex.android.smoothprogressbar.SmoothProgressBar;
|
||||
import uk.co.senab.actionbarpulltorefresh.library.sdk.Compat;
|
||||
|
||||
/**
|
||||
* Default Header Transformer.
|
||||
*/
|
||||
public class DefaultHeaderTransformer extends HeaderTransformer {
|
||||
|
||||
public static final int PROGRESS_BAR_STYLE_INSIDE = 0;
|
||||
public static final int PROGRESS_BAR_STYLE_OUTSIDE = 1;
|
||||
private final Interpolator mInterpolator = new AccelerateInterpolator();
|
||||
private View mHeaderView;
|
||||
private ViewGroup mContentLayout;
|
||||
private TextView mHeaderTextView;
|
||||
private SmoothProgressBar mHeaderProgressBar;
|
||||
private CharSequence mPullRefreshLabel, mRefreshingLabel, mReleaseLabel;
|
||||
private int mProgressDrawableColor;
|
||||
private long mAnimationDuration;
|
||||
private int mProgressBarStyle;
|
||||
private int mProgressBarHeight = RelativeLayout.LayoutParams.WRAP_CONTENT;
|
||||
|
||||
protected DefaultHeaderTransformer() {
|
||||
final int min = getMinimumApiLevel();
|
||||
if (Build.VERSION.SDK_INT < min) {
|
||||
throw new IllegalStateException("This HeaderTransformer is designed to run on SDK "
|
||||
+ min
|
||||
+ "+. If using ActionBarSherlock or ActionBarCompat you should use the appropriate provided extra.");
|
||||
}
|
||||
}
|
||||
|
||||
protected static TypedArray obtainStyledAttrsFromThemeAttr(Context context, int themeAttr,
|
||||
int[] styleAttrs) {
|
||||
// Need to get resource id of style pointed to from the theme attr
|
||||
TypedValue outValue = new TypedValue();
|
||||
context.getTheme().resolveAttribute(themeAttr, outValue, true);
|
||||
final int styleResId = outValue.resourceId;
|
||||
|
||||
// Now return the values (from styleAttrs) from the style
|
||||
return context.obtainStyledAttributes(styleResId, styleAttrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(Activity activity, View headerView) {
|
||||
mHeaderView = headerView;
|
||||
|
||||
// Get ProgressBar and TextView
|
||||
mHeaderProgressBar = (SmoothProgressBar) headerView.findViewById(R.id.ptr_progress);
|
||||
mHeaderTextView = (TextView) headerView.findViewById(R.id.ptr_text);
|
||||
mContentLayout = (ViewGroup) headerView.findViewById(R.id.ptr_content);
|
||||
|
||||
// Default Labels to display
|
||||
mPullRefreshLabel = activity.getString(R.string.pull_to_refresh_pull_label);
|
||||
mRefreshingLabel = activity.getString(R.string.pull_to_refresh_refreshing_label);
|
||||
mReleaseLabel = activity.getString(R.string.pull_to_refresh_release_label);
|
||||
|
||||
mAnimationDuration = activity.getResources()
|
||||
.getInteger(android.R.integer.config_shortAnimTime);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
mProgressDrawableColor = activity.getResources()
|
||||
.getColor(R.color.default_progress_bar_color, activity.getTheme());
|
||||
} else {
|
||||
mProgressDrawableColor = activity.getResources()
|
||||
.getColor(R.color.default_progress_bar_color);
|
||||
}
|
||||
|
||||
// Setup the View styles
|
||||
setupViewsFromStyles(activity, headerView);
|
||||
|
||||
applyProgressBarStyle();
|
||||
|
||||
// Apply any custom ProgressBar colors and corner radius
|
||||
applyProgressBarSettings();
|
||||
|
||||
// FIXME: I do not like this call here
|
||||
onReset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Activity activity, Configuration newConfig) {
|
||||
setupViewsFromStyles(activity, getHeaderView());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReset() {
|
||||
// Reset Progress Bar
|
||||
if (mHeaderProgressBar != null) {
|
||||
mHeaderProgressBar.setVisibility(View.VISIBLE);
|
||||
mHeaderProgressBar.setProgress(0);
|
||||
mHeaderProgressBar.setIndeterminate(false);
|
||||
}
|
||||
|
||||
// Reset Text View
|
||||
if (mHeaderTextView != null) {
|
||||
mHeaderTextView.setVisibility(View.VISIBLE);
|
||||
mHeaderTextView.setText(mPullRefreshLabel);
|
||||
}
|
||||
|
||||
// Reset the Content Layout
|
||||
if (mContentLayout != null) {
|
||||
mContentLayout.setVisibility(View.VISIBLE);
|
||||
Compat.setAlpha(mContentLayout, 1f);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPulled(float percentagePulled) {
|
||||
if (mHeaderProgressBar != null) {
|
||||
mHeaderProgressBar.setVisibility(View.VISIBLE);
|
||||
final float progress = mInterpolator.getInterpolation(percentagePulled);
|
||||
mHeaderProgressBar.setProgress(Math.round(mHeaderProgressBar.getMax() * progress));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefreshStarted() {
|
||||
if (mHeaderTextView != null) {
|
||||
mHeaderTextView.setText(mRefreshingLabel);
|
||||
}
|
||||
if (mHeaderProgressBar != null) {
|
||||
mHeaderProgressBar.setVisibility(View.VISIBLE);
|
||||
mHeaderProgressBar.setIndeterminate(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReleaseToRefresh() {
|
||||
if (mHeaderTextView != null) {
|
||||
mHeaderTextView.setText(mReleaseLabel);
|
||||
}
|
||||
if (mHeaderProgressBar != null) {
|
||||
mHeaderProgressBar.setProgress(mHeaderProgressBar.getMax());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefreshMinimized() {
|
||||
// Here we fade out most of the header, leaving just the progress bar
|
||||
if (mContentLayout != null) {
|
||||
ObjectAnimator.ofFloat(mContentLayout, "alpha", 1f, 0f).start();
|
||||
}
|
||||
}
|
||||
|
||||
public View getHeaderView() {
|
||||
return mHeaderView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showHeaderView() {
|
||||
final boolean changeVis = mHeaderView.getVisibility() != View.VISIBLE;
|
||||
|
||||
if (changeVis) {
|
||||
mHeaderView.setVisibility(View.VISIBLE);
|
||||
AnimatorSet animSet = new AnimatorSet();
|
||||
ObjectAnimator transAnim = ObjectAnimator.ofFloat(mContentLayout, "translationY",
|
||||
-mContentLayout.getHeight(), 0f);
|
||||
ObjectAnimator alphaAnim = ObjectAnimator.ofFloat(mHeaderView, "alpha", 0f, 1f);
|
||||
animSet.playTogether(transAnim, alphaAnim);
|
||||
animSet.setDuration(mAnimationDuration);
|
||||
animSet.start();
|
||||
}
|
||||
|
||||
return changeVis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hideHeaderView() {
|
||||
final boolean changeVis = mHeaderView.getVisibility() != View.GONE;
|
||||
|
||||
if (changeVis) {
|
||||
Animator animator;
|
||||
if (mContentLayout.getAlpha() >= 0.5f) {
|
||||
// If the content layout is showing, translate and fade out
|
||||
animator = new AnimatorSet();
|
||||
ObjectAnimator transAnim = ObjectAnimator.ofFloat(mContentLayout, "translationY",
|
||||
0f, -mContentLayout.getHeight());
|
||||
ObjectAnimator alphaAnim = ObjectAnimator.ofFloat(mHeaderView, "alpha", 1f, 0f);
|
||||
((AnimatorSet) animator).playTogether(transAnim, alphaAnim);
|
||||
} else {
|
||||
// If the content layout isn't showing (minimized), just fade out
|
||||
animator = ObjectAnimator.ofFloat(mHeaderView, "alpha", 1f, 0f);
|
||||
}
|
||||
animator.setDuration(mAnimationDuration);
|
||||
animator.addListener(new HideAnimationCallback());
|
||||
animator.start();
|
||||
}
|
||||
|
||||
return changeVis;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set color to apply to the progress bar.
|
||||
* <p/>
|
||||
* The best way to apply a color is to load the color from resources: {@code
|
||||
* setProgressBarColor(getResources().getColor(R.color.your_color_name))}.
|
||||
*
|
||||
* @param color The color to use.
|
||||
*/
|
||||
public void setProgressBarColor(int color) {
|
||||
if (color != mProgressDrawableColor) {
|
||||
mProgressDrawableColor = color;
|
||||
mHeaderProgressBar.setSmoothProgressDrawableColor(color);
|
||||
applyProgressBarSettings();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the progress bar style. {@code style} must be one of {@link #PROGRESS_BAR_STYLE_OUTSIDE}
|
||||
* or {@link #PROGRESS_BAR_STYLE_INSIDE}.
|
||||
*/
|
||||
public void setProgressBarStyle(int style) {
|
||||
if (mProgressBarStyle != style) {
|
||||
mProgressBarStyle = style;
|
||||
applyProgressBarStyle();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the progress bar height.
|
||||
*/
|
||||
public void setProgressBarHeight(int height) {
|
||||
if (mProgressBarHeight != height) {
|
||||
mProgressBarHeight = height;
|
||||
applyProgressBarStyle();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Text to show to prompt the user is pull (or keep pulling).
|
||||
*
|
||||
* @param pullText - Text to display.
|
||||
*/
|
||||
public void setPullText(CharSequence pullText) {
|
||||
mPullRefreshLabel = pullText;
|
||||
if (mHeaderTextView != null) {
|
||||
mHeaderTextView.setText(mPullRefreshLabel);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Text to show to tell the user that a refresh is currently in progress.
|
||||
*
|
||||
* @param refreshingText - Text to display.
|
||||
*/
|
||||
public void setRefreshingText(CharSequence refreshingText) {
|
||||
mRefreshingLabel = refreshingText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Text to show to tell the user has scrolled enough to refresh.
|
||||
*
|
||||
* @param releaseText - Text to display.
|
||||
*/
|
||||
public void setReleaseText(CharSequence releaseText) {
|
||||
mReleaseLabel = releaseText;
|
||||
}
|
||||
|
||||
private void setupViewsFromStyles(Activity activity, View headerView) {
|
||||
final TypedArray styleAttrs = obtainStyledAttrsFromThemeAttr(activity,
|
||||
R.attr.ptrHeaderStyle, R.styleable.PullToRefreshHeader);
|
||||
|
||||
// Retrieve the Action Bar size from the app theme or the Action Bar's style
|
||||
if (mContentLayout != null) {
|
||||
final int height = styleAttrs.getDimensionPixelSize(
|
||||
R.styleable.PullToRefreshHeader_ptrHeaderHeight, getActionBarSize(activity));
|
||||
mContentLayout.getLayoutParams().height = height;
|
||||
mContentLayout.requestLayout();
|
||||
}
|
||||
|
||||
// Retrieve the Action Bar background from the app theme or the Action Bar's style (see #93)
|
||||
Drawable bg = styleAttrs.hasValue(R.styleable.PullToRefreshHeader_ptrHeaderBackground)
|
||||
? styleAttrs.getDrawable(R.styleable.PullToRefreshHeader_ptrHeaderBackground)
|
||||
: getActionBarBackground(activity);
|
||||
if (bg != null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
mHeaderTextView.setBackground(bg);
|
||||
} else {
|
||||
mHeaderTextView.setBackgroundDrawable(bg);
|
||||
}
|
||||
|
||||
// If we have an opaque background we can remove the background from the content layout
|
||||
if (mContentLayout != null && bg.getOpacity() == PixelFormat.OPAQUE) {
|
||||
mContentLayout.setBackgroundResource(0);
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve the Action Bar Title Style from the app theme or the Action Bar's style
|
||||
Context abContext = headerView.getContext();
|
||||
final int titleTextStyle = styleAttrs
|
||||
.getResourceId(R.styleable.PullToRefreshHeader_ptrHeaderTitleTextAppearance,
|
||||
getActionBarTitleStyle(abContext));
|
||||
if (titleTextStyle != 0) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
mHeaderTextView.setTextAppearance(titleTextStyle);
|
||||
} else {
|
||||
mHeaderTextView.setTextAppearance(abContext, titleTextStyle);
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve the Progress Bar Color the style
|
||||
if (styleAttrs.hasValue(R.styleable.PullToRefreshHeader_ptrProgressBarColor)) {
|
||||
mProgressDrawableColor = styleAttrs.getColor(
|
||||
R.styleable.PullToRefreshHeader_ptrProgressBarColor, mProgressDrawableColor);
|
||||
}
|
||||
|
||||
mProgressBarStyle = styleAttrs.getInt(
|
||||
R.styleable.PullToRefreshHeader_ptrProgressBarStyle, PROGRESS_BAR_STYLE_OUTSIDE);
|
||||
|
||||
if (styleAttrs.hasValue(R.styleable.PullToRefreshHeader_ptrProgressBarHeight)) {
|
||||
mProgressBarHeight = styleAttrs.getDimensionPixelSize(
|
||||
R.styleable.PullToRefreshHeader_ptrProgressBarHeight, mProgressBarHeight);
|
||||
}
|
||||
|
||||
// Retrieve the text strings from the style (if they're set)
|
||||
if (styleAttrs.hasValue(R.styleable.PullToRefreshHeader_ptrPullText)) {
|
||||
mPullRefreshLabel = styleAttrs.getString(R.styleable.PullToRefreshHeader_ptrPullText);
|
||||
}
|
||||
if (styleAttrs.hasValue(R.styleable.PullToRefreshHeader_ptrRefreshingText)) {
|
||||
mRefreshingLabel = styleAttrs
|
||||
.getString(R.styleable.PullToRefreshHeader_ptrRefreshingText);
|
||||
}
|
||||
if (styleAttrs.hasValue(R.styleable.PullToRefreshHeader_ptrReleaseText)) {
|
||||
mReleaseLabel = styleAttrs.getString(R.styleable.PullToRefreshHeader_ptrReleaseText);
|
||||
}
|
||||
|
||||
//SmoothProgressBar Style
|
||||
if (styleAttrs.hasValue(R.styleable.PullToRefreshHeader_ptrSmoothProgressBarStyle)) {
|
||||
int spbStyleRes = styleAttrs.getResourceId(R.styleable.PullToRefreshHeader_ptrSmoothProgressBarStyle, 0);
|
||||
if (spbStyleRes != 0)
|
||||
mHeaderProgressBar.applyStyle(spbStyleRes);
|
||||
|
||||
}
|
||||
|
||||
styleAttrs.recycle();
|
||||
}
|
||||
|
||||
private void applyProgressBarStyle() {
|
||||
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
|
||||
RelativeLayout.LayoutParams.MATCH_PARENT, mProgressBarHeight);
|
||||
|
||||
switch (mProgressBarStyle) {
|
||||
case PROGRESS_BAR_STYLE_INSIDE:
|
||||
lp.addRule(RelativeLayout.ALIGN_BOTTOM, R.id.ptr_content);
|
||||
break;
|
||||
case PROGRESS_BAR_STYLE_OUTSIDE:
|
||||
lp.addRule(RelativeLayout.BELOW, R.id.ptr_content);
|
||||
break;
|
||||
}
|
||||
|
||||
mHeaderProgressBar.setLayoutParams(lp);
|
||||
}
|
||||
|
||||
private void applyProgressBarSettings() {
|
||||
if (mHeaderProgressBar != null) {
|
||||
ShapeDrawable shape = new ShapeDrawable();
|
||||
shape.setShape(new RectShape());
|
||||
shape.getPaint().setColor(mProgressDrawableColor);
|
||||
ClipDrawable clipDrawable = new ClipDrawable(shape, Gravity.CENTER, ClipDrawable.HORIZONTAL);
|
||||
|
||||
mHeaderProgressBar.setProgressDrawable(clipDrawable);
|
||||
}
|
||||
}
|
||||
|
||||
protected Drawable getActionBarBackground(Context context) {
|
||||
int[] android_styleable_ActionBar = {android.R.attr.background};
|
||||
|
||||
// Now get the action bar style values...
|
||||
TypedArray abStyle = obtainStyledAttrsFromThemeAttr(context, android.R.attr.actionBarStyle,
|
||||
android_styleable_ActionBar);
|
||||
try {
|
||||
// background is the first attr in the array above so it's index is 0.
|
||||
return abStyle.getDrawable(0);
|
||||
} finally {
|
||||
abStyle.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
protected int getActionBarSize(Context context) {
|
||||
int[] attrs = {android.R.attr.actionBarSize};
|
||||
TypedArray values = context.getTheme().obtainStyledAttributes(attrs);
|
||||
try {
|
||||
return values.getDimensionPixelSize(0, 0);
|
||||
} finally {
|
||||
values.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
protected int getActionBarTitleStyle(Context context) {
|
||||
int[] android_styleable_ActionBar = {android.R.attr.titleTextStyle};
|
||||
|
||||
// Now get the action bar style values...
|
||||
TypedArray abStyle = obtainStyledAttrsFromThemeAttr(context, android.R.attr.actionBarStyle,
|
||||
android_styleable_ActionBar);
|
||||
try {
|
||||
// titleTextStyle is the first attr in the array above so it's index is 0.
|
||||
return abStyle.getResourceId(0, 0);
|
||||
} finally {
|
||||
abStyle.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
protected int getMinimumApiLevel() {
|
||||
return Build.VERSION_CODES.ICE_CREAM_SANDWICH;
|
||||
}
|
||||
|
||||
class HideAnimationCallback extends AnimatorListenerAdapter {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
View headerView = getHeaderView();
|
||||
if (headerView != null) {
|
||||
headerView.setVisibility(View.GONE);
|
||||
}
|
||||
onReset();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
package com.adins.mss.base.todolist.form;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import com.adins.mss.base.todolist.ToDoList;
|
||||
import com.adins.mss.dao.Scheme;
|
||||
import com.adins.mss.dao.TaskH;
|
||||
import com.adins.mss.dao.TaskHSequence;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by kusnendi.muhamad on 27/07/2017.
|
||||
*/
|
||||
|
||||
public interface TasklistInterface {
|
||||
public ToDoList getTodoList();
|
||||
|
||||
public String getParam();
|
||||
|
||||
public Scheme getSelectedScheme();
|
||||
|
||||
public void setSelectedScheme(Scheme scheme);
|
||||
|
||||
public int getSelectedTask();
|
||||
|
||||
public void setSelectedTask(int position);
|
||||
|
||||
public int getPtp();
|
||||
|
||||
public void setPtp(int ptp);
|
||||
|
||||
public String getTenorFromValue();
|
||||
|
||||
public void setTenorFromValue(String tenorFrom);
|
||||
|
||||
public String getTenorToValue();
|
||||
|
||||
public void setTenorToValue(String tenorTo);
|
||||
|
||||
public String getOsFromValue();
|
||||
|
||||
public void setOsFromValue(String osFrom);
|
||||
|
||||
public String getOsToValue();
|
||||
|
||||
public void setOsToValue(String osTo);
|
||||
|
||||
public String getCustName();
|
||||
|
||||
public void setCustName(String custName);
|
||||
|
||||
public List<Scheme> listScheme();
|
||||
|
||||
public List<TaskH> listTaskH();
|
||||
|
||||
public List<TaskHSequence> getTaskHSequences();
|
||||
|
||||
public List<TaskH> getSelectedTaskH(int position);
|
||||
|
||||
public List<TaskH> getAllTaskH(Scheme selectedScheme);
|
||||
|
||||
public List<TaskH> getTaskHInHighPriority(Scheme selectedScheme);
|
||||
|
||||
public List<TaskH> getTaskHInLowPriority(Scheme selectedScheme);
|
||||
|
||||
public List<TaskH> getTaskHInNormalPriority(Scheme selectedScheme);
|
||||
|
||||
public List<TaskH> getTaskH(Scheme selectedScheme, int searchType);
|
||||
|
||||
public String getTasklistFromServer(Context context);
|
||||
|
||||
public List<TaskH> refreshBackgroundTask(boolean isGetFromServer, int pos, SwipeRefreshLayout swipeRefreshLayout);
|
||||
|
||||
public AsyncTask<Void, Void, List<TaskH>> refreshBackgroundTask(boolean isGetFromServer);
|
||||
|
||||
public void cancelRefreshTask();
|
||||
|
||||
public void initiateRefresh(String type);
|
||||
|
||||
public void initiateRefresh(boolean getDataFromServer);
|
||||
|
||||
public TasklistImpl.PriorityHandler getPriorityHandler(boolean isPriorityOpen);
|
||||
}
|
|
@ -0,0 +1,251 @@
|
|||
package com.adins.mss.foundation.print.rv;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.Keep;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.adins.mss.base.GlobalData;
|
||||
import com.adins.mss.base.PrintActivity;
|
||||
import com.adins.mss.base.R;
|
||||
import com.adins.mss.base.dynamicform.CustomerFragment;
|
||||
import com.adins.mss.base.dynamicform.SendResultActivity;
|
||||
import com.adins.mss.base.util.EventBusHelper;
|
||||
import com.adins.mss.base.util.LocaleHelper;
|
||||
import com.adins.mss.dao.ReceiptVoucher;
|
||||
import com.adins.mss.dao.TaskH;
|
||||
import com.adins.mss.foundation.db.dataaccess.GeneralParameterDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.ReceiptVoucherDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.TaskHDataAccess;
|
||||
import com.adins.mss.foundation.dialog.NiftyDialogBuilder;
|
||||
import com.adins.mss.logger.Logger;
|
||||
import com.androidquery.AQuery;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Created by angga.permadi on 4/20/2016.
|
||||
*/
|
||||
public class InputRVNumberActivity extends Activity implements AdapterView.OnItemSelectedListener {
|
||||
private AQuery query;
|
||||
private RVNumberSender sender;
|
||||
private TaskH taskH;
|
||||
private ReceiptVoucher rvNumber;
|
||||
private String source;
|
||||
private Context context;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_input_rv_number);
|
||||
setupActionBar();
|
||||
|
||||
this.context = this;
|
||||
|
||||
if (getIntent() != null && getIntent().getExtras() != null &&
|
||||
!getIntent().getExtras().getString(PrintActivity.UUID_TASKH, "").isEmpty()) {
|
||||
String uuidTask = getIntent().getExtras().getString(PrintActivity.UUID_TASKH);
|
||||
taskH = TaskHDataAccess.getOneHeader(this, uuidTask);
|
||||
if (taskH == null) taskH = TaskHDataAccess.getOneTaskHeader(this, uuidTask);
|
||||
source = getIntent().getExtras().getString(PrintActivity.SOURCE_TASK);
|
||||
source = (source == null) ? "" : source;
|
||||
}
|
||||
|
||||
if (taskH == null) {
|
||||
Toast.makeText(this, "sorry something wrong, try again later", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
|
||||
query = new AQuery(this);
|
||||
Spinner snReceiptVouchers = (Spinner) query.id(R.id.sn_rv_numbers).getView();
|
||||
|
||||
List<ReceiptVoucher> rvNumbers;
|
||||
rvNumbers = ReceiptVoucherDataAccess.getByStatus(this,
|
||||
GlobalData.getSharedGlobalData().getUser().getUuid_user(),
|
||||
ReceiptVoucherDataAccess.STATUS_NEW);
|
||||
ReceiptVoucher hint = new ReceiptVoucher();
|
||||
hint.setRv_number(getString(R.string.select_rv_number));
|
||||
rvNumbers.add(0, hint);
|
||||
RvNumberAdapter spAdapter = new RvNumberAdapter(this, R.layout.spinner_style2, rvNumbers);
|
||||
spAdapter.setDropDownViewResource(R.layout.spinner_style);
|
||||
snReceiptVouchers.setAdapter(spAdapter);
|
||||
snReceiptVouchers.setOnItemSelectedListener(this);
|
||||
|
||||
query.id(R.id.bt_send).clicked(this, "sendRVNumber");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
sender = null;
|
||||
query = null;
|
||||
rvNumber = null;
|
||||
}
|
||||
|
||||
private OnSendRVListener listener = new OnSendRVListener() {
|
||||
@Override
|
||||
public void onSendReceiptVoucher(RVNumberResponse response) {
|
||||
if (taskH == null) {
|
||||
Toast.makeText(InputRVNumberActivity.this, "TaskH not available", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.getReqCode() != ApiCodes.RV_NUMBER)
|
||||
return;
|
||||
|
||||
Logger.d(this, "onEvent : RVNumberResponse = " + response.toString());
|
||||
|
||||
String title, message;
|
||||
|
||||
if (response.getErrorMessage() != null) {
|
||||
title = getString(R.string.failed);
|
||||
message = buildErrorMessage(response.getErrorMessage());
|
||||
showResultDialog(title, message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.getStatus() != null) {
|
||||
if (response.getStatus().getCode() == 0) {
|
||||
title = getString(R.string.success);
|
||||
message = getString(R.string.message_sending_success);
|
||||
} else {
|
||||
title = getString(R.string.failed);
|
||||
message = buildErrorMessage(response.getStatus().getMessage());
|
||||
}
|
||||
} else {
|
||||
title = getString(R.string.failed);
|
||||
message = buildErrorMessage(getString(R.string.input_rv_number_failed));
|
||||
}
|
||||
|
||||
showResultDialog(title, message);
|
||||
try {
|
||||
String statusRV = title.equals(getString(R.string.failed)) ? TaskHDataAccess.STATUS_RV_PENDING :
|
||||
TaskHDataAccess.STATUS_RV_SENT;
|
||||
if (taskH != null) {
|
||||
boolean isRVinFront = GeneralParameterDataAccess.isRvInFrontEnable(getApplicationContext(), GlobalData.getSharedGlobalData().getUser().getUuid_user());
|
||||
if (isRVinFront) {
|
||||
taskH.setRv_number(rvNumber.getUuid_receipt_voucher());
|
||||
taskH.setStatus_rv(statusRV);
|
||||
TaskHDataAccess.addOrReplace(context, taskH);
|
||||
} else {
|
||||
if (TaskHDataAccess.STATUS_RV_SENT.equalsIgnoreCase(statusRV)) {
|
||||
taskH.setRv_number(rvNumber.getUuid_receipt_voucher());
|
||||
taskH.setStatus_rv(statusRV);
|
||||
TaskHDataAccess.addOrReplace(context, taskH);
|
||||
if ("log".equalsIgnoreCase(source)) {
|
||||
CustomerFragment.getHeader().setRv_number(rvNumber.getUuid_receipt_voucher());
|
||||
} else if ("submit".equalsIgnoreCase(source)) {
|
||||
SendResultActivity.rvNumber = rvNumber.getUuid_receipt_voucher();
|
||||
}
|
||||
} else {
|
||||
ReceiptVoucherDataAccess.updateToNew(context, GlobalData.getSharedGlobalData().getUser().getUuid_user(), rvNumber.getUuid_receipt_voucher());
|
||||
}
|
||||
}
|
||||
|
||||
response.setReqCode(ApiCodes.RV_NUMBER_AUTO_SEND);
|
||||
// send event to MainService, jalanin autosend rv number
|
||||
EventBusHelper.post(response);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context newBase) {
|
||||
Context context = newBase;
|
||||
Locale locale;
|
||||
try{
|
||||
locale = new Locale(GlobalData.getSharedGlobalData().getLocale());
|
||||
context = LocaleHelper.wrap(newBase, locale);
|
||||
} catch (Exception e) {
|
||||
locale = new Locale(LocaleHelper.ENGLSIH);
|
||||
context = LocaleHelper.wrap(newBase, locale);
|
||||
} finally {
|
||||
super.attachBaseContext(context);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
if (position == 0) return;
|
||||
if (parent.getItemAtPosition(position) instanceof ReceiptVoucher) {
|
||||
rvNumber = (ReceiptVoucher) parent.getItemAtPosition(position);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
|
||||
}
|
||||
|
||||
private void setupActionBar() {
|
||||
if (getActionBar() == null) return;
|
||||
|
||||
getActionBar().setTitle(R.string.input_rv_number_title);
|
||||
}
|
||||
|
||||
@Keep // subcribe
|
||||
public void sendRVNumber() {
|
||||
if (rvNumber == null) {
|
||||
Toast.makeText(this, R.string.input_rv_number_error, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
doSend();
|
||||
}
|
||||
|
||||
private void doSend() {
|
||||
if (sender != null) return; // send harus cuma sekali
|
||||
if (GlobalData.getSharedGlobalData().getUser() == null) return;
|
||||
|
||||
ReceiptVoucherDataAccess.updateToUsed(this,
|
||||
GlobalData.getSharedGlobalData().getUser().getUuid_user(),
|
||||
rvNumber);
|
||||
|
||||
RVEntity rv = new RVEntity();
|
||||
rv.setUuid_task_h(taskH.getUuid_task_h());
|
||||
rv.setRv_number(rvNumber.getRv_number());
|
||||
rv.setDtm_use(rvNumber.getDtm_use());
|
||||
|
||||
RVNumberRequest entity = new RVNumberRequest();
|
||||
entity.setRvBlank(rv);
|
||||
|
||||
sender = new RVNumberSender(this, entity, ApiCodes.RV_NUMBER, listener);
|
||||
sender.execute();
|
||||
}
|
||||
|
||||
private void showResultDialog(String title, String message) {
|
||||
final NiftyDialogBuilder dialog = new NiftyDialogBuilder(this, R.style.dialog_untran);
|
||||
dialog.withTitle(title)
|
||||
.withMessage(message)
|
||||
.isCancelable(false)
|
||||
.isCancelableOnTouchOutside(false)
|
||||
.withButton1Text(getString(R.string.btnClose))
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
setResult(RESULT_OK);
|
||||
onBackPressed();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
private String buildErrorMessage(String message) {
|
||||
return message + ". ";
|
||||
}
|
||||
|
||||
public interface OnSendRVListener {
|
||||
public void onSendReceiptVoucher(RVNumberResponse response);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,128 @@
|
|||
package com.adins.mss.odr.catalogue;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Bundle;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.adins.mss.base.util.Utility;
|
||||
import com.adins.mss.dao.Catalogue;
|
||||
import com.adins.mss.dao.MobileContentD;
|
||||
import com.adins.mss.foundation.db.dataaccess.CatalogueDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.MobileContentDDataAccess;
|
||||
import com.adins.mss.foundation.image.Utils;
|
||||
import com.adins.mss.odr.R;
|
||||
import com.adins.mss.odr.catalogue.imageslider.FragmentSlider;
|
||||
import com.adins.mss.odr.catalogue.imageslider.SliderIndicator;
|
||||
import com.adins.mss.odr.catalogue.imageslider.SliderPagerAdapter;
|
||||
import com.adins.mss.odr.catalogue.imageslider.SliderView;
|
||||
import com.google.firebase.analytics.FirebaseAnalytics;
|
||||
|
||||
import org.acra.ACRA;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by olivia.dg on 11/28/2017.
|
||||
*/
|
||||
|
||||
public class FragmentCatalogue extends Fragment {
|
||||
private List<MobileContentD> promoList;
|
||||
private List<Catalogue> catalogueList;
|
||||
|
||||
private SliderView sliderView;
|
||||
private SliderPagerAdapter mAdapter;
|
||||
private SliderIndicator mIndicator;
|
||||
private LinearLayout mLinearLayout;
|
||||
|
||||
private RecyclerView list;
|
||||
private RecyclerView.LayoutManager layoutManager;
|
||||
private CatalogueListAdapter adapter;
|
||||
private FirebaseAnalytics screenName;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
setHasOptionsMenu(true);
|
||||
promoList = MobileContentDDataAccess.getAllContent(context);
|
||||
catalogueList = CatalogueDataAccess.getAll(context);
|
||||
ACRA.getErrorReporter().putCustomData("LAST_CLASS_ACCESSED", getClass().getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
Utility.freeMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
screenName = FirebaseAnalytics.getInstance(getActivity());
|
||||
View view = inflater.inflate(R.layout.fragment_catalogue, container, false);
|
||||
|
||||
list = (RecyclerView) view.findViewById(R.id.catalogueList);
|
||||
layoutManager = new LinearLayoutManager(getActivity());
|
||||
list.setLayoutManager(layoutManager);
|
||||
adapter = new CatalogueListAdapter(getActivity(), catalogueList);
|
||||
list.setAdapter(adapter);
|
||||
|
||||
sliderView = (SliderView) view.findViewById(R.id.sliderView);
|
||||
mLinearLayout = (LinearLayout) view.findViewById(R.id.pagesContainer);
|
||||
|
||||
setupSlider();
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
//Set Firebase screen name
|
||||
screenName.setCurrentScreen(getActivity(), getString(R.string.screen_name_promo_catalogue), null);
|
||||
getActivity().findViewById(com.adins.mss.base.R.id.search).setVisibility(View.GONE);
|
||||
getActivity().findViewById(com.adins.mss.base.R.id.spinner).setVisibility(View.GONE);
|
||||
getActivity().setTitle(getString(com.adins.mss.base.R.string.title_mn_catalogue));
|
||||
}
|
||||
|
||||
private void setupSlider() {
|
||||
List<Fragment> fragments = new ArrayList<>();
|
||||
if (promoList != null && promoList.size() != 0) {
|
||||
sliderView.setDurationScroll(800);
|
||||
sliderView.isVerticalScrollBarEnabled();
|
||||
for (MobileContentD content : promoList) {
|
||||
fragments.add(FragmentSlider.newInstance(content.getContent()));
|
||||
}
|
||||
} else {
|
||||
sliderView.setDurationScroll(0);
|
||||
Bitmap noPromo = BitmapFactory.decodeResource(getResources(), R.drawable.nopromotion);
|
||||
byte[] temp = Utils.bitmapToByte(noPromo);
|
||||
fragments.add(FragmentSlider.newInstance(temp));
|
||||
}
|
||||
// fragments.add(FragmentSlider.newInstance("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTHN2Mp-hEWSIUMgLVdnUwaP0V5x9dvpluFd8zsq0EMhzCQfsek"));
|
||||
// fragments.add(FragmentSlider.newInstance("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTcYsl7qSRTZI9zw7DnYxiGfv9foj6s7OpKek121ZFziqWGWjNi"));
|
||||
// fragments.add(FragmentSlider.newInstance("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQDEtJebJpj6EPoFzeaeMb1WdqyyawvyMpB59sMkdfW2HH0BXYp"));
|
||||
|
||||
mAdapter = new SliderPagerAdapter(getFragmentManager(), fragments);
|
||||
sliderView.setAdapter(mAdapter);
|
||||
mIndicator = new SliderIndicator(getContext(), mLinearLayout, sliderView, R.drawable.indicator_circle, true);
|
||||
mIndicator.setPageCount(fragments.size());
|
||||
try {
|
||||
mIndicator.show();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
// mIndicator.cleanup();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="14dp"
|
||||
android:height="14dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="@color/gradient_end"
|
||||
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13.41,18.09L13.41,20h-2.67v-1.93c-1.71,-0.36 -3.16,-1.46 -3.27,-3.4h1.96c0.1,1.05 0.82,1.87 2.65,1.87 1.96,0 2.4,-0.98 2.4,-1.59 0,-0.83 -0.44,-1.61 -2.67,-2.14 -2.48,-0.6 -4.18,-1.62 -4.18,-3.67 0,-1.72 1.39,-2.84 3.11,-3.21L10.74,4h2.67v1.95c1.86,0.45 2.79,1.86 2.85,3.39L14.3,9.34c-0.05,-1.11 -0.64,-1.87 -2.22,-1.87 -1.5,0 -2.4,0.68 -2.4,1.64 0,0.84 0.65,1.39 2.67,1.91s4.18,1.39 4.18,3.91c-0.01,1.83 -1.38,2.83 -3.12,3.16z"/>
|
||||
</vector>
|
|
@ -0,0 +1,31 @@
|
|||
<animated-vector xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
tools:targetApi="lollipop">
|
||||
<aapt:attr name="android:drawable">
|
||||
<vector
|
||||
android:name="vector"
|
||||
android:width="84dp"
|
||||
android:height="60dp"
|
||||
android:viewportWidth="84"
|
||||
android:viewportHeight="60">
|
||||
<path
|
||||
android:name="done"
|
||||
android:pathData="M 3.536 27.097 L 30.258 53.819 L 80.541 3.536"
|
||||
android:strokeColor="#ffffff"
|
||||
android:strokeWidth="10"
|
||||
android:trimPathEnd="0"/>
|
||||
</vector>
|
||||
</aapt:attr>
|
||||
<target android:name="done">
|
||||
<aapt:attr name="android:animation">
|
||||
<objectAnimator
|
||||
android:propertyName="trimPathEnd"
|
||||
android:duration="500"
|
||||
android:valueFrom="0"
|
||||
android:valueTo="1"
|
||||
android:valueType="floatType"
|
||||
android:interpolator="@android:interpolator/fast_out_slow_in"/>
|
||||
</aapt:attr>
|
||||
</target>
|
||||
</animated-vector>
|
Loading…
Add table
Add a link
Reference in a new issue