Search in sources :

Example 16 with AsyncRequest

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

the class StreamFragment method handleSendReplyAction.

private void handleSendReplyAction(final Comment comment, String reply) {
    if (reply.length() > 0) {
        Bundle params = new Bundle();
        params.putString("message", reply);
        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, comment.getId(), params, new AsyncRequest.Callback() {

            @Override
            public void onComplete(Response response) {
                publishing.hide();
                onReplyCommentRequestComplete(response, comment);
            }
        }).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)

Example 17 with AsyncRequest

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

the class StreamFragment method doLikeCommentAction.

private void doLikeCommentAction(final Comment comment) {
    if (comment.getUser_likes() == false) {
        comment.setUser_likes(true);
        comment.setLike_count(comment.getLike_count() + 1);
        String commentId = comment.getId();
        // if (!commentId.contains("_"))
        // commentId = comment.getObject_id() + "_" + commentId;
        new AsyncRequest(Query.POST_LIKE, commentId, "", new AsyncRequest.Callback() {

            @Override
            public void onComplete(Response response) {
                Log.d("onComplete", "" + response.getError());
                onCommentLikeRequestComplete(response, comment);
            }
        }).execute();
    } else {
        comment.setUser_likes(false);
        comment.setLike_count(comment.getLike_count() - 1);
        getAdapter().notifyDataSetChanged();
        String commentId = comment.getId();
        // if (!commentId.contains("_"))
        // commentId = comment.getObject_id() + "_" + commentId;
        new AsyncRequest(Query.POST_UNLIKE, commentId, "", new AsyncRequest.Callback() {

            @Override
            public void onComplete(Response response) {
                Log.d("onComplete", "" + response.getError());
                onCommentUnlikeRequestComplete(response, comment);
            }
        }).execute();
    }
}
Also used : 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 18 with AsyncRequest

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

the class StreamFragment method sendRequest.

private void sendRequest(Bundle params) {
    if (dialog == null) {
        dialog = AlertUtil.showAlert(getActivity(), R.string.publish_comment_dialog_title, R.string.publish_comment_dialog_message);
        dialog.setCancelable(false);
    }
    new AsyncRequest(Query.POST_COMMENT, getElementId(), params, new AsyncRequest.Callback() {

        @Override
        public void onComplete(Response response) {
            onCommentRequestComplete(response);
        }
    }).execute();
}
Also used : 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 19 with AsyncRequest

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

the class KlyphDialogFragment method refresh.

protected void refresh() {
    startLoading();
    Log.d(TAG, "request = " + requestType + ", id = " + elementId + ", offset = " + offset);
    request = new AsyncRequest(requestType, elementId, offset, new AsyncRequest.Callback() {

        @Override
        public void onComplete(Response response) {
            Log.i(TAG, "onCompleted");
            onRequestComplete(response);
        }
    });
    request.execute();
}
Also used : Response(com.abewy.android.apps.klyph.core.request.Response) AsyncRequest(com.abewy.android.apps.klyph.request.AsyncRequest)

Example 20 with AsyncRequest

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

the class PostActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = getIntent();
    if (intent.getStringExtra(KlyphBundleExtras.EVENT_ID) != null) {
        elementId = intent.getStringExtra(KlyphBundleExtras.EVENT_ID);
        isEventMessage = true;
    } else if (intent.getStringExtra(KlyphBundleExtras.PAGE_ID) != null) {
        elementId = intent.getStringExtra(KlyphBundleExtras.PAGE_ID);
        isPageMessage = true;
    } else if (intent.getStringExtra(KlyphBundleExtras.GROUP_ID) != null) {
        elementId = intent.getStringExtra(KlyphBundleExtras.GROUP_ID);
        isGroupMessage = true;
    } else {
        elementId = KlyphSession.getSessionUserId();
    }
    Log.d("PostActivity", "event " + isEventMessage + " page " + isPageMessage + " group " + isGroupMessage);
    boolean shareLink = intent.getBooleanExtra(KlyphBundleExtras.SHARE, false);
    String action = intent.getAction();
    String type = intent.getType();
    setTitle(isEventMessage == false ? R.string.publish_new_status : R.string.publish_new_event_message);
    photoUris = new ArrayList<String>();
    messageTextView = (TextView) findViewById(R.id.message_textview);
    friendsTextView = (TextView) findViewById(R.id.friends_textview);
    placeTextView = (TextView) findViewById(R.id.place_textview);
    photosFragment = (PostPhotos) getFragmentManager().findFragmentById(R.id.photos_fragment);
    albumsFragment = (PostAlbums) getFragmentManager().findFragmentById(R.id.albums_fragment);
    linkFragment = (PostLink) getFragmentManager().findFragmentById(R.id.link_fragment);
    shareFragment = (PostShare) getFragmentManager().findFragmentById(R.id.share_fragment);
    getFragmentManager().beginTransaction().hide(photosFragment).commitAllowingStateLoss();
    getFragmentManager().beginTransaction().hide(albumsFragment).commitAllowingStateLoss();
    getFragmentManager().beginTransaction().hide(linkFragment).commitAllowingStateLoss();
    if (shareLink == true) {
        shareFragment.initWithIntent(getIntent());
        shareFragmentVisible = true;
    } else {
        getFragmentManager().beginTransaction().hide(shareFragment).commit();
    }
    if (isEventMessage == true) {
        LinearLayout buttonBar = (LinearLayout) findViewById(R.id.button_bar);
        buttonBar.setVisibility(View.GONE);
    } else {
        ImageButton placeDeleteButton = (ImageButton) findViewById(R.id.place_delete_button);
        ImageButton friendsDeleteButton = (ImageButton) findViewById(R.id.friends_delete_button);
        friendsButton = (ImageButton) findViewById(R.id.friends_button);
        photosButton = (ImageButton) findViewById(R.id.picture_button);
        placeButton = (ImageButton) findViewById(R.id.place_button);
        linkButton = (ImageButton) findViewById(R.id.link_button);
        privacyButton = (ImageButton) findViewById(R.id.privacy_button);
        placeDeleteButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                clearPlace();
                updateButtonStatus();
            }
        });
        friendsDeleteButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                clearFriends();
                updateButtonStatus();
            }
        });
        friendsButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(PostActivity.this, FriendPickerActivity.class);
                if (friends != null && friends.size() > 0) {
                    ArrayList<String> ids = new ArrayList<String>();
                    ids.addAll(friends.keySet());
                    intent.putStringArrayListExtra(KlyphBundleExtras.FRIEND_PICKER_IDS, ids);
                }
                startActivityForResult(intent, FRIEND_PICKER);
            }
        });
        photosButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                startGallery();
            }
        });
        placeButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                startActivityForResult(new Intent(PostActivity.this, PlacePickerActivity.class), PLACE_PICKER);
            }
        });
        linkButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                linkFragment.reset();
                getFragmentManager().beginTransaction().show(linkFragment).commitAllowingStateLoss();
                linkFragmentVisible = true;
                updateButtonStatus();
            }
        });
        setPrivacyListenerApi11();
        setPrivacy(KlyphPreferences.getPrivacy());
        if (Intent.ACTION_SEND.equals(action) && type != null) {
            displayBackArrow(false);
            setAppIconBackToHomeEnabled(false);
            if ("text/plain".equals(type)) {
                String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
                String sharedSubject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
                if (sharedText != null) {
                    boolean isUrl = false;
                    try {
                        new URL(sharedText);
                        isUrl = true;
                    } catch (MalformedURLException e) {
                        isUrl = false;
                    }
                    if (isUrl == true) {
                        linkFragment.setUrl(sharedText);
                        linkFragment.setTitle(sharedSubject);
                        getFragmentManager().beginTransaction().show(linkFragment).commitAllowingStateLoss();
                    } else {
                        messageTextView.setText(sharedText);
                    }
                }
            } else if (type.startsWith("image/")) {
                Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
                if (imageUri != null) {
                    // Update UI to reflect image being shared
                    photoUris = new ArrayList<String>();
                    if (StringUtils.startsWith(imageUri.toString(), "content://")) {
                        photoUris.add(getRealPathFromURI(imageUri));
                    } else {
                        photoUris.add(imageUri.getPath());
                    }
                    photosFragment.setImages(photoUris);
                    getFragmentManager().beginTransaction().show(photosFragment).commitAllowingStateLoss();
                    photosFragment.updateLayout();
                }
            }
        } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
            displayBackArrow(false);
            setAppIconBackToHomeEnabled(false);
            if (type.startsWith("image/")) {
                ArrayList<Uri> imageUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
                if (imageUris != null) {
                    // Update UI to reflect multiple images being shared
                    photoUris = new ArrayList<String>();
                    for (Uri uri : imageUris) {
                        if (StringUtils.startsWith(uri.toString(), "content://")) {
                            photoUris.add(getRealPathFromURI(uri));
                        } else {
                            photoUris.add(uri.getPath());
                        }
                    }
                    photosFragment.setImages(photoUris);
                    getFragmentManager().beginTransaction().show(photosFragment).commitAllowingStateLoss();
                    photosFragment.updateLayout();
                }
            }
        } else {
            Log.d("PostActivity", "Received other");
        }
        updateButtonStatus();
        privacyButton.setVisibility(isGroupMessage == true || isEventMessage == true ? View.GONE : View.VISIBLE);
    }
    if (KlyphData.getFriendLists() == null) {
        new AsyncRequest(Query.FRIEND_LISTS, "", "", new Callback() {

            @Override
            public void onComplete(Response response) {
                onRequestComplete(response);
            }
        }).execute();
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) AsyncRequest(com.abewy.android.apps.klyph.request.AsyncRequest) ArrayList(java.util.ArrayList) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView) Uri(android.net.Uri) URL(java.net.URL) Response(com.abewy.android.apps.klyph.core.request.Response) ImageButton(android.widget.ImageButton) Callback(com.abewy.android.apps.klyph.core.request.BaseAsyncRequest.Callback) IFbPermissionCallback(com.abewy.android.apps.klyph.facebook.IFbPermissionCallback) TagCallback(com.abewy.android.apps.klyph.util.TextViewUtil.TagCallback) LinearLayout(android.widget.LinearLayout)

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