com.vk.sdk.api.VKRequest Java Examples

The following examples show how to use com.vk.sdk.api.VKRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AddTrackToPlaylistDialogFragment.java    From vk_music_android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onPlaylistClicked(VkApiAlbum playlist, int position) {
    if(binding.loadingIndicator.getVisibility() == View.VISIBLE){
        return; // Don't accept click events when loading
    }

    binding.loadingIndicator.setVisibility(View.VISIBLE);

    VKApi.audio().add(VKParameters.from("audio_id", audioToAdd.id, "owner_id", audioToAdd.owner_id, VKApiConst.ALBUM_ID, playlist.getId())).executeWithListener(new VKRequest.VKRequestListener() {
        @Override
        public void onComplete(VKResponse response) {
            if(listener != null){
                listener.onAudioAddedToPlaylist(audioToAdd, playlist);
            }
            dismissAllowingStateLoss();
        }
    });
}
 
Example #2
Source File: SocialVk.java    From cordova-social-vk with Apache License 2.0 6 votes vote down vote up
private boolean friends_getRequests(int offset, int count, int extended, int needs_mutual, int out, int sort, int suggested, CallbackContext context) {
    try {
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("offset", offset);
        params.put("count", count);
        params.put("extended", extended);
        params.put("needs_mutual", needs_mutual);
        params.put("out", out);
        params.put("sort", sort);
        params.put("suggested", suggested);
        VKRequest req = VKApi.friends().getRequests(new VKParameters(params));
        performRequest(req, context);
        return true;
    } catch(Exception ex) {
        return false;
    }
}
 
Example #3
Source File: SocialVk.java    From cordova-social-vk with Apache License 2.0 6 votes vote down vote up
private boolean friends_get(int user_id, String order, int count, int offset, String fields, String name_case, CallbackContext context) {
    try {
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("user_id", user_id);
        params.put("order", order);
        params.put("count", count);
        params.put("offset", offset);
        params.put("fields", fields);
        params.put("name_case", name_case);
        VKRequest req = VKApi.friends().get(new VKParameters(params));
        performRequest(req, context);
        return true;
    } catch(Exception ex) {
        return false;
    }
}
 
Example #4
Source File: VKShareDialogDelegate.java    From cordova-social-vk with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(View view) {
	setIsLoading(true);
	if (mAttachmentImages != null && VKSdk.getAccessToken() != null) {
		final Long userId = Long.parseLong(VKSdk.getAccessToken().userId);
		VKUploadWallPhotoRequest photoRequest = new VKUploadWallPhotoRequest(mAttachmentImages, userId, 0);
		photoRequest.executeWithListener(new VKRequest.VKRequestListener() {
			@Override
			public void onComplete(VKResponse response) {
				VKPhotoArray photos = (VKPhotoArray) response.parsedModel;
				VKAttachments attachments = new VKAttachments(photos);
				makePostWithAttachments(attachments);
			}

			@Override
			public void onError(VKError error) {
				setIsLoading(false);
				if (mListener != null) {
					mListener.onVkShareError(error);
				}
			}
		});
	} else {
		makePostWithAttachments(null);
	}
}
 
Example #5
Source File: VKUploadAlbumPhotoRequest.java    From cordova-social-vk with Apache License 2.0 5 votes vote down vote up
@Override
protected VKRequest getSaveRequest(JSONObject response) {
    VKRequest saveRequest;
    try {
        saveRequest = VKApi.photos().save(new VKParameters(VKJsonHelper.toMap(response)));
    } catch (JSONException e) {
        return null;
    }
    if (mAlbumId != 0)
        saveRequest.addExtraParameters(VKUtil.paramsFrom(VKApiConst.ALBUM_ID, mAlbumId));
    if (mGroupId != 0)
        saveRequest.addExtraParameters(VKUtil.paramsFrom(VKApiConst.GROUP_ID, mGroupId));
    return saveRequest;

}
 
Example #6
Source File: VKUploadWallPhotoRequest.java    From cordova-social-vk with Apache License 2.0 5 votes vote down vote up
@Override
protected VKRequest getSaveRequest(JSONObject response) {
    VKRequest saveRequest;
    try {
        saveRequest = VKApi.photos().saveWallPhoto(new VKParameters(VKJsonHelper.toMap(response)));
    } catch (JSONException e) {
        return null;
    }
    if (mUserId != 0)
        saveRequest.addExtraParameters(VKUtil.paramsFrom(VKApiConst.USER_ID, mUserId));
    if (mGroupId != 0)
        saveRequest.addExtraParameters(VKUtil.paramsFrom(VKApiConst.GROUP_ID, mGroupId));
    return saveRequest;
}
 
Example #7
Source File: VKUploadDocRequest.java    From cordova-social-vk with Apache License 2.0 5 votes vote down vote up
@Override
protected VKRequest getSaveRequest(JSONObject response) {
    VKRequest saveRequest;
    try {
        saveRequest = VKApi.docs().save(new VKParameters(VKJsonHelper.toMap(response)));
    } catch (JSONException e) {
        return null;
    }
    if (mGroupId != 0)
        saveRequest.addExtraParameters(VKUtil.paramsFrom(VKApiConst.GROUP_ID, mGroupId));
    return saveRequest;
}
 
Example #8
Source File: VKApiGroups.java    From cordova-social-vk with Apache License 2.0 5 votes vote down vote up
public VKRequest leave(final int group_id) {
    return prepareRequest("leave", new VKParameters() {
        {
            put(VKApiConst.GROUP_ID, String.valueOf(group_id));
        }
    });
}
 
Example #9
Source File: SocialVk.java    From cordova-social-vk with Apache License 2.0 5 votes vote down vote up
private boolean usersSearch(Map<String, Object> params, CallbackContext context) {
    try {
        VKRequest req = VKApi.users().search(new VKParameters(params));
        performRequest(req, context);
        return true;
    } catch(Exception ex) {
        return false;
    }
}
 
Example #10
Source File: VKHttpClient.java    From cordova-social-vk with Apache License 2.0 5 votes vote down vote up
/**
 * Prepares new "normal" request from VKRequest
 *
 * @param vkRequest Request, created for some method
 * @return Prepared request for creating VKHttpOperation
 */
public static VKHTTPRequest requestWithVkRequest(@NonNull VKRequest vkRequest) {
    VKAccessToken token = VKAccessToken.currentToken();
    VKHTTPRequest result = new VKHTTPRequest(String.format(Locale.US, "http%s://api.vk.com/method/%s", vkRequest.secure || (token != null && token.httpsRequired) ? "s" : "", vkRequest.methodName));
    result.headers = getDefaultHeaders();
    result.setVkParameters(vkRequest.getPreparedParameters());
    return result;
}
 
Example #11
Source File: VKApiWall.java    From cordova-social-vk with Apache License 2.0 5 votes vote down vote up
public VKRequest get(VKParameters params) {
    if (params.containsKey(EXTENDED) && (Integer) (params.get(EXTENDED)) == 1) {
        return prepareRequest("get", params, VKPostArray.class);
    } else {
        return prepareRequest("get", params);
    }
}
 
Example #12
Source File: VKApiFriends.java    From cordova-social-vk with Apache License 2.0 5 votes vote down vote up
public VKRequest get(VKParameters params) {
    if (params.get("fields") != null) {
        return prepareRequest("get", params, VKUsersArray.class);
    } else {
        return prepareRequest("get", params);
    }
}
 
Example #13
Source File: SocialVk.java    From cordova-social-vk with Apache License 2.0 5 votes vote down vote up
private boolean wallPost(Map<String, Object> params, CallbackContext context) {
    try {
        VKRequest req = VKApi.wall().post(new VKParameters(params));
        performRequest(req, context);
        return true;
    } catch(Exception ex) {
        return false;
    }
}
 
Example #14
Source File: VKSdk.java    From cordova-social-vk with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if an access token exist and performs a try to use it again
 *
 * @param context            An application context for store an access token
 * @param loginStateCallback if callback specified, {@link VKCallback#onResult(Object)} method will be called after login state changed
 * @return true, if an access token exists and not expired
 */
public static boolean wakeUpSession(@NonNull final Context context, final VKCallback<LoginState> loginStateCallback) {
    final Context appContext = context.getApplicationContext();
    VKUIHelper.setApplicationContext(appContext);

    VKAccessToken token = VKAccessToken.currentToken();

    if (token != null && token.accessToken != null && !token.isExpired()) {
        forceLoginState(LoginState.Pending, loginStateCallback);
        trackVisitor(new VKRequest.VKRequestListener() {
            @Override
            public void onComplete(VKResponse response) {
                updateLoginState(context, loginStateCallback);
            }

            @Override
            public void onError(VKError error) {
                //Possible double call of access token invalid
                if (error != null && error.apiError != null && error.apiError.errorCode == 5) {
                    onAccessTokenIsInvalid(appContext);
                }
                updateLoginState(context, loginStateCallback);
            }
        });
        return true;
    }
    updateLoginState(context, loginStateCallback);
    return false;
}
 
Example #15
Source File: VKApiUsers.java    From cordova-social-vk with Apache License 2.0 5 votes vote down vote up
/**
 * https://vk.com/dev/users.isAppUser
 *
 * @param userID ID of user to check
 * @return Request for load
 */
public VKRequest isAppUser(final int userID) {
    return prepareRequest("isAppUser",
            new VKParameters() {
                /**
                 *
                 */
                private static final long serialVersionUID = 7458591447441581671L;

                {
                    put(VKApiConst.USER_ID, String.valueOf(userID));
                }
            });
}
 
Example #16
Source File: SocialVk.java    From cordova-social-vk with Apache License 2.0 5 votes vote down vote up
private boolean photos_saveWallPhoto(String imageBase64, int user_id, int group_id, CallbackContext context) {
    try {
        VKRequest req = VKApi.uploadWallPhotoRequest(new VKUploadImage(Base64ToBitmap(imageBase64), VKImageParameters.pngImage()), user_id, group_id);
        performRequest(req, context);
        return true;
    } catch(Exception ex) {
        return false;
    }
}
 
Example #17
Source File: SocialVk.java    From cordova-social-vk with Apache License 2.0 5 votes vote down vote up
private boolean photos_save(String imageBase64, int album_id, int group_id, CallbackContext context) {
    try {
        VKRequest req = VKApi.uploadAlbumPhotoRequest(new VKUploadImage(Base64ToBitmap(imageBase64), VKImageParameters.pngImage()), album_id, group_id);
        performRequest(req, context);
        return true;
    } catch(Exception ex) {
        return false;
    }
}
 
Example #18
Source File: VKApiUsers.java    From cordova-social-vk with Apache License 2.0 5 votes vote down vote up
/**
 * https://vk.com/dev/users.get
 *
 * @param params use parameters from description with VKApiConst class
 * @return Request for load
 */
public VKRequest get(VKParameters params) {
    return prepareRequest("get", params, new VKParser() {
        @Override
        public Object createModel(JSONObject object) {
            return new VKList<>(object, VKApiUserFull.class);
        }
    });
}
 
Example #19
Source File: VKApiWall.java    From cordova-social-vk with Apache License 2.0 4 votes vote down vote up
public VKRequest getById(VKParameters params) {
    return prepareRequest("getById", params, VKPostArray.class);
}
 
Example #20
Source File: VKApiAudio.java    From cordova-social-vk with Apache License 2.0 4 votes vote down vote up
public VKRequest edit(VKParameters params) {
    return prepareRequest("edit", params);
}
 
Example #21
Source File: VKApiWall.java    From cordova-social-vk with Apache License 2.0 4 votes vote down vote up
public VKRequest reportPost(VKParameters params) {
    return prepareRequest("reportPost", params);
}
 
Example #22
Source File: VKApiVideo.java    From cordova-social-vk with Apache License 2.0 4 votes vote down vote up
public VKRequest getAlbums() {
    return getAlbums(null);
}
 
Example #23
Source File: VKApiAudio.java    From cordova-social-vk with Apache License 2.0 4 votes vote down vote up
public VKRequest restore(VKParameters params) {
    return prepareRequest("restore", params);
}
 
Example #24
Source File: VKApiVideo.java    From cordova-social-vk with Apache License 2.0 4 votes vote down vote up
public VKRequest getComments(VKParameters params) {
    return prepareRequest("getComments", params);
}
 
Example #25
Source File: VKApiBase.java    From cordova-social-vk with Apache License 2.0 4 votes vote down vote up
protected VKRequest prepareRequest(String methodName, VKParameters methodParameters) {
    return new VKRequest(String.format(Locale.US, "%s.%s", getMethodsGroup(), methodName), methodParameters, null);
}
 
Example #26
Source File: VKApiVideo.java    From cordova-social-vk with Apache License 2.0 4 votes vote down vote up
public VKRequest reorderVideos(VKParameters params) {
    return prepareRequest("getAlbumById", params);
}
 
Example #27
Source File: VKApiVideo.java    From cordova-social-vk with Apache License 2.0 4 votes vote down vote up
public VKRequest reorderAlbums(VKParameters params) {
    return prepareRequest("getAlbumById", params);
}
 
Example #28
Source File: VKApiVideo.java    From cordova-social-vk with Apache License 2.0 4 votes vote down vote up
public VKRequest addAlbum(VKParameters params) {
    return prepareRequest("addAlbum", params);
}
 
Example #29
Source File: VKApiVideo.java    From cordova-social-vk with Apache License 2.0 4 votes vote down vote up
public VKRequest getAlbumById(VKParameters params) {
    return prepareRequest("getAlbumById", params);
}
 
Example #30
Source File: VKApiAudio.java    From cordova-social-vk with Apache License 2.0 4 votes vote down vote up
public VKRequest get(VKParameters params) {
    return prepareRequest("get", params, VkAudioArray.class);
}