Commit abf181bd02bc2848fd068416f4d662f97a6279f7
1 parent
50ca3597
Exists in
yxb_dev
and in
2 other branches
no message
Showing
9 changed files
with
359 additions
and
31 deletions
Show diff stats
.idea/modules.xml
@@ -4,8 +4,8 @@ | @@ -4,8 +4,8 @@ | ||
4 | <modules> | 4 | <modules> |
5 | <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> | 5 | <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> |
6 | <module fileurl="file://$PROJECT_DIR$/mvpsdk/mvpsdk.iml" filepath="$PROJECT_DIR$/mvpsdk/mvpsdk.iml" /> | 6 | <module fileurl="file://$PROJECT_DIR$/mvpsdk/mvpsdk.iml" filepath="$PROJECT_DIR$/mvpsdk/mvpsdk.iml" /> |
7 | + <module fileurl="file://$PROJECT_DIR$/parentWorkHolper.iml" filepath="$PROJECT_DIR$/parentWorkHolper.iml" /> | ||
7 | <module fileurl="file://E:\parentwork\parentWorkHolper.iml" filepath="E:\parentwork\parentWorkHolper.iml" /> | 8 | <module fileurl="file://E:\parentwork\parentWorkHolper.iml" filepath="E:\parentwork\parentWorkHolper.iml" /> |
8 | - <module fileurl="file://$PROJECT_DIR$/parentwork.iml" filepath="$PROJECT_DIR$/parentwork.iml" /> | ||
9 | <module fileurl="file://F:\parentWorkHolper\parentwork.iml" filepath="F:\parentWorkHolper\parentwork.iml" /> | 9 | <module fileurl="file://F:\parentWorkHolper\parentwork.iml" filepath="F:\parentWorkHolper\parentwork.iml" /> |
10 | <module fileurl="file://$PROJECT_DIR$/roundedimageview-2.2.1/roundedimageview-2.2.1.iml" filepath="$PROJECT_DIR$/roundedimageview-2.2.1/roundedimageview-2.2.1.iml" /> | 10 | <module fileurl="file://$PROJECT_DIR$/roundedimageview-2.2.1/roundedimageview-2.2.1.iml" filepath="$PROJECT_DIR$/roundedimageview-2.2.1/roundedimageview-2.2.1.iml" /> |
11 | </modules> | 11 | </modules> |
app/build.gradle
@@ -47,4 +47,5 @@ dependencies { | @@ -47,4 +47,5 @@ dependencies { | ||
47 | implementation project(':roundedimageview-2.2.1') | 47 | implementation project(':roundedimageview-2.2.1') |
48 | implementation files('libs/AMap_Location_V3.8.0_20180201.jar') | 48 | implementation files('libs/AMap_Location_V3.8.0_20180201.jar') |
49 | implementation 'org.greenrobot:greendao:3.2.2' // add library | 49 | implementation 'org.greenrobot:greendao:3.2.2' // add library |
50 | + compile "me.leolin:ShortcutBadger:1.1.19@aar" | ||
50 | } | 51 | } |
app/src/main/AndroidManifest.xml
@@ -65,11 +65,11 @@ | @@ -65,11 +65,11 @@ | ||
65 | <!-- android:name="com.amap.api.v2.apikey" --> | 65 | <!-- android:name="com.amap.api.v2.apikey" --> |
66 | <!-- android:value="0da7965006ae0c8e4106c76c1867d976"/> --> | 66 | <!-- android:value="0da7965006ae0c8e4106c76c1867d976"/> --> |
67 | 67 | ||
68 | - <!--家长慧测试APPkey--> | 68 | + |
69 | + <!-- 家长慧测试APPkey --> | ||
69 | <meta-data | 70 | <meta-data |
70 | android:name="com.netease.nim.appKey" | 71 | android:name="com.netease.nim.appKey" |
71 | android:value="330158c080acdf4dc1092d6a74576c2c"/> | 72 | android:value="330158c080acdf4dc1092d6a74576c2c"/> |
72 | - | ||
73 | <meta-data | 73 | <meta-data |
74 | android:name="android.max_aspect" | 74 | android:name="android.max_aspect" |
75 | android:value="2.1"/> | 75 | android:value="2.1"/> |
@@ -112,7 +112,8 @@ | @@ -112,7 +112,8 @@ | ||
112 | android:name="com.amap.api.v2.apikey" | 112 | android:name="com.amap.api.v2.apikey" |
113 | android:value="1d130afb822d8a1019e6592cbaf10bcc"/> | 113 | android:value="1d130afb822d8a1019e6592cbaf10bcc"/> |
114 | 114 | ||
115 | - <activity android:name=".ui.activity.StartActivity" | 115 | + <activity |
116 | + android:name=".ui.activity.StartActivity" | ||
116 | android:launchMode="singleInstance" | 117 | android:launchMode="singleInstance" |
117 | android:windowSoftInputMode="adjustPan|stateAlwaysHidden"> | 118 | android:windowSoftInputMode="adjustPan|stateAlwaysHidden"> |
118 | <intent-filter> | 119 | <intent-filter> |
@@ -121,10 +122,10 @@ | @@ -121,10 +122,10 @@ | ||
121 | <category android:name="android.intent.category.LAUNCHER"/> | 122 | <category android:name="android.intent.category.LAUNCHER"/> |
122 | </intent-filter> | 123 | </intent-filter> |
123 | </activity> | 124 | </activity> |
124 | - <!--<activity--> | ||
125 | - <!--android:name=".ui.MainActivity"--> | ||
126 | - <!--android:screenOrientation="portrait"--> | ||
127 | - <!--android:windowSoftInputMode="adjustPan|stateAlwaysHidden" />--> | 125 | + <!-- <activity --> |
126 | + <!-- android:name=".ui.MainActivity" --> | ||
127 | + <!-- android:screenOrientation="portrait" --> | ||
128 | + <!-- android:windowSoftInputMode="adjustPan|stateAlwaysHidden" /> --> | ||
128 | <activity | 129 | <activity |
129 | android:name=".ui.activity.MyChildActivity" | 130 | android:name=".ui.activity.MyChildActivity" |
130 | android:screenOrientation="portrait"/> | 131 | android:screenOrientation="portrait"/> |
@@ -133,12 +134,12 @@ | @@ -133,12 +134,12 @@ | ||
133 | <activity | 134 | <activity |
134 | android:name=".ui.MainActivity" | 135 | android:name=".ui.MainActivity" |
135 | android:launchMode="singleInstance" | 136 | android:launchMode="singleInstance" |
136 | - android:windowSoftInputMode="adjustPan|stateAlwaysHidden" | ||
137 | - android:screenOrientation="portrait"/> | 137 | + android:screenOrientation="portrait" |
138 | + android:windowSoftInputMode="adjustPan|stateAlwaysHidden"/> | ||
138 | <activity | 139 | <activity |
139 | android:name=".ui.activity.ChildDetialActivity" | 140 | android:name=".ui.activity.ChildDetialActivity" |
140 | android:launchMode="singleInstance" | 141 | android:launchMode="singleInstance" |
141 | - android:screenOrientation="portrait" /> | 142 | + android:screenOrientation="portrait"/> |
142 | <activity | 143 | <activity |
143 | android:name=".ui.activity.binding.CreateChildInfoActivity" | 144 | android:name=".ui.activity.binding.CreateChildInfoActivity" |
144 | android:launchMode="singleInstance" | 145 | android:launchMode="singleInstance" |
@@ -148,37 +149,38 @@ | @@ -148,37 +149,38 @@ | ||
148 | android:name=".ui.activity.binding.SelectSchoolActivity" | 149 | android:name=".ui.activity.binding.SelectSchoolActivity" |
149 | android:screenOrientation="portrait" | 150 | android:screenOrientation="portrait" |
150 | android:windowSoftInputMode="adjustPan|stateHidden"/> | 151 | android:windowSoftInputMode="adjustPan|stateHidden"/> |
151 | - | ||
152 | - <activity android:name=".ui.activity.LoginAndRegistActivity" | ||
153 | - android:screenOrientation="portrait" | ||
154 | - /> | 152 | + <activity |
153 | + android:name=".ui.activity.LoginAndRegistActivity" | ||
154 | + android:screenOrientation="portrait"/> | ||
155 | <activity | 155 | <activity |
156 | android:name=".ui.activity.PersonInfoActivity" | 156 | android:name=".ui.activity.PersonInfoActivity" |
157 | android:launchMode="singleInstance" | 157 | android:launchMode="singleInstance" |
158 | android:screenOrientation="portrait" | 158 | android:screenOrientation="portrait" |
159 | android:windowSoftInputMode="adjustPan|stateHidden"/> | 159 | android:windowSoftInputMode="adjustPan|stateHidden"/> |
160 | - | ||
161 | <activity | 160 | <activity |
162 | android:name=".ui.activity.binding.CheckInfoActivity" | 161 | android:name=".ui.activity.binding.CheckInfoActivity" |
163 | android:launchMode="singleInstance" | 162 | android:launchMode="singleInstance" |
164 | android:screenOrientation="portrait" | 163 | android:screenOrientation="portrait" |
165 | android:windowSoftInputMode="adjustPan|stateHidden"/> | 164 | android:windowSoftInputMode="adjustPan|stateHidden"/> |
166 | - | ||
167 | <activity | 165 | <activity |
168 | android:name=".ui.activity.binding.InviteCodeActivity" | 166 | android:name=".ui.activity.binding.InviteCodeActivity" |
169 | android:launchMode="singleInstance" | 167 | android:launchMode="singleInstance" |
170 | - android:screenOrientation="portrait" /> | ||
171 | - | 168 | + android:screenOrientation="portrait"/> |
172 | <activity | 169 | <activity |
173 | android:name=".ui.activity.mywebview.WebViewActivity" | 170 | android:name=".ui.activity.mywebview.WebViewActivity" |
174 | android:launchMode="singleInstance" | 171 | android:launchMode="singleInstance" |
175 | - android:screenOrientation="portrait" /> | ||
176 | - | ||
177 | - <activity android:name=".ui.activity.consult.ConsultTwoLevelActivity" | 172 | + android:screenOrientation="portrait"/> |
173 | + <activity | ||
174 | + android:name=".ui.activity.consult.ConsultTwoLevelActivity" | ||
178 | android:launchMode="singleInstance"/> | 175 | android:launchMode="singleInstance"/> |
179 | - | ||
180 | - <activity android:name=".ui.activity.orderdetail.OrderDetailActivity" | 176 | + <activity |
177 | + android:name=".ui.activity.orderdetail.OrderDetailActivity" | ||
181 | android:launchMode="singleInstance"/> | 178 | android:launchMode="singleInstance"/> |
179 | + | ||
180 | + <service | ||
181 | + android:name=".ui.service.BadgeIntentService" | ||
182 | + android:exported="false"> | ||
183 | + </service> | ||
182 | </application> | 184 | </application> |
183 | 185 | ||
184 | </manifest> | 186 | </manifest> |
185 | \ No newline at end of file | 187 | \ No newline at end of file |
app/src/main/java/com/shunzhi/parent/AppConfig.java
@@ -22,6 +22,8 @@ public class AppConfig { | @@ -22,6 +22,8 @@ public class AppConfig { | ||
22 | public static String USER_SEX = "user_sex"; | 22 | public static String USER_SEX = "user_sex"; |
23 | public static String USER_IMAGE = "user_image"; | 23 | public static String USER_IMAGE = "user_image"; |
24 | public static String PARENT_ID = "parent_id"; | 24 | public static String PARENT_ID = "parent_id"; |
25 | + public static String NIM_CONFIG_VIBRATE = "nim_config_vibrate"; | ||
26 | + public static String NIM_CONFIG_SOUND = "nim_config_sound"; | ||
25 | 27 | ||
26 | 28 | ||
27 | public static boolean ISLOGIN = false; | 29 | public static boolean ISLOGIN = false; |
app/src/main/java/com/shunzhi/parent/bean/message/PHMessage.java
1 | package com.shunzhi.parent.bean.message; | 1 | package com.shunzhi.parent.bean.message; |
2 | 2 | ||
3 | +import com.shunzhi.parent.AppContext; | ||
4 | + | ||
3 | import org.greenrobot.greendao.annotation.Entity; | 5 | import org.greenrobot.greendao.annotation.Entity; |
4 | import org.greenrobot.greendao.annotation.Id; | 6 | import org.greenrobot.greendao.annotation.Id; |
7 | +import org.greenrobot.greendao.annotation.Keep; | ||
5 | import org.greenrobot.greendao.annotation.NotNull; | 8 | import org.greenrobot.greendao.annotation.NotNull; |
6 | 9 | ||
10 | +import java.util.Collection; | ||
11 | +import java.util.Collections; | ||
7 | import java.util.Date; | 12 | import java.util.Date; |
13 | +import java.util.List; | ||
8 | 14 | ||
9 | import org.greenrobot.greendao.annotation.Generated; | 15 | import org.greenrobot.greendao.annotation.Generated; |
10 | 16 | ||
@@ -26,11 +32,13 @@ public class PHMessage { | @@ -26,11 +32,13 @@ public class PHMessage { | ||
26 | private String fileUrl; | 32 | private String fileUrl; |
27 | private String messageType; | 33 | private String messageType; |
28 | private Integer sendState;//消息发送的状态 1未发送(或者null,不建议使用null) 2发送中 3发送成功 4发送失败 | 34 | private Integer sendState;//消息发送的状态 1未发送(或者null,不建议使用null) 2发送中 3发送成功 4发送失败 |
35 | + private Integer sessionType; | ||
29 | 36 | ||
30 | - @Generated(hash = 1293964777) | 37 | + @Generated(hash = 1935192071) |
31 | public PHMessage(Long id, Date date, String messageId, String sessionId, | 38 | public PHMessage(Long id, Date date, String messageId, String sessionId, |
32 | @NotNull String messageText, String exValue, String filePath, | 39 | @NotNull String messageText, String exValue, String filePath, |
33 | - String fileUrl, String messageType, Integer sendState) { | 40 | + String fileUrl, String messageType, Integer sendState, |
41 | + Integer sessionType) { | ||
34 | this.id = id; | 42 | this.id = id; |
35 | this.date = date; | 43 | this.date = date; |
36 | this.messageId = messageId; | 44 | this.messageId = messageId; |
@@ -41,12 +49,31 @@ public class PHMessage { | @@ -41,12 +49,31 @@ public class PHMessage { | ||
41 | this.fileUrl = fileUrl; | 49 | this.fileUrl = fileUrl; |
42 | this.messageType = messageType; | 50 | this.messageType = messageType; |
43 | this.sendState = sendState; | 51 | this.sendState = sendState; |
52 | + this.sessionType = sessionType; | ||
44 | } | 53 | } |
45 | 54 | ||
46 | @Generated(hash = 1001489632) | 55 | @Generated(hash = 1001489632) |
47 | public PHMessage() { | 56 | public PHMessage() { |
48 | } | 57 | } |
49 | 58 | ||
59 | + | ||
60 | + @Keep | ||
61 | + public static long findUnreadNotificationCountBySessionType(Collection<Integer> types) { | ||
62 | + PHMessageDao dao = AppContext.getInstance().getDaoSession().getPHMessageDao(); | ||
63 | + return dao.queryBuilder().where(PHMessageDao.Properties.SessionType.in(types)).count(); | ||
64 | + } | ||
65 | + | ||
66 | + @Keep | ||
67 | + public static long findUnreadNotificationCount() { | ||
68 | + PHMessageDao dao = AppContext.getInstance().getDaoSession().getPHMessageDao(); | ||
69 | + return dao.queryBuilder() | ||
70 | + .where(PHMessageDao.Properties.SessionType.in( | ||
71 | + PHMessageSession.sessionType_homework, | ||
72 | + PHMessageSession.sessionType_notification//新加通知类型请在此处加上,否则会导致计数不准确 | ||
73 | + )) | ||
74 | + .count(); | ||
75 | + } | ||
76 | + | ||
50 | public Long getId() { | 77 | public Long getId() { |
51 | return this.id; | 78 | return this.id; |
52 | } | 79 | } |
@@ -126,4 +153,12 @@ public class PHMessage { | @@ -126,4 +153,12 @@ public class PHMessage { | ||
126 | public void setSendState(Integer sendState) { | 153 | public void setSendState(Integer sendState) { |
127 | this.sendState = sendState; | 154 | this.sendState = sendState; |
128 | } | 155 | } |
156 | + | ||
157 | + public Integer getSessionType() { | ||
158 | + return this.sessionType; | ||
159 | + } | ||
160 | + | ||
161 | + public void setSessionType(Integer sessionType) { | ||
162 | + this.sessionType = sessionType; | ||
163 | + } | ||
129 | } | 164 | } |
app/src/main/java/com/shunzhi/parent/bean/message/PHMessageSession.java
1 | package com.shunzhi.parent.bean.message; | 1 | package com.shunzhi.parent.bean.message; |
2 | 2 | ||
3 | +import com.shunzhi.parent.AppConfig; | ||
4 | +import com.shunzhi.parent.AppContext; | ||
5 | + | ||
3 | import org.greenrobot.greendao.annotation.Entity; | 6 | import org.greenrobot.greendao.annotation.Entity; |
4 | import org.greenrobot.greendao.annotation.Id; | 7 | import org.greenrobot.greendao.annotation.Id; |
5 | 8 | ||
6 | import java.util.Date; | 9 | import java.util.Date; |
7 | 10 | ||
8 | import org.greenrobot.greendao.annotation.Generated; | 11 | import org.greenrobot.greendao.annotation.Generated; |
12 | +import org.greenrobot.greendao.annotation.Keep; | ||
9 | 13 | ||
10 | /** | 14 | /** |
11 | * Created by 10501 on 2018/3/20. | 15 | * Created by 10501 on 2018/3/20. |
@@ -24,10 +28,15 @@ public class PHMessageSession { | @@ -24,10 +28,15 @@ public class PHMessageSession { | ||
24 | private String exValues; | 28 | private String exValues; |
25 | private Boolean isTop; | 29 | private Boolean isTop; |
26 | 30 | ||
31 | + @Keep | ||
32 | + public static final int sessionType_notification = 101; | ||
33 | + @Keep | ||
34 | + public static final int sessionType_homework = 102; | ||
35 | + | ||
27 | @Generated(hash = 1156938953) | 36 | @Generated(hash = 1156938953) |
28 | public PHMessageSession(Long id, String sessionId, String sessionText, String sessionName, | 37 | public PHMessageSession(Long id, String sessionId, String sessionText, String sessionName, |
29 | - Date date, Integer sessionType, Integer newMessageCount, Integer unReadMessageCount, | ||
30 | - String exValues, Boolean isTop) { | 38 | + Date date, Integer sessionType, Integer newMessageCount, Integer unReadMessageCount, |
39 | + String exValues, Boolean isTop) { | ||
31 | this.id = id; | 40 | this.id = id; |
32 | this.sessionId = sessionId; | 41 | this.sessionId = sessionId; |
33 | this.sessionText = sessionText; | 42 | this.sessionText = sessionText; |
@@ -44,6 +53,28 @@ public class PHMessageSession { | @@ -44,6 +53,28 @@ public class PHMessageSession { | ||
44 | public PHMessageSession() { | 53 | public PHMessageSession() { |
45 | } | 54 | } |
46 | 55 | ||
56 | + @Keep | ||
57 | + public static PHMessageSession findAndCreateSession(int sessionType, boolean autoCreate) { | ||
58 | + PHMessageSession session = findSessionByType(sessionType); | ||
59 | + if (autoCreate && session == null) { | ||
60 | + session = new PHMessageSession(); | ||
61 | + switch (sessionType) { | ||
62 | + case sessionType_homework: | ||
63 | + session.setSessionId(AppConfig.getAppConfig(AppContext.getInstance()).get(AppConfig.USER_ID) + "_homework_" + System.currentTimeMillis()); | ||
64 | + session.setSessionName("作业通知"); | ||
65 | + break; | ||
66 | + } | ||
67 | + AppContext.getInstance().getDaoSession().getPHMessageSessionDao().insert(session); | ||
68 | + } | ||
69 | + return session; | ||
70 | + } | ||
71 | + | ||
72 | + @Keep | ||
73 | + public static PHMessageSession findSessionByType(int sessionType) { | ||
74 | + PHMessageSessionDao dao = AppContext.getInstance().getDaoSession().getPHMessageSessionDao(); | ||
75 | + return dao.queryBuilder().where(PHMessageSessionDao.Properties.SessionType.eq(sessionType)).unique(); | ||
76 | + } | ||
77 | + | ||
47 | public Long getId() { | 78 | public Long getId() { |
48 | return this.id; | 79 | return this.id; |
49 | } | 80 | } |
app/src/main/java/com/shunzhi/parent/manager/MessageManager.java
1 | package com.shunzhi.parent.manager; | 1 | package com.shunzhi.parent.manager; |
2 | 2 | ||
3 | +import android.app.Notification; | ||
4 | +import android.app.NotificationManager; | ||
5 | +import android.app.PendingIntent; | ||
3 | import android.content.Context; | 6 | import android.content.Context; |
4 | import android.content.Intent; | 7 | import android.content.Intent; |
5 | import android.content.SharedPreferences; | 8 | import android.content.SharedPreferences; |
6 | -import android.support.annotation.NonNull; | 9 | +import android.support.v4.app.NotificationCompat; |
7 | 10 | ||
8 | import com.netease.nimlib.sdk.NIMClient; | 11 | import com.netease.nimlib.sdk.NIMClient; |
9 | import com.netease.nimlib.sdk.Observer; | 12 | import com.netease.nimlib.sdk.Observer; |
@@ -16,14 +19,26 @@ import com.netease.nimlib.sdk.msg.MsgServiceObserve; | @@ -16,14 +19,26 @@ import com.netease.nimlib.sdk.msg.MsgServiceObserve; | ||
16 | import com.netease.nimlib.sdk.msg.model.CustomNotification; | 19 | import com.netease.nimlib.sdk.msg.model.CustomNotification; |
17 | import com.netease.nimlib.sdk.msg.model.IMMessage; | 20 | import com.netease.nimlib.sdk.msg.model.IMMessage; |
18 | import com.share.mvpsdk.utils.ToastUtils; | 21 | import com.share.mvpsdk.utils.ToastUtils; |
22 | +import com.shunzhi.parent.AppConfig; | ||
19 | import com.shunzhi.parent.AppContext; | 23 | import com.shunzhi.parent.AppContext; |
24 | +import com.shunzhi.parent.R; | ||
20 | import com.shunzhi.parent.bean.NIMLoginResultBean; | 25 | import com.shunzhi.parent.bean.NIMLoginResultBean; |
26 | +import com.shunzhi.parent.bean.message.PHMessage; | ||
27 | +import com.shunzhi.parent.bean.message.PHMessageDao; | ||
28 | +import com.shunzhi.parent.bean.message.PHMessageSession; | ||
29 | +import com.shunzhi.parent.ui.MainActivity; | ||
21 | import com.shunzhi.parent.ui.activity.LoginAndRegistActivity; | 30 | import com.shunzhi.parent.ui.activity.LoginAndRegistActivity; |
31 | +import com.shunzhi.parent.ui.service.BadgeIntentService; | ||
22 | 32 | ||
33 | +import org.json.JSONException; | ||
34 | +import org.json.JSONObject; | ||
35 | + | ||
36 | +import java.util.Date; | ||
23 | import java.util.List; | 37 | import java.util.List; |
24 | 38 | ||
25 | import io.reactivex.Observable; | 39 | import io.reactivex.Observable; |
26 | import io.reactivex.subjects.PublishSubject; | 40 | import io.reactivex.subjects.PublishSubject; |
41 | +import me.leolin.shortcutbadger.ShortcutBadger; | ||
27 | import timber.log.Timber; | 42 | import timber.log.Timber; |
28 | 43 | ||
29 | /** | 44 | /** |
@@ -32,6 +47,8 @@ import timber.log.Timber; | @@ -32,6 +47,8 @@ import timber.log.Timber; | ||
32 | 47 | ||
33 | public class MessageManager { | 48 | public class MessageManager { |
34 | 49 | ||
50 | + public boolean isNotiNotification = true; | ||
51 | + | ||
35 | private static class InstanceHolder { | 52 | private static class InstanceHolder { |
36 | static final MessageManager instance = new MessageManager(); | 53 | static final MessageManager instance = new MessageManager(); |
37 | } | 54 | } |
@@ -75,10 +92,79 @@ public class MessageManager { | @@ -75,10 +92,79 @@ public class MessageManager { | ||
75 | 92 | ||
76 | } | 93 | } |
77 | 94 | ||
78 | - private void onCustomNotificationReceive(CustomNotification customnotification) { | 95 | + private void onCustomNotificationReceive(CustomNotification customNotification) { |
96 | + try { | ||
97 | + JSONObject json = new JSONObject(customNotification.getContent()); | ||
98 | + String type = json.optString("type"); | ||
99 | + String uuid = json.optString("msgId"); | ||
100 | + if ("homework".equals(type)) { | ||
101 | + PHMessageSession session = PHMessageSession.findAndCreateSession(PHMessageSession.sessionType_homework, true); | ||
102 | + session.setSessionName("作业通知"); | ||
103 | + session.setDate(new Date(customNotification.getTime())); | ||
104 | + session.setSessionText(json.optString("title")); | ||
105 | + PHMessage message = new PHMessage(); | ||
106 | + PHMessageDao messageDao = AppContext.getInstance().getDaoSession().getPHMessageDao(); | ||
107 | + message.setDate(new Date(customNotification.getTime())); | ||
108 | + message.setMessageId(uuid); | ||
109 | + message.setSessionId(session.getSessionId()); | ||
110 | + message.setSessionType(session.getSessionType()); | ||
111 | + Long id = messageDao.insert(message); | ||
112 | + notifyNotification(uuid, id, "收到一条作业通知"); | ||
113 | + } | ||
114 | + | ||
115 | + | ||
116 | + } catch (JSONException e) { | ||
117 | + e.printStackTrace(); | ||
118 | + } | ||
119 | + } | ||
120 | + | ||
121 | + public void notifyNotification(String uuid, long msgLongId, String text) { | ||
122 | + if (!isNotiNotification) | ||
123 | + return; | ||
124 | + int notificationCount = (int) PHMessage.findUnreadNotificationCount();//XSTMessage.findUnreadNotificationCount(); | ||
125 | + boolean setBadgerSuccessful = ShortcutBadger.applyCount(AppContext.getInstance(), notificationCount); | ||
126 | + Timber.i("----== notificationCount : %s ,setBadgerSuccessful : %s", notificationCount, setBadgerSuccessful); | ||
127 | + if (!setBadgerSuccessful) { | ||
128 | + BadgeIntentService.start(AppContext.getInstance(), notificationCount, "通知", text, uuid, msgLongId); | ||
129 | + return; | ||
130 | + } | ||
131 | + Intent resultIntent = new Intent(AppContext.getInstance(), MainActivity.class); | ||
132 | + resultIntent.putExtra("sid", msgLongId); | ||
133 | + resultIntent.putExtra("uuid", uuid); | ||
134 | + //resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); | ||
135 | + PendingIntent resultPendingIntent = | ||
136 | + PendingIntent.getActivity( | ||
137 | + AppContext.getInstance(), | ||
138 | + 0, | ||
139 | + resultIntent, | ||
140 | + PendingIntent.FLAG_UPDATE_CURRENT | ||
141 | + ); | ||
142 | + NotificationCompat.Builder mBuilder = | ||
143 | + new NotificationCompat.Builder(AppContext.getInstance()) | ||
144 | + .setSmallIcon(R.mipmap.ic_launcher) | ||
145 | + .setContentTitle("通知") | ||
146 | + .setContentText(text) | ||
147 | + //.setDefaults(Notification.DEFAULT_SOUND|Notification.DEFAULT_VIBRATE) | ||
148 | + .setAutoCancel(true) | ||
149 | + .setContentIntent(resultPendingIntent); | ||
150 | + AppConfig config = AppConfig.getAppConfig(AppContext.getInstance()); | ||
151 | + boolean vibrate = Boolean.parseBoolean(config.get(AppConfig.NIM_CONFIG_VIBRATE));//XSTApp.instance.getVibrateState(); | ||
152 | + boolean sound = Boolean.parseBoolean(config.get(AppConfig.NIM_CONFIG_SOUND));//XSTApp.instance.getRingState(); | ||
153 | + if (vibrate && sound) { | ||
154 | + mBuilder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE); | ||
155 | + } else if (vibrate) { | ||
156 | + mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); | ||
157 | + } else if (sound) { | ||
158 | + mBuilder.setDefaults(Notification.DEFAULT_SOUND); | ||
159 | + } | ||
160 | + NotificationManager notifyMgr = | ||
161 | + (NotificationManager) AppContext.getInstance().getSystemService(Context.NOTIFICATION_SERVICE); | ||
162 | + notifyMgr.notify((int) msgLongId, mBuilder.build()); | ||
163 | + | ||
79 | 164 | ||
80 | } | 165 | } |
81 | 166 | ||
167 | + | ||
82 | public Observable<NIMLoginResultBean> login(String account, String password) { | 168 | public Observable<NIMLoginResultBean> login(String account, String password) { |
83 | final PublishSubject<NIMLoginResultBean> subject = PublishSubject.create(); | 169 | final PublishSubject<NIMLoginResultBean> subject = PublishSubject.create(); |
84 | SharedPreferences sp = AppContext.getInstance().getApplicationContext().getSharedPreferences("info", Context.MODE_PRIVATE); | 170 | SharedPreferences sp = AppContext.getInstance().getApplicationContext().getSharedPreferences("info", Context.MODE_PRIVATE); |
@@ -91,7 +177,7 @@ public class MessageManager { | @@ -91,7 +177,7 @@ public class MessageManager { | ||
91 | public void onSuccess(Object o) { | 177 | public void onSuccess(Object o) { |
92 | NIMLoginResultBean bean = new NIMLoginResultBean(true, 200, null); | 178 | NIMLoginResultBean bean = new NIMLoginResultBean(true, 200, null); |
93 | subject.onNext(bean); | 179 | subject.onNext(bean); |
94 | - Timber.i("----===onSuccess : %s",o); | 180 | + Timber.i("----===onSuccess : %s", o); |
95 | } | 181 | } |
96 | 182 | ||
97 | @Override | 183 | @Override |
app/src/main/java/com/shunzhi/parent/ui/MainActivity.java
1 | package com.shunzhi.parent.ui; | 1 | package com.shunzhi.parent.ui; |
2 | 2 | ||
3 | +import android.content.Intent; | ||
3 | import android.os.Bundle; | 4 | import android.os.Bundle; |
4 | import android.support.annotation.NonNull; | 5 | import android.support.annotation.NonNull; |
5 | import android.support.design.widget.BottomNavigationView; | 6 | import android.support.design.widget.BottomNavigationView; |
@@ -12,6 +13,10 @@ import com.share.mvpsdk.helper.BottomNavigationViewHelper; | @@ -12,6 +13,10 @@ import com.share.mvpsdk.helper.BottomNavigationViewHelper; | ||
12 | import com.share.mvpsdk.utils.PermissionUtils; | 13 | import com.share.mvpsdk.utils.PermissionUtils; |
13 | import com.shunzhi.parent.AppContext; | 14 | import com.shunzhi.parent.AppContext; |
14 | import com.shunzhi.parent.R; | 15 | import com.shunzhi.parent.R; |
16 | +import com.shunzhi.parent.bean.message.PHMessage; | ||
17 | +import com.shunzhi.parent.bean.message.PHMessageDao; | ||
18 | +import com.shunzhi.parent.bean.message.PHMessageSession; | ||
19 | +import com.shunzhi.parent.manager.MessageManager; | ||
15 | import com.shunzhi.parent.ui.fragment.CePingFragment; | 20 | import com.shunzhi.parent.ui.fragment.CePingFragment; |
16 | import com.shunzhi.parent.ui.fragment.ConsultFragment; | 21 | import com.shunzhi.parent.ui.fragment.ConsultFragment; |
17 | import com.shunzhi.parent.ui.fragment.MineFragment; | 22 | import com.shunzhi.parent.ui.fragment.MineFragment; |
@@ -102,11 +107,33 @@ public class MainActivity extends BaseCompatActivity implements PermissionUtils. | @@ -102,11 +107,33 @@ public class MainActivity extends BaseCompatActivity implements PermissionUtils. | ||
102 | } | 107 | } |
103 | 108 | ||
104 | @Override | 109 | @Override |
110 | + protected void onNewIntent(Intent intent) { | ||
111 | + super.onNewIntent(intent); | ||
112 | + handIntent(intent); | ||
113 | + } | ||
114 | + | ||
115 | + private void handIntent(Intent intent) { | ||
116 | + long msgLongId = intent.getLongExtra("sid", -1); | ||
117 | + PHMessageDao dao = AppContext.getInstance().getDaoSession().getPHMessageDao(); | ||
118 | + PHMessage message = dao.queryBuilder().where(PHMessageDao.Properties.Id.eq(msgLongId)).unique(); | ||
119 | + if (message == null) return; | ||
120 | + if (message.getSessionType() == PHMessageSession.sessionType_homework) { | ||
121 | + //TODO 跳转 | ||
122 | + } | ||
123 | + } | ||
124 | + | ||
125 | + @Override | ||
105 | protected int getLayoutId() { | 126 | protected int getLayoutId() { |
106 | return R.layout.activity_main; | 127 | return R.layout.activity_main; |
107 | } | 128 | } |
108 | 129 | ||
109 | @Override | 130 | @Override |
131 | + protected void onPause() { | ||
132 | + super.onPause(); | ||
133 | + MessageManager.getInstance().isNotiNotification = true; | ||
134 | + } | ||
135 | + | ||
136 | + @Override | ||
110 | protected void onDestroy() { | 137 | protected void onDestroy() { |
111 | super.onDestroy(); | 138 | super.onDestroy(); |
112 | AppContext.getInstance().destoryLocation(); | 139 | AppContext.getInstance().destoryLocation(); |
@@ -120,5 +147,6 @@ public class MainActivity extends BaseCompatActivity implements PermissionUtils. | @@ -120,5 +147,6 @@ public class MainActivity extends BaseCompatActivity implements PermissionUtils. | ||
120 | @Override | 147 | @Override |
121 | protected void onResume() { | 148 | protected void onResume() { |
122 | super.onResume(); | 149 | super.onResume(); |
150 | + MessageManager.getInstance().isNotiNotification = false; | ||
123 | } | 151 | } |
124 | } | 152 | } |
app/src/main/java/com/shunzhi/parent/ui/service/BadgeIntentService.java
0 → 100644
@@ -0,0 +1,143 @@ | @@ -0,0 +1,143 @@ | ||
1 | +package com.shunzhi.parent.ui.service; | ||
2 | + | ||
3 | +import android.app.IntentService; | ||
4 | +import android.app.Notification; | ||
5 | +import android.app.NotificationManager; | ||
6 | +import android.app.PendingIntent; | ||
7 | +import android.content.Context; | ||
8 | +import android.content.Intent; | ||
9 | +import android.os.Build; | ||
10 | +import android.support.annotation.Nullable; | ||
11 | +import android.support.v4.app.NotificationCompat; | ||
12 | +import android.text.TextUtils; | ||
13 | + | ||
14 | +import com.shunzhi.parent.AppConfig; | ||
15 | +import com.shunzhi.parent.AppContext; | ||
16 | +import com.shunzhi.parent.R; | ||
17 | +import com.shunzhi.parent.ui.MainActivity; | ||
18 | + | ||
19 | +import me.leolin.shortcutbadger.ShortcutBadger; | ||
20 | + | ||
21 | + | ||
22 | +/** | ||
23 | + * An {@link IntentService} subclass for handling asynchronous task requests in | ||
24 | + * a service on a separate handler thread. | ||
25 | + * <p> | ||
26 | + * TODO: Customize class - update intent actions and extra parameters. | ||
27 | + */ | ||
28 | +public class BadgeIntentService extends IntentService { | ||
29 | + private int notificationId = 0; | ||
30 | + | ||
31 | + public BadgeIntentService() { | ||
32 | + super("BadgeIntentService"); | ||
33 | + } | ||
34 | + | ||
35 | + private NotificationManager mNotificationManager; | ||
36 | + | ||
37 | + public static void start(Context context, int badgeCount, String title, String message) { | ||
38 | + Intent i = new Intent(context, BadgeIntentService.class); | ||
39 | + i.putExtra("badgeCount", badgeCount); | ||
40 | + i.putExtra("title", title); | ||
41 | + i.putExtra("message", message); | ||
42 | + context.startService(i); | ||
43 | + } | ||
44 | + | ||
45 | + public static void start(Context context, int badgeCount, String title, String message, String uuid, long xstsid) { | ||
46 | + Intent i = new Intent(context, BadgeIntentService.class); | ||
47 | + i.putExtra("badgeCount", badgeCount); | ||
48 | + i.putExtra("title", title); | ||
49 | + i.putExtra("uuid", uuid); | ||
50 | + i.putExtra("xstsid", xstsid); | ||
51 | + i.putExtra("message", message); | ||
52 | + context.startService(i); | ||
53 | + } | ||
54 | + | ||
55 | + public BadgeIntentService(String name) { | ||
56 | + super(name); | ||
57 | + } | ||
58 | + | ||
59 | + @Override | ||
60 | + public void onStart(Intent intent, int startId) { | ||
61 | + super.onStart(intent, startId); | ||
62 | + mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); | ||
63 | + } | ||
64 | + | ||
65 | + @Override | ||
66 | + protected void onHandleIntent(Intent intent) { | ||
67 | + if (intent != null) { | ||
68 | + int badgeCount = intent.getIntExtra("badgeCount", 0); | ||
69 | + String title = intent.getStringExtra("title"); | ||
70 | + String message = intent.getStringExtra("message"); | ||
71 | + //String uuid, long xstsid | ||
72 | + String uuid = intent.getStringExtra("uuid"); | ||
73 | + long xstsid = intent.getLongExtra("xstsid", -1); | ||
74 | + if (xstsid == -1 || TextUtils.isEmpty(uuid)) | ||
75 | + createIntentNotification(badgeCount, title, message); | ||
76 | + if (xstsid != -1 && !TextUtils.isEmpty(uuid)) | ||
77 | + createPendingIntentNotification(badgeCount, title, message, uuid, xstsid); | ||
78 | + | ||
79 | + } | ||
80 | + } | ||
81 | + | ||
82 | + private void createIntentNotification(int badgeCount, String title, String message) { | ||
83 | + if (mNotificationManager == null) { | ||
84 | + mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); | ||
85 | + } | ||
86 | + if (title == null) title = ""; | ||
87 | + if (message == null) message = ""; | ||
88 | + if (mNotificationManager != null) | ||
89 | + mNotificationManager.cancel(notificationId); | ||
90 | + | ||
91 | + notificationId++; | ||
92 | + | ||
93 | + Notification.Builder builder = new Notification.Builder(getApplicationContext()) | ||
94 | + .setContentTitle(title) | ||
95 | + .setContentText(message) | ||
96 | + .setSmallIcon(R.mipmap.ic_launcher); | ||
97 | + Notification notification = Build.VERSION.SDK_INT > 15 ? builder.build() : builder.getNotification(); | ||
98 | + ShortcutBadger.applyNotification(getApplicationContext(), notification, badgeCount); | ||
99 | + if (mNotificationManager != null) | ||
100 | + mNotificationManager.notify(notificationId, notification); | ||
101 | + } | ||
102 | + | ||
103 | + private void createPendingIntentNotification(int badgeCount, String title, String message, String uuid, long xstsid) { | ||
104 | + if (mNotificationManager == null) { | ||
105 | + mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); | ||
106 | + } | ||
107 | + Intent resultIntent = new Intent(AppContext.getInstance(), MainActivity.class); | ||
108 | + resultIntent.putExtra("sid", xstsid); | ||
109 | + resultIntent.putExtra("uuid", uuid); | ||
110 | + mNotificationManager.cancel(notificationId); | ||
111 | + notificationId = (int) xstsid; | ||
112 | + //resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); | ||
113 | + PendingIntent resultPendingIntent = | ||
114 | + PendingIntent.getActivity( | ||
115 | + AppContext.getInstance(), | ||
116 | + 0, | ||
117 | + resultIntent, | ||
118 | + PendingIntent.FLAG_UPDATE_CURRENT | ||
119 | + ); | ||
120 | + NotificationCompat.Builder mBuilder = | ||
121 | + new NotificationCompat.Builder(AppContext.getInstance()) | ||
122 | + .setSmallIcon(R.mipmap.ic_launcher) | ||
123 | + .setContentTitle("通知") | ||
124 | + .setContentText(message) | ||
125 | + //.setDefaults(Notification.DEFAULT_SOUND|Notification.DEFAULT_VIBRATE) | ||
126 | + .setAutoCancel(true) | ||
127 | + .setContentIntent(resultPendingIntent); | ||
128 | + AppConfig config = AppConfig.getAppConfig(AppContext.getInstance()); | ||
129 | + boolean vibrate = Boolean.parseBoolean(config.get(AppConfig.NIM_CONFIG_VIBRATE));//XSTApp.instance.getVibrateState(); | ||
130 | + boolean sound = Boolean.parseBoolean(config.get(AppConfig.NIM_CONFIG_SOUND));//XSTApp.instance.getRingState(); | ||
131 | + if (vibrate && sound) { | ||
132 | + mBuilder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE); | ||
133 | + } else if (vibrate) { | ||
134 | + mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); | ||
135 | + } else if (sound) { | ||
136 | + mBuilder.setDefaults(Notification.DEFAULT_SOUND); | ||
137 | + } | ||
138 | + Notification notification = mBuilder.build(); | ||
139 | + ShortcutBadger.applyNotification(getApplicationContext(), notification, badgeCount); | ||
140 | + mNotificationManager.notify((int) xstsid, notification); | ||
141 | + | ||
142 | + } | ||
143 | +} |