Android Open Source - SimpleTwitterClient Tweet Adapter






From Project

Back to project page SimpleTwitterClient.

License

The source code is released under:

Apache License

If you think the Android project SimpleTwitterClient listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.codepath.apps.basictwitter.adapters;
//  w  w  w  . jav a 2  s.  c  om
import android.content.Context;
import android.content.Intent;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.codepath.apps.basictwitter.R;
import com.codepath.apps.basictwitter.activities.ThirdPartyActivity;
import com.codepath.apps.basictwitter.helpers.DateTimeUtils;
import com.codepath.apps.basictwitter.models.Tweet;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * TweetAdapter is an ArrayAdapter that adapts a List of Tweet objects to the context's view.
 */
public class TweetAdapter extends ArrayAdapter<Tweet> {
    public TweetAdapter(Context context, List<Tweet> objects) {
        super(context, 0, objects);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Tweet tweet = getItem(position);
        View v;
        if (convertView == null) {
            LayoutInflater inflator = LayoutInflater.from(getContext());
            v = inflator.inflate(R.layout.tweet_item, parent, false);
        } else {
            v = convertView;
        }
        // Find views within template
        ImageView ivProfileImage = (ImageView) v.findViewById(R.id.ivProfileImage);
        ivProfileImage.setImageResource(android.R.color.transparent);
        ivProfileImage.setTag(tweet.getUser().getScreenName());
        ivProfileImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(v.getContext(), ThirdPartyActivity.class);
                i.putExtra("screenName", v.findViewById(R.id.ivProfileImage).getTag().toString());
                v.getContext().startActivity(i);
            }
        });

        if (tweet.getUser() != null) {
            TextView tvUserName = (TextView) v.findViewById(R.id.tvUserName);
            tvUserName.setText(Html.fromHtml("<b> " + tweet.getUser().getName() + " </b>"));
            TextView tvUserScreenName = (TextView) v.findViewById(R.id.tvUserScreenName);
            tvUserScreenName.setText(tweet.getUser().getScreenName());
            ImageLoader imageLoader = ImageLoader.getInstance();
            imageLoader.displayImage(tweet.getUser().getProfileImageUrl(), ivProfileImage);
        }
        TextView tvBody = (TextView) v.findViewById(R.id.tvBody);
        tvBody.setText(tweet.getBody());
        TextView tvRelativeTime = (TextView) v.findViewById(R.id.tvRelativeTime);
        tvRelativeTime.setText(DateTimeUtils.getRelativeTimeAgo(tweet.getCreatedAt()));
        return v;
    }
}




Java Source Code List

com.codepath.apps.basictwitter.TwitterApplication.java
com.codepath.apps.basictwitter.activities.ComposeActivity.java
com.codepath.apps.basictwitter.activities.LoginActivity.java
com.codepath.apps.basictwitter.activities.ProfileActivity.java
com.codepath.apps.basictwitter.activities.ThirdPartyActivity.java
com.codepath.apps.basictwitter.activities.TimelineActivity.java
com.codepath.apps.basictwitter.adapters.TweetAdapter.java
com.codepath.apps.basictwitter.clients.TwitterClient.java
com.codepath.apps.basictwitter.fragments.HomeTimelineFragment.java
com.codepath.apps.basictwitter.fragments.MentionsTimelineFragment.java
com.codepath.apps.basictwitter.fragments.ThirdPartyTimelineFragment.java
com.codepath.apps.basictwitter.fragments.TweetsListFragment.java
com.codepath.apps.basictwitter.fragments.UserTimelineFragment.java
com.codepath.apps.basictwitter.helpers.DateTimeUtils.java
com.codepath.apps.basictwitter.helpers.NetworkUtils.java
com.codepath.apps.basictwitter.helpers.UserUtils.java
com.codepath.apps.basictwitter.listeners.EndlessScrollListener.java
com.codepath.apps.basictwitter.listeners.SupportFragmentTabListener.java
com.codepath.apps.basictwitter.models.Tweet.java
com.codepath.apps.basictwitter.models.User.java