package org.phphub.app.common.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.View;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import org.phphub.app.R;
import org.phphub.app.api.entity.element.Topic;
import org.phphub.app.common.base.BaseAdapterItemView;

import butterknife.Bind;
import cn.bingoogolapple.badgeview.BGABadgeRelativeLayout;
import static org.phphub.app.common.qualified.ClickType.*;

public class TopicItemView extends BaseAdapterItemView<Topic> {
    @Bind(R.id.bga_rlyt_content)
    BGABadgeRelativeLayout topicContentView;

    @Bind(R.id.tv_title)
    TextView titleView;

    @Bind(R.id.sdv_avatar)
    SimpleDraweeView avatarView;

    public TopicItemView(Context context) {
        super(context);
    }

    @Override
    public int getLayoutId() {
        return R.layout.topic_item;
    }

    @Override
    public void bind(Topic topic) {

        Uri avatarUri = Uri.parse(topic.getUserInfo().getData().getAvatar());
        String commentCount = String.valueOf(topic.getReplyCount());

        if (topic.getReplyCount() > 99) {
            commentCount = "99+";
        }

        topicContentView.showTextBadge(commentCount);
        titleView.setText(topic.getTitle());
        avatarView.setImageURI(avatarUri);

        topicContentView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                notifyItemAction(CLICK_TYPE_TOPIC_CLICKED);
            }
        });
    }
}

@@ -193,24 +193,67 @@
 eDraweeView;
+%0Aimport com.ocpsoft.pretty.time.PrettyTime;
 %0A%0Aimport org
@@ -367,24 +367,118 @@
 rItemView;%0A%0A
+import java.text.ParseException;%0Aimport java.text.SimpleDateFormat;%0Aimport java.util.Locale;%0A%0A
 import butte
@@ -859,24 +859,86 @@
 vatarView;%0A%0A
+    @Bind(R.id.tv_description)%0A    TextView descriptionView;%0A%0A
     public T
@@ -1137,16 +1137,41 @@
 topic) %7B
+%0A        String des = %22%22;
 %0A%0A      
@@ -1395,24 +1395,888 @@
 %0A        %7D%0A%0A
+        if (topic.getNodeInfo() != null) %7B%0A            des += topic.getNodeInfo().getData().getName();%0A        %7D%0A%0A        if (topic.getLastReplyUser() != null) %7B%0A            des += %22 %E2%80%A2 %22 + getResources().getString(R.string.last_for) + %22 %22 + topic.getLastReplyUser().getData().getName();%0A        %7D%0A%0A        if (topic.getUpdatedAt() != null) %7B%0A            Locale locale = getResources().getConfiguration().locale;%0A            PrettyTime prettyTime = new PrettyTime(locale);%0A            String dateStr = topic.getUpdatedAt().getDate();%0A            SimpleDateFormat sdf = new SimpleDateFormat(%22yyyy-MM-dd HH:mm:ss%22);%0A            try %7B%0A                String prettyTimeString = prettyTime.format(sdf.parse(dateStr));%0A                des += %22 %E2%80%A2 %22 + prettyTimeString;%0A            %7D catch (ParseException e) %7B%0A                e.printStackTrace();%0A            %7D%0A        %7D%0A%0A
         topi
@@ -2358,24 +2358,24 @@
 etTitle());%0A
-
         avat
@@ -2404,16 +2404,54 @@
 tarUri);
+%0A        descriptionView.setText(des);
 %0A%0A      

add description