Skip to content

Commit 0f35f79

Browse files
committed
闪存UI细节优化
1 parent 489be63 commit 0f35f79

File tree

15 files changed

+120
-24
lines changed

15 files changed

+120
-24
lines changed

app/src/main/java/com/rae/cnblogs/adapter/MomentAdapter.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ public void onBindViewHolder(SimpleViewHolder viewHolder, int position, MomentBe
130130
holder.authorView.setText(m.getAuthorName());
131131
holder.dateView.setText(m.getPostTime());
132132
holder.summaryView.setText(m.getContent());
133-
holder.commentView.setText(m.getCommentCount());
133+
holder.androidTagView.setVisibility(m.isAndroidClient() ? View.VISIBLE : View.GONE);
134+
holder.commentView.setVisibility("0".equals(m.getCommentCount()) ? View.GONE : View.VISIBLE);
135+
holder.commentView.setText("0".equals(m.getCommentCount()) ? "" : m.getCommentCount() + "条回复");
134136
}
135137

136138
private static class ItemDeleteClickListener implements View.OnClickListener {

app/src/main/java/com/rae/cnblogs/fragment/MomentFragment.java

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.os.Bundle;
44
import android.support.annotation.Nullable;
5+
import android.util.Log;
56
import android.view.View;
67

78
import com.jcodecraeer.xrecyclerview.XRecyclerView;
@@ -210,6 +211,11 @@ public void onDeleteMomentSuccess() {
210211
AppUI.success(getContext(), R.string.tips_del_moment_success);
211212
}
212213

214+
@Override
215+
public void onReplyContChanged(int number) {
216+
Log.i("rae", "有回复我的;" + number);
217+
}
218+
213219
/**
214220
* 滚动到顶部
215221
*/

app/src/main/java/com/rae/cnblogs/model/MomentHolder.java

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class MomentHolder extends SimpleViewHolder {
4141
public View deleteView; // 删除
4242
public Button followView; // 关注
4343
public ImageView thumbView; // 单张图片
44+
public View androidTagView; // 客户端标志
4445

4546

4647
// @BindView(R.id.img_blog_list_large_thumb)
@@ -63,6 +64,7 @@ public MomentHolder(View itemView) {
6364
deleteView = itemView.findViewById(R.id.img_close);
6465
thumbView = itemView.findViewById(R.id.img_thumb);
6566
followView = itemView.findViewById(R.id.btn_blogger_follow);
67+
androidTagView = itemView.findViewById(R.id.tv_android_tag);
6668
ButterKnife.bind(this, itemView);
6769
}
6870
}

app/src/main/java/com/rae/cnblogs/presenter/IMomentContract.java

+4
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,9 @@ interface View extends IPageView<MomentBean> {
3232
*/
3333
void onDeleteMomentSuccess();
3434

35+
/**
36+
* 有回复我的消息数量
37+
*/
38+
void onReplyContChanged(int number);
3539
}
3640
}

app/src/main/java/com/rae/cnblogs/presenter/impl/MomentPresenterImpl.java

+20
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.rae.cnblogs.sdk.Empty;
1313
import com.rae.cnblogs.sdk.api.IMomentApi;
1414
import com.rae.cnblogs.sdk.bean.MomentBean;
15+
import com.rae.swift.Rx;
1516

1617
import org.greenrobot.eventbus.EventBus;
1718
import org.greenrobot.eventbus.Subscribe;
@@ -48,6 +49,25 @@ protected Observable<List<MomentBean>> onCreateObserver(int page) {
4849
public void start() {
4950
super.start();
5051
mPageObservable.start();
52+
53+
// 查询回复我的数量
54+
if (isLogin()) {
55+
createObservable(mMomentApi.queryReplyCount(System.currentTimeMillis()))
56+
.subscribe(new ApiDefaultObserver<String>() {
57+
@Override
58+
protected void onError(String message) {
59+
60+
}
61+
62+
@Override
63+
protected void accept(String s) {
64+
int number = Rx.parseInt(s);
65+
if (number > 0) {
66+
mView.onReplyContChanged(number);
67+
}
68+
}
69+
});
70+
}
5171
}
5272

5373
@Override

app/src/main/java/com/rae/cnblogs/presenter/impl/PostMomentPresenterImpl.java

+4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ public boolean post() {
7474
mView.onPostMomentInProgress();
7575
return false;
7676
} else {
77+
78+
// 加上客户端标志
79+
content = "[来自Android客户端] " + content;
80+
7781
createObservable(mMomentApi.publish(content, 1))
7882
.subscribe(new ApiDefaultObserver<Empty>() {
7983
@Override
Loading

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,15 @@
4646

4747
</android.support.design.widget.DesignTabLayout>
4848

49-
<TextView
49+
<ImageView
5050
android:id="@+id/tv_post"
5151
android:layout_width="wrap_content"
5252
android:layout_height="wrap_content"
53+
android:layout_alignParentEnd="true"
5354
android:layout_alignParentRight="true"
54-
android:padding="12dp"
55-
android:text="发布"/>
55+
android:layout_centerVertical="true"
56+
android:layout_marginRight="@dimen/default_margin"
57+
android:src="@drawable/ic_moment_post"/>
5658

5759
</RelativeLayout>
5860
</android.support.v7.widget.Toolbar>

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

+37-19
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<RelativeLayout
33
xmlns:android="http://schemas.android.com/apk/res/android"
4-
xmlns:app="http://schemas.android.com/apk/res-auto"
54
android:layout_width="match_parent"
65
android:layout_height="wrap_content"
7-
android:layout_marginBottom="4dp"
6+
android:layout_marginBottom="1dp"
87
android:background="@drawable/bg_blog_item_selector"
98
android:foreground="?selectableItemBackground"
109
android:orientation="vertical"
11-
android:paddingBottom="@dimen/default_margin"
10+
android:paddingBottom="12dp"
1211
android:paddingLeft="@dimen/default_margin"
1312
android:paddingRight="@dimen/default_margin"
14-
android:paddingTop="@dimen/default_margin">
13+
android:paddingTop="18dp">
1514

16-
<ImageButton
15+
<ImageView
1716
android:id="@+id/img_close"
18-
android:layout_width="32dp"
19-
android:layout_height="32dp"
17+
android:layout_width="30dp"
18+
android:layout_height="30dp"
2019
android:layout_alignParentRight="true"
2120
android:background="@android:color/transparent"
22-
android:scaleType="center"
21+
android:padding="8dp"
22+
android:scaleType="fitCenter"
2323
android:src="@drawable/ic_close"/>
2424

25-
<com.makeramen.roundedimageview.RoundedImageView
25+
<ImageView
2626
android:id="@+id/img_blog_avatar"
2727
android:layout_width="40dp"
2828
android:layout_height="40dp"
2929
android:layout_marginRight="12dp"
3030
android:scaleType="centerCrop"
31-
android:src="@drawable/bg_user_avatar"
32-
app:riv_corner_radius="4dp"/>
31+
android:src="@drawable/bg_user_avatar"/>
3332

3433

3534
<com.rae.cnblogs.widget.RaeTextView
@@ -40,7 +39,7 @@
4039
android:layout_alignTop="@+id/img_blog_avatar"
4140
android:layout_toRightOf="@+id/img_blog_avatar"
4241
android:text="RAE"
43-
android:textColor="@color/ph2"
42+
android:textColor="@color/moment_author"
4443
android:textSize="@dimen/h2"/>
4544

4645
<com.rae.cnblogs.widget.RaeTextView
@@ -53,7 +52,7 @@
5352
android:gravity="bottom"
5453
android:text="今天18:30"
5554
android:textAlignment="gravity"
56-
android:textColor="@color/ph3"
55+
android:textColor="#767676"
5756
android:textSize="11sp"/>
5857

5958
<com.rae.cnblogs.widget.RaeTextView
@@ -94,12 +93,31 @@
9493
android:layout_below="@+id/img_thumb"
9594
android:layout_marginTop="18dp"
9695
android:layout_toRightOf="@+id/img_blog_avatar"
97-
android:drawableLeft="@drawable/ic_comment_min"
98-
android:drawablePadding="7dp"
99-
android:gravity="center"
100-
android:text="0"
101-
android:textColor="@color/ph2"
102-
android:textSize="@dimen/h2"/>
96+
android:drawableLeft="@drawable/ic_moment_comment"
97+
android:drawablePadding="6dp"
98+
android:gravity="center_vertical|end"
99+
android:minWidth="45dp"
100+
android:text="0条回复"
101+
android:textColor="#c4c4c4"
102+
android:textSize="@dimen/h3"/>
103+
104+
<TextView
105+
android:id="@+id/tv_android_tag"
106+
android:layout_width="wrap_content"
107+
android:layout_height="wrap_content"
108+
android:layout_alignBaseline="@+id/tv_blog_comment"
109+
android:layout_alignParentRight="true"
110+
android:layout_below="@+id/img_thumb"
111+
android:text="客户端"
112+
android:textColor="@color/dividerColor"
113+
android:textSize="@dimen/h3"/>
114+
115+
<!-- <View
116+
android:layout_width="match_parent"
117+
android:layout_height="1dp"
118+
android:layout_below="@+id/tv_blog_comment"
119+
android:layout_marginTop="12dp"
120+
android:background="@color/dividerPrimary"/>-->
103121

104122

105123
</RelativeLayout>

app/src/main/res/values/colors.xml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<color name="dividerColor">#dedede</color>
1414
<color name="ph1">#2d2d2d</color>
1515
<color name="ph2">#595959</color>
16+
<color name="moment_author">#576b95</color>
1617
<color name="ph3">#929292</color>
1718
<color name="ph4">#999999</color>
1819
<color name="default_background">#f9f9f9</color>

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

+3
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ final class ApiUrls {
118118
// 闪存-发表评论
119119
static final String API_MOMENT_POST_COMMENT = "https://ing.cnblogs.com/ajax/ing/PostComment";
120120

121+
// 闪存-回复我的数量
122+
static final String API_MOMENT_REPLY_COUNT = "https://ing.cnblogs.com/ajax/ing/UnviewedReplyToMeCount";
123+
121124
// 上传图片
122125
static final String API_POST_IMAGE = "https://upload.cnblogs.com/imageuploader/processupload?host=www.cnblogs.com";
123126

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

+8
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ public interface IMomentApi {
6363
@Parser(MomentDelParser.class)
6464
Observable<Empty> deleteMoment(@Field("ingId") String ingId);
6565

66+
/**
67+
* 获取回复我的数量
68+
*/
69+
@POST(ApiUrls.API_MOMENT_REPLY_COUNT)
70+
@FormUrlEncoded
71+
@Headers({JsonBody.XHR})
72+
Observable<String> queryReplyCount(@Field("_") long timestamp);
73+
6674
/**
6775
* 发表闪存评论
6876
*

sdk/src/main/java/com/rae/cnblogs/sdk/bean/MomentBean.java

+13
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public class MomentBean implements Parcelable {
3737
// 源地址
3838
private String sourceUrl;
3939

40+
// 是否发自于Android客户端
41+
private boolean isAndroidClient;
42+
4043
// 评论列表
4144
private List<MomentCommentBean> commentList;
4245

@@ -91,6 +94,14 @@ public void setAuthorName(String authorName) {
9194
this.authorName = authorName;
9295
}
9396

97+
public boolean isAndroidClient() {
98+
return isAndroidClient;
99+
}
100+
101+
public void setAndroidClient(boolean androidClient) {
102+
isAndroidClient = androidClient;
103+
}
104+
94105
public String getUserAlias() {
95106
return userAlias;
96107
}
@@ -151,6 +162,7 @@ public void writeToParcel(Parcel dest, int flags) {
151162
dest.writeString(this.content);
152163
dest.writeString(this.userAlias);
153164
dest.writeString(this.sourceUrl);
165+
dest.writeByte(this.isAndroidClient ? (byte) 1 : (byte) 0);
154166
dest.writeTypedList(this.commentList);
155167
dest.writeStringList(this.imageList);
156168
}
@@ -165,6 +177,7 @@ protected MomentBean(Parcel in) {
165177
this.content = in.readString();
166178
this.userAlias = in.readString();
167179
this.sourceUrl = in.readString();
180+
this.isAndroidClient = in.readByte() != 0;
168181
this.commentList = in.createTypedArrayList(MomentCommentBean.CREATOR);
169182
this.imageList = in.createStringArrayList();
170183
}

sdk/src/main/java/com/rae/cnblogs/sdk/converter/TextResponseBodyConverter.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ private boolean ignoreLogin() {
7777
}
7878

7979
@Override
80+
@SuppressWarnings("unchecked")
8081
public T convert(ResponseBody value) throws IOException {
8182
// 解析
8283
String text = value.string();
@@ -88,8 +89,9 @@ public T convert(ResponseBody value) throws IOException {
8889
if (text.startsWith("{") || text.startsWith("[")) {
8990
// 解析JSON
9091
return json2Entity(text);
92+
} else if (type == String.class) {
93+
return (T) text;
9194
}
92-
9395
return html2Entity(text);
9496
}
9597

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

+11
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public List<MomentBean> parse(Document doc, String html) throws IOException {
3030

3131
Elements elements = doc.select("#feed_list li");
3232

33+
final String androidTag = "[来自Android客户端]";
3334
for (Element element : elements) {
3435
MomentBean m = new MomentBean();
3536
String id = ApiUtils.getNumber(element.select(".feed_body").attr("id"));
@@ -45,6 +46,7 @@ public List<MomentBean> parse(Document doc, String html) throws IOException {
4546
m.setBlogApp(ApiUtils.getBlogApp(element.select(".ing-author").attr("href"))); // blogApp
4647
m.setSourceUrl(ApiUtils.getUrl(element.select(".ing-author").attr("href")).replace("home", "ing") + "status/" + id); // blogApp
4748

49+
4850
// 解析评论
4951
m.setCommentList(mMomentCommentHelper.parse(element));
5052

@@ -53,6 +55,7 @@ public List<MomentBean> parse(Document doc, String html) throws IOException {
5355
String content = m.getContent();
5456
int startIndex = content.indexOf("#img");
5557
int endIndex = content.indexOf("#end");
58+
5659
if (startIndex > 0 && endIndex > 0) {
5760
String json = content.substring(startIndex + 4, endIndex);
5861
try {
@@ -70,6 +73,14 @@ public List<MomentBean> parse(Document doc, String html) throws IOException {
7073
}
7174
}
7275

76+
// Android标签处理
77+
if (m.getContent().contains(androidTag) || (startIndex > 0 && endIndex > 0)) {
78+
// 来自安卓客户端
79+
m.setAndroidClient(true);
80+
// 去除标签
81+
m.setContent(m.getContent().replace(androidTag, ""));
82+
}
83+
7384
result.add(m);
7485
}
7586

0 commit comments

Comments
 (0)