Skip to content

Commit bf918ab

Browse files
committed
add entrance of blogerbloglist in iteye and oschina
1 parent d6214a3 commit bf918ab

File tree

7 files changed

+79
-11
lines changed

7 files changed

+79
-11
lines changed

app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ android {
1616
applicationId "com.brian.csdnblog"
1717
minSdkVersion 15
1818
targetSdkVersion 24
19-
versionCode 76
20-
versionName "1.3.76"
19+
versionCode 78
20+
versionName "1.3.78"
2121
multiDexEnabled true
2222
vectorDrawables.useSupportLibrary = true
2323

@@ -65,7 +65,7 @@ android {
6565
// 签名
6666
signingConfig signingConfigs.release
6767

68-
// 修改包名
68+
// 修改文件名
6969
applicationVariants.all { variant ->
7070
variant.outputs.each { output ->
7171
def outputFile = output.outputFile

app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@
3737

3838
<meta-data android:name="DEBUG_ENABLE" android:value="${DEBUG_ENABLE}" />
3939

40-
<!--腾讯X5内核-->
41-
<meta-data android:name="QBSDKAppKey" android:value="OExstf3r76Yf79YF/kJrUb+Q"/>
42-
4340
<activity
4441
android:name="com.brian.csdnblog.activity.SplashActivity"
4542
android:screenOrientation="portrait">

app/src/main/java/com/brian/csdnblog/manager/BlogerManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.brian.csdnblog.datacenter.preference.CommonPreference;
44
import com.brian.csdnblog.model.Bloger;
55
import com.brian.csdnblog.model.event.CurrBlogerEvent;
6+
import com.brian.csdnblog.util.LogUtil;
67

78
import org.greenrobot.eventbus.EventBus;
89

@@ -42,6 +43,8 @@ public void setCurrBloger(Bloger bloger) {
4243
CurrBlogerEvent event = new CurrBlogerEvent();
4344
event.bloger = mCurrBloger;
4445
EventBus.getDefault().post(event);
46+
47+
LogUtil.log("mCurrBloger=" + mCurrBloger.toJson());
4548
}
4649
}
4750
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import android.text.TextUtils;
1212

1313
import com.brian.csdnblog.Env;
14+
import com.brian.csdnblog.manager.BlogerManager;
1415
import com.brian.csdnblog.manager.Constants;
1516
import com.brian.csdnblog.manager.TypeManager;
1617
import com.brian.csdnblog.model.BlogInfo;
@@ -21,6 +22,8 @@
2122
import com.brian.csdnblog.util.Md5;
2223
import com.umeng.analytics.MobclickAgent;
2324

25+
import static com.brian.csdnblog.manager.BlogerManager.getsInstance;
26+
2427
/**
2528
* 博客园网页解析类
2629
* @author huamm
@@ -90,13 +93,18 @@ private List<BlogInfo> doGetBlogerItemList(int type, String str) {
9093
if (blogList == null) {
9194
return list;
9295
}
96+
Bloger bloger = BlogerManager.getsInstance().getCurrBloger();
97+
String host = getBlogBaseUrl();
98+
if (!TextUtils.isEmpty(bloger.homePageUrl)) {
99+
host = bloger.homePageUrl.substring(0, bloger.homePageUrl.indexOf(".com")+4);
100+
}
93101

94102
for (Element blogItem : blogList) {
95103
BlogInfo item = new BlogInfo();
96104
item.title = blogItem.select("h3").select("a").text(); // 得到标题
97105
item.link = blogItem.select("h3").select("a").attr("href");
98106
if (item.link.startsWith("/")) {
99-
item.link = getBlogBaseUrl() + item.link;
107+
item.link = host + item.link;
100108
}
101109
item.summary = blogItem.getElementsByClass("blog_content").first().text();
102110
item.blogId = Md5.getMD5ofStr(item.link);

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

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
import com.brian.csdnblog.Env;
66
import com.brian.csdnblog.datacenter.preference.CommonPreference;
7+
import com.brian.csdnblog.manager.TypeManager;
78
import com.brian.csdnblog.model.BlogInfo;
9+
import com.brian.csdnblog.model.Bloger;
810
import com.brian.csdnblog.util.JsoupUtil;
911
import com.brian.csdnblog.util.LogUtil;
1012
import com.brian.csdnblog.util.Md5;
@@ -59,14 +61,48 @@ public static OsChinaHtmlParser getInstance() {
5961
@Override
6062
public List<BlogInfo> getBlogList(int type, String strHtml) {
6163
try {
62-
return doGetBlogList(type, strHtml);
64+
if (TypeManager.getCateType(type) == TypeManager.TYPE_CAT_BLOGER) {
65+
return doGetBlogerItemList(type, strHtml);
66+
} else {
67+
return doGetBlogList(type, strHtml);
68+
}
6369
} catch (Exception e) {
6470
e.printStackTrace();
6571
MobclickAgent.reportError(Env.getContext(), e);
6672
return null;
6773
}
6874
}
6975

76+
private List<BlogInfo> doGetBlogerItemList(int type, String str) {
77+
List<BlogInfo> list = new ArrayList<>();
78+
if (TextUtils.isEmpty(str)) {
79+
return list;
80+
}
81+
// LogUtil.d("str=" + str);
82+
// 获取文档对象
83+
Document doc = Jsoup.parse(str);
84+
// 获取class="article_item"的所有元素
85+
Element blogs = doc.getElementById("list");
86+
if (blogs == null) {
87+
return list;
88+
}
89+
Elements blogList = blogs.getElementsByClass("list-item");
90+
91+
for (Element blogItem : blogList) {
92+
BlogInfo item = new BlogInfo();
93+
item.title = blogItem.getElementsByClass("title").get(0).select("a").text(); // 得到标题
94+
item.link = blogItem.getElementsByClass("title").get(0).select("a").attr("href");
95+
item.summary = "";
96+
item.extraMsg = blogItem.getElementsByClass("time").get(0).text();
97+
item.blogId = Md5.getMD5ofStr(item.link);
98+
99+
item.type = type;
100+
101+
list.add(item);
102+
}
103+
return list;
104+
}
105+
70106
private List<BlogInfo> doGetBlogList(int type, String str) {
71107
List<BlogInfo> list = new ArrayList<>();
72108
if (TextUtils.isEmpty(str)) {
@@ -92,6 +128,20 @@ private List<BlogInfo> doGetBlogList(int type, String str) {
92128

93129
item.type = type;
94130

131+
String homePageUrl = blogItem.select("a").get(0).attr("href");
132+
if (!TextUtils.isEmpty(homePageUrl)) {
133+
Bloger bloger = new Bloger();
134+
bloger.blogerType = type;
135+
bloger.nickName = blogItem.select("a").get(0).select("img").attr("title");
136+
bloger.headUrl = blogItem.select("a").get(0).select("img").attr("src");
137+
bloger.homePageUrl = homePageUrl;
138+
bloger.blogerID = Bloger.getBlogerId(bloger.homePageUrl);
139+
140+
// BlogerTable.getInstance().insert(bloger);//保存用户信息
141+
item.blogerJson = bloger.toJson();
142+
item.blogerID = bloger.blogerID;
143+
}
144+
95145
list.add(item);
96146
}
97147
return list;
@@ -101,6 +151,7 @@ public String getBlogContent(int type, String contentSrc) {
101151
try {
102152
return doGetBlogContent(contentSrc);
103153
} catch (Exception e) {
154+
LogUtil.printError(e);
104155
MobclickAgent.reportError(Env.getContext(), e);
105156
return "";
106157
}

app/src/main/java/com/brian/csdnblog/util/DeviceUtil.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,17 @@ public static String getUUID() {
4848
} catch (Exception e) {
4949
deviceId = "";
5050
}
51-
tmSerial = "" + tm.getSimSerialNumber();
52-
androidId = "" + Settings.Secure.getString(Env.getContext().getContentResolver(), Settings.Secure.ANDROID_ID);
51+
try {
52+
tmSerial = "" + tm.getSimSerialNumber();
53+
} catch (Exception e) {
54+
tmSerial = "";
55+
}
56+
try {
57+
androidId = "" + Settings.Secure.getString(Env.getContext().getContentResolver(), Settings.Secure.ANDROID_ID);
58+
} catch (Exception e) {
59+
androidId = "";
60+
}
61+
5362
UUID deviceUuid = new UUID(androidId.hashCode(), ((long) deviceId.hashCode() << 32) | tmSerial.hashCode());
5463
uniqueId = Md5.getMD5ofStr(deviceUuid.toString());
5564
LogUtil.d("uuid=" + uniqueId);

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include ':app'
1+
include ':app'

0 commit comments

Comments
 (0)