admin
2022-01-12 4a7367a869ef12375ea6678ca44e102b8919c624
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package cn.jpush.api.push.model.notification;
 
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
 
import java.util.Map;
 
/**
 * <p><b>Windows Phone 通知类</b></p>
 * <br>
 * 具体使用方法请参考官方文档 https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push/#platform
 * 支持 Winphone Notification 的参数:
 * <ul>
 * <li>alert: 继承自父类 PlatformNotification 的 alert 属性;本类设置则覆盖。</li>
 * <li>title: 支持 setTitle(string) 方法来设置;可替换通知标题。 </li>
 * <li>_open_page: 支持 setOpenPage(String) 方法来设置;可设置点击打开的页面名称</li>
 * <li>extras: 继承自父类 PlatformNotification 的 extras 属性;支持通过 addExtra(key, value) 来添加自定义字段,具体看代码。 </li>
 * </ul>
 * <br>
 */
public class WinphoneNotification extends PlatformNotification {
    private static final String NOTIFICATION_WINPHONE = "winphone";
    
    private static final String TITLE = "title";
    private static final String _OPEN_PAGE = "_open_page";
    
    private final String title;
    private final String openPage;
 
    private WinphoneNotification(Object alert, String title, String openPage,
            Map<String, String> extras, 
            Map<String, Number> numberExtras, 
            Map<String, Boolean> booleanExtras,
            Map<String, JsonObject> jsonExtras,
            Map<String, JsonPrimitive> customData) {
        super(alert, extras, numberExtras, booleanExtras, jsonExtras, customData);
        
        this.title = title;
        this.openPage = openPage;
    }
    
    public static Builder newBuilder() {
        return new Builder();
    }
    
    public static WinphoneNotification alert(String alert) {
        return newBuilder().setAlert(alert).build();
    }
    
    
    @Override
    public String getPlatform() {
        return NOTIFICATION_WINPHONE;
    }
    
    @Override
    public JsonElement toJSON() {
        JsonObject json = super.toJSON().getAsJsonObject();
        
        if (null != title) {
            json.add(TITLE, new JsonPrimitive(title));
        }
        if (null != openPage) {
            json.add(_OPEN_PAGE, new JsonPrimitive(openPage));
        }
        
        return json;
    }
    
    
    public static class Builder extends PlatformNotification.Builder<WinphoneNotification, Builder> {
        private String title;
        private String openPage;
        
        @Override
        protected Builder getThis() {
            return this;
        }
        
        public Builder setTitle(String title) {
            this.title = title;
            return this;
        }
        
        public Builder setOpenPage(String openPage) {
            this.openPage = openPage;
            return this;
        }
        
        @Override
        public Builder setAlert(Object alert) {
            this.alert = alert;
            return this;
        }
 
        
        public WinphoneNotification build() {
            return new WinphoneNotification(alert, title, openPage, 
                    extrasBuilder, numberExtrasBuilder, booleanExtrasBuilder, jsonExtrasBuilder, super.customData);
        }
    }
}