Skip to content

Commit 68fa02b

Browse files
committed
Refactoring
1 parent d2fffcf commit 68fa02b

File tree

4 files changed

+105
-53
lines changed

4 files changed

+105
-53
lines changed

Sources/FCM/FCMAndroidConfig/FCMAndroidNotification.swift

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
21
public struct FCMAndroidNotification: Codable, Equatable {
3-
42
/// The notification's title.
53
/// If present, it will override FCMNotification.title.
64
public var title: String?
@@ -48,48 +46,83 @@ public struct FCMAndroidNotification: Codable, Equatable {
4846
/// See Formatting and Styling for more information.
4947
public var title_loc_args: [String]?
5048

51-
/// The notification's channel id (new in Android O). The app must create a channel with this channel ID before any notification with this channel ID is received. If you don't send this channel ID in the request, or if the channel ID provided has not yet been created by the app, FCM uses the channel ID specified in the app manifest.
49+
/// The notification's channel id (new in Android O).
50+
/// The app must create a channel with this channel ID before any notification with this channel ID is received.
51+
/// If you don't send this channel ID in the request, or if the channel ID provided has not yet been created by the app,
52+
/// FCM uses the channel ID specified in the app manifest.
5253
public var channel_id: String?
5354

54-
/// Sets the "ticker" text, which is sent to accessibility services. Prior to API level 21 (Lollipop), sets the text that is displayed in the status bar when the notification first arrives.
55+
/// Sets the "ticker" text, which is sent to accessibility services.
56+
/// Prior to API level 21 (Lollipop), sets the text that is displayed in the status bar when the notification first arrives.
5557
public var ticker: String?
5658

57-
/// When set to false or unset, the notification is automatically dismissed when the user clicks it in the panel. When set to true, the notification persists even when the user clicks it.
59+
/// When set to false or unset, the notification is automatically dismissed when the user clicks it in the panel.
60+
/// When set to true, the notification persists even when the user clicks it.
5861
public var sticky: Bool?
5962

60-
/// Set the time that the event in the notification occurred. Notifications in the panel are sorted by this time. A point in time is represented using protobuf.Timestamp.
61-
/// A timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds. Example: "2014-10-02T15:01:23.045123456Z".
63+
/// Set the time that the event in the notification occurred. Notifications in the panel are sorted by this time.
64+
/// A point in time is represented using protobuf.Timestamp.
65+
/// A timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds.
66+
/// Example: "2014-10-02T15:01:23.045123456Z".
6267
public var event_time: String?
6368

64-
/// Set whether or not this notification is relevant only to the current device. Some notifications can be bridged to other devices for remote display, such as a Wear OS watch. This hint can be set to recommend this notification not be bridged. See Wear OS guides
69+
/// Set whether or not this notification is relevant only to the current device.
70+
/// Some notifications can be bridged to other devices for remote display, such as a Wear OS watch.
71+
/// This hint can be set to recommend this notification not be bridged. See Wear OS guides
6572
public var local_only: Bool?
6673

67-
/// Set the relative priority for this notification. Priority is an indication of how much of the user's attention should be consumed by this notification. Low-priority notifications may be hidden from the user in certain situations, while the user might be interrupted for a higher-priority notification. The effect of setting the same priorities may differ slightly on different platforms. Note this priority differs from AndroidMessagePriority. This priority is processed by the client after the message has been delivered, whereas AndroidMessagePriority is an FCM concept that controls when the message is delivered.
74+
/// Set the relative priority for this notification.
75+
/// Priority is an indication of how much of the user's attention should be consumed by this notification.
76+
/// Low-priority notifications may be hidden from the user in certain situations, while the user might be interrupted for a higher-priority notification.
77+
/// The effect of setting the same priorities may differ slightly on different platforms.
78+
/// Note this priority differs from AndroidMessagePriority.
79+
/// This priority is processed by the client after the message has been delivered,
80+
/// whereas AndroidMessagePriority is an FCM concept that controls when the message is delivered.
6881
public var notification_priority: FCMAndroidNotificationPriority?
6982

70-
/// If set to true, use the Android framework's default sound for the notification. Default values are specified in config.xml.
83+
/// If set to true, use the Android framework's default sound for the notification.
84+
/// Default values are specified in config.xml.
7185
public var default_sound: Bool?
7286

73-
/// If set to true, use the Android framework's default vibrate pattern for the notification. Default values are specified in config.xml. If default_vibrate_timings is set to true and vibrate_timings is also set, the default value is used instead of the user-specified vibrate_timings.
87+
/// If set to true, use the Android framework's default vibrate pattern for the notification.
88+
/// Default values are specified in config.xml.
89+
/// If default_vibrate_timings is set to true and vibrate_timings is also set,
90+
/// the default value is used instead of the user-specified vibrate_timings.
7491
public var default_vibrate_timings: Bool?
7592

76-
/// If set to true, use the Android framework's default LED light settings for the notification. Default values are specified in config.xml. If default_light_settings is set to true and light_settings is also set, the user-specified light_settings is used instead of the default value.
93+
/// If set to true, use the Android framework's default LED light settings for the notification.
94+
/// Default values are specified in config.xml.
95+
/// If default_light_settings is set to true and light_settings is also set,
96+
/// the user-specified light_settings is used instead of the default value.
7797
public var default_light_settings: Bool?
7898

79-
/// Set the vibration pattern to use. Pass in an array of protobuf.Duration to turn on or off the vibrator. The first value indicates the Duration to wait before turning the vibrator on. The next value indicates the Duration to keep the vibrator on. Subsequent values alternate between Duration to turn the vibrator off and to turn the vibrator on. If vibrate_timings is set and default_vibrate_timings is set to true, the default value is used instead of the user-specified vibrate_timings.
99+
/// Set the vibration pattern to use.
100+
/// Pass in an array of protobuf.Duration to turn on or off the vibrator.
101+
/// The first value indicates the Duration to wait before turning the vibrator on.
102+
/// The next value indicates the Duration to keep the vibrator on.
103+
/// Subsequent values alternate between Duration to turn the vibrator off and to turn the vibrator on.
104+
/// If vibrate_timings is set and default_vibrate_timings is set to true,
105+
/// the default value is used instead of the user-specified vibrate_timings.
80106
/// A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".
81107
public var vibrate_timings: [String]?
82108

83109
/// Set the Notification.visibility of the notification.
84110
public var visibility: FCMAndroidNotificationVisibility?
85111

86-
/// Sets the number of items this notification represents. May be displayed as a badge count for launchers that support badging.See Notification Badge. For example, this might be useful if you're using just one notification to represent multiple new messages but you want the count here to represent the number of total new messages. If zero or unspecified, systems that support badging use the default, which is to increment a number displayed on the long-press menu each time a new notification arrives.
112+
/// Sets the number of items this notification represents.
113+
/// May be displayed as a badge count for launchers that support badging.See Notification Badge.
114+
/// For example, this might be useful if you're using just one notification to represent multiple new messages
115+
/// but you want the count here to represent the number of total new messages.
116+
/// If zero or unspecified, systems that support badging use the default,
117+
/// which is to increment a number displayed on the long-press menu each time a new notification arrives.
87118
public var notification_count: Int?
88119

89-
/// Settings to control the notification's LED blinking rate and color if LED is available on the device. The total blinking time is controlled by the OS.
120+
/// Settings to control the notification's LED blinking rate and color if LED is available on the device.
121+
/// The total blinking time is controlled by the OS.
90122
public var light_settings: FCMAndroidNotificationLightSettings?
91123

92-
/// Contains the URL of an image that is going to be displayed in a notification. If present, it will override google.firebase.fcm.v1.Notification.image.
124+
/// Contains the URL of an image that is going to be displayed in a notification.
125+
/// If present, it will override google.firebase.fcm.v1.Notification.image.
93126
public var image: String?
94127

95128
/// Public Initializer

Sources/FCM/FCMAndroidConfig/FCMAndroidNotificationLightSettings.swift

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,40 @@
55
// Created by Oleh Hudeichuk on 13.12.2019.
66
//
77

8-
public struct FCMAndroidNotificationLightSettingsColor: Codable, Equatable {
9-
10-
public var red: Float
11-
12-
public var green: Float
13-
14-
public var blue: Float
15-
16-
public var alpha: Float
17-
}
8+
public typealias FCMAndroidNotificationLightSettingsColor = FCMAndroidNotificationLightSettings.Color
189

1910
public struct FCMAndroidNotificationLightSettings: Codable, Equatable {
11+
/// Required. Set color of the LED with google.type.Color.
12+
public var color: Color
2013

21-
/// Required. Set color of the LED with google.type.Color.
22-
public var color: FCMAndroidNotificationLightSettingsColor
23-
24-
/// Required. Along with light_off_duration, define the blink rate of LED flashes. Resolution defined by proto.Duration
25-
/// A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".
14+
/// Required. Along with light_off_duration, define the blink rate of LED flashes.
15+
/// Resolution defined by proto.Duration
16+
/// A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".
2617
public var light_on_duration: String
2718

28-
/// Required. Along with light_on_duration, define the blink rate of LED flashes. Resolution defined by proto.Duration
29-
/// A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".
19+
/// Required. Along with light_on_duration, define the blink rate of LED flashes.
20+
/// Resolution defined by proto.Duration
21+
/// A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".
3022
public var light_off_duration: String
23+
24+
public init (color: Color,
25+
light_on_duration: String,
26+
light_off_duration: String) {
27+
self.color = color
28+
self.light_on_duration = light_on_duration
29+
self.light_off_duration = light_off_duration
30+
}
3131
}
3232

33+
extension FCMAndroidNotificationLightSettings {
34+
public struct Color: Codable, Equatable {
35+
public var red, green, blue, alpha: Float
36+
37+
public init (red: Float, green: Float, blue: Float, alpha: Float) {
38+
self.red = red
39+
self.green = green
40+
self.blue = blue
41+
self.alpha = alpha
42+
}
43+
}
44+
}

Sources/FCM/FCMAndroidConfig/FCMAndroidNotificationPriority.swift

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,30 @@
66
//
77

88
public enum FCMAndroidNotificationPriority: String, Codable, Equatable {
9-
10-
/// If priority is unspecified, notification priority is set to PRIORITY_DEFAULT.
9+
/// If priority is unspecified, notification priority is set to PRIORITY_DEFAULT.
1110
case unspecified = "PRIORITY_UNSPECIFIED"
1211

13-
/// Lowest notification priority. Notifications with this PRIORITY_MIN might not be shown to the user except under special circumstances, such as detailed notification logs.
14-
case min = "PRIORITY_MIN"
12+
/// Lowest notification priority.
13+
/// Notifications with this PRIORITY_MIN might not be shown to the user
14+
/// except under special circumstances, such as detailed notification logs.
15+
case min = "PRIORITY_MIN"
1516

16-
/// Lower notification priority. The UI may choose to show the notifications smaller, or at a different position in the list, compared with notifications with PRIORITY_DEFAULT.
17-
case low = "PRIORITY_LOW"
17+
/// Lower notification priority.
18+
/// The UI may choose to show the notifications smaller,
19+
/// or at a different position in the list, compared with notifications with PRIORITY_DEFAULT.
20+
case low = "PRIORITY_LOW"
1821

19-
/// Default notification priority. If the application does not prioritize its own notifications, use this value for all notifications.
20-
case `default` = "PRIORITY_DEFAULT"
22+
/// Default notification priority.
23+
/// If the application does not prioritize its own notifications, use this value for all notifications.
24+
case `default` = "PRIORITY_DEFAULT"
2125

22-
/// Higher notification priority. Use this for more important notifications or alerts. The UI may choose to show these notifications larger, or at a different position in the notification lists, compared with notifications with PRIORITY_DEFAULT.
23-
case high = "PRIORITY_HIGH"
26+
/// Higher notification priority.
27+
/// Use this for more important notifications or alerts.
28+
/// The UI may choose to show these notifications larger,
29+
/// or at a different position in the notification lists, compared with notifications with PRIORITY_DEFAULT.
30+
case high = "PRIORITY_HIGH"
2431

25-
/// Highest notification priority. Use this for the application's most important items that require the user's prompt attention or input.
26-
case max = "PRIORITY_MAX"
32+
/// Highest notification priority.
33+
/// Use this for the application's most important items that require the user's prompt attention or input.
34+
case max = "PRIORITY_MAX"
2735
}

Sources/FCM/FCMAndroidConfig/FCMAndroidNotificationVisibility.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
//
77

88
public enum FCMAndroidNotificationVisibility: String, Codable, Equatable {
9-
10-
/// If unspecified, default to Visibility.PRIVATE.
9+
/// If unspecified, default to Visibility.PRIVATE.
1110
case unspecified = "VISIBILITY_UNSPECIFIED"
1211

13-
/// Show this notification on all lockscreens, but conceal sensitive or private information on secure lockscreens.
14-
case `private` = "PRIVATE"
12+
/// Show this notification on all lockscreens, but conceal sensitive or private information on secure lockscreens.
13+
case `private` = "PRIVATE"
1514

16-
/// Show this notification in its entirety on all lockscreens.
17-
case `public` = "PUBLIC"
15+
/// Show this notification in its entirety on all lockscreens.
16+
case `public` = "PUBLIC"
1817

19-
/// Do not reveal any part of this notification on a secure lockscreen.
20-
case secret = "SECRET"
18+
/// Do not reveal any part of this notification on a secure lockscreen.
19+
case secret = "SECRET"
2120
}

0 commit comments

Comments
 (0)