Commit 8176e156c31f815d23fe964882801ac969a2c86a
Exists in
yxb_dev
and in
2 other branches
no message
Showing
14 changed files
with
373 additions
and
24 deletions
Show diff stats
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" /> |
@@ -126,6 +126,10 @@ | @@ -126,6 +126,10 @@ | ||
126 | <!--android:name=".ui.MainActivity"--> | 126 | <!--android:name=".ui.MainActivity"--> |
127 | <!--android:screenOrientation="portrait"--> | 127 | <!--android:screenOrientation="portrait"--> |
128 | <!--android:windowSoftInputMode="adjustPan|stateAlwaysHidden" />--> | 128 | <!--android:windowSoftInputMode="adjustPan|stateAlwaysHidden" />--> |
129 | + <!-- <activity --> | ||
130 | + <!-- android:name=".ui.MainActivity" --> | ||
131 | + <!-- android:screenOrientation="portrait" --> | ||
132 | + <!-- android:windowSoftInputMode="adjustPan|stateAlwaysHidden" /> --> | ||
129 | <activity | 133 | <activity |
130 | android:name=".ui.activity.MyChildActivity" | 134 | android:name=".ui.activity.MyChildActivity" |
131 | android:screenOrientation="portrait" /> | 135 | android:screenOrientation="portrait" /> |
@@ -136,12 +140,12 @@ | @@ -136,12 +140,12 @@ | ||
136 | <activity | 140 | <activity |
137 | android:name=".ui.MainActivity" | 141 | android:name=".ui.MainActivity" |
138 | android:launchMode="singleInstance" | 142 | android:launchMode="singleInstance" |
139 | - android:screenOrientation="portrait" | ||
140 | - android:windowSoftInputMode="adjustPan|stateAlwaysHidden" /> | 143 | + android:screenOrientation="portrait"/> |
144 | + | ||
141 | <activity | 145 | <activity |
142 | android:name=".ui.activity.ChildDetialActivity" | 146 | android:name=".ui.activity.ChildDetialActivity" |
143 | android:launchMode="singleInstance" | 147 | android:launchMode="singleInstance" |
144 | - android:screenOrientation="portrait" /> | 148 | + android:screenOrientation="portrait"/> |
145 | <activity | 149 | <activity |
146 | android:name=".ui.activity.binding.CreateChildInfoActivity" | 150 | android:name=".ui.activity.binding.CreateChildInfoActivity" |
147 | android:launchMode="singleInstance" | 151 | android:launchMode="singleInstance" |
@@ -161,7 +165,6 @@ | @@ -161,7 +165,6 @@ | ||
161 | android:launchMode="singleInstance" | 165 | android:launchMode="singleInstance" |
162 | android:screenOrientation="portrait" | 166 | android:screenOrientation="portrait" |
163 | android:windowSoftInputMode="adjustPan|stateHidden" /> | 167 | android:windowSoftInputMode="adjustPan|stateHidden" /> |
164 | - | ||
165 | <activity | 168 | <activity |
166 | android:name=".ui.activity.binding.CheckInfoActivity" | 169 | android:name=".ui.activity.binding.CheckInfoActivity" |
167 | android:launchMode="singleInstance" | 170 | android:launchMode="singleInstance" |
@@ -171,11 +174,11 @@ | @@ -171,11 +174,11 @@ | ||
171 | <activity | 174 | <activity |
172 | android:name=".ui.activity.binding.InviteCodeActivity" | 175 | android:name=".ui.activity.binding.InviteCodeActivity" |
173 | android:launchMode="singleInstance" | 176 | android:launchMode="singleInstance" |
174 | - android:screenOrientation="portrait" /> | ||
175 | - | 177 | + android:screenOrientation="portrait"/> |
176 | <activity | 178 | <activity |
177 | android:name=".ui.activity.mywebview.WebViewActivity" | 179 | android:name=".ui.activity.mywebview.WebViewActivity" |
178 | - android:screenOrientation="portrait" /> | 180 | + android:launchMode="singleInstance" |
181 | + android:screenOrientation="portrait"/> | ||
179 | 182 | ||
180 | <activity | 183 | <activity |
181 | android:name=".ui.activity.consult.ConsultTwoLevelActivity" | 184 | android:name=".ui.activity.consult.ConsultTwoLevelActivity" |
@@ -185,6 +188,11 @@ | @@ -185,6 +188,11 @@ | ||
185 | <activity | 188 | <activity |
186 | android:name=".ui.activity.orderdetail.OrderDetailActivity" | 189 | android:name=".ui.activity.orderdetail.OrderDetailActivity" |
187 | android:launchMode="singleInstance" /> | 190 | android:launchMode="singleInstance" /> |
191 | + | ||
192 | + <service | ||
193 | + android:name=".ui.service.BadgeIntentService" | ||
194 | + android:exported="false"> | ||
195 | + </service> | ||
188 | </application> | 196 | </application> |
189 | 197 | ||
190 | </manifest> | 198 | </manifest> |
191 | \ No newline at end of file | 199 | \ 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/adapter/MyConsultAdapter.java
@@ -39,7 +39,10 @@ public class MyConsultAdapter extends BaseRecyclerViewAdapter<ChannelContextBean | @@ -39,7 +39,10 @@ public class MyConsultAdapter extends BaseRecyclerViewAdapter<ChannelContextBean | ||
39 | super.onAttachedToRecyclerView(recyclerView); | 39 | super.onAttachedToRecyclerView(recyclerView); |
40 | LinearLayoutManager layoutManager = new LinearLayoutManager(mContext); | 40 | LinearLayoutManager layoutManager = new LinearLayoutManager(mContext); |
41 | layoutManager.setOrientation(LinearLayoutManager.VERTICAL); | 41 | layoutManager.setOrientation(LinearLayoutManager.VERTICAL); |
42 | + layoutManager.setSmoothScrollbarEnabled(true); | ||
43 | + layoutManager.setAutoMeasureEnabled(true); | ||
42 | recyclerView.setLayoutManager(layoutManager); | 44 | recyclerView.setLayoutManager(layoutManager); |
45 | + recyclerView.setHasFixedSize(true); | ||
43 | } | 46 | } |
44 | 47 | ||
45 | @Override | 48 | @Override |
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,30 @@ public class PHMessage { | @@ -41,12 +49,30 @@ 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 | + @Keep | ||
60 | + public static long findUnreadNotificationCountBySessionType(Collection<Integer> types) { | ||
61 | + PHMessageDao dao = AppContext.getInstance().getDaoSession().getPHMessageDao(); | ||
62 | + return dao.queryBuilder().where(PHMessageDao.Properties.SessionType.in(types)).count(); | ||
63 | + } | ||
64 | + | ||
65 | + @Keep | ||
66 | + public static long findUnreadNotificationCount() { | ||
67 | + PHMessageDao dao = AppContext.getInstance().getDaoSession().getPHMessageDao(); | ||
68 | + return dao.queryBuilder() | ||
69 | + .where(PHMessageDao.Properties.SessionType.in( | ||
70 | + PHMessageSession.sessionType_homework, | ||
71 | + PHMessageSession.sessionType_notification//新加通知类型请在此处加上,否则会导致计数不准确 | ||
72 | + )) | ||
73 | + .count(); | ||
74 | + } | ||
75 | + | ||
50 | public Long getId() { | 76 | public Long getId() { |
51 | return this.id; | 77 | return this.id; |
52 | } | 78 | } |
@@ -126,4 +152,12 @@ public class PHMessage { | @@ -126,4 +152,12 @@ public class PHMessage { | ||
126 | public void setSendState(Integer sendState) { | 152 | public void setSendState(Integer sendState) { |
127 | this.sendState = sendState; | 153 | this.sendState = sendState; |
128 | } | 154 | } |
155 | + | ||
156 | + public Integer getSessionType() { | ||
157 | + return this.sessionType; | ||
158 | + } | ||
159 | + | ||
160 | + public void setSessionType(Integer sessionType) { | ||
161 | + this.sessionType = sessionType; | ||
162 | + } | ||
129 | } | 163 | } |
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,80 @@ public class MessageManager { | @@ -75,10 +92,80 @@ 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.setExValue(customNotification.getContent()); | ||
111 | + message.setSessionType(session.getSessionType()); | ||
112 | + Long id = messageDao.insert(message); | ||
113 | + notifyNotification(uuid, id, "收到一条作业通知"); | ||
114 | + } | ||
115 | + | ||
116 | + | ||
117 | + } catch (JSONException e) { | ||
118 | + e.printStackTrace(); | ||
119 | + } | ||
120 | + } | ||
121 | + | ||
122 | + public void notifyNotification(String uuid, long msgLongId, String text) { | ||
123 | + if (!isNotiNotification) | ||
124 | + return; | ||
125 | + int notificationCount = (int) PHMessage.findUnreadNotificationCount();//XSTMessage.findUnreadNotificationCount(); | ||
126 | + boolean setBadgerSuccessful = ShortcutBadger.applyCount(AppContext.getInstance(), notificationCount); | ||
127 | + Timber.i("----== notificationCount : %s ,setBadgerSuccessful : %s", notificationCount, setBadgerSuccessful); | ||
128 | + if (!setBadgerSuccessful) { | ||
129 | + BadgeIntentService.start(AppContext.getInstance(), notificationCount, "通知", text, uuid, msgLongId); | ||
130 | + return; | ||
131 | + } | ||
132 | + Intent resultIntent = new Intent(AppContext.getInstance(), MainActivity.class); | ||
133 | + resultIntent.putExtra("sid", msgLongId); | ||
134 | + resultIntent.putExtra("uuid", uuid); | ||
135 | + //resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); | ||
136 | + PendingIntent resultPendingIntent = | ||
137 | + PendingIntent.getActivity( | ||
138 | + AppContext.getInstance(), | ||
139 | + 0, | ||
140 | + resultIntent, | ||
141 | + PendingIntent.FLAG_UPDATE_CURRENT | ||
142 | + ); | ||
143 | + NotificationCompat.Builder mBuilder = | ||
144 | + new NotificationCompat.Builder(AppContext.getInstance()) | ||
145 | + .setSmallIcon(R.mipmap.ic_launcher) | ||
146 | + .setContentTitle("通知") | ||
147 | + .setContentText(text) | ||
148 | + //.setDefaults(Notification.DEFAULT_SOUND|Notification.DEFAULT_VIBRATE) | ||
149 | + .setAutoCancel(true) | ||
150 | + .setContentIntent(resultPendingIntent); | ||
151 | + AppConfig config = AppConfig.getAppConfig(AppContext.getInstance()); | ||
152 | + boolean vibrate = Boolean.parseBoolean(config.get(AppConfig.NIM_CONFIG_VIBRATE));//XSTApp.instance.getVibrateState(); | ||
153 | + boolean sound = Boolean.parseBoolean(config.get(AppConfig.NIM_CONFIG_SOUND));//XSTApp.instance.getRingState(); | ||
154 | + if (vibrate && sound) { | ||
155 | + mBuilder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE); | ||
156 | + } else if (vibrate) { | ||
157 | + mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); | ||
158 | + } else if (sound) { | ||
159 | + mBuilder.setDefaults(Notification.DEFAULT_SOUND); | ||
160 | + } | ||
161 | + NotificationManager notifyMgr = | ||
162 | + (NotificationManager) AppContext.getInstance().getSystemService(Context.NOTIFICATION_SERVICE); | ||
163 | + notifyMgr.notify((int) msgLongId, mBuilder.build()); | ||
164 | + | ||
79 | 165 | ||
80 | } | 166 | } |
81 | 167 | ||
168 | + | ||
82 | public Observable<NIMLoginResultBean> login(String account, String password) { | 169 | public Observable<NIMLoginResultBean> login(String account, String password) { |
83 | final PublishSubject<NIMLoginResultBean> subject = PublishSubject.create(); | 170 | final PublishSubject<NIMLoginResultBean> subject = PublishSubject.create(); |
84 | SharedPreferences sp = AppContext.getInstance().getApplicationContext().getSharedPreferences("info", Context.MODE_PRIVATE); | 171 | SharedPreferences sp = AppContext.getInstance().getApplicationContext().getSharedPreferences("info", Context.MODE_PRIVATE); |
@@ -91,7 +178,7 @@ public class MessageManager { | @@ -91,7 +178,7 @@ public class MessageManager { | ||
91 | public void onSuccess(Object o) { | 178 | public void onSuccess(Object o) { |
92 | NIMLoginResultBean bean = new NIMLoginResultBean(true, 200, null); | 179 | NIMLoginResultBean bean = new NIMLoginResultBean(true, 200, null); |
93 | subject.onNext(bean); | 180 | subject.onNext(bean); |
94 | - Timber.i("----===onSuccess : %s",o); | 181 | + Timber.i("----===onSuccess : %s", o); |
95 | } | 182 | } |
96 | 183 | ||
97 | @Override | 184 | @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/fragment/CePingFragment.java
@@ -68,7 +68,7 @@ public class CePingFragment extends BaseMVPCompatFragment<CepingContract.CePingP | @@ -68,7 +68,7 @@ public class CePingFragment extends BaseMVPCompatFragment<CepingContract.CePingP | ||
68 | ivCourse2 = view.findViewById(R.id.ivCourse2); | 68 | ivCourse2 = view.findViewById(R.id.ivCourse2); |
69 | ivCourse3 = view.findViewById(R.id.ivCourse3); | 69 | ivCourse3 = view.findViewById(R.id.ivCourse3); |
70 | 70 | ||
71 | - addTools(); | 71 | + addTools(AppContext.getInstance().district); |
72 | 72 | ||
73 | textAndImg_xqjc.setTextColor(R.color.white); | 73 | textAndImg_xqjc.setTextColor(R.color.white); |
74 | textAndImg_xqjc.setText("学情检测"); | 74 | textAndImg_xqjc.setText("学情检测"); |
@@ -91,9 +91,9 @@ public class CePingFragment extends BaseMVPCompatFragment<CepingContract.CePingP | @@ -91,9 +91,9 @@ public class CePingFragment extends BaseMVPCompatFragment<CepingContract.CePingP | ||
91 | }); | 91 | }); |
92 | } | 92 | } |
93 | 93 | ||
94 | - private void addTools() { | 94 | + private void addTools(String districtName) { |
95 | layout_control.measure(0, 0); | 95 | layout_control.measure(0, 0); |
96 | - mPresenter.getTools(layout_control, AppContext.getInstance().district); | 96 | + mPresenter.getTools(layout_control,districtName ); |
97 | 97 | ||
98 | } | 98 | } |
99 | 99 | ||
@@ -184,7 +184,8 @@ public class CePingFragment extends BaseMVPCompatFragment<CepingContract.CePingP | @@ -184,7 +184,8 @@ public class CePingFragment extends BaseMVPCompatFragment<CepingContract.CePingP | ||
184 | @Override | 184 | @Override |
185 | public void getCity(String name) { | 185 | public void getCity(String name) { |
186 | tvLocalAddress.setText(name.split(" ")[2]); | 186 | tvLocalAddress.setText(name.split(" ")[2]); |
187 | - mPresenter.getTools(layout_control, name.split(" ")[2]); | 187 | + addTools(name.split(" ")[2]); |
188 | +// mPresenter.getTools(layout_control, name.split(" ")[2]); | ||
188 | AppContext.getInstance().cityName = name.split(" ")[1]; | 189 | AppContext.getInstance().cityName = name.split(" ")[1]; |
189 | AppContext.getInstance().district = name.split(" ")[2]; | 190 | AppContext.getInstance().district = name.split(" ")[2]; |
190 | } | 191 | } |
app/src/main/java/com/shunzhi/parent/ui/fragment/ConsultFragment.java
@@ -7,6 +7,7 @@ import android.content.IntentFilter; | @@ -7,6 +7,7 @@ import android.content.IntentFilter; | ||
7 | import android.os.Bundle; | 7 | import android.os.Bundle; |
8 | import android.support.annotation.NonNull; | 8 | import android.support.annotation.NonNull; |
9 | import android.support.annotation.Nullable; | 9 | import android.support.annotation.Nullable; |
10 | +import android.support.v4.widget.NestedScrollView; | ||
10 | import android.support.v7.widget.LinearLayoutManager; | 11 | import android.support.v7.widget.LinearLayoutManager; |
11 | import android.text.TextUtils; | 12 | import android.text.TextUtils; |
12 | import android.view.View; | 13 | import android.view.View; |
@@ -70,6 +71,7 @@ public class ConsultFragment extends BaseMVPCompatFragment<ConsultContract.Consu | @@ -70,6 +71,7 @@ public class ConsultFragment extends BaseMVPCompatFragment<ConsultContract.Consu | ||
70 | int pageIndex = 1; | 71 | int pageIndex = 1; |
71 | boolean first = true; | 72 | boolean first = true; |
72 | 73 | ||
74 | + | ||
73 | @Override | 75 | @Override |
74 | public int getLayoutId() { | 76 | public int getLayoutId() { |
75 | return R.layout.fragment_zi_xun; | 77 | return R.layout.fragment_zi_xun; |
@@ -92,6 +94,7 @@ public class ConsultFragment extends BaseMVPCompatFragment<ConsultContract.Consu | @@ -92,6 +94,7 @@ public class ConsultFragment extends BaseMVPCompatFragment<ConsultContract.Consu | ||
92 | videoplayer.replayTextView.setVisibility(View.GONE); | 94 | videoplayer.replayTextView.setVisibility(View.GONE); |
93 | videoplayer.backButton.setVisibility(View.GONE); | 95 | videoplayer.backButton.setVisibility(View.GONE); |
94 | 96 | ||
97 | + | ||
95 | mPresenter.getBanners("2", AppContext.getInstance().district); | 98 | mPresenter.getBanners("2", AppContext.getInstance().district); |
96 | 99 | ||
97 | initBroadCast(); | 100 | initBroadCast(); |
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 | +} |
app/src/main/res/layout/fragment_zi_xun.xml
@@ -9,6 +9,7 @@ | @@ -9,6 +9,7 @@ | ||
9 | <include layout="@layout/layout_search" /> | 9 | <include layout="@layout/layout_search" /> |
10 | 10 | ||
11 | <android.support.v4.widget.NestedScrollView | 11 | <android.support.v4.widget.NestedScrollView |
12 | + android:id="@+id/nesteScrollView" | ||
12 | android:layout_width="match_parent" | 13 | android:layout_width="match_parent" |
13 | android:layout_height="match_parent"> | 14 | android:layout_height="match_parent"> |
14 | 15 | ||
@@ -21,11 +22,12 @@ | @@ -21,11 +22,12 @@ | ||
21 | <com.stx.xhb.xbanner.XBanner | 22 | <com.stx.xhb.xbanner.XBanner |
22 | android:id="@+id/xBanner" | 23 | android:id="@+id/xBanner" |
23 | android:layout_width="match_parent" | 24 | android:layout_width="match_parent" |
24 | - android:layout_height="0dp" | ||
25 | - android:layout_weight="2"></com.stx.xhb.xbanner.XBanner> | 25 | + android:layout_height="150dp" |
26 | + ></com.stx.xhb.xbanner.XBanner> | ||
26 | 27 | ||
27 | 28 | ||
28 | - <include layout="@layout/layout_textandimgshow" /> | 29 | + <include |
30 | + layout="@layout/layout_textandimgshow" /> | ||
29 | 31 | ||
30 | 32 | ||
31 | <LinearLayout | 33 | <LinearLayout |
app/src/main/res/layout/layout_textandimgshow.xml
@@ -3,6 +3,7 @@ | @@ -3,6 +3,7 @@ | ||
3 | android:layout_width="match_parent" | 3 | android:layout_width="match_parent" |
4 | android:layout_height="wrap_content" | 4 | android:layout_height="wrap_content" |
5 | android:orientation="horizontal" | 5 | android:orientation="horizontal" |
6 | + android:layout_margin="@dimen/size_dp_10" | ||
6 | android:background="@drawable/report_white" | 7 | android:background="@drawable/report_white" |
7 | android:scrollbars="none"> | 8 | android:scrollbars="none"> |
8 | 9 |
mvpsdk/src/main/java/com/share/mvpsdk/helper/okhttp/CacheInterceptor.java
@@ -24,6 +24,8 @@ public class CacheInterceptor implements Interceptor { | @@ -24,6 +24,8 @@ public class CacheInterceptor implements Interceptor { | ||
24 | 24 | ||
25 | @Override | 25 | @Override |
26 | public Response intercept(Chain chain) throws IOException { | 26 | public Response intercept(Chain chain) throws IOException { |
27 | + try { | ||
28 | + | ||
27 | Request request = chain.request(); | 29 | Request request = chain.request(); |
28 | if (NetworkConnectionUtils.isNetworkConnected(AppUtils.getContext())) { | 30 | if (NetworkConnectionUtils.isNetworkConnected(AppUtils.getContext())) { |
29 | // 有网络时, 缓存1小时 | 31 | // 有网络时, 缓存1小时 |
@@ -55,7 +57,10 @@ public class CacheInterceptor implements Interceptor { | @@ -55,7 +57,10 @@ public class CacheInterceptor implements Interceptor { | ||
55 | .header("Cache-Control", "public, only-if-cached, max-stale=" + maxStale) | 57 | .header("Cache-Control", "public, only-if-cached, max-stale=" + maxStale) |
56 | .build(); | 58 | .build(); |
57 | } | 59 | } |
58 | - | 60 | + }catch (Exception e){ |
61 | + e.printStackTrace(); | ||
62 | + return null; | ||
63 | + } | ||
59 | // Request request = chain.request(); | 64 | // Request request = chain.request(); |
60 | // if (!NetworkConnectionUtils.isConnected(AppUtils.getContext())) { | 65 | // if (!NetworkConnectionUtils.isConnected(AppUtils.getContext())) { |
61 | // request = request.newBuilder() | 66 | // request = request.newBuilder() |