com.vk.sdk.api.VKApiConst Java Examples

The following examples show how to use com.vk.sdk.api.VKApiConst. 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: MainActivity.java    From vk_music_android with GNU General Public License v3.0 6 votes vote down vote up
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 #3
Source File: VKShareDialogDelegate.java    From cordova-social-vk with Apache License 2.0 5 votes vote down vote up
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 #4
Source File: AddTrackToPlaylistDialogFragment.java    From vk_music_android with GNU General Public License v3.0 5 votes vote down vote up
@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 #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: 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 #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: VKApiGroups.java    From cordova-social-vk with Apache License 2.0 5 votes vote down vote up
public VKRequest get(VKParameters params) {
    if (params.containsKey(VKApiConst.EXTENDED) && ((Integer) params.get(VKApiConst.EXTENDED)) == 1) {
        return prepareRequest("get", params, VKApiCommunityArray.class);
    } else {
        return prepareRequest("get", params);
    }
}
 
Example #10
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 #11
Source File: VKUploadWallDocRequest.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 #12
Source File: RadioFragment.java    From vk_music_android with GNU General Public License v3.0 5 votes vote down vote up
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 #13
Source File: VKApiPhotos.java    From cordova-social-vk with Apache License 2.0 4 votes vote down vote up
public VKRequest getUploadServer(long albumId) {
    return prepareRequest("getUploadServer", VKUtil.paramsFrom(VKApiConst.ALBUM_ID, String.valueOf(albumId)));
}
 
Example #14
Source File: VKApiPhotos.java    From cordova-social-vk with Apache License 2.0 4 votes vote down vote up
public VKRequest getUploadServer(long albumId, long groupId) {
    return prepareRequest("getUploadServer", VKUtil.paramsFrom(VKApiConst.ALBUM_ID, albumId, VKApiConst.GROUP_ID, groupId));
}
 
Example #15
Source File: VKApiPhotos.java    From cordova-social-vk with Apache License 2.0 4 votes vote down vote up
public VKRequest getWallUploadServer(long groupId) {
    return prepareRequest("getWallUploadServer", VKUtil.paramsFrom(VKApiConst.GROUP_ID, groupId));
}
 
Example #16
Source File: AudioListFragment.java    From vk_music_android with GNU General Public License v3.0 4 votes vote down vote up
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 #17
Source File: VKApiMessages.java    From cordova-social-vk with Apache License 2.0 2 votes vote down vote up
/**
 * Returns messages current user
 *
 * @return Request for load
 */
public VKRequest get() {
    return get(VKParameters.from(VKApiConst.COUNT, "10"));
}
 
Example #18
Source File: VKApiMessages.java    From cordova-social-vk with Apache License 2.0 2 votes vote down vote up
/**
 * Returns dialogs current user
 *
 * @return Request for load
 */
public VKRequest getDialogs() {
    return getDialogs(VKParameters.from(VKApiConst.COUNT, "5"));
}
 
Example #19
Source File: VKApiDocs.java    From cordova-social-vk with Apache License 2.0 2 votes vote down vote up
/**
 * https://vk.com/dev/docs.getUploadServer
 * Returns upload server for document
 * @param groupId community ID (if the document will be uploaded to the community).
 * @return Request for get server address
 */
public VKRequest getUploadServer(long groupId) {
    return prepareRequest("getUploadServer", VKUtil.paramsFrom(VKApiConst.GROUP_ID, groupId));
}
 
Example #20
Source File: VKApiDocs.java    From cordova-social-vk with Apache License 2.0 2 votes vote down vote up
/**
 * https://vk.com/dev/docs.getWallUploadServer
 * Returns wall upload server for document
 * @param groupId community ID (if the document will be uploaded to the community).
 * @return Request for get server address
 */
public VKRequest getUploadWallServer(long groupId) {
    return prepareRequest("getWallUploadServer", VKUtil.paramsFrom(VKApiConst.GROUP_ID, groupId));
}