|
6 | 6 | import android.os.Bundle; |
7 | 7 | import android.os.Handler; |
8 | 8 | import android.os.Message; |
| 9 | +import android.text.Spannable; |
| 10 | +import android.text.SpannableStringBuilder; |
9 | 11 | import android.text.TextUtils; |
| 12 | +import android.text.style.ForegroundColorSpan; |
10 | 13 | import android.view.KeyEvent; |
11 | 14 | import android.view.View; |
12 | 15 | import android.view.View.OnClickListener; |
|
28 | 31 | import com.brian.csdnblog.manager.DataFetcher.Result; |
29 | 32 | import com.brian.csdnblog.manager.ThreadManager; |
30 | 33 | import com.brian.csdnblog.manager.UsageStatsManager; |
| 34 | +import com.brian.csdnblog.model.Bloger; |
31 | 35 | import com.brian.csdnblog.model.SearchResult; |
32 | 36 | import com.brian.csdnblog.parser.CSDNHtmlParser; |
33 | 37 | import com.brian.csdnblog.util.CommonAdapter; |
| 38 | +import com.brian.csdnblog.util.LogUtil; |
| 39 | +import com.brian.csdnblog.util.ResourceUtil; |
34 | 40 | import com.brian.csdnblog.util.ToastUtil; |
35 | 41 | import com.brian.csdnblog.util.UIUtil; |
36 | 42 | import com.brian.csdnblog.util.WeakRefHandler; |
@@ -82,13 +88,38 @@ private void initUI() { |
82 | 88 | mTitleBar.setRightImageVisible(View.INVISIBLE); |
83 | 89 |
|
84 | 90 | mAdapter = new CommonAdapter<SearchResult>(Env.getContext(), null, R.layout.item_list_search) { |
85 | | - |
| 91 | + private ForegroundColorSpan mColorSpanName = new ForegroundColorSpan(ResourceUtil.getColor(R.color.light_blue)); |
86 | 92 | @Override |
87 | 93 | public void convert(ViewHolder holder, final SearchResult item) { |
88 | 94 | holder.setText(R.id.title, item.title); |
89 | 95 | holder.setText(R.id.authorTime, item.authorTime); |
90 | 96 | holder.setText(R.id.searchDetail, item.searchDetail); |
91 | 97 |
|
| 98 | + TextView nameView = holder.getView(R.id.authorTime); |
| 99 | + Bloger bloger = Bloger.fromJson(item.blogerJson); |
| 100 | + if (bloger != null && !TextUtils.isEmpty(bloger.nickName) && !TextUtils.isEmpty(item.authorTime)) { |
| 101 | + SpannableStringBuilder builder = new SpannableStringBuilder(item.authorTime); |
| 102 | + int indexStart = item.authorTime.indexOf(bloger.nickName); |
| 103 | + builder.setSpan(mColorSpanName, indexStart, indexStart + bloger.nickName.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); |
| 104 | + nameView.setText(builder); |
| 105 | + } else { |
| 106 | + nameView.setText(item.authorTime); |
| 107 | + } |
| 108 | + |
| 109 | + nameView.setOnClickListener(new OnClickListener() { |
| 110 | + @Override |
| 111 | + public void onClick(View v) { |
| 112 | + if (!TextUtils.isEmpty(item.blogerID)) { |
| 113 | + LogUtil.log(item.blogerJson); |
| 114 | + Bloger bloger = Bloger.fromJson(item.blogerJson); |
| 115 | + if (bloger != null) { |
| 116 | + BlogerBlogListActivity.startActivity(SearchActivity.this, item.type, bloger); |
| 117 | + UsageStatsManager.sendUsageData(UsageStatsManager.USAGE_BLOGER_ENTR, "bloglist"); |
| 118 | + } |
| 119 | + } |
| 120 | + } |
| 121 | + }); |
| 122 | + |
92 | 123 | holder.setOnClickListener(new OnClickListener() { |
93 | 124 | @Override |
94 | 125 | public void onClick(View v) { |
|
0 commit comments