@Override protected Integer doInBackground(Void... params) { Log.d(TAG, "Authenticating user from " + VM_SERVER_ADDRESS); try { URL url = new URL(VM_SERVER_ADDRESS); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); try { urlConnection.setDoOutput(true); urlConnection.setDoInput(true); urlConnection.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); urlConnection.setRequestProperty("Accept", "application/json"); urlConnection.setRequestProperty("Authorization", "Token token=" + accessToken.getToken()); urlConnection.setRequestMethod("POST"); String json = new Gson().toJson(accessToken, AccessToken.class); OutputStreamWriter out = new OutputStreamWriter(urlConnection.getOutputStream()); out.write(json); out.close(); int httpResult = urlConnection.getResponseCode(); InputStream in = new BufferedInputStream(urlConnection.getInputStream()); String httpResponseStream = ZZZUtility.convertStreamToString(in); if (httpResult == HttpURLConnection.HTTP_OK) { Log.d(TAG, httpResponseStream); user = new HHUserFullProcess( new Gson().fromJson(httpResponseStream, HHUserFullNested.class)); HHAuthToken = urlConnection.getHeaderField("Authorization"); return httpResult; } else if (httpResult == HttpURLConnection.HTTP_ACCEPTED) { return httpResult; } else { Log.e(TAG, "HTTP ERROR! " + httpResult); } } finally { urlConnection.disconnect(); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return HttpURLConnection.HTTP_NOT_ACCEPTABLE; }
@Override public void onBindViewHolder(final ViewHolder holder, int position) { HHFriendshipUser friendship = user.getFriendships().get(position); holder.position = position; holder.btnFollowOnClickListener.setFriendship(friendship); holder.btnUnfollowOnClickListener.setFriendship(friendship); holder.txtUserName.setText(friendship.getUser().getName()); holder.onClickUserListener.setUser(friendship.getUser()); boolean friendIsFollowed = HHUser.userIsFollowed(user, friendship.getUser()); boolean friendFollowsMe = HHUser.userFollowsMe(user, friendship.getUser()); boolean friendIsRequested = HHUser.userIsRequested(user, friendship.getUser()); // boolean userRequestedMe = HHUser.userRequestedMe(user, friendship.getUser()); if (friendIsFollowed) { holder.btnFollow.setVisibility(View.GONE); holder.btnUnfollow.setVisibility(View.VISIBLE); } else { holder.btnFollow.setVisibility(View.VISIBLE); holder.btnFollow.setEnabled(true); holder.btnFollow.clearColorFilter(); holder.btnUnfollow.setVisibility(View.GONE); } if (friendIsRequested) { holder.btnFollow.setColorFilter( ZZZUtility.screen(ContextCompat.getColor(context, R.color.adam_theme_darkest))); holder.btnFollow.setEnabled(false); } if (friendIsFollowed && friendFollowsMe) { holder.imgFollowStatus.setImageResource(R.drawable.follow_in_out); } else if (friendIsFollowed) { holder.imgFollowStatus.setImageResource(R.drawable.follow_out); } else if (friendFollowsMe) { holder.imgFollowStatus.setImageResource(R.drawable.follow_in); } else { holder.imgFollowStatus.setImageResource(R.drawable.follow_none); } // get User Image WebHelper.getFacebookProfilePicture( friendship.getUser().getFBUserID(), new WebHelper.GetFacebookProfilePictureCallback() { @Override public void returnFacebookProfilePicture(Bitmap bitmap) { holder.imgProfile.setImageBitmap(bitmap); } }); }