com.vk.sdk.api.VKApi Java Examples
The following examples show how to use
com.vk.sdk.api.VKApi.
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 |
@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 |
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 #3
Source File: SocialVk.java From cordova-social-vk with Apache License 2.0 | 6 votes |
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 #4
Source File: MainActivity.java From vk_music_android with GNU General Public License v3.0 | 6 votes |
private void onPlaylistItemLongClicked(VkApiAlbum playlist) { new AlertDialog.Builder(this) .setMessage("Are you sure you want to delete " + playlist.getTitle() + "?") .setNegativeButton(android.R.string.cancel, null) .setPositiveButton(android.R.string.ok, (dialog, which) -> { VKApi.audio().deleteAlbum(VKParameters.from(VKApiConst.ALBUM_ID, playlist.getId())).executeWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { drawer.removeItem(playlist.getId()); loadPlaylists(); Snackbar.make(binding.slidinglayout, R.string.deleted_playlist, Snackbar.LENGTH_SHORT).show(); } }); }) .show(); }
Example #5
Source File: MainActivity.java From vk_music_android with GNU General Public License v3.0 | 6 votes |
private void onAddPlaylistClicked() { View alertView = LayoutInflater.from(this).inflate(R.layout.layout_dialog_createplaylist, null, false); EditText playlistTitle = (EditText) alertView.findViewById(R.id.playlist_title); new AlertDialog.Builder(this) .setTitle(R.string.create_playlist) .setView(alertView) .setNegativeButton(android.R.string.cancel, null) .setPositiveButton(android.R.string.ok, (dialog, which) -> { VKApi.audio().addAlbum(VKParameters.from("title", playlistTitle.getText())).executeWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { loadPlaylists(); } }); }) .show(); }
Example #6
Source File: AudioListFragment.java From vk_music_android with GNU General Public License v3.0 | 6 votes |
private void removeAudio(VKApiAudio audio, int position) { VKApi.audio().delete(VKParameters.from("audio_id", audio.id, "owner_id", audio.owner_id)).executeWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { try { int responseCode = response.json.getInt("response"); if (responseCode == 1) { audioArray.remove(position); adapter.notifyItemRemoved(position); Snackbar.make(binding.getRoot(), R.string.track_removed, Snackbar.LENGTH_SHORT).show(); } } catch (JSONException e) { onError(null); } } @Override public void onError(VKError error) { Snackbar.make(binding.getRoot(), R.string.error_deleting_track, Snackbar.LENGTH_LONG).show(); } }); }
Example #7
Source File: VKUploadAlbumPhotoRequest.java From cordova-social-vk with Apache License 2.0 | 5 votes |
@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 #8
Source File: VKUploadMessagesPhotoRequest.java From cordova-social-vk with Apache License 2.0 | 5 votes |
@Override protected VKRequest getSaveRequest(JSONObject response) { VKRequest saveRequest; try { saveRequest = VKApi.photos().saveMessagesPhoto(new VKParameters(VKJsonHelper.toMap(response))); } catch (JSONException e) { return null; } return saveRequest; }
Example #9
Source File: VKUploadWallPhotoRequest.java From cordova-social-vk with Apache License 2.0 | 5 votes |
@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 #10
Source File: VKUploadWallPhotoRequest.java From cordova-social-vk with Apache License 2.0 | 5 votes |
@Override protected VKRequest getServerRequest() { if (mGroupId != 0) return VKApi.photos().getWallUploadServer(mGroupId); else return VKApi.photos().getWallUploadServer(); }
Example #11
Source File: VKUploadDocRequest.java From cordova-social-vk with Apache License 2.0 | 5 votes |
@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 #12
Source File: VKUploadWallDocRequest.java From cordova-social-vk with Apache License 2.0 | 5 votes |
@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 #13
Source File: AddTrackToPlaylistDialogFragment.java From vk_music_android with GNU General Public License v3.0 | 5 votes |
@Override public void onResume() { super.onResume(); binding.loadingIndicator.setVisibility(View.VISIBLE); VKApi.audio().getAlbums(VKParameters.from(VKApiConst.OWNER_ID, user.getId())).executeWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { VkApiAlbumArrayResponse albumsResponse = gson.fromJson(response.responseString, VkApiAlbumArrayResponse.class); playlists.clear(); playlists.addAll(albumsResponse.getResponse().getItems()); for (VkApiAlbum album : playlists) { String fixedTitle; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { fixedTitle = Html.fromHtml(album.getTitle(), Html.FROM_HTML_MODE_LEGACY).toString(); } else { fixedTitle = Html.fromHtml(album.getTitle()).toString(); } album.setTitle(fixedTitle); } adapter.notifyDataSetChanged(); binding.loadingIndicator.setVisibility(View.GONE); } @Override public void onError(VKError error) { binding.loadingIndicator.setVisibility(View.VISIBLE); Snackbar.make(binding.rcvPlaylists, "Error loading playlists", Snackbar.LENGTH_LONG).show(); } }); }
Example #14
Source File: SocialVk.java From cordova-social-vk with Apache License 2.0 | 5 votes |
private boolean friends_getRecent(int count, CallbackContext context) { try { HashMap<String, Object> params = new HashMap<String, Object>(); params.put("count", count); VKRequest req = VKApi.friends().getRecent(new VKParameters(params)); performRequest(req, context); return true; } catch(Exception ex) { return false; } }
Example #15
Source File: SocialVk.java From cordova-social-vk with Apache License 2.0 | 5 votes |
private boolean friends_getMutual(int source_id, int target_id, String order, int count, int offset, CallbackContext context) { try { HashMap<String, Object> params = new HashMap<String, Object>(); params.put("source_id", source_id); params.put("target_id", target_id); params.put("order", order); params.put("count", count); params.put("offset", offset); VKRequest req = VKApi.friends().getMutual(new VKParameters(params)); performRequest(req, context); return true; } catch(Exception ex) { return false; } }
Example #16
Source File: SocialVk.java From cordova-social-vk with Apache License 2.0 | 5 votes |
private boolean friends_getOnline(int user_id, String order, int count, int offset, 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); VKRequest req = VKApi.friends().getOnline(new VKParameters(params)); performRequest(req, context); return true; } catch(Exception ex) { return false; } }
Example #17
Source File: VKShareDialogDelegate.java From cordova-social-vk with Apache License 2.0 | 5 votes |
private void makePostWithAttachments(VKAttachments attachments) { if (attachments == null) { attachments = new VKAttachments(); } if (mExistingPhotos != null) { attachments.addAll(mExistingPhotos); } if (mAttachmentLink != null) { attachments.add(new VKApiLink(mAttachmentLink.linkUrl)); } String message = mShareTextField.getText().toString(); final Long userId = Long.parseLong(VKSdk.getAccessToken().userId); VKRequest wallPost = VKApi.wall().post(VKParameters.from(VKApiConst.OWNER_ID, userId, VKApiConst.MESSAGE, message, VKApiConst.ATTACHMENTS, attachments.toAttachmentsString())); wallPost.executeWithListener(new VKRequest.VKRequestListener() { @Override public void onError(VKError error) { setIsLoading(false); if (mListener != null) { mListener.onVkShareError(error); } } @Override public void onComplete(VKResponse response) { setIsLoading(false); VKWallPostResult res = (VKWallPostResult) response.parsedModel; if (mListener != null) { mListener.onVkShareComplete(res.post_id); } dialogFragmentI.dismissAllowingStateLoss(); } }); }
Example #18
Source File: SocialVk.java From cordova-social-vk with Apache License 2.0 | 5 votes |
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 #19
Source File: SocialVk.java From cordova-social-vk with Apache License 2.0 | 5 votes |
private boolean photos_getWallUploadServer(int group_id, CallbackContext context) { try { VKRequest req = VKApi.photos().getWallUploadServer(group_id); performRequest(req, context); return true; } catch(Exception ex) { return false; } }
Example #20
Source File: SocialVk.java From cordova-social-vk with Apache License 2.0 | 5 votes |
private boolean photos_getUploadServer(int album_id, int group_id, CallbackContext context) { try { VKRequest req = VKApi.photos().getUploadServer(album_id, group_id); performRequest(req, context); return true; } catch(Exception ex) { return false; } }
Example #21
Source File: SocialVk.java From cordova-social-vk with Apache License 2.0 | 5 votes |
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 #22
Source File: SocialVk.java From cordova-social-vk with Apache License 2.0 | 5 votes |
private boolean usersGetFollowers(Map<String, Object> params, CallbackContext context) { try { VKRequest req = VKApi.users().getFollowers(new VKParameters(params)); performRequest(req, context); return true; } catch(Exception ex) { return false; } }
Example #23
Source File: SocialVk.java From cordova-social-vk with Apache License 2.0 | 5 votes |
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 #24
Source File: SocialVk.java From cordova-social-vk with Apache License 2.0 | 5 votes |
private boolean usersGetSubscriptions(Map<String, Object> params, CallbackContext context) { try { VKRequest req = VKApi.users().getSubscriptions(new VKParameters(params)); performRequest(req, context); return true; } catch(Exception ex) { return false; } }
Example #25
Source File: RadioFragment.java From vk_music_android with GNU General Public License v3.0 | 5 votes |
public void loadRadio(@Nullable VKApiAudio radioTrack, @Nullable Action0 onCompletedCallback) { binding.loadingIndicator.setVisibility(View.VISIBLE); VKParameters parameters; if (radioTrack == null) { parameters = VKParameters.from(VKApiConst.COUNT, 100, "shuffle", 1); } else { parameters = VKParameters.from("target_audio", radioTrack.owner_id + "_" + radioTrack.id, VKApiConst.COUNT, 100, "shuffle", 1); } VKApi.audio().getRecommendations(parameters).executeWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { audioArray.clear(); audioArray.addAll((VkAudioArray) response.parsedModel); adapter.notifyDataSetChanged(); binding.loadingIndicator.setVisibility(View.GONE); if (audioArray.size() == 0) { Snackbar.make(binding.getRoot(), R.string.no_similar_tracks, Snackbar.LENGTH_LONG).show(); binding.noData.getRoot().setVisibility(View.VISIBLE); } else { binding.noData.getRoot().setVisibility(View.GONE); } if (onCompletedCallback != null) onCompletedCallback.call(); } @Override public void onError(VKError error) { Snackbar.make(binding.rcvAudio, R.string.error_loading_radio, Snackbar.LENGTH_LONG); binding.loadingIndicator.setVisibility(View.GONE); } }); }
Example #26
Source File: SocialVk.java From cordova-social-vk with Apache License 2.0 | 5 votes |
private boolean usersIsAppUser(int user_id, CallbackContext context) { try { VKRequest req = VKApi.users().isAppUser(user_id); performRequest(req, context); return true; } catch(Exception ex) { return false; } }
Example #27
Source File: SocialVk.java From cordova-social-vk with Apache License 2.0 | 5 votes |
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 #28
Source File: SocialVk.java From cordova-social-vk with Apache License 2.0 | 5 votes |
private boolean usersGet(Map<String, Object> params, CallbackContext context) { try { VKRequest req = VKApi.users().get(new VKParameters(params)); performRequest(req, context); return true; } catch(Exception ex) { return false; } }
Example #29
Source File: AudioListFragment.java From vk_music_android with GNU General Public License v3.0 | 4 votes |
public void loadData() { binding.swiperefresh.setRefreshing(true); VKParameters parameters = null; switch (listType) { case MY_AUDIO: parameters = VKParameters.from(); break; case PLAYLIST: parameters = VKParameters.from(VKApiConst.ALBUM_ID, playlist.getId()); break; case SEARCH: parameters = VKParameters.from(VKApiConst.Q, searchQuery, VKApiConst.COUNT, 100); break; case POPULAR: parameters = VKParameters.from("only_eng", 1); break; } VKRequest.VKRequestListener listener = new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { audioArray.clear(); audioArray.addAll((VkAudioArray) response.parsedModel); adapter.notifyDataSetChanged(); binding.swiperefresh.setRefreshing(false); if (audioArray.size() == 0) { binding.noData.getRoot().setVisibility(View.VISIBLE); } else { binding.noData.getRoot().setVisibility(View.GONE); } } @Override public void onError(VKError error) { Snackbar.make(binding.rcvAudio, "Error loading search results", Snackbar.LENGTH_LONG); binding.swiperefresh.setRefreshing(false); } }; if (listType == AudioListType.SEARCH) { VKApi.audio().search(parameters).executeWithListener(listener); } else if (listType == AudioListType.POPULAR) { VKApi.audio().getPopular(parameters).executeWithListener(listener); } else { VKApi.audio().get(parameters).executeWithListener(listener); } }
Example #30
Source File: VKUploadMessagesPhotoRequest.java From cordova-social-vk with Apache License 2.0 | 4 votes |
@Override protected VKRequest getServerRequest() { return VKApi.photos().getMessagesUploadServer(); }