Search in sources :

Example 6 with AsyncRequest

use of com.abewy.android.apps.klyph.request.AsyncRequest in project Klyph by jonathangerbaud.

the class PhotoAdapter method doLikeAction.

private void doLikeAction(final PhotoHolder holder, final Photo photo) {
    // manageLikeButton(holder, stream, subStream, false);
    final Context context = getContext(holder.getAuthorProfileImage());
    if (!photo.getLike_info().getUser_likes()) {
        photo.getLike_info().setUser_likes(true);
        photo.getLike_info().setLike_count(photo.getLike_info().getLike_count() + 1);
        manageLikeButton(holder, photo);
        holder.getLikeButton().setEnabled(false);
        new AsyncRequest(Query.POST_LIKE, photo.getObject_id(), "", new AsyncRequest.Callback() {

            @Override
            public void onComplete(Response response) {
                Log.d("onComplete", "" + response.getError());
                if (response.getError() != null) {
                    Toast.makeText(context, R.string.like_error, Toast.LENGTH_SHORT).show();
                    photo.getLike_info().setUser_likes(false);
                    photo.getLike_info().setLike_count(photo.getLike_info().getLike_count() - 1);
                }
                holder.getLikeButton().setEnabled(true);
                manageLikeButton(holder, photo);
                parentAdapter.notifyDataSetChanged();
            }
        }).execute();
        parentAdapter.notifyDataSetChanged();
    } else {
        photo.getLike_info().setUser_likes(false);
        photo.getLike_info().setLike_count(photo.getLike_info().getLike_count() - 1);
        manageLikeButton(holder, photo);
        holder.getLikeButton().setEnabled(false);
        new AsyncRequest(Query.POST_UNLIKE, photo.getObject_id(), "", new AsyncRequest.Callback() {

            @Override
            public void onComplete(Response response) {
                Log.d("onComplete", "" + response.getError());
                if (response.getError() != null) {
                    Toast.makeText(context, R.string.unlike_error, Toast.LENGTH_SHORT).show();
                    photo.getLike_info().setUser_likes(true);
                    photo.getLike_info().setLike_count(photo.getLike_info().getLike_count() + 1);
                }
                holder.getLikeButton().setEnabled(true);
                manageLikeButton(holder, photo);
                parentAdapter.notifyDataSetChanged();
            }
        }).execute();
        parentAdapter.notifyDataSetChanged();
    }
}
Also used : Context(android.content.Context) Response(com.abewy.android.apps.klyph.core.request.Response) AsyncRequest(com.abewy.android.apps.klyph.request.AsyncRequest) IFbPermissionCallback(com.abewy.android.apps.klyph.facebook.IFbPermissionCallback)

Example 7 with AsyncRequest

use of com.abewy.android.apps.klyph.request.AsyncRequest in project Klyph by jonathangerbaud.

the class AlbumSpinner method createAlbum.

@Override
public void createAlbum(final Album album, String privacy) {
    Bundle bundle = new Bundle();
    bundle.putString("name", album.getName());
    bundle.putString("location", album.getLocation());
    bundle.putString("message", album.getDescription());
    bundle.putString("privacy", privacy);
    final AlertDialog dialog = AlertUtil.showAlert(getActivity(), R.string.new_album, R.string.creating_album);
    new AsyncRequest(Query.NEW_ALBUM, "", bundle, new AsyncRequest.Callback() {

        @Override
        public void onComplete(Response response) {
            dialog.dismiss();
            if (response.getError() == null) {
                Log.d("AlbumSpinner", "createAlbum id = " + response.getReturnedId());
                album.setObject_id(response.getReturnedId());
                ((SpinnerAdapter) spinner.getAdapter()).add(album);
                ((SpinnerAdapter) spinner.getAdapter()).notifyDataSetChanged();
                spinner.setSelection(spinner.getCount() - 1);
            } else {
                Toast.makeText(getActivity(), R.string.request_error, Toast.LENGTH_SHORT).show();
            }
        }
    }).execute();
}
Also used : AlertDialog(android.app.AlertDialog) Response(com.abewy.android.apps.klyph.core.request.Response) AsyncRequest(com.abewy.android.apps.klyph.request.AsyncRequest) Bundle(android.os.Bundle)

Example 8 with AsyncRequest

use of com.abewy.android.apps.klyph.request.AsyncRequest in project Klyph by jonathangerbaud.

the class AlbumSpinner method loadAlbums.

private void loadAlbums() {
    AsyncRequest request = new AsyncRequest(Query.UPLOADABLE_ALBUM, KlyphSession.getSessionUserId(), "", new AsyncRequest.Callback() {

        public void onComplete(Response response) {
            onRequestComplete(response);
        }
    });
    request.execute();
}
Also used : Response(com.abewy.android.apps.klyph.core.request.Response) AsyncRequest(com.abewy.android.apps.klyph.request.AsyncRequest)

Example 9 with AsyncRequest

use of com.abewy.android.apps.klyph.request.AsyncRequest in project Klyph by jonathangerbaud.

the class EventFragment method sendRequest.

private void sendRequest(int query) {
    final EventResponse eventResponse;
    switch(query) {
        case Query.POST_EVENT_ATTEND:
            {
                eventResponse = EventResponse.ATTENDING;
                break;
            }
        case Query.POST_EVENT_UNSURE:
            {
                eventResponse = EventResponse.UNSURE;
                break;
            }
        case Query.POST_EVENT_DECLINE:
            {
                eventResponse = EventResponse.DECLINED;
                break;
            }
        default:
            {
                eventResponse = EventResponse.NOT_REPLIED;
                break;
            }
    }
    final AlertDialog publishing = new AlertDialog.Builder(getActivity()).setTitle(R.string.event_response_dialog_title).setMessage(R.string.event_response_dialog_message).setCancelable(false).create();
    publishing.show();
    new AsyncRequest(query, event.getEid(), "", new AsyncRequest.Callback() {

        @Override
        public void onComplete(Response response) {
            publishing.dismiss();
            onRequestComplete(response, eventResponse);
        }
    }).execute();
}
Also used : AlertDialog(android.app.AlertDialog) Response(com.abewy.android.apps.klyph.core.request.Response) EventResponse(com.abewy.android.apps.klyph.core.fql.Event.EventResponse) AsyncRequest(com.abewy.android.apps.klyph.request.AsyncRequest) IFbPermissionCallback(com.abewy.android.apps.klyph.facebook.IFbPermissionCallback) EventResponse(com.abewy.android.apps.klyph.core.fql.Event.EventResponse)

Example 10 with AsyncRequest

use of com.abewy.android.apps.klyph.request.AsyncRequest in project Klyph by jonathangerbaud.

the class ImageFragment method postComment.

private void postComment() {
    if (sendTextEdit.getText().toString().length() > 0) {
        Bundle params = new Bundle();
        params.putString("message", sendTextEdit.getText().toString());
        InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(sendTextEdit.getWindowToken(), 0);
        final AlertDialog publishing = new AlertDialog.Builder(getActivity()).setTitle(R.string.publish_comment_dialog_title).setMessage(R.string.publish_comment_dialog_message).setCancelable(false).create();
        publishing.show();
        new AsyncRequest(Query.POST_COMMENT, getElementId(), params, new AsyncRequest.Callback() {

            @Override
            public void onComplete(Response response) {
                publishing.hide();
                onCommentRequestComplete(response);
            }
        }).execute();
    } else {
        new AlertDialog.Builder(getActivity()).setTitle(R.string.error).setMessage(R.string.define_comment_before_publish).setPositiveButton(R.string.ok, null).create().show();
    }
}
Also used : AlertDialog(android.app.AlertDialog) Response(com.abewy.android.apps.klyph.core.request.Response) AsyncRequest(com.abewy.android.apps.klyph.request.AsyncRequest) IFbPermissionCallback(com.abewy.android.apps.klyph.facebook.IFbPermissionCallback) Bundle(android.os.Bundle) InputMethodManager(android.view.inputmethod.InputMethodManager)

Aggregations

AsyncRequest (com.abewy.android.apps.klyph.request.AsyncRequest)37 Response (com.abewy.android.apps.klyph.core.request.Response)34 IFbPermissionCallback (com.abewy.android.apps.klyph.facebook.IFbPermissionCallback)17 AlertDialog (android.app.AlertDialog)9 ArrayList (java.util.ArrayList)6 Bundle (android.os.Bundle)4 GraphObject (com.abewy.android.apps.klyph.core.graph.GraphObject)4 Callback (com.abewy.android.apps.klyph.core.request.BaseAsyncRequest.Callback)4 Context (android.content.Context)3 TagCallback (com.abewy.android.apps.klyph.util.TextViewUtil.TagCallback)3 Intent (android.content.Intent)2 View (android.view.View)2 ImageButton (android.widget.ImageButton)2 TextView (android.widget.TextView)2 Photo (com.abewy.android.apps.klyph.core.fql.Photo)2 TextButtonItem (com.abewy.klyph.items.TextButtonItem)2 UiLifecycleHelper (com.facebook.UiLifecycleHelper)2 Uri (android.net.Uri)1 FragmentActivity (android.support.v4.app.FragmentActivity)1 ViewGroup (android.view.ViewGroup)1