13
13
public class NotificationHubUtil {
14
14
private static NotificationHubUtil sharedNotificationHubUtilInstance = null ;
15
15
16
- private static final String SHARED_PREFS_NAME =
17
- "com.azure.reactnative.notificationhub.NotificationHubUtil" ;
18
- private static final String KEY_FOR_PREFS_REGISTRATIONID =
19
- "AzureNotificationHub_registrationID" ;
20
- private static final String KEY_FOR_PREFS_CONNECTIONSTRING =
21
- "AzureNotificationHub_connectionString" ;
22
- private static final String KEY_FOR_PREFS_HUBNAME =
23
- "AzureNotificationHub_hubName" ;
24
- private static final String KEY_FOR_PREFS_FCMTOKEN =
25
- "AzureNotificationHub_FCMToken" ;
26
- private static final String KEY_FOR_PREFS_TAGS =
27
- "AzureNotificationHub_Tags" ;
16
+ private static final String SHARED_PREFS_NAME = "com.azure.reactnative.notificationhub.NotificationHubUtil" ;
17
+ private static final String KEY_FOR_PREFS_REGISTRATIONID = "AzureNotificationHub_registrationID" ;
18
+ private static final String KEY_FOR_PREFS_CONNECTIONSTRING = "AzureNotificationHub_connectionString" ;
19
+ private static final String KEY_FOR_PREFS_HUBNAME = "AzureNotificationHub_hubName" ;
20
+ private static final String KEY_FOR_PREFS_FCMTOKEN = "AzureNotificationHub_FCMToken" ;
21
+ private static final String KEY_FOR_PREFS_TAGS = "AzureNotificationHub_Tags" ;
22
+ private static final String KEY_FOR_PREFS_SENDERID = "AzureNotificationHub_senderID" ;
23
+ private static final String KEY_FOR_PREFS_CHANNELIMPORTANCE = "AzureNotificationHub_channelImportance" ;
24
+ private static final String KEY_FOR_PREFS_CHANNELSHOWBADGE = "AzureNotificationHub_channelShowBadge" ;
25
+ private static final String KEY_FOR_PREFS_CHANNELENABLELIGHTS = "AzureNotificationHub_channelEnableLights" ;
26
+ private static final String KEY_FOR_PREFS_CHANNELENABLEVIBRATION = "AzureNotificationHub_channelEnableVibration" ;
28
27
29
28
public static NotificationHubUtil getInstance () {
30
29
if (sharedNotificationHubUtilInstance == null ) {
@@ -75,6 +74,62 @@ public void setTags(Context context, String[] tags) {
75
74
setPrefSet (context , KEY_FOR_PREFS_TAGS , set );
76
75
}
77
76
77
+ public String getSenderID (Context context ) {
78
+ return getPref (context , KEY_FOR_PREFS_SENDERID );
79
+ }
80
+
81
+ public void setSenderID (Context context , String senderID ) {
82
+ setPref (context , KEY_FOR_PREFS_SENDERID , senderID );
83
+ }
84
+
85
+ public int getChannelImportance (Context context ) {
86
+ return getPrefInt (context , KEY_FOR_PREFS_CHANNELIMPORTANCE );
87
+ }
88
+
89
+ public void setChannelImportance (Context context , int channelImportance ) {
90
+ setPrefInt (context , KEY_FOR_PREFS_CHANNELIMPORTANCE , channelImportance );
91
+ }
92
+
93
+ public boolean hasChannelImportance (Context context ) {
94
+ return hasKey (context , KEY_FOR_PREFS_CHANNELIMPORTANCE );
95
+ }
96
+
97
+ public boolean getChannelShowBadge (Context context ) {
98
+ return getPrefBoolean (context , KEY_FOR_PREFS_CHANNELSHOWBADGE );
99
+ }
100
+
101
+ public void setChannelShowBadge (Context context , boolean channelShowBadge ) {
102
+ setPrefBoolean (context , KEY_FOR_PREFS_CHANNELSHOWBADGE , channelShowBadge );
103
+ }
104
+
105
+ public boolean hasChannelShowBadge (Context context ) {
106
+ return hasKey (context , KEY_FOR_PREFS_CHANNELSHOWBADGE );
107
+ }
108
+
109
+ public boolean getChannelEnableLights (Context context ) {
110
+ return getPrefBoolean (context , KEY_FOR_PREFS_CHANNELENABLELIGHTS );
111
+ }
112
+
113
+ public void setChannelEnableLights (Context context , boolean channelEnableLights ) {
114
+ setPrefBoolean (context , KEY_FOR_PREFS_CHANNELENABLELIGHTS , channelEnableLights );
115
+ }
116
+
117
+ public boolean hasChannelEnableLights (Context context ) {
118
+ return hasKey (context , KEY_FOR_PREFS_CHANNELENABLELIGHTS );
119
+ }
120
+
121
+ public boolean getChannelEnableVibration (Context context ) {
122
+ return getPrefBoolean (context , KEY_FOR_PREFS_CHANNELENABLEVIBRATION );
123
+ }
124
+
125
+ public void setChannelEnableVibration (Context context , boolean channelEnableVibration ) {
126
+ setPrefBoolean (context , KEY_FOR_PREFS_CHANNELENABLEVIBRATION , channelEnableVibration );
127
+ }
128
+
129
+ public boolean hasChannelEnableVibration (Context context ) {
130
+ return hasKey (context , KEY_FOR_PREFS_CHANNELENABLEVIBRATION );
131
+ }
132
+
78
133
public NotificationHub createNotificationHub (String hubName , String connectionString , ReactContext reactContext ) {
79
134
NotificationHub hub = new NotificationHub (hubName , connectionString , reactContext );
80
135
return hub ;
@@ -86,6 +141,18 @@ private String getPref(Context context, String key) {
86
141
return prefs .getString (key , null );
87
142
}
88
143
144
+ private int getPrefInt (Context context , String key ) {
145
+ SharedPreferences prefs =
146
+ context .getSharedPreferences (SHARED_PREFS_NAME , Context .MODE_PRIVATE );
147
+ return prefs .getInt (key , 0 );
148
+ }
149
+
150
+ private boolean getPrefBoolean (Context context , String key ) {
151
+ SharedPreferences prefs =
152
+ context .getSharedPreferences (SHARED_PREFS_NAME , Context .MODE_PRIVATE );
153
+ return prefs .getBoolean (key , false );
154
+ }
155
+
89
156
private Set <String > getPrefSet (Context context , String key ) {
90
157
SharedPreferences prefs =
91
158
context .getSharedPreferences (SHARED_PREFS_NAME , Context .MODE_PRIVATE );
@@ -99,10 +166,30 @@ private void setPref(Context context, String key, String value) {
99
166
editor .apply ();
100
167
}
101
168
169
+ private void setPrefInt (Context context , String key , int value ) {
170
+ SharedPreferences .Editor editor =
171
+ context .getSharedPreferences (SHARED_PREFS_NAME , Context .MODE_PRIVATE ).edit ();
172
+ editor .putInt (key , value );
173
+ editor .apply ();
174
+ }
175
+
176
+ private void setPrefBoolean (Context context , String key , boolean value ) {
177
+ SharedPreferences .Editor editor =
178
+ context .getSharedPreferences (SHARED_PREFS_NAME , Context .MODE_PRIVATE ).edit ();
179
+ editor .putBoolean (key , value );
180
+ editor .apply ();
181
+ }
182
+
102
183
private void setPrefSet (Context context , String key , Set <String > value ) {
103
184
SharedPreferences .Editor editor =
104
185
context .getSharedPreferences (SHARED_PREFS_NAME , Context .MODE_PRIVATE ).edit ();
105
186
editor .putStringSet (key , value );
106
187
editor .apply ();
107
188
}
189
+
190
+ private boolean hasKey (Context context , String key ) {
191
+ SharedPreferences prefs =
192
+ context .getSharedPreferences (SHARED_PREFS_NAME , Context .MODE_PRIVATE );
193
+ return prefs .contains (key );
194
+ }
108
195
}
0 commit comments