Search in sources :

Example 86 with GraphObject

use of com.abewy.android.apps.klyph.core.graph.GraphObject in project Klyph by jonathangerbaud.

the class KlyphFragment method onRequestError.

private void onRequestError(RequestError error) {
    Log.d(TAG, "error " + error.toString());
    if (getView() == null || getListView() == null)
        return;
    isError = true;
    loading = false;
    int errorText = this.errorText;
    if (!ConnectionState.getInstance(getActivity()).isOnline()) {
        errorText = R.string.request_connexion_error;
    }
    // Fragment can be destroyed but receive the error
    if (getAdapter() != null) {
        if (getAdapter().isEmpty()) {
            setEmptyText(errorText);
            populate(new ArrayList<GraphObject>());
        } else {
            TextButtonItem errorItem = new TextButtonItem();
            errorItem.setText(getString(errorText));
            // TODO This is not a good coding practice !
            errorItem.setButtonListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    retryRequestAfterError();
                }
            });
            getAdapter().add(errorItem);
            endLoading();
        }
    }
}
Also used : TextButtonItem(com.abewy.klyph.items.TextButtonItem) GraphObject(com.abewy.android.apps.klyph.core.graph.GraphObject) KlyphListView(com.abewy.android.apps.klyph.widget.KlyphListView) ListEmptyView(com.abewy.android.apps.klyph.view.ListEmptyView) View(android.view.View) AbsListView(android.widget.AbsListView) ListView(android.widget.ListView)

Example 87 with GraphObject

use of com.abewy.android.apps.klyph.core.graph.GraphObject in project Klyph by jonathangerbaud.

the class KlyphFragment2 method populate.

protected void populate(List<GraphObject> data) {
    if (getView() != null && getAdapter() != null) {
        MultiObjectAdapter adapter = getAdapter();
        for (GraphObject graphObject : data) {
            adapter.add(graphObject);
        }
        // adapter.addAll(data); is only available in api 11
        endLoading();
        boolean requestHasMoreData = request != null && request.hasMoreData();
        if (data.size() == 0 || !requestHasMoreData)
            noMoreData = true;
        else
            offset = String.valueOf(adapter.getCount());
    }
}
Also used : MultiObjectAdapter(com.abewy.android.apps.klyph.adapter.MultiObjectAdapter) GraphObject(com.abewy.android.apps.klyph.core.graph.GraphObject)

Example 88 with GraphObject

use of com.abewy.android.apps.klyph.core.graph.GraphObject in project Klyph by jonathangerbaud.

the class KlyphFragment2 method startLoading.

protected void startLoading() {
    loading = true;
    if (isError == true && getAdapter().getCount() > 0) {
        GraphObject lastObject = getAdapter().getLastItem();
        if (lastObject instanceof TextButtonItem) {
            getAdapter().remove(lastObject);
        }
    }
    isError = false;
    if (!firstLoad) {
        if (!loadingObjectAsFirstItem)
            getAdapter().add(loadingObject);
        else
            getAdapter().insert(loadingObject, 0);
        getAdapter().notifyDataSetChanged();
    }
}
Also used : TextButtonItem(com.abewy.klyph.items.TextButtonItem) GraphObject(com.abewy.android.apps.klyph.core.graph.GraphObject)

Example 89 with GraphObject

use of com.abewy.android.apps.klyph.core.graph.GraphObject in project Klyph by jonathangerbaud.

the class KlyphFragment2 method onRequestError.

private void onRequestError(RequestError error) {
    Log.d(TAG, "error " + error.toString());
    // Crashlytics report on request error
    try {
        throw new Exception("Class :�" + this.getClass().getName() + "\n, Request " + requestType + ", Id " + elementId + ", Offset " + offset + "\n, Error " + error.getMessage());
    } catch (Exception e) {
        Crashlytics.logException(e);
    }
    if (getView() == null || getGridView() == null)
        return;
    isError = true;
    loading = false;
    int errorText = this.errorText;
    if (!ConnectionState.getInstance(getActivity()).isOnline()) {
        errorText = R.string.request_connexion_error;
    }
    // Fragment can be destroyed but receive the error
    if (getAdapter() != null) {
        if (getAdapter().isEmpty()) {
            setEmptyText(errorText);
            populate(new ArrayList<GraphObject>());
        } else {
            TextButtonItem errorItem = new TextButtonItem();
            errorItem.setText(getString(errorText));
            // TODO This is not a good coding practice !
            errorItem.setButtonListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    retryRequestAfterError();
                }
            });
            getAdapter().add(errorItem);
            endLoading();
        }
    }
}
Also used : TextButtonItem(com.abewy.klyph.items.TextButtonItem) GraphObject(com.abewy.android.apps.klyph.core.graph.GraphObject) ListEmptyView(com.abewy.android.apps.klyph.view.ListEmptyView) View(android.view.View) AdapterView(android.widget.AdapterView) AbsListView(android.widget.AbsListView) KlyphGridView(com.abewy.android.apps.klyph.widget.KlyphGridView)

Example 90 with GraphObject

use of com.abewy.android.apps.klyph.core.graph.GraphObject in project Klyph by jonathangerbaud.

the class NewAlbumDialog method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.dialog_new_album, null);
    name = (TextView) view.findViewById(R.id.name);
    location = (TextView) view.findViewById(R.id.location);
    description = (TextView) view.findViewById(R.id.description);
    privacy = (Spinner) view.findViewById(R.id.privacy);
    /*ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.privacy,
				android.R.layout.simple_spinner_item);
		// Specify the layout to use when the list of choices appears
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);*/
    MultiObjectAdapter adapter = new MultiObjectAdapter(null, SpecialLayout.DROP_DOWN_ITEM);
    FriendList publicFL = new FriendList();
    publicFL.setName(getActivity().getString(R.string.menu_privacy_public));
    FriendList friendsFL = new FriendList();
    friendsFL.setName(getActivity().getString(R.string.menu_privacy_friends));
    FriendList selfFL = new FriendList();
    selfFL.setName(getActivity().getString(R.string.menu_privacy_self));
    adapter.add(publicFL);
    adapter.add(friendsFL);
    adapter.add(selfFL);
    List<GraphObject> friendLists = KlyphData.getFriendLists();
    if (friendLists != null) {
        for (GraphObject graphObject : friendLists) {
            adapter.add(graphObject);
        }
    }
    privacy.setAdapter(adapter);
    privacy.setSelection(KlyphPreferences.getPrivacy());
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(view);
    builder.setTitle(R.string.new_album).setPositiveButton(R.string.create, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            createAlbum();
        }
    }).setNegativeButton(R.string.cancel, null);
    return builder.create();
}
Also used : AlertDialog(android.app.AlertDialog) FriendList(com.abewy.android.apps.klyph.core.fql.FriendList) DialogInterface(android.content.DialogInterface) MultiObjectAdapter(com.abewy.android.apps.klyph.adapter.MultiObjectAdapter) LayoutInflater(android.view.LayoutInflater) GraphObject(com.abewy.android.apps.klyph.core.graph.GraphObject) TextView(android.widget.TextView) View(android.view.View)

Aggregations

GraphObject (com.abewy.android.apps.klyph.core.graph.GraphObject)101 ArrayList (java.util.ArrayList)71 JSONArray (org.json.JSONArray)41 JSONObject (org.json.JSONObject)16 FriendDeserializer (com.abewy.android.apps.klyph.core.fql.serializer.FriendDeserializer)11 PhotoDeserializer (com.abewy.android.apps.klyph.core.fql.serializer.PhotoDeserializer)9 MultiObjectAdapter (com.abewy.android.apps.klyph.adapter.MultiObjectAdapter)7 Stream (com.abewy.android.apps.klyph.core.fql.Stream)7 View (android.view.View)6 KlyphNotification (com.abewy.android.apps.klyph.KlyphNotification)6 Notification (com.abewy.android.apps.klyph.core.fql.Notification)6 Photo (com.abewy.android.apps.klyph.core.fql.Photo)6 JSONException (org.json.JSONException)6 StreamDeserializer (com.abewy.android.apps.klyph.core.fql.serializer.StreamDeserializer)5 Intent (android.content.Intent)4 ListView (android.widget.ListView)4 Event (com.abewy.android.apps.klyph.core.fql.Event)4 AsyncRequest (com.abewy.android.apps.klyph.request.AsyncRequest)4 TextButtonItem (com.abewy.klyph.items.TextButtonItem)4 AbsListView (android.widget.AbsListView)3