Skip to content

Commit 7c49715

Browse files
author
ChenRui
committed
添加系统消息功能
1 parent ea665f4 commit 7c49715

File tree

20 files changed

+440
-18
lines changed

20 files changed

+440
-18
lines changed

app/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ dependencies {
121121
compile 'io.reactivex.rxjava2:rxjava:2.1.0'
122122
// 主题切换
123123
compile 'skin.support:skin-support:2.1.2'
124+
compile 'skin.support:skin-support-design:1.2.5'
125+
124126
compile 'com.kyleduo.switchbutton:library:1.4.6'
125127
}
126128

app/src/main/AndroidManifest.xml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@
4545
</intent-filter>
4646
</activity>
4747

48-
<!-- <activity
49-
android:name=".activity.TestActivity"
50-
android:label="博客园测试"
51-
android:screenOrientation="portrait"
52-
android:theme="@style/AppTheme.Dark">
53-
<intent-filter>
54-
<action android:name="android.intent.action.MAIN"/>
55-
56-
<category android:name="android.intent.category.LAUNCHER"/>
57-
</intent-filter>
58-
</activity>-->
48+
<!-- <activity
49+
android:name=".activity.TestActivity"
50+
android:label="博客园测试"
51+
android:screenOrientation="portrait"
52+
android:theme="@style/AppTheme.Dark">
53+
<intent-filter>
54+
<action android:name="android.intent.action.MAIN"/>
55+
56+
<category android:name="android.intent.category.LAUNCHER"/>
57+
</intent-filter>
58+
</activity>-->
5959

6060
<!--博文-->
6161
<activity
@@ -184,6 +184,11 @@
184184
android:name=".activity.SearchActivity"
185185
android:windowSoftInputMode="stateVisible"/>
186186

187+
<activity
188+
android:name=".activity.SystemMessageActivity"
189+
android:label="@string/system_message"
190+
android:screenOrientation="portrait"/>
191+
187192

188193
<meta-data
189194
android:name="UMENG_APPKEY"

app/src/main/java/com/rae/cnblogs/AppRoute.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.rae.cnblogs.activity.MainActivity;
1818
import com.rae.cnblogs.activity.SearchActivity;
1919
import com.rae.cnblogs.activity.SettingActivity;
20+
import com.rae.cnblogs.activity.SystemMessageActivity;
2021
import com.rae.cnblogs.activity.WebActivity;
2122
import com.rae.cnblogs.activity.WebLoginActivity;
2223
import com.rae.cnblogs.image.ImagePreviewActivity;
@@ -268,4 +269,11 @@ public static void jumpToSearchKb(Context context) {
268269
intent.putExtra("position", 3);
269270
startActivity(context, intent);
270271
}
272+
273+
/**
274+
* 系统消息
275+
*/
276+
public static void jumpToSystemMessage(Context context) {
277+
startActivity(context, SystemMessageActivity.class);
278+
}
271279
}

app/src/main/java/com/rae/cnblogs/CnblogsApplication.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.umeng.socialize.UMShareAPI;
1717

1818
import skin.support.SkinCompatManager;
19+
import skin.support.design.app.SkinMaterialViewInflater;
1920

2021
/**
2122
* 集成热更新的应用程序
@@ -45,7 +46,10 @@ public void onCreate() {
4546

4647
// 加载皮肤
4748
SkinCompatManager.withoutActivity(getApplication()).loadSkin();
48-
SkinCompatManager.getInstance().addInflater(new CnblogsLayoutInflater());
49+
SkinCompatManager.getInstance()
50+
.setSkinStatusBarColorEnable(false)
51+
.addInflater(new SkinMaterialViewInflater())
52+
.addInflater(new CnblogsLayoutInflater());
4953

5054
// 一些要求不高的初始化操作放到线程中去操作
5155
new Thread(new Runnable() {
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package com.rae.cnblogs.activity;
2+
3+
import android.os.Bundle;
4+
import android.support.annotation.Nullable;
5+
6+
import com.rae.cnblogs.AppRoute;
7+
import com.rae.cnblogs.R;
8+
import com.rae.cnblogs.RxObservable;
9+
import com.rae.cnblogs.adapter.BaseItemAdapter;
10+
import com.rae.cnblogs.adapter.SystemMessageAdapter;
11+
import com.rae.cnblogs.sdk.ApiDefaultObserver;
12+
import com.rae.cnblogs.sdk.CnblogsApiFactory;
13+
import com.rae.cnblogs.sdk.api.IRaeServerApi;
14+
import com.rae.cnblogs.sdk.bean.SystemMessageBean;
15+
import com.rae.cnblogs.widget.PlaceholderView;
16+
import com.rae.cnblogs.widget.RaeRecyclerView;
17+
import com.rae.swift.Rx;
18+
19+
import java.util.List;
20+
21+
import butterknife.BindView;
22+
23+
/**
24+
* 系统消息
25+
* Created by ChenRui on 2017/9/5 0005 15:39.
26+
*/
27+
public class SystemMessageActivity extends SwipeBackBaseActivity {
28+
29+
@BindView(R.id.recycler_view)
30+
RaeRecyclerView mRecyclerView;
31+
@BindView(R.id.placeholder)
32+
PlaceholderView mPlaceholderView;
33+
34+
IRaeServerApi mRaeServerApi;
35+
36+
SystemMessageAdapter mAdapter;
37+
38+
private String mTag = "SystemMessageActivity";
39+
40+
@Override
41+
protected void onCreate(@Nullable Bundle savedInstanceState) {
42+
super.onCreate(savedInstanceState);
43+
setContentView(R.layout.activity_system_message);
44+
showHomeAsUp();
45+
mRaeServerApi = CnblogsApiFactory.getInstance(this).getRaeServerApi();
46+
mAdapter = new SystemMessageAdapter();
47+
48+
mRecyclerView.setAdapter(mAdapter);
49+
50+
mAdapter.setOnItemClickListener(new BaseItemAdapter.onItemClickListener<SystemMessageBean>() {
51+
@Override
52+
public void onItemClick(SystemMessageBean item) {
53+
AppRoute.jumpToWeb(getContext(), item.getUrl());
54+
}
55+
});
56+
57+
// 获取消息列表
58+
RxObservable.create(mRaeServerApi.getMessages(), mTag)
59+
.subscribe(new ApiDefaultObserver<List<SystemMessageBean>>() {
60+
@Override
61+
protected void onError(String message) {
62+
mPlaceholderView.empty();
63+
}
64+
65+
@Override
66+
protected void accept(List<SystemMessageBean> data) {
67+
if (Rx.isEmpty(data)) {
68+
mPlaceholderView.empty();
69+
return;
70+
}
71+
mPlaceholderView.dismiss();
72+
mAdapter.invalidate(data);
73+
mAdapter.notifyDataSetChanged();
74+
}
75+
});
76+
77+
// 更新消息数量
78+
RxObservable.create(mRaeServerApi.getMessageCount(), mTag)
79+
.subscribe(new ApiDefaultObserver<Integer>() {
80+
@Override
81+
protected void onError(String message) {
82+
83+
}
84+
85+
@Override
86+
protected void accept(Integer count) {
87+
config().setMessageCount(count);
88+
}
89+
});
90+
91+
}
92+
93+
@Override
94+
protected void onDestroy() {
95+
super.onDestroy();
96+
RxObservable.dispose(mTag);
97+
}
98+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.rae.cnblogs.adapter;
2+
3+
import android.view.LayoutInflater;
4+
import android.view.ViewGroup;
5+
6+
import com.rae.cnblogs.R;
7+
import com.rae.cnblogs.RaeImageLoader;
8+
import com.rae.cnblogs.ThemeCompat;
9+
import com.rae.cnblogs.model.SystemMessageHolder;
10+
import com.rae.cnblogs.sdk.bean.SystemMessageBean;
11+
12+
/**
13+
* 系统消息
14+
* Created by ChenRui on 2017/9/5 0005 17:23.
15+
*/
16+
public class SystemMessageAdapter extends BaseItemAdapter<SystemMessageBean, SystemMessageHolder> {
17+
18+
@Override
19+
public SystemMessageHolder onCreateViewHolder(LayoutInflater inflater, ViewGroup parent, int viewType) {
20+
return new SystemMessageHolder(inflateView(parent, R.layout.item_system_message));
21+
}
22+
23+
@Override
24+
public void onBindViewHolder(SystemMessageHolder holder, int position, SystemMessageBean m) {
25+
holder.getTitleView().setText(m.getSummary());
26+
holder.getDateView().setText(m.getCreateTime());
27+
RaeImageLoader.displayImage(m.getThumbUrl(), holder.getThumbImageView());
28+
if (ThemeCompat.isNight()) {
29+
holder.getThumbImageView().setAlpha(0.4f);
30+
}
31+
}
32+
33+
}

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public static MineFragment newInstance() {
5151

5252
@BindView(R.id.ll_follow_fans)
5353
View mFansAndFollowLayout;
54+
@BindView(R.id.img_system_message_badge)
55+
View mSystemMessageBadgeView;
5456

5557
@BindView(R.id.sb_night_mode)
5658
SwitchButton mNightModeButton;
@@ -73,9 +75,23 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
7375
}
7476

7577
@Override
76-
public void onCreate(@Nullable Bundle savedInstanceState) {
77-
super.onCreate(savedInstanceState);
78-
// 模拟登录
78+
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
79+
super.onActivityCreated(savedInstanceState);
80+
81+
// 获取系统消息
82+
RxObservable.create(CnblogsApiFactory.getInstance(getContext()).getRaeServerApi().getMessageCount(), "MineFragment")
83+
.subscribe(new ApiDefaultObserver<Integer>() {
84+
@Override
85+
protected void onError(String message) {
86+
87+
}
88+
89+
@Override
90+
protected void accept(Integer integer) {
91+
if (integer == null) return;
92+
mSystemMessageBadgeView.setVisibility(config().getMessageCount() != integer ? View.VISIBLE : View.INVISIBLE);
93+
}
94+
});
7995
}
8096

8197
@Override
@@ -215,6 +231,15 @@ public void onFeedbackClick() {
215231
}
216232

217233

234+
/**
235+
* 系统消息
236+
*/
237+
@OnClick(R.id.ll_system_message)
238+
public void onSystemMessageClick() {
239+
mSystemMessageBadgeView.setVisibility(View.INVISIBLE);
240+
AppRoute.jumpToSystemMessage(this.getContext());
241+
}
242+
218243
/**
219244
* 设置
220245
*/
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.rae.cnblogs.model;
2+
3+
import android.view.View;
4+
import android.widget.ImageView;
5+
import android.widget.TextView;
6+
7+
import com.rae.cnblogs.R;
8+
9+
import butterknife.BindView;
10+
import butterknife.ButterKnife;
11+
12+
public class SystemMessageHolder extends SimpleViewHolder {
13+
@BindView(R.id.img_thumb)
14+
ImageView mThumbImageView;
15+
@BindView(R.id.tv_title)
16+
TextView mTitleView;
17+
@BindView(R.id.tv_date)
18+
TextView mDateView;
19+
20+
public SystemMessageHolder(View itemView) {
21+
super(itemView);
22+
ButterKnife.bind(this, itemView);
23+
}
24+
25+
public ImageView getThumbImageView() {
26+
return mThumbImageView;
27+
}
28+
29+
public TextView getTitleView() {
30+
return mTitleView;
31+
}
32+
33+
public TextView getDateView() {
34+
return mDateView;
35+
}
36+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:state_pressed="true">
4+
<shape>
5+
<solid android:color="@color/dividerColor"/>
6+
<corners android:radius="4dp"/>
7+
</shape>
8+
</item>
9+
<item>
10+
<shape>
11+
<solid android:color="@color/white"/>
12+
<corners android:radius="4dp"/>
13+
<stroke android:width="0.5dp" android:color="@color/dividerColor"/>
14+
</shape>
15+
</item>
16+
</selector>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<item>
5+
<shape>
6+
<solid android:color="@color/white_night"/>
7+
<corners android:radius="4dp"/>
8+
<stroke android:width="0.5dp" android:color="@color/dividerColor_night"/>
9+
</shape>
10+
</item>
11+
</selector>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
android:background="@drawable/tab_main_background"
2323
android:gravity="center">
2424

25-
<android.support.design.widget.TabLayout
25+
<com.rae.cnblogs.widget.RaeTabLayout
2626
android:id="@+id/tab_main"
2727
android:layout_width="match_parent"
2828
android:layout_height="match_parent"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:background="@color/white"
7+
android:orientation="vertical"
8+
android:paddingTop="@dimen/default_padding_top">
9+
10+
<include layout="@layout/view_title"/>
11+
12+
<com.rae.cnblogs.widget.PlaceholderView
13+
android:id="@+id/placeholder"
14+
android:layout_width="match_parent"
15+
android:layout_height="match_parent"
16+
android:background="@color/background_divider"
17+
app:empty_message="暂无消息">
18+
19+
<com.rae.cnblogs.widget.RaeRecyclerView
20+
android:id="@+id/recycler_view"
21+
android:layout_width="match_parent"
22+
android:layout_height="match_parent"
23+
android:background="@color/background_divider"/>
24+
25+
</com.rae.cnblogs.widget.PlaceholderView>
26+
</LinearLayout>

0 commit comments

Comments
 (0)