Commit 8176e156c31f815d23fe964882801ac969a2c86a

Authored by 陶汉栋
2 parents c5aac4c3 ec9c6c5d

no message

app/build.gradle
... ... @@ -47,4 +47,5 @@ dependencies {
47 47 implementation project(':roundedimageview-2.2.1')
48 48 implementation files('libs/AMap_Location_V3.8.0_20180201.jar')
49 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 65 <!-- android:name="com.amap.api.v2.apikey" -->
66 66 <!-- android:value="0da7965006ae0c8e4106c76c1867d976"/> -->
67 67  
68   - <!--家长慧测试APPkey-->
  68 +
  69 + <!-- 家长慧测试APPkey -->
69 70 <meta-data
70 71 android:name="com.netease.nim.appKey"
71 72 android:value="330158c080acdf4dc1092d6a74576c2c" />
72   -
73 73 <meta-data
74 74 android:name="android.max_aspect"
75 75 android:value="2.1" />
... ... @@ -126,6 +126,10 @@
126 126 <!--android:name=".ui.MainActivity"-->
127 127 <!--android:screenOrientation="portrait"-->
128 128 <!--android:windowSoftInputMode="adjustPan|stateAlwaysHidden" />-->
  129 + <!-- <activity -->
  130 + <!-- android:name=".ui.MainActivity" -->
  131 + <!-- android:screenOrientation="portrait" -->
  132 + <!-- android:windowSoftInputMode="adjustPan|stateAlwaysHidden" /> -->
129 133 <activity
130 134 android:name=".ui.activity.MyChildActivity"
131 135 android:screenOrientation="portrait" />
... ... @@ -136,12 +140,12 @@
136 140 <activity
137 141 android:name=".ui.MainActivity"
138 142 android:launchMode="singleInstance"
139   - android:screenOrientation="portrait"
140   - android:windowSoftInputMode="adjustPan|stateAlwaysHidden" />
  143 + android:screenOrientation="portrait"/>
  144 +
141 145 <activity
142 146 android:name=".ui.activity.ChildDetialActivity"
143 147 android:launchMode="singleInstance"
144   - android:screenOrientation="portrait" />
  148 + android:screenOrientation="portrait"/>
145 149 <activity
146 150 android:name=".ui.activity.binding.CreateChildInfoActivity"
147 151 android:launchMode="singleInstance"
... ... @@ -161,7 +165,6 @@
161 165 android:launchMode="singleInstance"
162 166 android:screenOrientation="portrait"
163 167 android:windowSoftInputMode="adjustPan|stateHidden" />
164   -
165 168 <activity
166 169 android:name=".ui.activity.binding.CheckInfoActivity"
167 170 android:launchMode="singleInstance"
... ... @@ -171,11 +174,11 @@
171 174 <activity
172 175 android:name=".ui.activity.binding.InviteCodeActivity"
173 176 android:launchMode="singleInstance"
174   - android:screenOrientation="portrait" />
175   -
  177 + android:screenOrientation="portrait"/>
176 178 <activity
177 179 android:name=".ui.activity.mywebview.WebViewActivity"
178   - android:screenOrientation="portrait" />
  180 + android:launchMode="singleInstance"
  181 + android:screenOrientation="portrait"/>
179 182  
180 183 <activity
181 184 android:name=".ui.activity.consult.ConsultTwoLevelActivity"
... ... @@ -185,6 +188,11 @@
185 188 <activity
186 189 android:name=".ui.activity.orderdetail.OrderDetailActivity"
187 190 android:launchMode="singleInstance" />
  191 +
  192 + <service
  193 + android:name=".ui.service.BadgeIntentService"
  194 + android:exported="false">
  195 + </service>
188 196 </application>
189 197  
190 198 </manifest>
191 199 \ No newline at end of file
... ...
app/src/main/java/com/shunzhi/parent/AppConfig.java
... ... @@ -22,6 +22,8 @@ public class AppConfig {
22 22 public static String USER_SEX = "user_sex";
23 23 public static String USER_IMAGE = "user_image";
24 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 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&lt;ChannelContextBean
39 39 super.onAttachedToRecyclerView(recyclerView);
40 40 LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
41 41 layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
  42 + layoutManager.setSmoothScrollbarEnabled(true);
  43 + layoutManager.setAutoMeasureEnabled(true);
42 44 recyclerView.setLayoutManager(layoutManager);
  45 + recyclerView.setHasFixedSize(true);
43 46 }
44 47  
45 48 @Override
... ...
app/src/main/java/com/shunzhi/parent/bean/message/PHMessage.java
1 1 package com.shunzhi.parent.bean.message;
2 2  
  3 +import com.shunzhi.parent.AppContext;
  4 +
3 5 import org.greenrobot.greendao.annotation.Entity;
4 6 import org.greenrobot.greendao.annotation.Id;
  7 +import org.greenrobot.greendao.annotation.Keep;
5 8 import org.greenrobot.greendao.annotation.NotNull;
6 9  
  10 +import java.util.Collection;
  11 +import java.util.Collections;
7 12 import java.util.Date;
  13 +import java.util.List;
8 14  
9 15 import org.greenrobot.greendao.annotation.Generated;
10 16  
... ... @@ -26,11 +32,13 @@ public class PHMessage {
26 32 private String fileUrl;
27 33 private String messageType;
28 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 38 public PHMessage(Long id, Date date, String messageId, String sessionId,
32 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 42 this.id = id;
35 43 this.date = date;
36 44 this.messageId = messageId;
... ... @@ -41,12 +49,30 @@ public class PHMessage {
41 49 this.fileUrl = fileUrl;
42 50 this.messageType = messageType;
43 51 this.sendState = sendState;
  52 + this.sessionType = sessionType;
44 53 }
45 54  
46 55 @Generated(hash = 1001489632)
47 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 76 public Long getId() {
51 77 return this.id;
52 78 }
... ... @@ -126,4 +152,12 @@ public class PHMessage {
126 152 public void setSendState(Integer sendState) {
127 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 1 package com.shunzhi.parent.bean.message;
2 2  
  3 +import com.shunzhi.parent.AppConfig;
  4 +import com.shunzhi.parent.AppContext;
  5 +
3 6 import org.greenrobot.greendao.annotation.Entity;
4 7 import org.greenrobot.greendao.annotation.Id;
5 8  
6 9 import java.util.Date;
7 10  
8 11 import org.greenrobot.greendao.annotation.Generated;
  12 +import org.greenrobot.greendao.annotation.Keep;
9 13  
10 14 /**
11 15 * Created by 10501 on 2018/3/20.
... ... @@ -24,10 +28,15 @@ public class PHMessageSession {
24 28 private String exValues;
25 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 36 @Generated(hash = 1156938953)
28 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 40 this.id = id;
32 41 this.sessionId = sessionId;
33 42 this.sessionText = sessionText;
... ... @@ -44,6 +53,28 @@ public class PHMessageSession {
44 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 78 public Long getId() {
48 79 return this.id;
49 80 }
... ...
app/src/main/java/com/shunzhi/parent/manager/MessageManager.java
1 1 package com.shunzhi.parent.manager;
2 2  
  3 +import android.app.Notification;
  4 +import android.app.NotificationManager;
  5 +import android.app.PendingIntent;
3 6 import android.content.Context;
4 7 import android.content.Intent;
5 8 import android.content.SharedPreferences;
6   -import android.support.annotation.NonNull;
  9 +import android.support.v4.app.NotificationCompat;
7 10  
8 11 import com.netease.nimlib.sdk.NIMClient;
9 12 import com.netease.nimlib.sdk.Observer;
... ... @@ -16,14 +19,26 @@ import com.netease.nimlib.sdk.msg.MsgServiceObserve;
16 19 import com.netease.nimlib.sdk.msg.model.CustomNotification;
17 20 import com.netease.nimlib.sdk.msg.model.IMMessage;
18 21 import com.share.mvpsdk.utils.ToastUtils;
  22 +import com.shunzhi.parent.AppConfig;
19 23 import com.shunzhi.parent.AppContext;
  24 +import com.shunzhi.parent.R;
20 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 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 37 import java.util.List;
24 38  
25 39 import io.reactivex.Observable;
26 40 import io.reactivex.subjects.PublishSubject;
  41 +import me.leolin.shortcutbadger.ShortcutBadger;
27 42 import timber.log.Timber;
28 43  
29 44 /**
... ... @@ -32,6 +47,8 @@ import timber.log.Timber;
32 47  
33 48 public class MessageManager {
34 49  
  50 + public boolean isNotiNotification = true;
  51 +
35 52 private static class InstanceHolder {
36 53 static final MessageManager instance = new MessageManager();
37 54 }
... ... @@ -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 169 public Observable<NIMLoginResultBean> login(String account, String password) {
83 170 final PublishSubject<NIMLoginResultBean> subject = PublishSubject.create();
84 171 SharedPreferences sp = AppContext.getInstance().getApplicationContext().getSharedPreferences("info", Context.MODE_PRIVATE);
... ... @@ -91,7 +178,7 @@ public class MessageManager {
91 178 public void onSuccess(Object o) {
92 179 NIMLoginResultBean bean = new NIMLoginResultBean(true, 200, null);
93 180 subject.onNext(bean);
94   - Timber.i("----===onSuccess : %s",o);
  181 + Timber.i("----===onSuccess : %s", o);
95 182 }
96 183  
97 184 @Override
... ...
app/src/main/java/com/shunzhi/parent/ui/MainActivity.java
1 1 package com.shunzhi.parent.ui;
2 2  
  3 +import android.content.Intent;
3 4 import android.os.Bundle;
4 5 import android.support.annotation.NonNull;
5 6 import android.support.design.widget.BottomNavigationView;
... ... @@ -12,6 +13,10 @@ import com.share.mvpsdk.helper.BottomNavigationViewHelper;
12 13 import com.share.mvpsdk.utils.PermissionUtils;
13 14 import com.shunzhi.parent.AppContext;
14 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 20 import com.shunzhi.parent.ui.fragment.CePingFragment;
16 21 import com.shunzhi.parent.ui.fragment.ConsultFragment;
17 22 import com.shunzhi.parent.ui.fragment.MineFragment;
... ... @@ -102,11 +107,33 @@ public class MainActivity extends BaseCompatActivity implements PermissionUtils.
102 107 }
103 108  
104 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 126 protected int getLayoutId() {
106 127 return R.layout.activity_main;
107 128 }
108 129  
109 130 @Override
  131 + protected void onPause() {
  132 + super.onPause();
  133 + MessageManager.getInstance().isNotiNotification = true;
  134 + }
  135 +
  136 + @Override
110 137 protected void onDestroy() {
111 138 super.onDestroy();
112 139 AppContext.getInstance().destoryLocation();
... ... @@ -120,5 +147,6 @@ public class MainActivity extends BaseCompatActivity implements PermissionUtils.
120 147 @Override
121 148 protected void onResume() {
122 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&lt;CepingContract.CePingP
68 68 ivCourse2 = view.findViewById(R.id.ivCourse2);
69 69 ivCourse3 = view.findViewById(R.id.ivCourse3);
70 70  
71   - addTools();
  71 + addTools(AppContext.getInstance().district);
72 72  
73 73 textAndImg_xqjc.setTextColor(R.color.white);
74 74 textAndImg_xqjc.setText("学情检测");
... ... @@ -91,9 +91,9 @@ public class CePingFragment extends BaseMVPCompatFragment&lt;CepingContract.CePingP
91 91 });
92 92 }
93 93  
94   - private void addTools() {
  94 + private void addTools(String districtName) {
95 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&lt;CepingContract.CePingP
184 184 @Override
185 185 public void getCity(String name) {
186 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 189 AppContext.getInstance().cityName = name.split(" ")[1];
189 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 7 import android.os.Bundle;
8 8 import android.support.annotation.NonNull;
9 9 import android.support.annotation.Nullable;
  10 +import android.support.v4.widget.NestedScrollView;
10 11 import android.support.v7.widget.LinearLayoutManager;
11 12 import android.text.TextUtils;
12 13 import android.view.View;
... ... @@ -70,6 +71,7 @@ public class ConsultFragment extends BaseMVPCompatFragment&lt;ConsultContract.Consu
70 71 int pageIndex = 1;
71 72 boolean first = true;
72 73  
  74 +
73 75 @Override
74 76 public int getLayoutId() {
75 77 return R.layout.fragment_zi_xun;
... ... @@ -92,6 +94,7 @@ public class ConsultFragment extends BaseMVPCompatFragment&lt;ConsultContract.Consu
92 94 videoplayer.replayTextView.setVisibility(View.GONE);
93 95 videoplayer.backButton.setVisibility(View.GONE);
94 96  
  97 +
95 98 mPresenter.getBanners("2", AppContext.getInstance().district);
96 99  
97 100 initBroadCast();
... ...
app/src/main/java/com/shunzhi/parent/ui/service/BadgeIntentService.java 0 → 100644
... ... @@ -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 9 <include layout="@layout/layout_search" />
10 10  
11 11 <android.support.v4.widget.NestedScrollView
  12 + android:id="@+id/nesteScrollView"
12 13 android:layout_width="match_parent"
13 14 android:layout_height="match_parent">
14 15  
... ... @@ -21,11 +22,12 @@
21 22 <com.stx.xhb.xbanner.XBanner
22 23 android:id="@+id/xBanner"
23 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 33 <LinearLayout
... ...
app/src/main/res/layout/layout_textandimgshow.xml
... ... @@ -3,6 +3,7 @@
3 3 android:layout_width="match_parent"
4 4 android:layout_height="wrap_content"
5 5 android:orientation="horizontal"
  6 + android:layout_margin="@dimen/size_dp_10"
6 7 android:background="@drawable/report_white"
7 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 24  
25 25 @Override
26 26 public Response intercept(Chain chain) throws IOException {
  27 + try {
  28 +
27 29 Request request = chain.request();
28 30 if (NetworkConnectionUtils.isNetworkConnected(AppUtils.getContext())) {
29 31 // 有网络时, 缓存1小时
... ... @@ -55,7 +57,10 @@ public class CacheInterceptor implements Interceptor {
55 57 .header("Cache-Control", "public, only-if-cached, max-stale=" + maxStale)
56 58 .build();
57 59 }
58   -
  60 + }catch (Exception e){
  61 + e.printStackTrace();
  62 + return null;
  63 + }
59 64 // Request request = chain.request();
60 65 // if (!NetworkConnectionUtils.isConnected(AppUtils.getContext())) {
61 66 // request = request.newBuilder()
... ...