Blame | Last modification | View Log | RSS feed
package com.saholic.profittill.Volley;import android.content.Context;import android.content.SharedPreferences;import com.android.volley.AuthFailureError;import com.android.volley.NetworkResponse;import com.android.volley.Request;import com.android.volley.RequestQueue;import com.android.volley.Response;import com.android.volley.toolbox.StringRequest;import com.saholic.profittill.main.GoogleAnalyticsTracker;import org.json.JSONObject;import java.util.Map;public class NotificationCountRequest extends Request<JSONObject> {private Response.Listener<JSONObject> listener;private Response.Listener<String> stringListener;private Response.ErrorListener errorListener ;private Map<String, String> params;private String analyticsUrl;private static Context context;public NotificationCountRequest(String url, Map<String, String> params,Response.Listener<JSONObject> reponseListener, Response.ErrorListener errorListener, Context c) {super(Method.GET, url, errorListener);this.listener = reponseListener;this.errorListener = errorListener;this.params = params;this.analyticsUrl=url;context= c;}public void notificationCountRequest(Context c){RequestQueue queue = AnalyticsSingleton.getmInstance().getRequestQueue();StringRequest request = new StringRequest(Method.GET,analyticsUrl,NotificationCountResponse.getNotificationCountStringRequestInstance(),errorListener){@Overrideprotected Map<String, String> getParams() throws AuthFailureError {return params;}};queue.add(request);}@Overrideprotected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {return null;}@Overrideprotected void deliverResponse(JSONObject response) {}public static void setCount(String response){SharedPreferences userData;SharedPreferences.Editor userDataEditor;userData = GoogleAnalyticsTracker.getAppContext().getSharedPreferences("User_Data", Context.MODE_PRIVATE);userDataEditor=userData.edit();try {JSONObject js = new JSONObject(response);userDataEditor.putInt("notification_count",js.getInt("count")).apply();}catch (Exception e){e.printStackTrace();}}}class NotificationCountResponse implements Response.Listener<String> {private static NotificationCountResponse mInstance = null;public NotificationCountResponse() {}public static NotificationCountResponse getNotificationCountStringRequestInstance() {if (mInstance == null) {mInstance = new NotificationCountResponse();}return mInstance;}@Overridepublic void onResponse(String response) {NotificationCountRequest.setCount(response);}}