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
Binary file not shown.
|
@ -0,0 +1,78 @@
|
|||
package com.adins.mss.base.mainmenu.settings;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.RadioButton;
|
||||
|
||||
import com.adins.mss.base.GlobalData;
|
||||
import com.adins.mss.base.R;
|
||||
import com.adins.mss.base.commons.Common;
|
||||
import com.adins.mss.base.commons.CommonImpl;
|
||||
import com.adins.mss.base.commons.SettingImpl;
|
||||
import com.adins.mss.base.commons.SettingInterface;
|
||||
import com.adins.mss.base.util.LocaleHelper;
|
||||
import com.adins.mss.constant.Global;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class SettingActivity extends Activity {
|
||||
|
||||
private Button btnSave;
|
||||
private RadioButton rdIndonesia;
|
||||
private RadioButton rdEnglish;
|
||||
private SettingInterface setting;
|
||||
private Common common;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_setting);
|
||||
btnSave = (Button) findViewById(R.id.btnSave);
|
||||
rdIndonesia = (RadioButton) findViewById(R.id.rdBahasa);
|
||||
rdEnglish = (RadioButton) findViewById(R.id.rdEnglish);
|
||||
|
||||
Global.isMenuMoreClicked = true;
|
||||
|
||||
common = new CommonImpl();
|
||||
setting = new SettingImpl(getApplicationContext());
|
||||
String language = setting.getLanguage();
|
||||
|
||||
if (language.equals(LocaleHelper.BAHASA_INDONESIA)) {
|
||||
rdIndonesia.setChecked(true);
|
||||
} else {
|
||||
rdEnglish.setChecked(true);
|
||||
}
|
||||
|
||||
btnSave.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (rdEnglish.isChecked()) {
|
||||
setting.setLanguage(LocaleHelper.ENGLSIH);
|
||||
} else if (rdIndonesia.isChecked()) {
|
||||
setting.setLanguage(LocaleHelper.BAHASA_INDONESIA);
|
||||
}
|
||||
common.setAuditData();
|
||||
Global.isMenuMoreClicked = false;
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.adins.mss.foundation.camerainapp.helper;
|
||||
|
||||
/**
|
||||
* Created by angga.permadi on 6/21/2016.
|
||||
*/
|
||||
public interface BasePresenterInterface {
|
||||
|
||||
void start();
|
||||
|
||||
void destroy();
|
||||
}
|
|
@ -0,0 +1,255 @@
|
|||
package com.adins.mss.svy.assignment;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import androidx.annotation.Keep;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.adins.mss.base.GlobalData;
|
||||
import com.adins.mss.base.checkin.CheckInManager;
|
||||
import com.adins.mss.base.crashlytics.FireCrash;
|
||||
import com.adins.mss.base.util.GsonHelper;
|
||||
import com.adins.mss.base.util.LocaleHelper;
|
||||
import com.adins.mss.base.util.Utility;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.foundation.UserHelp.UserHelp;
|
||||
import com.adins.mss.foundation.dialog.NiftyDialogBuilder;
|
||||
import com.adins.mss.foundation.http.HttpConnectionResult;
|
||||
import com.adins.mss.foundation.http.HttpCryptedConnection;
|
||||
import com.adins.mss.foundation.location.UpdateMenuIcon;
|
||||
import com.adins.mss.svy.R;
|
||||
import com.adins.mss.svy.reassignment.JsonRequestDetailOrder;
|
||||
import com.adins.mss.svy.reassignment.JsonResponseServer;
|
||||
import com.adins.mss.svy.reassignment.JsonResponseServer.ResponseServer;
|
||||
import com.androidquery.AQuery;
|
||||
import com.google.firebase.perf.FirebasePerformance;
|
||||
import com.google.firebase.perf.metrics.HttpMetric;
|
||||
|
||||
import org.acra.ACRA;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static com.adins.mss.constant.Global.SHOW_USERHELP_DELAY_DEFAULT;
|
||||
|
||||
public class LookupAssignment extends AppCompatActivity{
|
||||
AQuery query ;
|
||||
OrderAssignmentAdapter adapter;
|
||||
List<ResponseServer> responseServer;
|
||||
ListView listView;
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater menuInflater = getMenuInflater();
|
||||
menuInflater.inflate(com.adins.mss.base.R.menu.main_menu, menu);
|
||||
mainMenu = menu;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
updateMenuIcon();
|
||||
|
||||
if(Global.ENABLE_USER_HELP &&
|
||||
(Global.userHelpGuide.get(LookupAssignment.this.getClass().getSimpleName())!=null) ||
|
||||
Global.userHelpDummyGuide.get(LookupAssignment.this.getClass().getSimpleName()) != null){
|
||||
menu.findItem(com.adins.mss.base.R.id.mnGuide).setVisible(true);
|
||||
}
|
||||
return super.onPrepareOptionsMenu(menu);
|
||||
}
|
||||
|
||||
private static Menu mainMenu;
|
||||
|
||||
public static void updateMenuIcon() {
|
||||
UpdateMenuIcon uItem = new UpdateMenuIcon();
|
||||
uItem.updateGPSIcon(mainMenu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
if (id == com.adins.mss.base.R.id.mnGPS && Global.LTM != null) {
|
||||
if (Global.LTM.getIsConnected()) {
|
||||
Global.LTM.removeLocationListener();
|
||||
Global.LTM.connectLocationClient();
|
||||
} else {
|
||||
CheckInManager.startGPSTracking(getApplicationContext());
|
||||
}
|
||||
Animation a = AnimationUtils.loadAnimation(this, com.adins.mss.base.R.anim.gps_rotate);
|
||||
findViewById(com.adins.mss.base.R.id.mnGPS).startAnimation(a);
|
||||
}
|
||||
if(id==R.id.mnGuide && !Global.BACKPRESS_RESTRICTION){
|
||||
UserHelp.reloadUserHelp(getApplicationContext(), LookupAssignment.this);
|
||||
Handler handler = new Handler();
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
UserHelp.showAllUserHelp(LookupAssignment.this, LookupAssignment.this.getClass().getSimpleName());
|
||||
}
|
||||
}, SHOW_USERHELP_DELAY_DEFAULT);
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.default_listview);
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(com.adins.mss.base.R.id.toolbar);
|
||||
toolbar.setTitleTextColor(getResources().getColor(com.adins.mss.base.R.color.fontColorWhite));
|
||||
toolbar.setTitle(getString(R.string.title_mn_surveyassign));
|
||||
setSupportActionBar(toolbar);
|
||||
listView = findViewById(android.R.id.list);
|
||||
ACRA.getErrorReporter().putCustomData("LAST_CLASS_ACCESSED", getClass().getSimpleName());
|
||||
query = new AQuery(this);
|
||||
query.id(android.R.id.list).itemClicked(this, "itemClick").margin(5, 5, 5, 5);
|
||||
String flag = getIntent().getStringExtra(Global.BUND_KEY_TASK);
|
||||
String uuid_task_h = getIntent().getStringExtra(Global.BUND_KEY_UUID_TASKH);
|
||||
new GetRequestDataLookup(uuid_task_h,flag).execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
|
||||
if(!Global.BACKPRESS_RESTRICTION){
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
@Keep
|
||||
public void itemClick(AdapterView<?> parent, View v, int position, long id){
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(Global.BUND_KEY_ASSIGNEE_ID, responseServer.get(position).getKey());
|
||||
intent.putExtra(Global.BUND_KEY_ASSIGNEE_VALUE, responseServer.get(position).getValue());
|
||||
intent.putExtra(Global.BUND_KEY_ASSIGNEE_JOB, responseServer.get(position).getFlag());
|
||||
setResult(Global.REQUEST_CODE_LOOKUP, intent);
|
||||
finish();
|
||||
}
|
||||
private class GetRequestDataLookup extends AsyncTask<Void, Void, JsonResponseServer> {
|
||||
private ProgressDialog progressDialog;
|
||||
private String errMessage = null;
|
||||
private String uuid_task_h;
|
||||
private String flag;
|
||||
|
||||
public GetRequestDataLookup(String uuid_task_h, String flag) {
|
||||
this.flag = flag;
|
||||
this.uuid_task_h=uuid_task_h;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
progressDialog = ProgressDialog.show(LookupAssignment.this,
|
||||
"", getString(R.string.progressWait), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonResponseServer doInBackground(Void... params) {
|
||||
String result = null;
|
||||
|
||||
JsonRequestDetailOrder request = new JsonRequestDetailOrder();
|
||||
request.setAudit(GlobalData.getSharedGlobalData().getAuditData());
|
||||
request.setUuid_task_h(uuid_task_h);
|
||||
request.setFlag(flag);
|
||||
String json = GsonHelper.toJson(request);
|
||||
String url = GlobalData.getSharedGlobalData().getURL_GET_LOOKUP();
|
||||
boolean encrypt = GlobalData.getSharedGlobalData().isEncrypt();
|
||||
boolean decrypt = GlobalData.getSharedGlobalData().isDecrypt();
|
||||
HttpCryptedConnection httpConn = new HttpCryptedConnection(LookupAssignment.this, encrypt, decrypt);
|
||||
HttpConnectionResult serverResult = null;
|
||||
|
||||
//Firebase Performance Trace HTTP Request
|
||||
HttpMetric networkMetric =
|
||||
FirebasePerformance.getInstance().newHttpMetric(url, FirebasePerformance.HttpMethod.POST);
|
||||
Utility.metricStart(networkMetric, json);
|
||||
|
||||
try {
|
||||
serverResult = httpConn.requestToServer(url, json, Global.DEFAULTCONNECTIONTIMEOUT);
|
||||
Utility.metricStop(networkMetric, serverResult);
|
||||
if(serverResult.isOK())
|
||||
result = serverResult.getResult();
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
e.printStackTrace();
|
||||
try {
|
||||
progressDialog.dismiss();
|
||||
} catch (Exception ex) {
|
||||
FireCrash.log(e);
|
||||
}
|
||||
errMessage = e.getMessage();
|
||||
}
|
||||
|
||||
JsonResponseServer response =null;
|
||||
try {
|
||||
if(null!=result)
|
||||
response = GsonHelper.fromJson(result, JsonResponseServer.class);
|
||||
} catch (Exception e) { FireCrash.log(e);
|
||||
errMessage = e.getMessage();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
@Override
|
||||
protected void onPostExecute(JsonResponseServer result){
|
||||
if (progressDialog.isShowing()){
|
||||
try {
|
||||
progressDialog.dismiss();
|
||||
} catch (Exception e) { FireCrash.log(e);
|
||||
}
|
||||
}
|
||||
if(errMessage!=null){
|
||||
NiftyDialogBuilder dialogBuilder = NiftyDialogBuilder.getInstance(LookupAssignment.this);
|
||||
dialogBuilder.withTitle(getApplicationContext().getString(R.string.error_capital))
|
||||
.withMessage(errMessage)
|
||||
.show();
|
||||
}
|
||||
else if(result != null){
|
||||
if(result.getStatus().getCode()==0){
|
||||
responseServer = result.getListResponseServer();
|
||||
adapter = new OrderAssignmentAdapter(getApplicationContext(), responseServer, true);
|
||||
query.id(android.R.id.list).adapter(adapter);
|
||||
Handler handler = new Handler();
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
UserHelp.showAllUserHelpWithListView(LookupAssignment.this,
|
||||
LookupAssignment.this.getClass().getSimpleName(),
|
||||
listView,0);
|
||||
}
|
||||
}, SHOW_USERHELP_DELAY_DEFAULT);
|
||||
}else{
|
||||
NiftyDialogBuilder dialogBuilder = NiftyDialogBuilder.getInstance(LookupAssignment.this);
|
||||
dialogBuilder.withTitle(getApplicationContext().getString(R.string.info_capital))
|
||||
.withMessage(result.getStatus().getMessage())
|
||||
.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<shape>
|
||||
<gradient
|
||||
android:startColor="#fbb34c"
|
||||
android:endColor="#d98002"
|
||||
android:angle="270" />
|
||||
<corners
|
||||
android:radius="0dp" />
|
||||
<padding
|
||||
android:left="10dp"
|
||||
android:top="10dp"
|
||||
android:right="10dp"
|
||||
android:bottom="10dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
Binary file not shown.
|
@ -0,0 +1,45 @@
|
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:background="@drawable/bottomnav_background">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="30dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:layout_marginBottom="10dp">
|
||||
<TextView
|
||||
android:id="@+id/txtSelectFOrm"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:text="@string/selectForm"
|
||||
android:textColor="@color/gradient_end"
|
||||
android:textStyle="bold"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnCancel"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_alignParentRight="true"
|
||||
android:background="@drawable/button_background"
|
||||
android:text="@string/btnCancel"
|
||||
android:textColor="@color/fontColorWhite"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
</RelativeLayout>
|
||||
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:layout_marginBottom="30dp"
|
||||
android:divider="@android:color/transparent"
|
||||
android:dividerHeight="4dp"
|
||||
android:headerDividersEnabled="true"/>
|
||||
</LinearLayout>
|
|
@ -0,0 +1,21 @@
|
|||
package com.adins.mss.odr.accounts.api;
|
||||
|
||||
import com.adins.mss.foundation.http.MssRequestType;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* Created by olivia.dg on 11/21/2017.
|
||||
*/
|
||||
|
||||
public class LoadOpportunityDetailRequest extends MssRequestType {
|
||||
@SerializedName("group_task_id")
|
||||
private String group_task_id;
|
||||
|
||||
public String getGroup_task_id() {
|
||||
return group_task_id;
|
||||
}
|
||||
|
||||
public void setGroup_task_id(String group_task_id) {
|
||||
this.group_task_id = group_task_id;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,522 @@
|
|||
package com.adins.mss.foundation.sync.api;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.adins.mss.base.GlobalData;
|
||||
import com.adins.mss.base.common.LinkedHashMapToObject;
|
||||
import com.adins.mss.base.crashlytics.FireCrash;
|
||||
import com.adins.mss.base.util.GsonHelper;
|
||||
import com.adins.mss.base.util.Utility;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.dao.Holiday;
|
||||
import com.adins.mss.dao.Lookup;
|
||||
import com.adins.mss.dao.Sync;
|
||||
import com.adins.mss.dao.User;
|
||||
import com.adins.mss.foundation.db.dataaccess.HolidayDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.LookupDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.SyncDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.UserDataAccess;
|
||||
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.security.storepreferences.ObscuredSharedPreferences;
|
||||
import com.adins.mss.foundation.sync.api.model.SynchronizeCOHRequestModel;
|
||||
import com.adins.mss.foundation.sync.api.model.SynchronizeRequestModel;
|
||||
import com.adins.mss.foundation.sync.api.model.SynchronizeResponse;
|
||||
import com.google.firebase.perf.FirebasePerformance;
|
||||
import com.google.firebase.perf.metrics.HttpMetric;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by adityapurwa on 11/03/15.
|
||||
* Automatically do a synchronization with the server.
|
||||
*/
|
||||
public class DataSynchronizer {
|
||||
public static final String IS_SYNCHRONIZE_SYNC = "IS_SYNCHRONIZE_SYNC";
|
||||
public static final String IS_SYNCHRONIZE_LOOKUP = "IS_SYNCHRONIZE_LOOKUP";
|
||||
public static final String IS_SYNCHRONIZE_HOLIDAY = "IS_SYNCHRONIZE_HOLIDAY";
|
||||
public static final String IS_SYNCHRONIZE_COH = "IS_SYNCHRONIZE_COH";
|
||||
public static final String IS_SYNCHRONIZE_USER= "IS_SYNCHRONIZE_USER";
|
||||
private static final String SYNCHRONIZATION_PREFERENCE = "com.adins.mss.base.SynchronizationPreference";
|
||||
private static final String DTM_UPD_KEY = "com.adins.mss.base.SynchronizationPreference";
|
||||
private final Context context;
|
||||
|
||||
/**
|
||||
* New data synchronization instance.
|
||||
*
|
||||
* @param context The context of synchronization.
|
||||
*/
|
||||
public DataSynchronizer(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reflect server database to local database
|
||||
*
|
||||
* @param <T> Dao class type.
|
||||
* @param <TDataAccess> Dao data access type.
|
||||
* @param tableName Name of the table to reflect.
|
||||
* @param daoClass The dao class of the table.
|
||||
* @param dataAccessClass Data access class of the table. The class must have add(Context, List<daoClass>)
|
||||
* static method on it to be able to handle the reflection.
|
||||
* @param synchronizationCallback Callback called during synchronization event, may be null.
|
||||
* @param init
|
||||
* @param generateUuid
|
||||
* @throws IOException Bubbled from http request to the server.
|
||||
*/
|
||||
public <T, TDataAccess> void reflect(
|
||||
String tableName,
|
||||
final Class<T> daoClass,
|
||||
final Class<TDataAccess> dataAccessClass,
|
||||
List parameters,
|
||||
final SynchronizationCallback synchronizationCallback,
|
||||
int init, final boolean generateUuid, String flag) throws IOException {
|
||||
|
||||
// Get last dtm_upd.
|
||||
final ObscuredSharedPreferences synchronizationPreference =
|
||||
ObscuredSharedPreferences.getPrefs(context, SYNCHRONIZATION_PREFERENCE + "." + tableName, Context.MODE_PRIVATE);
|
||||
|
||||
Date date = null;
|
||||
if (synchronizationPreference.contains(DTM_UPD_KEY)) {
|
||||
date = new Date(Long.parseLong(synchronizationPreference.getString(DTM_UPD_KEY, "")));
|
||||
}
|
||||
|
||||
SynchronizeRequestModel request = new SynchronizeRequestModel();
|
||||
request.setInit(init);
|
||||
if (parameters != null)
|
||||
request.setList(parameters);
|
||||
request.setAudit(GlobalData.getSharedGlobalData().getAuditData());
|
||||
|
||||
request.setTableName(tableName);
|
||||
if (date != null) {
|
||||
request.setDtm_upd(date);
|
||||
}
|
||||
|
||||
String jsonRequest = GsonHelper.toJson(request);
|
||||
boolean encrypt = GlobalData.getSharedGlobalData().isEncrypt();
|
||||
boolean decrypt = GlobalData.getSharedGlobalData().isDecrypt();
|
||||
HttpCryptedConnection httpConn = new HttpCryptedConnection(context, encrypt, decrypt);
|
||||
HttpConnectionResult serverResult = null;
|
||||
String url = GlobalData.getSharedGlobalData().getURL_SYNCPARAM();
|
||||
|
||||
//Firebase Performance Trace HTTP Request
|
||||
HttpMetric networkMetric =
|
||||
FirebasePerformance.getInstance().newHttpMetric(url, FirebasePerformance.HttpMethod.POST);
|
||||
Utility.metricStart(networkMetric, jsonRequest);
|
||||
|
||||
try {
|
||||
serverResult = httpConn.requestToServer(url, jsonRequest, Global.DEFAULTCONNECTIONTIMEOUT);
|
||||
Utility.metricStop(networkMetric, serverResult);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
}
|
||||
String body = null;
|
||||
if (serverResult != null && serverResult.isOK()) {
|
||||
body = serverResult.getResult();
|
||||
} else {
|
||||
reportFailure(synchronizationCallback);
|
||||
return;
|
||||
}
|
||||
if (Global.IS_DEV)
|
||||
Log.i("DataSynchronizer", body);
|
||||
// This may not work, the requested entity is typed but gson
|
||||
// give us entity with linked hash map as the sync entries.
|
||||
// BLAME THE DAMN TYPE ERASURE OF JAVA !!!
|
||||
// HACK use an object mapper.
|
||||
|
||||
|
||||
SynchronizeResponseSync entitySync = null;
|
||||
SynchronizeResponseLookup entityLookup = null;
|
||||
SynchronizeResponseHoliday entityHoliday = null;
|
||||
SynchronizeResponseCOH entityCOH = null;
|
||||
SynchronizeResponse<LinkedHashMap> entity = null;
|
||||
boolean dataWasHere = false;
|
||||
|
||||
if (flag.equals(IS_SYNCHRONIZE_SYNC)) {
|
||||
entitySync = GsonHelper.fromJson(body, SynchronizeResponseSync.class);
|
||||
if (entitySync != null && entitySync.getListSync() != null && !entitySync.getListSync().isEmpty())
|
||||
dataWasHere = true;
|
||||
} else if (flag.equals(IS_SYNCHRONIZE_LOOKUP)) {
|
||||
entityLookup = GsonHelper.fromJson(body, SynchronizeResponseLookup.class);
|
||||
if (entityLookup != null && entityLookup.getListSync() != null && !entityLookup.getListSync().isEmpty())
|
||||
dataWasHere = true;
|
||||
} else if (flag.equals(IS_SYNCHRONIZE_HOLIDAY)) {
|
||||
entityHoliday = GsonHelper.fromJson(body, SynchronizeResponseHoliday.class);
|
||||
if (entityHoliday != null && entityHoliday.getListSync() != null && !entityHoliday.getListSync().isEmpty())
|
||||
dataWasHere = true;
|
||||
} else if (flag.equals(IS_SYNCHRONIZE_COH)) {
|
||||
entityCOH = GsonHelper.fromJson(body, SynchronizeResponseCOH.class);
|
||||
if (entityCOH != null && entityCOH.getListSync() != null && !entityCOH.getListSync().isEmpty())
|
||||
dataWasHere = true;
|
||||
}
|
||||
else {
|
||||
entity = GsonHelper.fromJson(body, SynchronizeResponse.class);
|
||||
if (entity != null && entity.getListSync() != null && !entity.getListSync().isEmpty())
|
||||
dataWasHere = true;
|
||||
}
|
||||
|
||||
if (dataWasHere) {
|
||||
saveNewDtmUpd(synchronizationPreference);
|
||||
|
||||
try {
|
||||
Method add = dataAccessClass.getMethod("addOrUpdateAll", Context.class, List.class);
|
||||
List<Sync> entitiesSync;
|
||||
List<Lookup> entitiesLookup;
|
||||
List<Holiday> entitiesHoliday;
|
||||
List<User> entitiesCOH;
|
||||
if (flag.equals(IS_SYNCHRONIZE_SYNC)) {
|
||||
if (generateUuid) {
|
||||
entitiesSync = new ArrayList<>();
|
||||
for (Sync sch : entitySync.getListSync()) {
|
||||
sch.setUuid_sync(Tool.getUUID());
|
||||
entitiesSync.add(sch);
|
||||
}
|
||||
} else {
|
||||
entitiesSync = entitySync.getListSync();
|
||||
}
|
||||
SyncDataAccess.addOrReplaceAll(context, entitiesSync);
|
||||
} else if (flag.equals(IS_SYNCHRONIZE_LOOKUP)) {
|
||||
if (generateUuid) {
|
||||
entitiesLookup = new ArrayList<>();
|
||||
for (Lookup sch : entityLookup.getListSync()) {
|
||||
sch.setUuid_lookup(Tool.getUUID());
|
||||
entitiesLookup.add(sch);
|
||||
}
|
||||
} else {
|
||||
entitiesLookup = entityLookup.getListSync();
|
||||
}
|
||||
LookupDataAccess.addOrUpdateAll(context, entitiesLookup);
|
||||
} else if (flag.equals(IS_SYNCHRONIZE_HOLIDAY)) {
|
||||
if (generateUuid) {
|
||||
entitiesHoliday = new ArrayList<>();
|
||||
for (Holiday sch : entityHoliday.getListSync()) {
|
||||
sch.setUuid_holiday(Tool.getUUID());
|
||||
entitiesHoliday.add(sch);
|
||||
}
|
||||
} else {
|
||||
entitiesHoliday = entityHoliday.getListSync();
|
||||
}
|
||||
HolidayDataAccess.addOrReplace(context, entitiesHoliday);
|
||||
} else if (flag.equals(IS_SYNCHRONIZE_COH)) {
|
||||
entitiesCOH = entityCOH.getListSync();
|
||||
UserDataAccess.addOrReplace(context, entitiesCOH);
|
||||
}
|
||||
else {
|
||||
// Gson return a linked hash map. Change it to entities.
|
||||
List<T> entities = LinkedHashMapToObject.convert(entity.getListSync(), daoClass, generateUuid);
|
||||
// Invoke the static method add.
|
||||
add.invoke(null, context, entities);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
reportFailure(synchronizationCallback);
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
reportSuccess(synchronizationCallback);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fake reflect server database to local database. This does not actually update the database or
|
||||
* update the timestamp.
|
||||
*
|
||||
* @param <T> Dao class type.
|
||||
* @param tableName Name of the table to reflect.
|
||||
* @param daoClass The dao class of the table.
|
||||
* @param synchronizationCallback Callback called during synchronization event, may be null.
|
||||
* @param init
|
||||
* @param generateUuid
|
||||
* @throws IOException Bubbled from http request to the server.
|
||||
*/
|
||||
public <T, TDataAccess> void fakeReflect(
|
||||
String tableName,
|
||||
final Class<T> daoClass,
|
||||
List parameters,
|
||||
final FakeSynchronizationCallback<T> synchronizationCallback,
|
||||
int init, final boolean generateUuid, String flag) throws IOException {
|
||||
|
||||
// Get last dtm_upd.
|
||||
final ObscuredSharedPreferences synchronizationPreference =
|
||||
ObscuredSharedPreferences.getPrefs(context, SYNCHRONIZATION_PREFERENCE + "." + tableName, Context.MODE_PRIVATE);
|
||||
|
||||
Date date = null;
|
||||
if (synchronizationPreference.contains(DTM_UPD_KEY)) {
|
||||
date = new Date(Long.parseLong(synchronizationPreference.getString(DTM_UPD_KEY, "")));
|
||||
}
|
||||
|
||||
SynchronizeRequestModel request = new SynchronizeRequestModel();
|
||||
request.setInit(init);
|
||||
if (parameters != null){
|
||||
//Perbaikan jika setelah embed CSV ada lov group yang belum di insert ke database mobile, set dtm_upd null
|
||||
if (flag.equals(IS_SYNCHRONIZE_LOOKUP)) {
|
||||
for (int i = 0; i < parameters.size(); i++) {
|
||||
Map lovGroup = (Map) parameters.get(i);
|
||||
Sync sync = SyncDataAccess.getOneByLovGroupName(context, (String) lovGroup.get("lov_group"));
|
||||
if (sync == null) {
|
||||
lovGroup.put("dtm_upd", null);
|
||||
parameters.set(i, lovGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
//end
|
||||
request.setList(parameters);
|
||||
}
|
||||
request.setAudit(GlobalData.getSharedGlobalData().getAuditData());
|
||||
request.setTableName(tableName);
|
||||
if (date != null) {
|
||||
request.setDtm_upd(date);
|
||||
}
|
||||
|
||||
String jsonRequest = GsonHelper.toJson(request);
|
||||
if (flag.equals(IS_SYNCHRONIZE_COH)) {
|
||||
SynchronizeCOHRequestModel requestModel = new SynchronizeCOHRequestModel(request);
|
||||
String loginId = GlobalData.getSharedGlobalData().getUser().getLogin_id();
|
||||
int idxOfOpenAt = loginId.indexOf('@');
|
||||
if (idxOfOpenAt != -1) {
|
||||
loginId = loginId.substring(0, idxOfOpenAt);
|
||||
}
|
||||
requestModel.setLogin_ID(loginId);
|
||||
requestModel.setAudit(GlobalData.getSharedGlobalData().getAuditData());
|
||||
jsonRequest = GsonHelper.toJson(requestModel);
|
||||
}
|
||||
|
||||
boolean encrypt = GlobalData.getSharedGlobalData().isEncrypt();
|
||||
boolean decrypt = GlobalData.getSharedGlobalData().isDecrypt();
|
||||
HttpCryptedConnection httpConn = new HttpCryptedConnection(context, encrypt, decrypt);
|
||||
HttpConnectionResult serverResult = null;
|
||||
String url = GlobalData.getSharedGlobalData().getURL_SYNCPARAM();
|
||||
|
||||
//Firebase Performance Trace HTTP Request
|
||||
HttpMetric networkMetric =
|
||||
FirebasePerformance.getInstance().newHttpMetric(url, FirebasePerformance.HttpMethod.POST);
|
||||
Utility.metricStart(networkMetric, jsonRequest);
|
||||
|
||||
try {
|
||||
serverResult = httpConn.requestToServer(url, jsonRequest, Global.DEFAULTCONNECTIONTIMEOUT);
|
||||
Utility.metricStop(networkMetric, serverResult);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
}
|
||||
String body = null;
|
||||
if (serverResult != null && serverResult.isOK()) {
|
||||
body = serverResult.getResult();
|
||||
} else {
|
||||
if (serverResult != null)
|
||||
reportFakeFailure(synchronizationCallback, serverResult.getResult());
|
||||
else
|
||||
reportFakeFailure(synchronizationCallback, null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Global.IS_DEV)
|
||||
Log.i("DataSynchronizer", body);
|
||||
// This may not work, the requested entity is typed but gson
|
||||
// give us entity with linked hash map as the sync entries.
|
||||
// BLAME THE DAMN TYPE ERASURE OF JAVA !!!
|
||||
// HACK use an object mapper.
|
||||
SynchronizeResponseSync entitySync = null;
|
||||
SynchronizeResponseLookup entityLookup = null;
|
||||
SynchronizeResponseHoliday entityHoliday = null;
|
||||
SynchronizeResponseCOH entityCOH = null;
|
||||
SynchronizeResponse<LinkedHashMap> entity = null;
|
||||
boolean dataWasHere = false;
|
||||
boolean datawasZero = false;
|
||||
|
||||
|
||||
if (flag.equals(IS_SYNCHRONIZE_SYNC)) {
|
||||
entitySync = GsonHelper.fromJson(body, SynchronizeResponseSync.class);
|
||||
if (entitySync != null && entitySync.getListSync() != null && !entitySync.getListSync().isEmpty())
|
||||
dataWasHere = true;
|
||||
else if (entitySync != null && entitySync.getListSync() != null && entitySync.getListSync().isEmpty())
|
||||
datawasZero = true;
|
||||
} else if (flag.equals(IS_SYNCHRONIZE_LOOKUP)) {
|
||||
entityLookup = GsonHelper.fromJson(body, SynchronizeResponseLookup.class);
|
||||
if (entityLookup != null && entityLookup.getListSync() != null && !entityLookup.getListSync().isEmpty())
|
||||
dataWasHere = true;
|
||||
else if (entityLookup != null && entityLookup.getListSync() != null && entityLookup.getListSync().isEmpty())
|
||||
datawasZero = true;
|
||||
} else if (flag.equals(IS_SYNCHRONIZE_HOLIDAY)) {
|
||||
entityHoliday = GsonHelper.fromJson(body, SynchronizeResponseHoliday.class);
|
||||
if (entityHoliday != null && entityHoliday.getListSync() != null && !entityHoliday.getListSync().isEmpty())
|
||||
dataWasHere = true;
|
||||
else if (entityHoliday != null && entityHoliday.getListSync() != null && entityHoliday.getListSync().isEmpty())
|
||||
datawasZero = true;
|
||||
} else if (flag.equals(IS_SYNCHRONIZE_COH)) {
|
||||
entityCOH = GsonHelper.fromJson(body, SynchronizeResponseCOH.class);
|
||||
if (entityCOH != null && entityCOH.getListSync() != null && !entityCOH.getListSync().isEmpty()) {
|
||||
dataWasHere = true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
entity = GsonHelper.fromJson(body, SynchronizeResponse.class);
|
||||
if (entity != null && entity.getListSync() != null && !entity.getListSync().isEmpty())
|
||||
dataWasHere = true;
|
||||
else if (entity != null && entity.getListSync() != null && entity.getListSync().isEmpty())
|
||||
datawasZero = true;
|
||||
}
|
||||
|
||||
if (dataWasHere) {
|
||||
|
||||
try {
|
||||
List<Sync> entitiesSync;
|
||||
List<Lookup> entitiesLookup;
|
||||
List<Holiday> entitiesHoliday;
|
||||
List<User> entitiesCOH;
|
||||
if (flag.equals(IS_SYNCHRONIZE_SYNC)) {
|
||||
if (generateUuid) {
|
||||
entitiesSync = new ArrayList<>();
|
||||
for (Sync sch : entitySync.getListSync()) {
|
||||
sch.setUuid_sync(Tool.getUUID());
|
||||
entitiesSync.add(sch);
|
||||
}
|
||||
} else {
|
||||
entitiesSync = entitySync.getListSync();
|
||||
}
|
||||
reportFakeSuccess(synchronizationCallback, entitiesSync);
|
||||
} else if (flag.equals(IS_SYNCHRONIZE_LOOKUP)) {
|
||||
if (generateUuid) {
|
||||
entitiesLookup = new ArrayList<>();
|
||||
for (Lookup sch : entityLookup.getListSync()) {
|
||||
sch.setUuid_lookup(Tool.getUUID());
|
||||
entitiesLookup.add(sch);
|
||||
}
|
||||
} else {
|
||||
entitiesLookup = entityLookup.getListSync();
|
||||
}
|
||||
reportFakeSuccess(synchronizationCallback, entitiesLookup);
|
||||
} else if (flag.equals(IS_SYNCHRONIZE_HOLIDAY)) {
|
||||
saveNewDtmUpd(synchronizationPreference);
|
||||
if (generateUuid) {
|
||||
entitiesHoliday = new ArrayList<>();
|
||||
for (Holiday sch : entityHoliday.getListSync()) {
|
||||
sch.setUuid_holiday(Tool.getUUID());
|
||||
entitiesHoliday.add(sch);
|
||||
}
|
||||
} else {
|
||||
entitiesHoliday = entityHoliday.getListSync();
|
||||
}
|
||||
reportFakeSuccess(synchronizationCallback, entitiesHoliday);
|
||||
} else if (flag.equals(IS_SYNCHRONIZE_COH)) {
|
||||
entitiesCOH = entityCOH.getListSync();
|
||||
User ucash = GlobalData.getSharedGlobalData().getUser();
|
||||
|
||||
if (entitiesCOH.get(0).getCash_limit() == null)
|
||||
ucash.setCash_limit("0");
|
||||
else
|
||||
ucash.setCash_limit(entitiesCOH.get(0).getCash_limit());
|
||||
|
||||
ucash.setCash_on_hand(entitiesCOH.get(0).getCash_on_hand());
|
||||
UserDataAccess.addOrReplace(context, ucash);
|
||||
reportFakeSuccess(synchronizationCallback, entitiesCOH);
|
||||
}
|
||||
else {
|
||||
// Gson return a linked hash map. Change it to entities.
|
||||
List<T> entities = LinkedHashMapToObject.convert(entity.getListSync(), daoClass, generateUuid);
|
||||
reportFakeSuccess(synchronizationCallback, entities);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
reportFakeFailure(synchronizationCallback, e.getMessage());
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
} else if (datawasZero) {
|
||||
try {
|
||||
List<Sync> entitiesSync;
|
||||
List<Lookup> entitiesLookup;
|
||||
List<Holiday> entitiesHoliday;
|
||||
List<User> entitiesCOH;
|
||||
|
||||
if (flag.equals(IS_SYNCHRONIZE_SYNC)) {
|
||||
if (generateUuid) {
|
||||
entitiesSync = new ArrayList<>();
|
||||
for (Sync sch : entitySync.getListSync()) {
|
||||
sch.setUuid_sync(Tool.getUUID());
|
||||
entitiesSync.add(sch);
|
||||
}
|
||||
} else {
|
||||
entitiesSync = entitySync.getListSync();
|
||||
}
|
||||
reportFakeSuccess(synchronizationCallback, entitiesSync);
|
||||
} else if (flag.equals(IS_SYNCHRONIZE_LOOKUP)) {
|
||||
if (generateUuid) {
|
||||
entitiesLookup = new ArrayList<>();
|
||||
for (Lookup sch : entityLookup.getListSync()) {
|
||||
sch.setUuid_lookup(Tool.getUUID());
|
||||
entitiesLookup.add(sch);
|
||||
}
|
||||
} else {
|
||||
entitiesLookup = entityLookup.getListSync();
|
||||
}
|
||||
reportFakeSuccess(synchronizationCallback, entitiesLookup);
|
||||
} else if (flag.equals(IS_SYNCHRONIZE_HOLIDAY)) {
|
||||
if (generateUuid) {
|
||||
entitiesHoliday = new ArrayList<>();
|
||||
for (Holiday sch : entityHoliday.getListSync()) {
|
||||
sch.setUuid_holiday(Tool.getUUID());
|
||||
entitiesHoliday.add(sch);
|
||||
}
|
||||
} else {
|
||||
entitiesHoliday = entityHoliday.getListSync();
|
||||
}
|
||||
reportFakeSuccess(synchronizationCallback, entitiesHoliday);
|
||||
} else if (flag.equals(IS_SYNCHRONIZE_COH)) {
|
||||
entitiesCOH = entityCOH.getListSync();
|
||||
reportFakeSuccess(synchronizationCallback, entitiesCOH);
|
||||
}
|
||||
else {
|
||||
// Gson return a linked hash map. Change it to entities.
|
||||
List<T> entities = LinkedHashMapToObject.convert(entity.getListSync(), daoClass, generateUuid);
|
||||
reportFakeSuccess(synchronizationCallback, entities);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void reportFakeFailure(FakeSynchronizationCallback synchronizationCallback, String errorMessage) {
|
||||
if (synchronizationCallback != null) {
|
||||
String errMessage = errorMessage != null ? errorMessage : "";
|
||||
synchronizationCallback.onFailed(errMessage);
|
||||
}
|
||||
}
|
||||
|
||||
private <T> void reportFakeSuccess(FakeSynchronizationCallback synchronizationCallback, List<T> entities) {
|
||||
if (synchronizationCallback != null) {
|
||||
synchronizationCallback.onSuccess(entities);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveNewDtmUpd(ObscuredSharedPreferences synchronizationPreference) {
|
||||
ObscuredSharedPreferences.Editor editor = synchronizationPreference.edit();
|
||||
editor.putString(DTM_UPD_KEY, String.valueOf(Calendar.getInstance().getTime().getTime()));
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
private void reportSuccess(SynchronizationCallback synchronizationCallback) {
|
||||
if (synchronizationCallback != null)
|
||||
synchronizationCallback.onSuccess();
|
||||
}
|
||||
|
||||
private void reportFailure(SynchronizationCallback synchronizationCallback) {
|
||||
if (synchronizationCallback != null)
|
||||
synchronizationCallback.onFailed();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue