| 21478 |
rajender |
1 |
package com.saholic.profittill.Volley;
|
|
|
2 |
|
|
|
3 |
import android.content.Context;
|
|
|
4 |
import android.content.SharedPreferences;
|
|
|
5 |
|
|
|
6 |
import com.android.volley.AuthFailureError;
|
|
|
7 |
import com.android.volley.NetworkResponse;
|
|
|
8 |
import com.android.volley.Request;
|
|
|
9 |
import com.android.volley.RequestQueue;
|
|
|
10 |
import com.android.volley.Response;
|
|
|
11 |
import com.android.volley.toolbox.StringRequest;
|
|
|
12 |
import com.saholic.profittill.main.GoogleAnalyticsTracker;
|
|
|
13 |
|
|
|
14 |
import org.json.JSONObject;
|
|
|
15 |
|
|
|
16 |
import java.util.Map;
|
|
|
17 |
|
|
|
18 |
public class NotificationCountRequest extends Request<JSONObject> {
|
|
|
19 |
|
|
|
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 NotificationCountRequest(String url, Map<String, String> params,
|
|
|
28 |
Response.Listener<JSONObject> reponseListener, Response.ErrorListener errorListener, Context c) {
|
|
|
29 |
super(Method.GET, url, errorListener);
|
|
|
30 |
this.listener = reponseListener;
|
|
|
31 |
this.errorListener = errorListener;
|
|
|
32 |
this.params = params;
|
|
|
33 |
this.analyticsUrl=url;
|
|
|
34 |
context= c;
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
public void notificationCountRequest(Context c){
|
|
|
38 |
RequestQueue queue = AnalyticsSingleton.getmInstance().getRequestQueue();
|
|
|
39 |
StringRequest request = new StringRequest(
|
|
|
40 |
Method.GET,
|
|
|
41 |
analyticsUrl,
|
|
|
42 |
NotificationCountResponse.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 |
public static void setCount(String response){
|
|
|
63 |
SharedPreferences userData;
|
|
|
64 |
SharedPreferences.Editor userDataEditor;
|
|
|
65 |
userData = GoogleAnalyticsTracker.getAppContext().getSharedPreferences("User_Data", Context.MODE_PRIVATE);
|
|
|
66 |
userDataEditor=userData.edit();
|
|
|
67 |
try {
|
|
|
68 |
JSONObject js = new JSONObject(response);
|
|
|
69 |
userDataEditor.putInt("notification_count",js.getInt("count")).apply();
|
|
|
70 |
}catch (Exception e){
|
|
|
71 |
e.printStackTrace();
|
|
|
72 |
}
|
|
|
73 |
}
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
class NotificationCountResponse implements Response.Listener<String> {
|
|
|
77 |
|
|
|
78 |
private static NotificationCountResponse mInstance = null;
|
|
|
79 |
|
|
|
80 |
public NotificationCountResponse() {
|
|
|
81 |
|
|
|
82 |
}
|
|
|
83 |
public static NotificationCountResponse getNotificationCountStringRequestInstance() {
|
|
|
84 |
if (mInstance == null) {
|
|
|
85 |
mInstance = new NotificationCountResponse();
|
|
|
86 |
}
|
|
|
87 |
return mInstance;
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
@Override
|
|
|
91 |
public void onResponse(String response) {
|
|
|
92 |
NotificationCountRequest.setCount(response);
|
|
|
93 |
}
|
|
|
94 |
}
|