private void toggleLike(Button button) { if (post.isLiked()) { post.setLiked(false); button.setText("Like"); button.setTextColor(getResources().getColor(R.color.normalColor)); } else { post.setLiked(true); button.setText("Liked!"); button.setTextColor(getResources().getColor(R.color.toogleColor)); } }
private void changeLike(final Button button, final TextView textView) { String routing = ""; if (post.isLiked()) { routing = "delete"; } else { routing = "new"; } new HttpRequestTask(routing) { @Override protected void atPostExecute(JSONObject jsonObject) { toggleLike(button); fetchLikeCount(textView); } }.execute(JSONFactory.createLike(post.getId())); }
private void fetchLikeCount(final TextView textView) { new HttpRequestTask("liked_count") { @Override protected void atPostExecute(JSONObject jsonObject) { textView.setText("Likes: " + JSONParser.parseLikedCount(jsonObject, getActivity())); } }.execute(JSONFactory.createLike(post.getId())); }
private void initLikeButton(Button button) { if (LoginInfo.hasLoggedIn()) { if (post.isLiked()) { button.setText("Liked!"); button.setTextColor(getResources().getColor(R.color.toogleColor)); } else { button.setText("Like"); button.setTextColor(getResources().getColor(R.color.normalColor)); } } else { button.setVisibility(View.INVISIBLE); button.setEnabled(false); } }
private void sendComment() { String text = comment.getText().toString(); new HttpRequestTask("new") { @Override protected void atPostExecute(JSONObject jsonObject) { if (JSONParser.wasSuccessful(jsonObject)) { fetchComments(); } else { Toast.makeText(getActivity(), JSONParser.extractError(jsonObject), Toast.LENGTH_SHORT) .show(); } } }.execute(JSONFactory.createNewComment(text, post.getId())); }
private void fetchComments() { ResultsReceiver.newSearch(); final List<Comment> comments = new ArrayList<>(); new HttpRequestTask("comments", getActivity()) { @Override protected void atPostExecute(JSONObject jsonObject) { try { JSONParser.parseJSONObject(jsonObject); List<Serializable> serializables = ResultsReceiver.getResults(Comment.class); if (serializables != null && !serializables.isEmpty()) { for (Serializable serializable : serializables) { comments.add((Comment) serializable); } } setItems(comments); doneFetching(); } catch (JSONException e) { e.printStackTrace(); } } }.execute(JSONFactory.createPostIdData(post.getId())); }