Android Open Source - Test-SimpleTwitterClient Concrete User Timeline Adapter






From Project

Back to project page Test-SimpleTwitterClient.

License

The source code is released under:

This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...

If you think the Android project Test-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.example.Twitter_Android.Fragments.Adapters;
//from w  w w .  j a  v a 2s . co  m
import android.app.Activity;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import com.example.Twitter_Android.AsynkTasks.ImageDownloader;
import com.example.Twitter_Android.Fragments.Dialogs.ReplyDialog;
import com.example.Twitter_Android.Fragments.Dialogs.RetweetDialog;
import com.example.Twitter_Android.Logic.DataCache;
import com.example.Twitter_Android.Logic.Person;
import com.example.Twitter_Android.Logic.Tweet;
import com.example.Twitter_Android.R;

import java.util.List;

/**
 * ??????? ??? ??????????? TimeLine ??????????? ????????????.
 * TODO: ???????????? ??? ????. ???????????, ????? ????? ???? ???????????? ?????? ?????????.
 */
public class ConcreteUserTimelineAdapter extends TimelineAdapter<Tweet> {
  private final LayoutInflater layoutInflater;
  private Activity mainActivity;
  private final ImageDownloader imageDownloader;

  //------------------------------------------------------------------------------------------------------------------
  private static class ViewHolder {
    TextView retweetedBy;
    TextView name;
    TextView screenName;
    TextView date;
    TextView text;
    ImageView attachedImage;
    Button button;
    ImageButton buttonReply;
    ImageButton buttonRetweet;
    ImageButton buttonFavorite;
  }
  //------------------------------------------------------------------------------------------------------------------

  public ConcreteUserTimelineAdapter(Activity activity, List<Tweet> newTweets, String tag) {
    super(newTweets, tag);
    mainActivity = activity;
    layoutInflater = LayoutInflater.from(mainActivity);
    imageDownloader = new ImageDownloader();
  }

  //------------------------------------------------------------------------------------------------------------------
  @Override
  public int getItemViewType(int position) {
    return 0;
  }
  //------------------------------------------------------------------------------------------------------------------

  @Override
  public int getViewTypeCount() {
    return 1;
  }
  //------------------------------------------------------------------------------------------------------------------

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder holder;
    if (convertView == null) {
      convertView = layoutInflater.inflate(R.layout.single_tweet_layout_without_avatar, null);
      holder = new ViewHolder();
      holder.retweetedBy = (TextView) convertView.findViewById(R.id.retweeted_by);
      holder.name = (TextView) convertView.findViewById(R.id.username_textview);
      holder.screenName = (TextView) convertView.findViewById(R.id.user_screen_name_textview);
      holder.date = (TextView) convertView.findViewById(R.id.tweet_date_textview);
      holder.text = (TextView) convertView.findViewById(R.id.tweet_text_textview);
      holder.attachedImage = (ImageView) convertView.findViewById(R.id.attached_image);
      holder.button = (Button) convertView.findViewById(R.id.button_show_image);
      holder.buttonReply = (ImageButton) convertView.findViewById(R.id.image_button_reply);
      holder.buttonRetweet = (ImageButton) convertView.findViewById(R.id.image_button_retweet);
      holder.buttonFavorite = (ImageButton) convertView.findViewById(R.id.image_button_favorite);
      convertView.setTag(holder);
    } else {
      holder = (ViewHolder) convertView.getTag();
    }
    final Tweet tweet = getItem(position);
    Person author = tweet.getAuthor();

    if (tweet.isRetweeted()) {
      Person p = tweet.retweetedBy();
      holder.retweetedBy.setText(mainActivity.getString(R.string.text_retweeted_by) + " " + p.getName() + " @" + p.getScreenName());
      holder.retweetedBy.setVisibility(View.VISIBLE);
    } else {
      holder.retweetedBy.setVisibility(View.GONE);
    }
    holder.name.setText(author.getName());
    holder.screenName.setText("@" + author.getScreenName());
    holder.date.setText(tweet.getCreationTime());
    holder.text.setText(tweet.getText());

    if (tweet.hasLinkInText()) {
      holder.text.setFocusable(false);
      holder.text.setFocusableInTouchMode(false);
    }

    if (tweet.hasMedia()) {
      Bitmap bitmap = DataCache.getInstance().getImage(tweet.getMediaUrl());
      if (bitmap != null) {
        holder.attachedImage.setImageBitmap(bitmap);
        holder.attachedImage.setVisibility(View.VISIBLE);
        holder.button.setVisibility(View.GONE);
      } else {
        holder.attachedImage.setVisibility(View.GONE);
        holder.button.setVisibility(View.VISIBLE);

        holder.button.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            imageDownloader.loadBitmap(tweet.getMediaUrl(), holder.attachedImage);
            v.setVisibility(View.GONE);
          }
        });
        holder.button.setFocusable(false);
      }
    } else {
      holder.button.setVisibility(View.GONE);
      holder.attachedImage.setVisibility(View.GONE);
    }

    holder.buttonReply.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        reply(tweet);
      }
    });

    holder.buttonRetweet.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        retweet(tweet);
      }
    });

    holder.buttonFavorite.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        Toast.makeText(mainActivity, "Need to create favorite method", Toast.LENGTH_LONG).show();
      }
    });

    holder.buttonReply.setFocusable(false);
    holder.buttonRetweet.setFocusable(false);
    holder.buttonFavorite.setFocusable(false);
    return convertView;
  }

  //------------------------------------------------------------------------------------------------------------------
  private void reply(Tweet toReply) {
    ReplyDialog dialog = ReplyDialog.getInstance(toReply);
    dialog.show(mainActivity.getFragmentManager().beginTransaction(), ReplyDialog.TAG);
  }
  //------------------------------------------------------------------------------------------------------------------

  private void retweet(Tweet toRetweet) {
    RetweetDialog dialog = RetweetDialog.getInstance(toRetweet);
    dialog.show(mainActivity.getFragmentManager().beginTransaction(), RetweetDialog.TAG);
  }
  //------------------------------------------------------------------------------------------------------------------

  @Override
  public void updateContext(Activity context) {
    mainActivity = context;
  }
}




Java Source Code List

com.example.Twitter_Android.AppActivity.ConcreteUserTimelineActivity.java
com.example.Twitter_Android.AppActivity.MainActivity.java
com.example.Twitter_Android.AppActivity.MessagesActivity.java
com.example.Twitter_Android.AppActivity.SearchableActivity.java
com.example.Twitter_Android.AppActivity.SettingsActivity.java
com.example.Twitter_Android.AsynkTasks.ImageDownloader.java
com.example.Twitter_Android.AsynkTasks.TaskDeleteTweet.java
com.example.Twitter_Android.AsynkTasks.TaskFollow.java
com.example.Twitter_Android.AsynkTasks.TaskPostTweet.java
com.example.Twitter_Android.AsynkTasks.TaskReply.java
com.example.Twitter_Android.AsynkTasks.TaskRetweet.java
com.example.Twitter_Android.AsynkTasks.TaskSendMessage.java
com.example.Twitter_Android.AsynkTasks.TaskUnfollow.java
com.example.Twitter_Android.Fragments.ConcreteUserTimelineFragment.java
com.example.Twitter_Android.Fragments.ConnectedUserTimelineFragment.java
com.example.Twitter_Android.Fragments.FollowersFragment.java
com.example.Twitter_Android.Fragments.FollowingsFragment.java
com.example.Twitter_Android.Fragments.HomeTimelineFragment.java
com.example.Twitter_Android.Fragments.TimelineFragment.java
com.example.Twitter_Android.Fragments.UserInfoFragment.java
com.example.Twitter_Android.Fragments.Adapters.ConcreteUserTimelineAdapter.java
com.example.Twitter_Android.Fragments.Adapters.FollowingsListAdapter.java
com.example.Twitter_Android.Fragments.Adapters.MessagesAdapter.java
com.example.Twitter_Android.Fragments.Adapters.TimelineAdapter.java
com.example.Twitter_Android.Fragments.Adapters.TweetAdapter.java
com.example.Twitter_Android.Fragments.Dialogs.DeleteTweetDialog.java
com.example.Twitter_Android.Fragments.Dialogs.DirectMessageDialog.java
com.example.Twitter_Android.Fragments.Dialogs.ErrorDialog.java
com.example.Twitter_Android.Fragments.Dialogs.PostTweetDialog.java
com.example.Twitter_Android.Fragments.Dialogs.ReplyDialog.java
com.example.Twitter_Android.Fragments.Dialogs.RetweetDialog.java
com.example.Twitter_Android.Fragments.Dialogs.ShowImageDialog.java
com.example.Twitter_Android.Fragments.Dialogs.UserInfoDialog.java
com.example.Twitter_Android.Fragments.Preferences.SettingsFragment.java
com.example.Twitter_Android.Loaders.AsyncUserInfoLoader.java
com.example.Twitter_Android.Loaders.FollowersLoader.java
com.example.Twitter_Android.Loaders.FollowingsLoader.java
com.example.Twitter_Android.Loaders.HomeTimelineLoader.java
com.example.Twitter_Android.Loaders.MessageLoader.java
com.example.Twitter_Android.Loaders.Task_LoadSearchedTweets.java
com.example.Twitter_Android.Loaders.Task_LoadSearchedUsers.java
com.example.Twitter_Android.Loaders.TweetLoader.java
com.example.Twitter_Android.Loaders.UserTimelineLoader.java
com.example.Twitter_Android.Logic.AppDatabase.java
com.example.Twitter_Android.Logic.Constants.java
com.example.Twitter_Android.Logic.DataCache.java
com.example.Twitter_Android.Logic.FileWorker.java
com.example.Twitter_Android.Logic.Person.java
com.example.Twitter_Android.Logic.Tweet.java
com.example.Twitter_Android.Net.Connector.java
com.example.Twitter_Android.Net.Parser.java
com.mass.cmassive.CMassive.java