add project adins

This commit is contained in:
Alfrid Sanjaya Leo Putra 2024-07-25 14:44:22 +07:00
commit f8f85d679d
5299 changed files with 625430 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 4 KiB

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<com.github.jjobes.slidedatetimepicker.CustomDatePicker
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/datePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:calendarViewShown="false" />

View file

@ -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="M22,10l-6,-6L4,4c-1.1,0 -2,0.9 -2,2v12.01c0,1.1 0.9,1.99 2,1.99l16,-0.01c1.1,0 2,-0.89 2,-1.99v-8zM15,5.5l5.5,5.5L15,11L15,5.5z"/>
</vector>

View file

@ -0,0 +1,221 @@
package com.adins.mss.foundation.sync;
import com.adins.mss.base.GlobalData;
import com.adins.mss.base.util.GsonHelper;
import com.adins.mss.foundation.camerainapp.helper.Logger;
import com.adins.mss.foundation.http.HttpBackgroundConnection;
import com.adins.mss.foundation.http.HttpBackgroundConnection.HttpBackgroundConnectionListener;
import com.adins.mss.foundation.http.HttpConnection;
import com.adins.mss.foundation.http.HttpConnectionResult;
import com.adins.mss.foundation.http.HttpCryptedConnection;
import java.util.List;
/**
* A class to perform a sequence of synchronization. Items to be synchronized are defined in SynchronizeScheme, which
* will provide Synchronize with the list of SynchronizeItem and the process of inserting it to database. Connection will be made
* on background thread, while the progress update will be done on UI Thread
* <p>
* <p>The steps needed to use Synchronize to do a synchronization process are:
* <li>Create a Synchronize object
* <li>Set a SynchronizeScheme to the object. Use DefaultSynchronizeScheme for MSS default scheme, or use own implementation of SynchronizeScheme
* <li>Set a SychronizeListener to respond on synchronize progress
* <li>Call startSynchronize() to start sync process. Method would return true/false based on result of the process. Synchronize
* object will also call progressUpdated() or synchronizeFailed(). It is recommended to handle the progress from the callback
* instead of using the method return
* <li>When sync process failed in one of the process, sync process will stopped. To resume from the last sync process, call
* resumeSync(). As long as no changes are made to the scheme, resumeSync() will resume process from the last step of synchronization
*
* @author glen.iglesias
* @see Synchronize
* @see SynchronizeScheme
* @see SynchronizeItem
*/
public class BackgroundSynchronize implements HttpBackgroundConnectionListener {
/**
* To store last progress of sync, so sync process can be resumed based on this parameter.
*/
private int currProgress;
/**
* To store how many retries or resume has been made after a synchronize failure
*/
private int numOfRetries;
/**
* A list of SynchronizeItem to get information on what and where to request to server, and on how and where to store
* data returned from server. This list determines the steps of synchronize process.
* <br>This is automatically set on set SynchronizeScheme
*/
private List<SynchronizeItem> syncItems;
/**
* Current SynchonizeItem which being processed
*/
private SynchronizeItem currSyncItem;
/**
* A scheme which tells Synchronize object what are the items that need to be synchronized, in a form of a
* SynchronizeItem object, and tells how to process received data from server
* <p>
* <P>When the scheme is changed, it is considered as a new synchronize process, thus reset it's state
*/
private SynchronizeScheme scheme;
/**
* The listener to update synchronize progress
*/
private SynchronizeListener listener;
public BackgroundSynchronize() {
}
public SynchronizeListener getListener() {
return listener;
}
public void setListener(SynchronizeListener listener) {
this.listener = listener;
}
public void setSynchronizeScheme(SynchronizeScheme scheme) {
this.scheme = scheme;
syncItems = scheme.getSynchronizeItemList();
initialize();
}
public void startSynchronize() {
initialize();
synchronizeCurrentProgress();
}
private void initialize() {
currProgress = 0;
numOfRetries = 0;
}
private void synchronizeCurrentProgress() {
SynchronizeItem syncItem = syncItems.get(currProgress);
synchronize(syncItem);
}
private void synchronize(SynchronizeItem syncItem) {
//register as currSyncItem, so the connection callback can access currSyncItem
currSyncItem = syncItem;
//get last_update
//TODO
//create json to send to server
String data;
SynchronizeRequestModel model = new SynchronizeRequestModel(true, syncItem.getAction(), "lastupdate");
data = GsonHelper.toJson(model);
Logger.d("Sync", "JSON = " + data);
//request connection to server
GlobalData gd = GlobalData.getSharedGlobalData();
String url = gd.getUrlSync();
boolean enc = gd.isEncrypt();
boolean dec = gd.isDecrypt();
HttpCryptedConnection conn = new HttpCryptedConnection(enc, dec);
HttpBackgroundConnection connTask = new HttpBackgroundConnection(url, data, conn, this);
connTask.execute();
}
/**
* Call this to resume synchronize form the last step tried but failed. It counts the number of retries up.
* <br>This should only be used to resume, not as the start of synchronize process
*/
public void resumeSync() {
numOfRetries++;
synchronizeCurrentProgress();
}
//=== Background Connection Listener ===//
@Override
public void onConnectionResult(HttpBackgroundConnection connTask,
HttpConnection conn, HttpConnectionResult result) {
if (!result.isOK()) {
//numOfRetries are incremented on resumeSync()
listener.synchronizeFailed(currSyncItem, result, numOfRetries);
return;
}
//reset numOfRetries
numOfRetries = 0;
//process server return
String resultString = result.getResult();
//save to db
scheme.insertToDb(resultString, currSyncItem.getSyncItemId());
//update progress
currProgress++;
int totalItem = syncItems.size();
float progress = ((float) currProgress / totalItem);
listener.progressUpdated(progress);
synchronizeCurrentProgress();
}
//=== Interfaces ===//
/**
* Interface definition for a callback to be invoked on Synchronize process, which are when progress updated successfully
* and when it failed
*
* @author glen.iglesias
*/
public interface SynchronizeListener {
/**
* Called when a step of synchronization succeed.
*
* @param progress the updated current progress of synchronization in percentage
*/
void progressUpdated(float progress);
/**
* Called when a step of synchronization failed.
*
* @param syncItem SynchronizeItem in which step is failed
* @param errorResult the connection error. Null if the cause of error is not connection
* @param numOfRetries how many time
*/
void synchronizeFailed(SynchronizeItem syncItem, HttpConnectionResult errorResult, int numOfRetries);
}
/**
* Interface definition on which Synchronize object will call when in need of Synchronize info.
*
* @author glen.iglesias
*/
public interface SynchronizeScheme {
/**
* Provide Synchronize with a list of SynchronizeItem
*
* @return a list of SynchronizeItem to be used by Synchronize object
*/
List<SynchronizeItem> getSynchronizeItemList();
/**
* Responsible to insert data returned from server to specific database table
* <p>
* <p>We are supposed to create the implementation of how to process the returned data in form of a JSON
* <br>The JSON format depends on how server return the data, thus an agreement on JSON format is needed
*
* @param json returned data from server in a form of JSON
* @param syncItemId corresponding SynchonizeItem id for returned JSON
* @return true if successfully processed the data
*/
boolean insertToDb(String json, String syncItemId);
}
}

View file

@ -0,0 +1,87 @@
package com.adins.mss.base;
/**
* BaseCommunicationModel provides a class with basic parameters needed in most communication with MSS Server,
* like user login Id and IMEI code. Any class which are going to communicate in JSON should use/subclass this model object
* to convert to JSON to ensure the same JSON format with MSS Server's JSON
*
* @author glen.iglesias
* @deprecated as of 17 Dec 2014, communication should use MssRequestType and MssResponseType as standard format
*/
public class BaseCommunicationModel {
protected String osName;
protected String userId;
protected String deviceModel;
protected String imei;
protected String imsi;
protected String pin;
protected String androidId;
public BaseCommunicationModel() {
}
public BaseCommunicationModel(boolean useDefault) {
if (useDefault) {
GlobalData gd = GlobalData.getSharedGlobalData();
osName = gd.getOsName();
deviceModel = gd.getDeviceModel();
imei = gd.getImei();
imsi = gd.getImsi();
pin = "ANDROID";
androidId = GlobalData.getSharedGlobalData().getAndroidId();
userId = gd.getUser().getLogin_id();
}
}
public String getOsName() {
return osName;
}
public void setOsName(String osName) {
this.osName = osName;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getDeviceModel() {
return deviceModel;
}
public void setDeviceModel(String deviceModel) {
this.deviceModel = deviceModel;
}
public String getImei() {
return imei;
}
public void setImei(String imei) {
this.imei = imei;
}
public String getImsi() {
return imsi;
}
public void setImsi(String imsi) {
this.imsi = imsi;
}
public String getPin() {
return pin;
}
public void setPin(String pin) {
this.pin = pin;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

View file

@ -0,0 +1,29 @@
package com.adins.mss.foundation.broadcast;
import com.adins.mss.foundation.http.MssRequestType;
import com.google.gson.annotations.SerializedName;
import java.util.List;
public class SubmitTopicRequest extends MssRequestType {
@SerializedName("uuid_user")
String uuidUser;
@SerializedName("subscribedTopic")
List<String> subscribedTopic;
public String getUuidUser() {
return uuidUser;
}
public void setUuidUser(String uuidUser) {
this.uuidUser = uuidUser;
}
public List<String> getSubscribedTopic() {
return subscribedTopic;
}
public void setSubscribedTopic(List<String> subscribedTopic) {
this.subscribedTopic = subscribedTopic;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB