public void requestFriends() { VKRequest request = VKApi.friends() .get( VKParameters.from( VKApiConst.OFFSET, "1", VKApiConst.FIELDS, "first_name,photo_100,photo_200", VKApiConst.VERSION, "5.37")); request.executeWithListener( new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { parseFriends(response); for (int i = 0; i < observerList.size(); i++) { observerList.get(i).update(); } } @Override public void attemptFailed(VKRequest request, int attemptNumber, int totalAttempts) { super.attemptFailed(request, attemptNumber, totalAttempts); } @Override public void onError(VKError error) { super.onError(error); } }); }
@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()); } }); }
private void updateVideoList() { VKRequest videoRequest = VKApi.video() .get( VKParameters.from( VKApiConst.OWNER_ID, ownerId, VKApiConst.ALBUM_ID, albumId)); videoRequest.executeWithListener( new VKRequest.VKRequestListener() { @Override public void onError(VKError error) { super.onError(error); if (error.errorCode == -105) { swipeRefresh.setRefreshing(false); progressBar.setVisibility(View.GONE); if (videoList.isEmpty()) { noConnectionView.setVisibility(View.VISIBLE); } else if (videoList.size() > 0) { Snackbar.make( rootView, getString(R.string.no_connection_snack_message), Snackbar.LENGTH_LONG) .setAction( R.string.no_connection_snack_button, view -> { updateVideoList(); }) .show(); } } else if (error.errorCode == -101) { progressBar.setVisibility(View.GONE); swipeRefresh.setRefreshing(false); noVideosView.setText(R.string.no_added_videos); noVideosView.setVisibility(View.VISIBLE); noVideos = true; } } @Override public void onComplete(VKResponse response) { super.onComplete(response); noConnectionView.setVisibility(View.GONE); progressBar.setVisibility(View.GONE); swipeRefresh.setRefreshing(false); videoList.clear(); videoList = Parser.parseVideos(response); offset = videoList.size(); videoAdapter = new VideoAdapter(getActivity(), videoList, VideosFragment.this); recyclerView.setAdapter(videoAdapter); if (videoList.isEmpty()) { noVideosView.setText(R.string.no_added_videos); noVideosView.setVisibility(View.VISIBLE); noVideos = true; } } }); }
public void SearchFiles(String searchName) { try { VKParameters params = new VKParameters(); params.put(VKApiConst.Q, searchName); params.put(VKApiConst.COUNT, "200"); VKRequest request = VKApi.audio().search(params); request.executeWithListener( new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { super.onComplete(response); try { searchFiles.clear(); VkAudioArray audioArray = new VkAudioArray(); audioArray.parse(response.json); for (int i = 0; i < audioArray.size(); i++) searchFiles.add( new MusicFile( audioArray.get(i).id, audioArray.get(i).owner_id, audioArray.get(i).artist, audioArray.get(i).title, audioArray.get(i).duration, audioArray.get(i).url, audioArray.get(i).genre)); searchAdapter.notifyDataSetChanged(); } catch (JSONException e) { e.printStackTrace(); } } @Override public void onError(VKError error) { super.onError(error); } }); } catch (NullPointerException e) { Toast.makeText( getApplicationContext(), "Please authrorize app in settings", Toast.LENGTH_LONG) .show(); e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Error with getting list", Toast.LENGTH_LONG).show(); } }
@Override protected Void doInBackground(Void... voids) { final VKRequest vkRequest = Requests.vkFriendsRequest(Requests.LOCALE_RUS); vkRequest.executeWithListener( new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { super.onComplete(response); vkTask = new ParseVkResponseTask(vkFriends, listener, response); vkTask.setShowResults(false); vkTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } }); while (vkTask == null) {} try { vkTask.get(); Request fbRequest = Requests.fbFriendsRequest(); Response response = fbRequest.executeAndWait(); fbTask = new ParseFbResponseTask(fbFriends, listener, response); fbTask.setShowResults(false); Handler mainHandler = new Handler(Looper.getMainLooper()); mainHandler.post( new Runnable() { @Override public void run() { fbTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } }); fbTask.get(); } catch (Exception e) { e.printStackTrace(); return null; } fillSyncContactsList(); storeSyncContacts(); return null; }
private void loadMore() { offset += offset; VKRequest videoRequest = VKApi.video() .get( VKParameters.from( VKApiConst.OWNER_ID, ownerId, VKApiConst.ALBUM_ID, albumId, VKApiConst.OFFSET, offset)); videoRequest.executeWithListener( new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { super.onComplete(response); videoList.addAll(Parser.parseVideos(response)); int curSize = videoAdapter.getItemCount(); videoAdapter.notifyItemRangeInserted(curSize, videoList.size() - 1); } }); }
void start() { logging.Write("Service started"); // Загрузка настроек Properties properties = new Properties(context); properties.LoadData(); // Установка языка Configuration config = new Configuration(); config.locale = new Locale(properties.locale); Locale.setDefault(config.locale); context.getResources().updateConfiguration(config, null); // Отправка запроса на выявления пользователя VKRequest request = VKApi.users().get(); request.executeWithListener( new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { // Заполнение данных пользователя JSON json = new JSON(); String info; info = json.getInfo(response, "first_name"); info += " "; info += json.getInfo(response, "last_name"); Toast.makeText( context, context.getResources().getString(R.string.Connected) + info, Toast.LENGTH_SHORT) .show(); } }); Intent intent = new Intent(context, Receiver.class); pIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); aManager = (AlarmManager) context.getSystemService(ALARM_SERVICE); aManager.setRepeating( AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(), 600000, pIntent); }
private void makePost(VKAttachments attachments, String message) { final VKRequest post = VKApi.wall() .post( VKParameters.from( VKApiConst.ATTACHMENTS, attachments, VKApiConst.MESSAGE, message)); post.setModelClass(VKWallPostResult.class); post.executeWithListener( new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { try { super.onComplete(response); Log.d("LOG_TAG", "post ok"); VKWallPostResult result = (VKWallPostResult) response.parsedModel; Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse( String.format("https://vk.com/wall" + userID + "_" + result.post_id))); startActivity(intent); } catch (NullPointerException e) { e.printStackTrace(); Log.d(LOG_TAG, "error"); } } }); }
@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()); } }); } }