Showing
3 changed files
with
57 additions
and
88 deletions
@@ -21,6 +21,16 @@ class EwinMixPushReceiver : MixPushReceiver() { | @@ -21,6 +21,16 @@ class EwinMixPushReceiver : MixPushReceiver() { | ||
21 | this.invokeListener(MixListenerTypeEnum.ReceiveRegisterResult, platform) | 21 | this.invokeListener(MixListenerTypeEnum.ReceiveRegisterResult, platform) |
22 | } | 22 | } |
23 | 23 | ||
24 | + override fun onNotificationMessageArrived(context: Context?, message: MixPushMessage?) { | ||
25 | + message?.run { | ||
26 | + if (isPassThrough){ | ||
27 | + this.invokeListener(MixListenerTypeEnum.ReceivePassThroughMessage, message) | ||
28 | + }else{ | ||
29 | + this.invokeListener(MixListenerTypeEnum.NotificationMessageArrived, message) | ||
30 | + } | ||
31 | + } | ||
32 | + } | ||
33 | + | ||
24 | override fun onNotificationMessageClicked(context: Context, message: MixPushMessage) { | 34 | override fun onNotificationMessageClicked(context: Context, message: MixPushMessage) { |
25 | this.invokeListener(MixListenerTypeEnum.NotificationMessageClicked, message) | 35 | this.invokeListener(MixListenerTypeEnum.NotificationMessageClicked, message) |
26 | 36 |
1 | class MixPushMessageEntity { | 1 | class MixPushMessageEntity { |
2 | - final bool? arrivedMessage; | ||
3 | - final String? content; | ||
4 | - final String? description; | ||
5 | - final MixPushMessageExtra? extra; | ||
6 | - final String? messageId; | ||
7 | - final int? messageType; | ||
8 | - final bool? notified; | ||
9 | - final int? notifyId; | ||
10 | - final int? notifyType; | ||
11 | - final int? passThrough; | 2 | + //通知栏标题,透传该字段为空 |
12 | final String? title; | 3 | final String? title; |
4 | + //通知栏副标题,透传该字段为空 | ||
5 | + final String? description; | ||
6 | + //推送所属平台,比如mi/huawei | ||
7 | + final String? platform; | ||
8 | + //推送附属的内容信息 | ||
9 | + final String? payload; | ||
10 | + //是否是透传推送 | ||
11 | + final bool? passThrough; | ||
12 | + final String? msgId; | ||
13 | 13 | ||
14 | - MixPushMessageEntity({ | ||
15 | - this.arrivedMessage, | ||
16 | - this.content, | ||
17 | - this.description, | ||
18 | - this.extra, | ||
19 | - this.messageId, | ||
20 | - this.messageType, | ||
21 | - this.notified, | ||
22 | - this.notifyId, | ||
23 | - this.notifyType, | ||
24 | - this.passThrough, | ||
25 | - this.title, | ||
26 | - }); | 14 | + MixPushMessageEntity( |
15 | + {this.title, | ||
16 | + this.description, | ||
17 | + this.platform, | ||
18 | + this.payload, | ||
19 | + this.passThrough, | ||
20 | + this.msgId}); | ||
27 | 21 | ||
28 | factory MixPushMessageEntity.fromJson(Map<String, dynamic> json) { | 22 | factory MixPushMessageEntity.fromJson(Map<String, dynamic> json) { |
29 | return MixPushMessageEntity( | 23 | return MixPushMessageEntity( |
30 | - arrivedMessage: json['arrivedMessage'], | ||
31 | - content: json['content'], | ||
32 | - description: json['description'], | ||
33 | - extra: json['extra'] == null | ||
34 | - ? null | ||
35 | - : MixPushMessageExtra.fromJson(json['extra']), | ||
36 | - messageId: json['messageId'], | ||
37 | - messageType: json['messageType'], | ||
38 | - notified: json['notified'], | ||
39 | - notifyId: json['notifyId'], | ||
40 | - notifyType: json['notifyType'], | ||
41 | - passThrough: json['passThrough'], | ||
42 | - title: json['title'], | ||
43 | - ); | 24 | + title: json['title'], |
25 | + description: json['description'], | ||
26 | + platform: json['platform'], | ||
27 | + payload: json['payload'], | ||
28 | + passThrough: json['passThrough'], | ||
29 | + msgId: json['msgId']); | ||
44 | } | 30 | } |
45 | - | ||
46 | Map<String, dynamic> toJson() => { | 31 | Map<String, dynamic> toJson() => { |
47 | - 'arrivedMessage': arrivedMessage, | ||
48 | - 'content': content, | 32 | + 'title': title, |
49 | 'description': description, | 33 | 'description': description, |
50 | - 'extra': extra == null ? null : extra!.toJson(), | ||
51 | - 'messageId': messageId, | ||
52 | - 'messageType': messageType, | ||
53 | - 'notified': notified, | ||
54 | - 'notifyId': notifyId, | ||
55 | - 'notifyType': notifyType, | 34 | + 'platform': platform, |
35 | + 'payload': payload, | ||
56 | 'passThrough': passThrough, | 36 | 'passThrough': passThrough, |
57 | - 'title': title, | 37 | + 'msgId': msgId, |
58 | }; | 38 | }; |
59 | } | 39 | } |
60 | 40 | ||
61 | -class MixPushMessageExtra { | ||
62 | - final String? highPriorityEvent; | ||
63 | - final String? feTs; | ||
64 | - final String? planId; | ||
65 | - final String? source; | ||
66 | - final String? notifyForeground; | ||
67 | - final String? mTs; | 41 | +class MixPushPlatformEntity { |
42 | + final String? platformName; | ||
43 | + final String? regId; | ||
68 | 44 | ||
69 | - MixPushMessageExtra({ | ||
70 | - this.highPriorityEvent, | ||
71 | - this.feTs, | ||
72 | - this.planId, | ||
73 | - this.source, | ||
74 | - this.notifyForeground, | ||
75 | - this.mTs, | ||
76 | - }); | 45 | + MixPushPlatformEntity({this.platformName, this.regId}); |
77 | 46 | ||
78 | - factory MixPushMessageExtra.fromJson(Map<String, dynamic> json) { | ||
79 | - return MixPushMessageExtra( | ||
80 | - highPriorityEvent: json['high_priority_event'], | ||
81 | - feTs: json['fe_ts'], | ||
82 | - planId: json['__planId__'], | ||
83 | - source: json['source'], | ||
84 | - notifyForeground: json['notify_foreground'], | ||
85 | - mTs: json['__m_ts'], | ||
86 | - ); | 47 | + factory MixPushPlatformEntity.fromJson(Map<String, dynamic> json) { |
48 | + return MixPushPlatformEntity( | ||
49 | + platformName: json['platformName'], regId: json['regId']); | ||
87 | } | 50 | } |
88 | 51 | ||
89 | Map<String, dynamic> toJson() => { | 52 | Map<String, dynamic> toJson() => { |
90 | - 'high_priority_event': highPriorityEvent, | ||
91 | - 'fe_ts': feTs, | ||
92 | - '__planId__': planId, | ||
93 | - 'source': source, | ||
94 | - 'notify_foreground': notifyForeground, | ||
95 | - '__m_ts': mTs, | 53 | + 'arrivedMessage': platformName, |
54 | + 'content': regId, | ||
96 | }; | 55 | }; |
97 | } | 56 | } |
@@ -27,10 +27,10 @@ class XiaoMiPushPluginListener { | @@ -27,10 +27,10 @@ class XiaoMiPushPluginListener { | ||
27 | : null; | 27 | : null; |
28 | 28 | ||
29 | // 封装回调类型和参数 | 29 | // 封装回调类型和参数 |
30 | - XiaoMixPushListenerTypeEnum? type; | 30 | + MixPushListenerTypeEnum? type; |
31 | 31 | ||
32 | // 初始化类型 | 32 | // 初始化类型 |
33 | - for (var item in XiaoMixPushListenerTypeEnum.values) { | 33 | + for (var item in MixPushListenerTypeEnum.values) { |
34 | var es = item.toString().split("."); | 34 | var es = item.toString().split("."); |
35 | if (es[es.length - 1] == typeStr) { | 35 | if (es[es.length - 1] == typeStr) { |
36 | type = item; | 36 | type = item; |
@@ -45,21 +45,21 @@ class XiaoMiPushPluginListener { | @@ -45,21 +45,21 @@ class XiaoMiPushPluginListener { | ||
45 | 45 | ||
46 | // 回调触发 | 46 | // 回调触发 |
47 | switch (type) { | 47 | switch (type) { |
48 | - case XiaoMixPushListenerTypeEnum.RequirePermissions: | 48 | + case MixPushListenerTypeEnum.RequirePermissions: |
49 | break; | 49 | break; |
50 | - case XiaoMixPushListenerTypeEnum.NotificationMessageClicked: | 50 | + case MixPushListenerTypeEnum.NotificationMessageClicked: |
51 | params = MixPushMessageEntity.fromJson(params); | 51 | params = MixPushMessageEntity.fromJson(params); |
52 | break; | 52 | break; |
53 | - case XiaoMixPushListenerTypeEnum.ReceivePassThroughMessage: | 53 | + case MixPushListenerTypeEnum.ReceivePassThroughMessage: |
54 | params = MixPushMessageEntity.fromJson(params); | 54 | params = MixPushMessageEntity.fromJson(params); |
55 | break; | 55 | break; |
56 | - case XiaoMixPushListenerTypeEnum.CommandResult: | 56 | + case MixPushListenerTypeEnum.CommandResult: |
57 | params = MixPushCommandMessageEntity.fromJson(params); | 57 | params = MixPushCommandMessageEntity.fromJson(params); |
58 | break; | 58 | break; |
59 | - case XiaoMixPushListenerTypeEnum.ReceiveRegisterResult: | ||
60 | - params = MixPushCommandMessageEntity.fromJson(params); | 59 | + case MixPushListenerTypeEnum.ReceiveRegisterResult: |
60 | + params = MixPushPlatformEntity.fromJson(params); | ||
61 | break; | 61 | break; |
62 | - case XiaoMixPushListenerTypeEnum.NotificationMessageArrived: | 62 | + case MixPushListenerTypeEnum.NotificationMessageArrived: |
63 | params = MixPushMessageEntity.fromJson(params); | 63 | params = MixPushMessageEntity.fromJson(params); |
64 | break; | 64 | break; |
65 | } | 65 | } |
@@ -88,10 +88,10 @@ class XiaoMiPushPluginListener { | @@ -88,10 +88,10 @@ class XiaoMiPushPluginListener { | ||
88 | 88 | ||
89 | /// 监听器值模型 | 89 | /// 监听器值模型 |
90 | typedef ListenerValue<P> = void Function( | 90 | typedef ListenerValue<P> = void Function( |
91 | - XiaoMixPushListenerTypeEnum type, P? params); | 91 | + MixPushListenerTypeEnum type, P? params); |
92 | 92 | ||
93 | /// 监听器类型枚举 | 93 | /// 监听器类型枚举 |
94 | -enum XiaoMixPushListenerTypeEnum { | 94 | +enum MixPushListenerTypeEnum { |
95 | NotificationMessageClicked, | 95 | NotificationMessageClicked, |
96 | RequirePermissions, | 96 | RequirePermissions, |
97 | ReceivePassThroughMessage, | 97 | ReceivePassThroughMessage, |
-
Please register or login to post a comment