Search in sources :

Example 41 with GraphObject

use of com.facebook.model.GraphObject in project phonegap-facebook-plugin by Wizcorp.

the class GraphObjectAdapter method rebuildSections.

private void rebuildSections() {
    sectionKeys = new ArrayList<String>();
    graphObjectsBySection = new HashMap<String, ArrayList<T>>();
    graphObjectsById = new HashMap<String, T>();
    displaySections = false;
    if (cursor == null || cursor.getCount() == 0) {
        return;
    }
    int objectsAdded = 0;
    cursor.moveToFirst();
    do {
        T graphObject = cursor.getGraphObject();
        if (!filterIncludesItem(graphObject)) {
            continue;
        }
        objectsAdded++;
        String sectionKeyOfItem = getSectionKeyOfGraphObject(graphObject);
        if (!graphObjectsBySection.containsKey(sectionKeyOfItem)) {
            sectionKeys.add(sectionKeyOfItem);
            graphObjectsBySection.put(sectionKeyOfItem, new ArrayList<T>());
        }
        List<T> section = graphObjectsBySection.get(sectionKeyOfItem);
        section.add(graphObject);
        graphObjectsById.put(getIdOfGraphObject(graphObject), graphObject);
    } while (cursor.moveToNext());
    if (sortFields != null) {
        final Collator collator = Collator.getInstance();
        for (List<T> section : graphObjectsBySection.values()) {
            Collections.sort(section, new Comparator<GraphObject>() {

                @Override
                public int compare(GraphObject a, GraphObject b) {
                    return compareGraphObjects(a, b, sortFields, collator);
                }
            });
        }
    }
    Collections.sort(sectionKeys, Collator.getInstance());
    displaySections = sectionKeys.size() > 1 && objectsAdded > DISPLAY_SECTIONS_THRESHOLD;
}
Also used : GraphObject(com.facebook.model.GraphObject) Collator(java.text.Collator)

Example 42 with GraphObject

use of com.facebook.model.GraphObject in project phonegap-facebook-plugin by Wizcorp.

the class ConnectPlugin method makeGraphCall.

private void makeGraphCall() {
    Session session = Session.getActiveSession();
    Request.Callback graphCallback = new Request.Callback() {

        @Override
        public void onCompleted(Response response) {
            if (graphContext != null) {
                if (response.getError() != null) {
                    graphContext.error(getFacebookRequestErrorResponse(response.getError()));
                } else {
                    GraphObject graphObject = response.getGraphObject();
                    graphContext.success(graphObject.getInnerJSONObject());
                }
                graphPath = null;
                graphContext = null;
            }
        }
    };
    //If you're using the paging URLs they will be URLEncoded, let's decode them.
    try {
        graphPath = URLDecoder.decode(graphPath, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    String[] urlParts = graphPath.split("\\?");
    String graphAction = urlParts[0];
    Request graphRequest = Request.newGraphPathRequest(null, graphAction, graphCallback);
    Bundle params = graphRequest.getParameters();
    if (urlParts.length > 1) {
        String[] queries = urlParts[1].split("&");
        for (String query : queries) {
            int splitPoint = query.indexOf("=");
            if (splitPoint > 0) {
                String key = query.substring(0, splitPoint);
                String value = query.substring(splitPoint + 1, query.length());
                params.putString(key, value);
            }
        }
    }
    params.putString("access_token", session.getAccessToken());
    graphRequest.setParameters(params);
    graphRequest.executeAsync();
}
Also used : Response(com.facebook.Response) GraphUserCallback(com.facebook.Request.GraphUserCallback) Bundle(android.os.Bundle) Request(com.facebook.Request) UnsupportedEncodingException(java.io.UnsupportedEncodingException) GraphObject(com.facebook.model.GraphObject) Session(com.facebook.Session)

Aggregations

GraphObject (com.facebook.model.GraphObject)42 JSONObject (org.json.JSONObject)23 Bundle (android.os.Bundle)13 JSONException (org.json.JSONException)11 JSONArray (org.json.JSONArray)10 GraphObjectList (com.facebook.model.GraphObjectList)6 SharedPreferences (android.content.SharedPreferences)5 Request (com.facebook.Request)4 GraphMultiResult (com.facebook.model.GraphMultiResult)4 URI (java.net.URI)4 URISyntaxException (java.net.URISyntaxException)4 Collator (java.text.Collator)4 JSONTokener (org.json.JSONTokener)4 GraphUser (com.facebook.model.GraphUser)3 ActivityNotFoundException (android.content.ActivityNotFoundException)2 Uri (android.net.Uri)2 AppLink (bolts.AppLink)2 Task (bolts.Task)2 FacebookException (com.facebook.FacebookException)2 GraphUserCallback (com.facebook.Request.GraphUserCallback)2