private void setupViews() { tweet = getIntent().getParcelableExtra("tweet"); ivUserProfile = (ImageView) findViewById(R.id.ivUserProfile); tvBody = (TextView) findViewById(R.id.tvBody); tvTimestamp = (TextView) findViewById(R.id.tvCreatedAt); tvUserName = (TextView) findViewById(R.id.tvScreenName); tvFav = (TextView) findViewById(R.id.tvFav); tvRetweet = (TextView) findViewById(R.id.tvRetweet); if (tweet.getUser().getProfileImageUri() != null) { Picasso.with(this).load(tweet.getUser().getProfileImageUri()).into(ivUserProfile); } tvBody.setText(tweet.getBody()); tvTimestamp.setText(RelativeTime.getRelativeTimeAgo(tweet.getCreatedAt())); tvUserName.setText("@" + tweet.getUser().getScreenName()); ivRetweet = (ImageView) findViewById(R.id.ivRetweet); ivReplyView = (ImageView) findViewById(R.id.ivReply); ivFav = (ImageView) findViewById(R.id.ivFav); ivRetweet.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(getApplicationContext(), RetweetActivity.class); i.putExtra("tweet", tweet); v.getContext().startActivity(i); } }); ivReplyView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(getApplicationContext(), ComposeActivity.class); i.putExtra("tweet", tweet); v.getContext().startActivity(i); } }); ivFav.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (!tweet.getIsFavorite()) { client.postFavorite( new JsonHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { ivFav.setImageResource(R.drawable.fav_red); tweet = Tweet.fromJson(response); tvFav.setText(String.valueOf(tweet.getFavoriteCount())); } @Override public void onFailure( int statusCode, Header[] headers, Throwable t, JSONObject response) { Log.d("Error", response.toString()); } }, String.valueOf(tweet.getUid())); } else { client.deleteFavorite( new JsonHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { ivFav.setImageResource(R.drawable.favorite); tweet = Tweet.fromJson(response); tvFav.setText(String.valueOf(tweet.getFavoriteCount())); } @Override public void onFailure( int statusCode, Header[] headers, Throwable t, JSONObject response) { Log.d("Error", response.toString()); } }, String.valueOf(tweet.getUid())); } } }); if (tweet.getIsFavorite() != null && tweet.getIsFavorite()) { ivFav.setBackground(new ColorDrawable(Color.RED)); } tvFav.setText(String.valueOf(tweet.getFavoriteCount())); tvRetweet.setText(String.valueOf(tweet.getRetweetCount())); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#4099FF"))); }
@Override protected List<Tweet> parseAndSaveRemoteResult(Context context, JSONArray resultJSON) { return Tweet.fromJsonArray(context, resultJSON); }