mac
2024-01-19 be5c9f324ac1d31f4f262d288c5f72a7a0c10c47
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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.getTitle());
            messageBean.setDeviceDesc(jPushMessageInfoBean.getContent());
            HdlMessageLogic.getInstance().setListMessage(messageBean, 0);
            HdlLogLogic.print("添加在推送数据到缓存列表中--->成功");
        } catch (Exception ignored) {
        }
    }
}