Skip to content

Commit 1fcb83a

Browse files
committed
Added developer id for istening tag
1 parent 5698fae commit 1fcb83a

File tree

7 files changed

+142
-24
lines changed

7 files changed

+142
-24
lines changed

ats-sdk/src/main/java/com/apporioinfolabs/ats_sdk/ATS.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ private Builder(Application application) {
124124
}
125125

126126
public Builder setAppId(String appId){
127-
this.AppId = appId ;
127+
this.AppId = "auth_token="+appId ;
128128
return this;
129129
}
130130

@@ -248,8 +248,8 @@ public static void removeAllListeners(AtsOnRemoveMessageListener atsOnRemoveMess
248248
}
249249

250250

251-
public static void listenTagAccordingToRadius(String tag, double latitude, double longitude, int radiusInMeter, AtsTagListener atsTagListener){
252-
SocketManager.listenToTag(tag, latitude, longitude, radiusInMeter, atsTagListener);
251+
public static void listenTagAccordingToRadius(String tag, double latitude, double longitude, int radiusInMeter, String developerId, AtsTagListener atsTagListener){
252+
SocketManager.listenToTag(tag, latitude, longitude, radiusInMeter, developerId, atsTagListener);
253253
}
254254

255255

ats-sdk/src/main/java/com/apporioinfolabs/ats_sdk/managers/AtsLocationManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ public void onLocationResult(LocationResult locationResult) {
8686
ATS.getAtsid()).put("location",locationString+ "_"
8787
+ATS.mBatteryLevel+"_"
8888
+(ATS.app_foreground?"1":"0")+"_"
89-
+sharedPrefrencesManager.fetchData(ATSConstants.KEYS.TAG)));
89+
+sharedPrefrencesManager.fetchData(ATSConstants.KEYS.TAG)+"_"
90+
+sharedPrefrencesManager.fetchData(ATSConstants.KEYS.DEVELOPER_ID)));
9091
}
9192
else{ databaseManager.addLocationLog(locationString+"_"+ATS.mBatteryLevel+"_"+(ATS.app_foreground?"1":"0")+"_"+sharedPrefrencesManager.fetchData(ATSConstants.KEYS.TAG)); }
9293
}catch (Exception e){

ats-sdk/src/main/java/com/apporioinfolabs/ats_sdk/managers/DataParsingManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public class DataParsingManager {
1111

1212
public static String getMessageType ( String message){
1313
try{
14-
ModelMessageType modelMessageType = ATS.gson.fromJson(""+message,ModelMessageType.class);
15-
return modelMessageType.getNameValuePairs().getType();
14+
ModelMessageType modelMessageType = ATS.gson.fromJson(message,ModelMessageType.class);
15+
return modelMessageType.getResponse().getType();
1616
}catch (Exception e){
1717
LOGS.e(TAG , ""+e.getMessage());
1818
return "NA";

ats-sdk/src/main/java/com/apporioinfolabs/ats_sdk/managers/SocketManager.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.apporioinfolabs.ats_sdk.AtsOnTripSetListener;
1111
import com.apporioinfolabs.ats_sdk.AtsTagListener;
1212
import com.apporioinfolabs.ats_sdk.models.LocationLogs;
13+
import com.apporioinfolabs.ats_sdk.models.ModelDeviceConnect;
1314
import com.apporioinfolabs.ats_sdk.models.ModelResultChecker;
1415
import com.apporioinfolabs.ats_sdk.models.ModelTag;
1516
import com.apporioinfolabs.ats_sdk.models.ModelTagListener;
@@ -115,8 +116,9 @@ public void call(final Object... args) {
115116
public static Emitter.Listener onAtsIdMessage = new Emitter.Listener() {
116117
@Override
117118
public void call(final Object... args) {
118-
LOGS.w(TAG , ""+ ATS.gson.toJson(args[0]));
119-
LOGS.w(TAG , ""+DataParsingManager.getMessageType(""+ ATS.gson.toJson(args[0])));
119+
LOGS.w(TAG , ATS.gson.toJson(""+args[0]));
120+
121+
LOGS.w(TAG , ""+DataParsingManager.getMessageType(""+args[0]));
120122
}
121123
};
122124

@@ -221,7 +223,6 @@ public static void addTag(String tag, final AtsOnTagSetListener atsOnTagSetListe
221223
mSocket.emit(ADD_TAG, new JSONObject().put("ats_id",""+ATS.getAtsid()).put("tag",tag), new Ack() {
222224
@Override
223225
public void call(Object... args) {
224-
225226
ModelResultChecker modelResultChecker = ATS.gson.fromJson(""+args[0],ModelResultChecker.class);
226227
if(modelResultChecker.getResult() == 1){
227228
handlerForSetTagsListeners(""+modelResultChecker.getMessage(), atsOnTagSetListener,1);
@@ -266,7 +267,7 @@ public void call(Object... args) {
266267
}
267268
}
268269

269-
public static void listenToTag(String tag, double latitiude , double longitide, int radius, final AtsTagListener atsTagListener){
270+
public static void listenToTag(String tag, double latitiude , double longitide, int radius, String developerid, final AtsTagListener atsTagListener){
270271
try{
271272
if(mSocket.connected()){
272273
mSocket.emit(LISTEN_TAG, new JSONObject()
@@ -275,7 +276,8 @@ public static void listenToTag(String tag, double latitiude , double longitide,
275276
.put("tag", tag)
276277
.put("latitude", latitiude)
277278
.put("longitude", longitide)
278-
.put("radius", radius), new Ack() {
279+
.put("radius", radius)
280+
.put("developer_id",""+developerid), new Ack() {
279281
@Override
280282
public void call(Object... args) {
281283
ModelResultChecker modelResultChecker = ATS.gson.fromJson(""+args[0],ModelResultChecker.class);
@@ -524,17 +526,25 @@ public void run() {
524526
}
525527

526528
// EMITTERS
527-
528529
public void emitDevice( String data){
529530
mSocket.emit(CONNECT_DEVICE, data, new Ack() {
530531
@Override
531532
public void call(Object... args) {
532-
LOGS.d(TAG , ""+args[0]);
533533
try{
534-
ATS.mBuilder.mApplication.getSharedPreferences(ATSConstants.PREFRENCES, Context.MODE_PRIVATE).edit().putString(ATSConstants.KEYS.ATS_ID,""+args[0]).commit();
535-
// after saving ats_id in SP it will start listening to this ats_id all message will be deliver in this code (notification, location, message from panel . . . )
536-
mSocket.off(""+args[0],onAtsIdMessage); // removing previous listening so that it will listen only one time.
537-
mSocket.on(""+args[0],onAtsIdMessage);
534+
ModelResultChecker modelResultChecker = ATS.gson.fromJson(""+args[0], ModelResultChecker.class);
535+
if(modelResultChecker.getResult() == 1){
536+
ModelDeviceConnect modelDeviceConnect = ATS.gson.fromJson(""+args[0],ModelDeviceConnect.class);
537+
ATS.mBuilder.mApplication.getSharedPreferences(ATSConstants.PREFRENCES, Context.MODE_PRIVATE).edit().putString(ATSConstants.KEYS.ATS_ID,""+modelDeviceConnect.getResponse().get(0).getAts_id()).commit();
538+
ATS.mBuilder.mApplication.getSharedPreferences(ATSConstants.PREFRENCES, Context.MODE_PRIVATE).edit().putString(ATSConstants.KEYS.DEVELOPER_ID,""+modelDeviceConnect.getResponse().get(0).getDeveloper_id()).commit();
539+
// after saving ats_id in SP it will start listening to this ats_id all message will be deliver in this code (notification, location, message from panel . . . )
540+
541+
String selfIdListener = ""+modelDeviceConnect.getResponse().get(0).getAts_id()+"_"+modelDeviceConnect.getResponse().get(0).getDeveloper_id();
542+
543+
mSocket.off(""+selfIdListener,onAtsIdMessage); // removing previous listening so that it will listen only one time.
544+
mSocket.on(""+selfIdListener,onAtsIdMessage);
545+
}else{
546+
LOGS.e(TAG , "Unable to Connect with socket server");
547+
}
538548
}catch (Exception e){
539549
LOGS.e(TAG , ""+e.getMessage());
540550
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.apporioinfolabs.ats_sdk.models;
2+
3+
import java.util.List;
4+
5+
public class ModelDeviceConnect {
6+
7+
/**
8+
* result : 1
9+
* message : some message from server
10+
* response : [{"ats_id":"some ats_id","developer_id":"some developer ID"}]
11+
*/
12+
13+
private int result;
14+
private String message;
15+
private List<ResponseBean> response;
16+
17+
public int getResult() {
18+
return result;
19+
}
20+
21+
public void setResult(int result) {
22+
this.result = result;
23+
}
24+
25+
public String getMessage() {
26+
return message;
27+
}
28+
29+
public void setMessage(String message) {
30+
this.message = message;
31+
}
32+
33+
public List<ResponseBean> getResponse() {
34+
return response;
35+
}
36+
37+
public void setResponse(List<ResponseBean> response) {
38+
this.response = response;
39+
}
40+
41+
public static class ResponseBean {
42+
/**
43+
* ats_id : some ats_id
44+
* developer_id : some developer ID
45+
*/
46+
47+
private String ats_id;
48+
private String developer_id;
49+
50+
public String getAts_id() {
51+
return ats_id;
52+
}
53+
54+
public void setAts_id(String ats_id) {
55+
this.ats_id = ats_id;
56+
}
57+
58+
public String getDeveloper_id() {
59+
return developer_id;
60+
}
61+
62+
public void setDeveloper_id(String developer_id) {
63+
this.developer_id = developer_id;
64+
}
65+
}
66+
}

ats-sdk/src/main/java/com/apporioinfolabs/ats_sdk/models/ModelMessageType.java

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,49 @@
33
public class ModelMessageType {
44

55
/**
6-
* nameValuePairs : {"type":"API"}
6+
* result : 1
7+
* message : Data incoming from API
8+
* response : {"type":"API","message":"Message from API goes here accordingly.","identification_no":"BJKFY97H9U9-JNDJ0I-JH5JH"}
79
*/
810

9-
private NameValuePairsBean nameValuePairs;
11+
private int result;
12+
private String message;
13+
private ResponseBean response;
1014

11-
public NameValuePairsBean getNameValuePairs() {
12-
return nameValuePairs;
15+
public int getResult() {
16+
return result;
1317
}
1418

15-
public void setNameValuePairs(NameValuePairsBean nameValuePairs) {
16-
this.nameValuePairs = nameValuePairs;
19+
public void setResult(int result) {
20+
this.result = result;
1721
}
1822

19-
public static class NameValuePairsBean {
23+
public String getMessage() {
24+
return message;
25+
}
26+
27+
public void setMessage(String message) {
28+
this.message = message;
29+
}
30+
31+
public ResponseBean getResponse() {
32+
return response;
33+
}
34+
35+
public void setResponse(ResponseBean response) {
36+
this.response = response;
37+
}
38+
39+
public static class ResponseBean {
2040
/**
2141
* type : API
42+
* message : Message from API goes here accordingly.
43+
* identification_no : BJKFY97H9U9-JNDJ0I-JH5JH
2244
*/
2345

2446
private String type;
47+
private String message;
48+
private String identification_no;
2549

2650
public String getType() {
2751
return type;
@@ -30,5 +54,21 @@ public String getType() {
3054
public void setType(String type) {
3155
this.type = type;
3256
}
57+
58+
public String getMessage() {
59+
return message;
60+
}
61+
62+
public void setMessage(String message) {
63+
this.message = message;
64+
}
65+
66+
public String getIdentification_no() {
67+
return identification_no;
68+
}
69+
70+
public void setIdentification_no(String identification_no) {
71+
this.identification_no = identification_no;
72+
}
3373
}
3474
}

ats-sdk/src/main/java/com/apporioinfolabs/ats_sdk/utils/ATSConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public interface KEYS{
1010
String LOCATION_INTERVAL = "location_interval";
1111
String LOCATION = "location";
1212
String ATS_ID = "ats_id";
13+
String DEVELOPER_ID = "developer_id";
1314
String LISTENING_KEYS = "listening_keys";
1415
String TAG = "tag";
1516
String LISTEN_TAG = "listen_tag";

0 commit comments

Comments
 (0)