| 21478 |
rajender |
1 |
package com.saholic.profittill.Volley;
|
|
|
2 |
|
|
|
3 |
import android.content.Context;
|
|
|
4 |
|
|
|
5 |
import com.android.volley.AuthFailureError;
|
|
|
6 |
import com.android.volley.NetworkResponse;
|
|
|
7 |
import com.android.volley.Request;
|
|
|
8 |
import com.android.volley.RequestQueue;
|
|
|
9 |
import com.android.volley.Response;
|
|
|
10 |
import com.android.volley.toolbox.StringRequest;
|
|
|
11 |
import com.saholic.profittill.MyFirebaseMessagingService;
|
|
|
12 |
|
|
|
13 |
import org.json.JSONArray;
|
|
|
14 |
import org.json.JSONException;
|
|
|
15 |
import org.json.JSONObject;
|
|
|
16 |
|
|
|
17 |
import java.util.Map;
|
|
|
18 |
|
|
|
19 |
public class NotificationPollingRequest extends Request<JSONObject> {
|
|
|
20 |
private Response.Listener<JSONObject> listener;
|
|
|
21 |
private Response.Listener<String> stringListener;
|
|
|
22 |
private Response.ErrorListener errorListener ;
|
|
|
23 |
private Map<String, String> params;
|
|
|
24 |
private String analyticsUrl;
|
|
|
25 |
private static Context context;
|
|
|
26 |
|
|
|
27 |
public NotificationPollingRequest(String url, Map<String, String> params,
|
|
|
28 |
Response.Listener<JSONObject> reponseListener, Response.ErrorListener errorListener, Context c) {
|
|
|
29 |
super(Request.Method.GET, url, errorListener);
|
|
|
30 |
this.listener = reponseListener;
|
|
|
31 |
this.errorListener = errorListener;
|
|
|
32 |
this.params = params;
|
|
|
33 |
this.analyticsUrl=url;
|
|
|
34 |
this.context= c;
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
public void notificationCountRequest(Context c){
|
|
|
38 |
RequestQueue queue = AnalyticsSingleton.getmInstance().getRequestQueue();
|
|
|
39 |
StringRequest request = new StringRequest(
|
|
|
40 |
Request.Method.GET,
|
|
|
41 |
analyticsUrl,
|
|
|
42 |
NotificationPollingResponse1.getNotificationCountStringRequestInstance(),
|
|
|
43 |
errorListener
|
|
|
44 |
){
|
|
|
45 |
@Override
|
|
|
46 |
protected Map<String, String> getParams() throws AuthFailureError {
|
|
|
47 |
return params;
|
|
|
48 |
}
|
|
|
49 |
};
|
|
|
50 |
queue.add(request);
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
@Override
|
|
|
54 |
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
|
|
|
55 |
return null;
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
@Override
|
|
|
59 |
protected void deliverResponse(JSONObject response) {
|
|
|
60 |
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
public static void getCount(String response){
|
|
|
65 |
MyFirebaseMessagingService gcmNotificationIntentService = new MyFirebaseMessagingService();
|
|
|
66 |
try {
|
|
|
67 |
gcmNotificationIntentService.sendNotificationByPolling(new JSONArray(response), context);
|
|
|
68 |
} catch (JSONException e) {
|
|
|
69 |
e.printStackTrace();
|
|
|
70 |
}
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
class NotificationPollingResponse1 implements Response.Listener<String> {
|
|
|
75 |
|
|
|
76 |
private static NotificationPollingResponse1 mInstance = null;
|
|
|
77 |
|
|
|
78 |
public NotificationPollingResponse1() {
|
|
|
79 |
|
|
|
80 |
}
|
|
|
81 |
public static NotificationPollingResponse1 getNotificationCountStringRequestInstance() {
|
|
|
82 |
if (mInstance == null) {
|
|
|
83 |
mInstance = new NotificationPollingResponse1();
|
|
|
84 |
}
|
|
|
85 |
return mInstance;
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
@Override
|
|
|
89 |
public void onResponse(String response) {
|
|
|
90 |
|
|
|
91 |
NotificationPollingRequest.getCount(response);
|
|
|
92 |
}}
|