Skip to content

Commit d6214a3

Browse files
committed
Merge branch 'master' of https://github.com/brian512/CodeBlog
2 parents 352c805 + 598b9e2 commit d6214a3

File tree

4 files changed

+66
-4
lines changed

4 files changed

+66
-4
lines changed

app/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ android {
9696
dexOptions {
9797
javaMaxHeapSize "2g"
9898
preDexLibraries = false
99-
incremental true
10099
}
101100

102101
aaptOptions {

app/src/main/java/com/brian/csdnblog/activity/BlogListFrag.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ public void onEventMainThread(TypeChangeEvent event) {
451451
}
452452

453453
private void startRefresh() {
454-
if (mRefreshable && checkUpdateTime()) {
454+
if (mRefreshable && (checkUpdateTime()||Config.isDebug)) {
455455
mRefreshLayout.setRefreshing(true);
456456
loadData(true);
457457
}

app/src/main/java/com/brian/csdnblog/parser/CSDNHtmlParser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ private List<BlogInfo> doGetHotBlogItemList(int type, String str) {
109109
String nickName = blogItem.getElementsByClass("nickname").get(0).text();
110110
item.extraMsg = nickName + " " + blogItem.getElementsByClass("blog_list_b_r").get(0).select("label").text();
111111
item.link = blogItem.select("h3").select("a").attr("href");
112+
if (item.link.startsWith("/")) {
113+
item.link = getBlogBaseUrl() + item.link;
114+
}
112115
item.blogId = Md5.getMD5ofStr(item.link);
113116
item.type = type;
114117
item.dateStamp = String.valueOf(System.currentTimeMillis());

app/src/main/java/com/brian/csdnblog/parser/ITEyeHtmlParser.java

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212

1313
import com.brian.csdnblog.Env;
1414
import com.brian.csdnblog.manager.Constants;
15+
import com.brian.csdnblog.manager.TypeManager;
1516
import com.brian.csdnblog.model.BlogInfo;
1617
import com.brian.csdnblog.datacenter.preference.CommonPreference;
18+
import com.brian.csdnblog.model.Bloger;
1719
import com.brian.csdnblog.util.JsoupUtil;
1820
import com.brian.csdnblog.util.LogUtil;
1921
import com.brian.csdnblog.util.Md5;
@@ -62,13 +64,54 @@ public static ITEyeHtmlParser getInstance() {
6264
@Override
6365
public List<BlogInfo> getBlogList(int type, String strHtml) {
6466
try {
65-
return doGetBlogList(type, strHtml);
67+
if (TypeManager.getCateType(type) == TypeManager.TYPE_CAT_BLOGER) {
68+
return doGetBlogerItemList(type, strHtml);
69+
} else {
70+
return doGetBlogList(type, strHtml);
71+
}
6672
} catch (Exception e) {
67-
e.printStackTrace();
73+
LogUtil.printError(e);
6874
MobclickAgent.reportError(Env.getContext(), e);
6975
return null;
7076
}
7177
}
78+
79+
80+
private List<BlogInfo> doGetBlogerItemList(int type, String str) {
81+
List<BlogInfo> list = new ArrayList<>();
82+
if (TextUtils.isEmpty(str)) {
83+
return list;
84+
}
85+
// LogUtil.d("str=" + str);
86+
// 获取文档对象
87+
Document doc = Jsoup.parse(str);
88+
// 获取class="article_item"的所有元素
89+
Elements blogList = doc.getElementsByClass("blog_main");
90+
if (blogList == null) {
91+
return list;
92+
}
93+
94+
for (Element blogItem : blogList) {
95+
BlogInfo item = new BlogInfo();
96+
item.title = blogItem.select("h3").select("a").text(); // 得到标题
97+
item.link = blogItem.select("h3").select("a").attr("href");
98+
if (item.link.startsWith("/")) {
99+
item.link = getBlogBaseUrl() + item.link;
100+
}
101+
item.summary = blogItem.getElementsByClass("blog_content").first().text();
102+
item.blogId = Md5.getMD5ofStr(item.link);
103+
104+
Element msgElement = blogItem.getElementsByClass("blog_bottom").get(0);
105+
msgElement.getElementsByClass("comment").remove();
106+
msgElement.getElementsByClass("view").remove();
107+
msgElement.getElementsByClass("digged").remove();
108+
item.extraMsg = msgElement.text();
109+
item.type = type;
110+
111+
list.add(item);
112+
}
113+
return list;
114+
}
72115

73116
private List<BlogInfo> doGetBlogList(int type, String str) {
74117
List<BlogInfo> list = new ArrayList<>();
@@ -89,6 +132,9 @@ private List<BlogInfo> doGetBlogList(int type, String str) {
89132
BlogInfo item = new BlogInfo();
90133
item.title = blogItem.select("h3").select("a").text(); // 得到标题
91134
item.link = blogItem.select("h3").select("a").attr("href");
135+
if (item.link.startsWith("/")) {
136+
item.link = getBlogBaseUrl() + item.link;
137+
}
92138
item.summary = blogItem.getElementsByIndexEquals(1).text();
93139
item.blogId = Md5.getMD5ofStr(item.link);
94140

@@ -99,6 +145,20 @@ private List<BlogInfo> doGetBlogList(int type, String str) {
99145
item.extraMsg = msgElement.text();
100146
item.type = type;
101147

148+
String homePageUrl = blogItem.getElementsByClass("blog_info").get(0).select("a").attr("href");
149+
if (!TextUtils.isEmpty(homePageUrl)) {
150+
Bloger bloger = new Bloger();
151+
bloger.blogerType = type;
152+
bloger.nickName = blogItem.getElementsByClass("blog_info").get(0).select("a").text();
153+
bloger.headUrl = blogItem.getElementsByClass("logo").get(0).select("img").attr("src");
154+
bloger.homePageUrl = homePageUrl;
155+
bloger.blogerID = Bloger.getBlogerId(bloger.homePageUrl);
156+
157+
// BlogerTable.getInstance().insert(bloger);//保存用户信息
158+
item.blogerJson = bloger.toJson();
159+
item.blogerID = bloger.blogerID;
160+
}
161+
102162
list.add(item);
103163
}
104164
return list;

0 commit comments

Comments
 (0)