Skip to content

Commit 4a7d683

Browse files
committed
添加删除闪存评论功能;
修复闪存BUG; 修复关注信息获取错误问题;
1 parent e83cce1 commit 4a7d683

File tree

6 files changed

+74
-25
lines changed

6 files changed

+74
-25
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@
4141
android:name=".activity.MainActivity"
4242
android:screenOrientation="portrait"
4343
android:theme="@style/AppTheme.Dark">
44-
<!-- <intent-filter>
45-
<action android:name="android.intent.action.MAIN"/>
44+
<intent-filter>
45+
<action android:name="android.intent.action.MAIN"/>
4646

47-
<category android:name="android.intent.category.LAUNCHER"/>
48-
</intent-filter>-->
47+
<category android:name="android.intent.category.LAUNCHER"/>
48+
</intent-filter>
4949
</activity>
5050

5151
<activity
@@ -157,13 +157,7 @@
157157
<activity
158158
android:name=".activity.MomentMessageActivity"
159159
android:label="@string/label_moment_message"
160-
android:screenOrientation="portrait">
161-
<intent-filter>
162-
<action android:name="android.intent.action.MAIN"/>
163-
164-
<category android:name="android.intent.category.LAUNCHER"/>
165-
</intent-filter>
166-
</activity>
160+
android:screenOrientation="portrait"/>
167161

168162
<service
169163
android:name=".service.CnblogsService"

app/src/main/java/com/rae/cnblogs/activity/MomentDetailActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private void loadMomentDetail() {
7474
}
7575

7676
IMomentApi momentApi = CnblogsApiFactory.getInstance(this).getMomentApi();
77-
RxObservable.create(momentApi.getMomentDetail(mUserId, mIngId), "moment")
77+
RxObservable.create(momentApi.getMomentDetail(mUserId, mIngId, System.currentTimeMillis()), "moment")
7878
.subscribe(new ApiDefaultObserver<MomentBean>() {
7979
@Override
8080
protected void onError(String message) {

app/src/main/res/layout/activity_moment_detail.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,22 @@
2222
android:scaleType="center"
2323
android:src="@drawable/ic_back"/>
2424

25+
26+
<TextView
27+
android:id="@+id/tv_title"
28+
android:layout_width="match_parent"
29+
android:layout_height="wrap_content"
30+
android:layout_centerVertical="true"
31+
android:layout_marginEnd="12dp"
32+
android:layout_marginRight="12dp"
33+
android:layout_toRightOf="@+id/back"
34+
android:ellipsize="end"
35+
android:singleLine="true"
36+
android:text="@string/label_moment_detail"
37+
android:textColor="@color/ph1"
38+
android:textSize="18sp"/>
39+
40+
2541
<ImageView
2642
android:id="@+id/btn_share"
2743
android:layout_width="wrap_content"

sdk/src/main/java/com/rae/cnblogs/sdk/api/ApiUrls.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ final class ApiUrls {
117117

118118
// 闪存-删除
119119
static final String API_MOMENT_DEL = "https://ing.cnblogs.com/ajax/ing/del";
120+
// 闪存-评论删除
121+
static final String API_MOMENT_COMMENT_DEL = "https://ing.cnblogs.com/ajax/ing/DeleteComment";
120122
// 闪存-发表评论
121123
static final String API_MOMENT_POST_COMMENT = "https://ing.cnblogs.com/ajax/ing/PostComment";
122124

sdk/src/main/java/com/rae/cnblogs/sdk/api/IMomentApi.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,23 @@ public interface IMomentApi {
136136
Observable<List<MomentCommentBean>> getMomentSingleComments(@Query("ingId") String ingId, @Query("userAlias") String userAlias, @Query("_") long timestamp);
137137

138138

139+
/**
140+
* 删除闪存评论
141+
*/
142+
@POST(ApiUrls.API_MOMENT_COMMENT_DEL)
143+
@FormUrlEncoded
144+
@Headers({JsonBody.XHR})
145+
Observable<Empty> deleteMomentComment(@Field("commentId") String commentId);
146+
147+
/**
148+
* 闪存详情
149+
*
150+
* @param userAlias 用户
151+
* @param ingId 闪存ID
152+
* @param timestamp 时间戳
153+
* @return
154+
*/
139155
@GET(ApiUrls.API_MOMENT_DETAIL)
140156
@Parser(MomentDetailParser.class)
141-
Observable<MomentBean> getMomentDetail(@Path("user") String userAlias, @Path("ingId") String ingId);
157+
Observable<MomentBean> getMomentDetail(@Path("user") String userAlias, @Path("ingId") String ingId, @Query("_") long timestamp);
142158
}

sdk/src/main/java/com/rae/cnblogs/sdk/parser/MomentCommentHelper.java

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.json.JSONArray;
1111
import org.json.JSONException;
1212
import org.jsoup.nodes.Element;
13+
import org.jsoup.nodes.TextNode;
1314
import org.jsoup.select.Elements;
1415

1516
import java.util.ArrayList;
@@ -90,6 +91,8 @@ public void parseCommentInDetail(Element element, MomentBean m) {
9091

9192
List<MomentCommentBean> commentList = new ArrayList<>();
9293

94+
StringBuilder sb = new StringBuilder();
95+
9396
for (Element commentLiElement : elements) {
9497
MomentCommentBean commentBean = new MomentCommentBean();
9598

@@ -98,13 +101,6 @@ public void parseCommentInDetail(Element element, MomentBean m) {
98101
if (TextUtils.isEmpty(commentId)) continue;
99102

100103

101-
// @用户处理
102-
Elements atUserElement = commentLiElement.select(".comment_author_" + commentId + " > a");
103-
if (atUserElement.text().contains("@")) {
104-
commentBean.setAtAuthorName(atUserElement.text());
105-
commentBean.setAtUserAlias(ApiUtils.getBlogApp(atUserElement.attr("href")));
106-
}
107-
108104
Matcher matcher = Pattern.compile("\\d+").matcher(commentLiElement.select(".gray3").attr("onclick"));
109105
int i = 0;
110106
while (matcher.find()) {
@@ -125,17 +121,42 @@ public void parseCommentInDetail(Element element, MomentBean m) {
125121
commentBean.setPostTime(commentLiElement.select(".text_green").text());
126122

127123

128-
// 获取文本,放到最后,因为是纯文本,要移除其他标签
124+
// @用户处理
125+
Elements atUserElement = commentLiElement.select("a:contains(@)");
126+
if (atUserElement.size() > 0) {
127+
commentBean.setAtAuthorName(atUserElement.text());
128+
commentBean.setAtUserAlias(ApiUtils.getBlogApp(atUserElement.attr("href")));
129+
}
129130

130-
int size = commentLiElement.childNodeSize();
131-
for (int k = 0; k < size; k++) {
132-
commentLiElement.child(i).remove();
131+
// 内容处理
132+
Elements divElements = commentLiElement.select("div");
133+
int size = divElements.size();
134+
if (size <= 0) {
135+
commentBean.setContent(commentLiElement.text());
136+
} else {
137+
Element div = divElements.get(0);
138+
List<TextNode> textNodes = div.textNodes();
139+
sb.delete(0, sb.length()); // 删除之前的
140+
141+
// 添加@用户
142+
if (!TextUtils.isEmpty(commentBean.getAtAuthorName())) {
143+
sb.append(commentBean.getAtAuthorName());
144+
sb.append(" ");
145+
}
146+
147+
for (TextNode node : textNodes) {
148+
String text = node.text().trim();
149+
if (TextUtils.isEmpty(text)) continue;
150+
if (text.startsWith(":") || text.startsWith(":")) text = text.substring(1);
151+
sb.append(text);
152+
}
153+
commentBean.setContent(sb.toString());
133154
}
134155

135-
commentBean.setContent(commentLiElement.text());
136156

137157
commentList.add(commentBean);
138158
}
159+
m.setCommentList(commentList);
139160
}
140161

141162

0 commit comments

Comments
 (0)