New file |
| | |
| | | package com.hdl.photovoltaic.other; |
| | | |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.text.TextUtils; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.hdl.photovoltaic.config.ConstantManage; |
| | | import com.hdl.photovoltaic.enums.MessageStateType; |
| | | import com.hdl.photovoltaic.jpush.JPushMessageInfoBean; |
| | | import com.hdl.photovoltaic.ui.MyPowerStationActivity; |
| | | import com.hdl.photovoltaic.ui.bean.MessageBean; |
| | | import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus; |
| | | |
| | | import org.greenrobot.eventbus.EventBus; |
| | | |
| | | |
| | | /** |
| | | * 极光推送信息处理逻辑 |
| | | */ |
| | | public class HdlJpushLogic { |
| | | private static volatile HdlJpushLogic sHdlJpushLogic; |
| | | |
| | | /** |
| | | * 获取当前对象 |
| | | * |
| | | * @return HdlAccountLogic |
| | | */ |
| | | public static synchronized HdlJpushLogic getInstance() { |
| | | if (sHdlJpushLogic == null) { |
| | | synchronized (HdlJpushLogic.class) { |
| | | if (sHdlJpushLogic == null) { |
| | | sHdlJpushLogic = new HdlJpushLogic(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | return sHdlJpushLogic; |
| | | } |
| | | |
| | | /** |
| | | * 极光推送数据统一处理的方法 |
| | | * |
| | | * @param context 上下文 |
| | | * @param jPushMessageInfoBean 推送数据对象实体 |
| | | * @param isOpened true=点击通知栏回调,false=收到推送通知回调; |
| | | */ |
| | | public void JpushPushCommonData(Context context, JPushMessageInfoBean jPushMessageInfoBean, boolean isOpened) { |
| | | //添加推送数据到缓存列表中; |
| | | this.addPushDataToMemoryList(jPushMessageInfoBean); |
| | | if (isOpened) { |
| | | Intent intent = new Intent(context, MyPowerStationActivity.class); |
| | | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| | | intent.putExtra("skip", "skip");//里面判断有这个标识就跳转到消息中心界面 |
| | | context.startActivity(intent); |
| | | } else { |
| | | BaseEventBus bus = new BaseEventBus(); |
| | | bus.setTopic(ConstantManage.message_function_push_post); |
| | | bus.setType(MessageStateType.untreated); |
| | | EventBus.getDefault().post(bus); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 添加在推送数据到缓存列表中 |
| | | */ |
| | | private void addPushDataToMemoryList(JPushMessageInfoBean jPushMessageInfoBean) { |
| | | try { |
| | | if (TextUtils.isEmpty(jPushMessageInfoBean.getExpantContent())) { |
| | | return; |
| | | } |
| | | Gson gson = new Gson(); |
| | | MessageBean messageBean = gson.fromJson(jPushMessageInfoBean.getExpantContent(), MessageBean.class); |
| | | if (messageBean == null) { |
| | | return; |
| | | } |
| | | messageBean.setTitle(jPushMessageInfoBean.getContent()); |
| | | messageBean.setDeviceDesc(jPushMessageInfoBean.getContent()); |
| | | HdlMessageLogic.getInstance().setListMessage(messageBean, 0); |
| | | HdlLogLogic.print("极光推送--->添加在推送数据到缓存列表中--->" + new Gson().toJson(jPushMessageInfoBean)); |
| | | } catch (Exception ignored) { |
| | | } |
| | | } |
| | | } |