Android Open Source - Android_Yellow_Pages_App_Content_Provider Volley Service Layer






From Project

Back to project page Android_Yellow_Pages_App_Content_Provider.

License

The source code is released under:

Apache License

If you think the Android project Android_Yellow_Pages_App_Content_Provider listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.tddrampup.serviceLayers;
//  w ww.  j av  a 2s.c om
import android.content.Context;
import android.util.Log;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import com.google.gson.Gson;
import com.tddrampup.fragments.ListFragment;
import com.tddrampup.models.Listing;
import com.tddrampup.models.YellowResponse;

import org.json.JSONObject;

/**
 * Created by WX009-PC on 2/20/14.
 */
public class VolleyServiceLayer {
    private final RequestQueue mRequestQueue;
    public VolleyServiceLayerCallback volleyServiceLayerCallback;

    public VolleyServiceLayer(Context context){
        mRequestQueue =  Volley.newRequestQueue(context);
    }

    public void GetListings(String url) {
        JsonObjectRequest jr = new JsonObjectRequest(Request.Method.GET,url,null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                Gson gson = new Gson();
                YellowResponse yellowResponse = gson.fromJson(response.toString(), YellowResponse.class);
                volleyServiceLayerCallback.listCallbackCall(yellowResponse.getListings());
            }
        },new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.d("LOGGING:", error.getMessage());
            }
        });
        mRequestQueue.add(jr);
    }

    public void GetListing(String id, final Boolean isSearchQuery) {
        String url ="http://api.sandbox.yellowapi.com/GetBusinessDetails/?listingId="+ id +"&bus-name=Yellow-Pages-Group&city=Toronto&prov=Ontario&fmt=JSON&lang=en&UID=fgdfg&apikey=" + ListFragment.API_KEY;
        JsonObjectRequest jr = new JsonObjectRequest(Request.Method.GET,url,null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                Gson gson = new Gson();
                Listing listing = gson.fromJson(response.toString(), Listing.class);
                volleyServiceLayerCallback.itemCallbackCall(listing, isSearchQuery);
            }
        },new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.d("LOGGING:", error.getMessage());
            }
        });
        mRequestQueue.add(jr);
    }
}




Java Source Code List

android.UnusedStub.java
com.tddrampup.ApplicationModule.java
com.tddrampup.YellowApplication.java
com.tddrampup.activities.MainActivity.java
com.tddrampup.contentProviders.YellowContentProvider.java
com.tddrampup.databases.ListingsTableHelper.java
com.tddrampup.databases.ListingsTable.java
com.tddrampup.databases.PreviousQueryTableHelper.java
com.tddrampup.databases.PreviousQueryTable.java
com.tddrampup.databases.SearchTableHelper.java
com.tddrampup.databases.SearchTable.java
com.tddrampup.databases.YellowDatabaseHelper.java
com.tddrampup.factories.CameraUpdateFactoryWrapperInterface.java
com.tddrampup.factories.CameraUpdateFactoryWrapper.java
com.tddrampup.factories.MarkerOptionsFactoryWrapperInterface.java
com.tddrampup.factories.MarkerOptionsFactoryWrapper.java
com.tddrampup.fragments.DetailFragment.java
com.tddrampup.fragments.GoogleMapFragment.java
com.tddrampup.fragments.HomeFragment.java
com.tddrampup.fragments.ListFragment.java
com.tddrampup.models.Address.java
com.tddrampup.models.GeoCode.java
com.tddrampup.models.Keywords.java
com.tddrampup.models.Listing.java
com.tddrampup.models.Phone.java
com.tddrampup.models.Products.java
com.tddrampup.models.Profile.java
com.tddrampup.models.Summary.java
com.tddrampup.models.YellowResponse.java
com.tddrampup.serviceLayers.VolleyServiceLayerCallback.java
com.tddrampup.serviceLayers.VolleyServiceLayer.java
com.tddrampup.views.MapView.java