@OnClick(R.id.post_share_button) void share() { VKRequest request = VKApi.wall() .repost( VKParameters.from( VKApiConst.OBJECT, "wall" + String.valueOf(mPost.source_id) + "_" + String.valueOf(mPost.post_id))); request.useSystemLanguage = false; request = VKRequest.getRegisteredRequest(request.registerObject()); if (request != null) { request.unregisterObject(); } request.executeWithListener( new VKRequestListener() { @Override public void onComplete(VKResponse response) { mPost.reposts_count += 1; postCountOfShare.setText(String.valueOf(mPost.reposts_count)); mPost.user_reposted = true; } @Override public void onError(VKError error) { Log.d("Error", error.toString()); } }); }
@OnClick(R.id.post_like_button) void like() { int post_id = mPost.post_id != 0 ? mPost.post_id : mPost.id; int source_id = mPost.source_id != 0 ? mPost.source_id : mPost.from_id; if (mPost.user_likes) { VKRequest request = VKApi.likes() .delete( VKParameters.from( "type", "post", VKApiConst.OWNER_ID, String.valueOf(source_id), "item_id", String.valueOf(post_id))); request.useSystemLanguage = false; request = VKRequest.getRegisteredRequest(request.registerObject()); if (request != null) { request.unregisterObject(); } request.executeWithListener( new VKRequestListener() { @Override public void onComplete(VKResponse response) { mPost.likes_count -= 1; postCountOfLike.setText(String.valueOf(mPost.likes_count)); mPost.user_likes = false; } @Override public void onError(VKError error) { Log.d("Error", error.toString()); } }); } else { VKRequest request = VKApi.likes() .add( VKParameters.from( "type", "post", VKApiConst.OWNER_ID, String.valueOf(source_id), "item_id", String.valueOf(post_id))); request.useSystemLanguage = false; request = VKRequest.getRegisteredRequest(request.registerObject()); if (request != null) { request.unregisterObject(); } request.executeWithListener( new VKRequestListener() { @Override public void onComplete(VKResponse response) { mPost.likes_count += 1; postCountOfLike.setText(String.valueOf(mPost.likes_count)); mPost.user_likes = true; } @Override public void onError(VKError error) { Log.d("Error", error.toString()); } }); } }