Ejemplo n.º 1
0
 @Override
 public View getView(final int position, final View convertView, final ViewGroup parent) {
   final View view =
       convertView != null ? convertView : mInflater.inflate(R.layout.activity_list_item, null);
   final Object tag = view.getTag();
   final ActivityViewHolder holder =
       tag instanceof ActivityViewHolder
           ? (ActivityViewHolder) tag
           : new ActivityViewHolder(view);
   if (!(tag instanceof ActivityViewHolder)) {
     view.setTag(holder);
   }
   holder.reset();
   holder.setTextSize(mTextSize);
   final twitter4j.Activity item = getItem(position);
   final Date created_at = item.getCreatedAt();
   if (created_at != null) {
     if (mShowAbsoluteTime) {
       holder.time.setText(formatSameDayTime(mContext, created_at.getTime()));
     } else {
       holder.time.setText(getRelativeTimeSpanString(created_at.getTime()));
     }
   }
   final User[] sources = item.getSources();
   final Status[] target_statuses = item.getTargetStatuses();
   final int sources_length = sources != null ? sources.length : 0;
   final int target_statuses_length = target_statuses != null ? target_statuses.length : 0;
   final Action action = item.getAction();
   holder.profile_image.setVisibility(mDisplayProfileImage ? View.VISIBLE : View.GONE);
   if (sources_length > 0) {
     final User first_source = sources[0];
     final Status[] target_objects = item.getTargetObjectStatuses();
     final String name = mDisplayName ? first_source.getName() : first_source.getScreenName();
     switch (action.getActionId()) {
       case Action.ACTION_FAVORITE:
         {
           if (target_statuses_length > 0) {
             final Status status = target_statuses[0];
             holder.text.setSingleLine(true);
             holder.text.setEllipsize(TruncateAt.END);
             holder.text.setText(status.getText());
           }
           if (sources_length == 1) {
             holder.title.setText(mContext.getString(R.string.activity_about_me_favorite, name));
           } else {
             holder.title.setText(
                 mContext.getString(
                     R.string.activity_about_me_favorite_multi, name, sources_length - 1));
           }
           holder.activity_profile_image_container.setVisibility(
               mDisplayProfileImage ? View.VISIBLE : View.GONE);
           setUserProfileImages(sources, holder);
           break;
         }
       case Action.ACTION_FOLLOW:
         {
           holder.text.setVisibility(View.GONE);
           if (sources_length == 1) {
             holder.title.setText(mContext.getString(R.string.activity_about_me_follow, name));
           } else {
             holder.title.setText(
                 mContext.getString(
                     R.string.activity_about_me_follow_multi, name, sources_length - 1));
           }
           holder.activity_profile_image_container.setVisibility(
               mDisplayProfileImage ? View.VISIBLE : View.GONE);
           setUserProfileImages(sources, holder);
           break;
         }
       case Action.ACTION_MENTION:
         {
           holder.title.setText(name);
           if (target_objects != null && target_objects.length > 0) {
             final Status status = target_objects[0];
             holder.text.setText(status.getText());
             if (status.getInReplyToStatusId() > 0 && status.getInReplyToScreenName() != null) {
               holder.reply_status.setVisibility(View.VISIBLE);
               holder.reply_status.setText(
                   mContext.getString(R.string.in_reply_to, status.getInReplyToScreenName()));
               holder.reply_status.setCompoundDrawablesWithIntrinsicBounds(
                   R.drawable.ic_indicator_reply, 0, 0, 0);
             }
           }
           setProfileImage(first_source.getProfileImageURL(), holder);
           break;
         }
       case Action.ACTION_REPLY:
         {
           holder.title.setText(name);
           if (target_statuses_length > 0) {
             final Status status = target_statuses[0];
             holder.text.setText(status.getText());
             if (status.getInReplyToStatusId() > 0 && status.getInReplyToScreenName() != null) {
               holder.reply_status.setVisibility(View.VISIBLE);
               holder.reply_status.setText(
                   mContext.getString(R.string.in_reply_to, status.getInReplyToScreenName()));
               holder.reply_status.setCompoundDrawablesWithIntrinsicBounds(
                   R.drawable.ic_indicator_reply, 0, 0, 0);
             }
           }
           setProfileImage(first_source.getProfileImageURL(), holder);
           break;
         }
       case Action.ACTION_RETWEET:
         {
           if (target_objects != null && target_objects.length > 0) {
             final Status status = target_objects[0];
             holder.text.setSingleLine(true);
             holder.text.setEllipsize(TruncateAt.END);
             holder.text.setText(status.getText());
           }
           if (sources_length == 1) {
             holder.title.setText(mContext.getString(R.string.activity_about_me_retweet, name));
           } else {
             holder.title.setText(
                 mContext.getString(
                     R.string.activity_about_me_retweet_multi, name, sources_length - 1));
           }
           holder.activity_profile_image_container.setVisibility(
               mDisplayProfileImage ? View.VISIBLE : View.GONE);
           setUserProfileImages(sources, holder);
           break;
         }
       case Action.ACTION_LIST_MEMBER_ADDED:
         {
           holder.text.setVisibility(View.GONE);
           if (sources_length == 1) {
             holder.title.setText(
                 mContext.getString(R.string.activity_about_me_list_member_added, name));
           } else {
             holder.title.setText(
                 mContext.getString(
                     R.string.activity_about_me_list_member_added_multi,
                     name,
                     sources_length - 1));
           }
           holder.activity_profile_image_container.setVisibility(
               mDisplayProfileImage ? View.VISIBLE : View.GONE);
           setUserProfileImages(sources, holder);
           break;
         }
     }
   }
   return view;
 }
Ejemplo n.º 2
0
 @Override
 public void onListItemClick(final ListView l, final View v, final int position, final long id) {
   if (mAccountId <= 0) return;
   final int adapter_pos = position - l.getHeaderViewsCount();
   final twitter4j.Activity item = mAdapter.getItem(adapter_pos);
   final User[] sources = item.getSources();
   final Status[] target_statuses = item.getTargetStatuses();
   final int sources_length = sources != null ? sources.length : 0;
   final Action action = item.getAction();
   final boolean hires_profile_image = getResources().getBoolean(R.bool.hires_profile_image);
   if (sources_length > 0) {
     final Status[] target_objects = item.getTargetObjectStatuses();
     switch (action.getActionId()) {
       case Action.ACTION_FAVORITE:
         {
           if (sources_length == 1) {
             openUserProfile(
                 getActivity(), new ParcelableUser(sources[0], mAccountId, hires_profile_image));
           } else {
             if (target_statuses != null && target_statuses.length > 0) {
               final Status status = target_statuses[0];
               openStatus(
                   getActivity(),
                   new ParcelableStatus(status, mAccountId, false, hires_profile_image));
             }
           }
           break;
         }
       case Action.ACTION_FOLLOW:
         {
           if (sources_length == 1) {
             openUserProfile(
                 getActivity(), new ParcelableUser(sources[0], mAccountId, hires_profile_image));
           } else {
             openUserFollowers(getActivity(), mAccountId, mAccountId, null);
           }
           break;
         }
       case Action.ACTION_MENTION:
         {
           if (target_objects != null && target_objects.length > 0) {
             final Status status = target_objects[0];
             openStatus(
                 getActivity(),
                 new ParcelableStatus(status, mAccountId, false, hires_profile_image));
           }
           break;
         }
       case Action.ACTION_REPLY:
         {
           if (target_statuses != null && target_statuses.length > 0) {
             final Status status = target_statuses[0];
             openStatus(
                 getActivity(),
                 new ParcelableStatus(status, mAccountId, false, hires_profile_image));
           }
           break;
         }
       case Action.ACTION_RETWEET:
         {
           if (sources_length == 1) {
             openUserProfile(
                 getActivity(), new ParcelableUser(sources[0], mAccountId, hires_profile_image));
           } else {
             if (target_objects != null && target_objects.length > 0) {
               final Status status = target_objects[0];
               openStatus(
                   getActivity(),
                   new ParcelableStatus(status, mAccountId, false, hires_profile_image));
             }
           }
           break;
         }
     }
   }
 }