From 2dae5f7a773b3305dc5706e7e2fc1ed425398034 Mon Sep 17 00:00:00 2001 From: Artyom <17145209+Korna@users.noreply.github.com> Date: Mon, 7 Nov 2022 17:14:59 +0300 Subject: [PATCH] Add HPK Android-related DTO's (#89) * Add HPK Android-related DTO's --- .../dto/android/AndroidBadgeNotification.kt | 78 ++++ .../hms_hpk/dto/android/AndroidButton.kt | 80 ++++ .../hms_hpk/dto/android/AndroidClickAction.kt | 93 ++++ .../hms_hpk/dto/android/AndroidColor.kt | 82 ++++ .../dto/android/AndroidLightSettings.kt | 63 +++ .../dto/android/AndroidNotificationConfig.kt | 417 ++++++++++++++++++ .../enums/android/AndroidActionType.kt | 17 + .../enums/android/AndroidClickActionType.kt | 13 + .../enums/android/AndroidFastAppTargetType.kt | 12 + .../enums/android/AndroidImportance.kt | 13 + .../enums/android/AndroidIntentType.kt | 12 + .../hms_hpk/enums/android/AndroidStyleType.kt | 13 + .../enums/android/AndroidTargetUserType.kt | 13 + .../enums/android/AndroidTopicOperation.kt | 13 + .../hms_hpk/enums/android/AndroidUrgency.kt | 12 + .../enums/android/AndroidVisibility.kt | 24 + 16 files changed, 955 insertions(+) create mode 100644 push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/dto/android/AndroidBadgeNotification.kt create mode 100644 push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/dto/android/AndroidButton.kt create mode 100644 push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/dto/android/AndroidClickAction.kt create mode 100644 push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/dto/android/AndroidColor.kt create mode 100644 push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/dto/android/AndroidLightSettings.kt create mode 100644 push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/dto/android/AndroidNotificationConfig.kt create mode 100644 push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidActionType.kt create mode 100644 push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidClickActionType.kt create mode 100644 push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidFastAppTargetType.kt create mode 100644 push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidImportance.kt create mode 100644 push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidIntentType.kt create mode 100644 push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidStyleType.kt create mode 100644 push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidTargetUserType.kt create mode 100644 push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidTopicOperation.kt create mode 100644 push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidUrgency.kt create mode 100644 push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidVisibility.kt diff --git a/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/dto/android/AndroidBadgeNotification.kt b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/dto/android/AndroidBadgeNotification.kt new file mode 100644 index 0000000..bdd39e6 --- /dev/null +++ b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/dto/android/AndroidBadgeNotification.kt @@ -0,0 +1,78 @@ +package ru.touchin.push.message.provider.hpk.clients.hms_hpk.dto.android + +import com.fasterxml.jackson.annotation.JsonProperty +import ru.touchin.push.message.provider.hpk.base.builders.Buildable + +internal data class AndroidBadgeNotification private constructor( + /** Accumulative badge number. */ + val addNum: Short?, + /** Full path of the app entry activity class. */ + @JsonProperty("class") + val clazz: String, + /** Badge number. Overrides [addNum]. */ + val setNum: Short?, +) { + + class Validator { + + fun check(androidBadgeNotification: AndroidBadgeNotification) { + with(androidBadgeNotification) { + if (addNum != null) { + require( + addNum in ADD_NUM_MIN_VALUE..ADD_NUM_MAX_VALUE + ) { "add_num must locate in $ADD_NUM_MIN_VALUE and $ADD_NUM_MAX_VALUE" } + } + + if (setNum != null) { + require( + setNum in SET_NUM_RANGE_CONSTRAINT + ) { "set_num must locate between $SET_NUM_MIN_VALUE and $SET_NUM_MAX_VALUE" } + } + } + } + + private companion object { + + const val ADD_NUM_MIN_VALUE: Byte = 1 + const val ADD_NUM_MAX_VALUE: Byte = 99 + val ADD_NUM_RANGE_CONSTRAINT: IntRange = ADD_NUM_MIN_VALUE..ADD_NUM_MAX_VALUE + const val SET_NUM_MIN_VALUE: Byte = 0 + const val SET_NUM_MAX_VALUE: Byte = 99 + val SET_NUM_RANGE_CONSTRAINT: IntRange = SET_NUM_MIN_VALUE..SET_NUM_MAX_VALUE + + } + + } + + class Builder : Buildable { + + private var addNum: Short? = null + private var setNum: Short? = null + + fun setAddNum(addNum: Short): Builder { + this.addNum = addNum + return this + } + + fun setSetNum(setNum: Short): Builder { + this.setNum = setNum + return this + } + + fun build(badgeClass: String): AndroidBadgeNotification { + return AndroidBadgeNotification( + addNum = addNum, + clazz = badgeClass, + setNum = setNum, + ) + } + } + + companion object { + + val validator = Validator() + + fun builder() = Builder() + + } +} diff --git a/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/dto/android/AndroidButton.kt b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/dto/android/AndroidButton.kt new file mode 100644 index 0000000..6f1b17e --- /dev/null +++ b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/dto/android/AndroidButton.kt @@ -0,0 +1,80 @@ +package ru.touchin.push.message.provider.hpk.clients.hms_hpk.dto.android + +import com.fasterxml.jackson.annotation.JsonProperty +import ru.touchin.push.message.provider.hpk.base.builders.Buildable +import ru.touchin.push.message.provider.hpk.clients.hms_hpk.enums.android.AndroidActionType +import ru.touchin.push.message.provider.hpk.clients.hms_hpk.enums.android.AndroidIntentType + +internal data class AndroidButton private constructor( + /** Button name. */ + val name: String, + /** Button action. */ + @JsonProperty("action_type") + val androidActionType: AndroidActionType, + /** Method of opening a custom app page. */ + @JsonProperty("intent_type") + val androidIntentType: AndroidIntentType?, + val intent: String?, + /** Map of key-values. */ + val data: String?, +) { + + class Validator { + + fun check(androidButton: AndroidButton) { + with(androidButton) { + require( + name.length <= NAME_MAX_LENGTH + ) { "Button name length cannot exceed $NAME_MAX_LENGTH" } + + if (androidActionType == AndroidActionType.SHARE_NOTIFICATION_MESSAGE) { + require(!data.isNullOrEmpty()) { "Data is needed when actionType is $androidActionType" } + require(data.length <= DATA_MAX_LENGTH) { "Data length cannot exceed $DATA_MAX_LENGTH chars" } + } + } + } + + private companion object { + + const val NAME_MAX_LENGTH: Byte = 40 + const val DATA_MAX_LENGTH: Short = 1024 + + } + + } + + class Builder : Buildable { + + private var intent: String? = null + private var data: String? = null + + fun setIntent(intent: String): Builder { + this.intent = intent + return this + } + + fun setData(data: String): Builder { + this.data = data + return this + } + + fun build(name: String, androidActionType: AndroidActionType, androidIntentType: AndroidIntentType): AndroidButton { + return AndroidButton( + name = name, + androidActionType = androidActionType, + androidIntentType = androidIntentType, + intent = intent, + data = data + ) + } + } + + companion object { + + val validator = Validator() + + fun builder() = Builder() + + } + +} diff --git a/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/dto/android/AndroidClickAction.kt b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/dto/android/AndroidClickAction.kt new file mode 100644 index 0000000..a15a7e4 --- /dev/null +++ b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/dto/android/AndroidClickAction.kt @@ -0,0 +1,93 @@ +package ru.touchin.push.message.provider.hpk.clients.hms_hpk.dto.android + +import com.fasterxml.jackson.annotation.JsonProperty +import ru.touchin.push.message.provider.hpk.base.builders.Buildable +import ru.touchin.push.message.provider.hpk.clients.hms_hpk.enums.android.AndroidClickActionType + +internal data class AndroidClickAction private constructor( + /** Message tapping action type. */ + @JsonProperty("type") + val androidClickActionType: AndroidClickActionType, + val intent: String?, + /** URL to be opened. */ + val url: String?, + /** Action corresponding to the activity of the page to be opened when the custom app page is opened through the action. */ + val action: String?, +) { + + class Validator { + + fun check(androidClickAction: AndroidClickAction) { + with(androidClickAction) { + when (androidClickActionType) { + AndroidClickActionType.CUSTOMIZE_ACTION -> require( + !intent.isNullOrBlank() || !action.isNullOrBlank() + ) { "intent or action is required when click type is $androidClickActionType" } + + AndroidClickActionType.OPEN_URL -> { + require(!url.isNullOrBlank()) { "url is required when click type is $androidClickActionType" } + require(url.startsWith(HTTPS_PATTERN_START)) { "url must start with $HTTPS_PATTERN_START" } + } + + AndroidClickActionType.OPEN_APP -> { + // no verification + } + } + } + } + + private companion object { + + const val HTTPS_PATTERN_START = "https" + + } + + } + + class Builder : Buildable { + + private var intent: String? = null + private var url: String? = null + private var richResource: String? = null + private var action: String? = null + + fun setIntent(intent: String): Builder { + this.intent = intent + return this + } + + fun setUrl(url: String): Builder { + this.url = url + return this + } + + fun setRichResource(richResource: String): Builder { + this.richResource = richResource + return this + } + + fun setAction(action: String): Builder { + this.action = action + return this + } + + fun build(androidClickActionType: AndroidClickActionType): AndroidClickAction { + return AndroidClickAction( + androidClickActionType = androidClickActionType, + intent = intent.takeIf { androidClickActionType == AndroidClickActionType.CUSTOMIZE_ACTION }, + action = action.takeIf { androidClickActionType == AndroidClickActionType.CUSTOMIZE_ACTION }, + url = url.takeIf { androidClickActionType == AndroidClickActionType.OPEN_URL }, + ) + } + + } + + companion object { + + val validator = Validator() + + fun builder() = Builder() + + } + +} diff --git a/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/dto/android/AndroidColor.kt b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/dto/android/AndroidColor.kt new file mode 100644 index 0000000..000d163 --- /dev/null +++ b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/dto/android/AndroidColor.kt @@ -0,0 +1,82 @@ +package ru.touchin.push.message.provider.hpk.clients.hms_hpk.dto.android + +import ru.touchin.push.message.provider.hpk.base.builders.Buildable + +internal data class AndroidColor private constructor( + /** Alpha setting of the RGB color.*/ + val alpha: Float, + /** Red setting of the RGB color. */ + val red: Float, + /** Green setting of the RGB color. */ + val green: Float, + /** Green setting of the RGB color. */ + val blue: Float, +) { + + class Validator { + + fun check(androidColor: AndroidColor) { + with(androidColor) { + require(alpha in COLOR_RANGE_CONSTRAINT) { "Alpha must be locate between [0,1]" } + require(red in COLOR_RANGE_CONSTRAINT) { "Red must be locate between [0,1]" } + require(green in COLOR_RANGE_CONSTRAINT) { "Green must be locate between [0,1]" } + require(blue in COLOR_RANGE_CONSTRAINT) { "Blue must be locate between [0,1]" } + } + } + + private companion object { + + private const val ZERO: Float = 0.0f + private const val ONE: Float = 1.0f + val COLOR_RANGE_CONSTRAINT = ZERO..ONE + + } + + } + + class Builder : Buildable { + + private var alpha: Float = 1.0f + private var red: Float = 0.0f + private var green: Float = 0.0f + private var blue: Float = 0.0f + + fun setAlpha(alpha: Float): Builder { + this.alpha = alpha + return this + } + + fun setRed(red: Float): Builder { + this.red = red + return this + } + + fun setGreen(green: Float): Builder { + this.green = green + return this + } + + fun setBlue(blue: Float): Builder { + this.blue = blue + return this + } + + fun build(): AndroidColor { + return AndroidColor( + alpha = alpha, + red = red, + green = green, + blue = blue + ) + } + } + + companion object { + + val validator = Validator() + + fun builder() = Builder() + + } + +} diff --git a/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/dto/android/AndroidLightSettings.kt b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/dto/android/AndroidLightSettings.kt new file mode 100644 index 0000000..7d4a837 --- /dev/null +++ b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/dto/android/AndroidLightSettings.kt @@ -0,0 +1,63 @@ +package ru.touchin.push.message.provider.hpk.clients.hms_hpk.dto.android + +import com.fasterxml.jackson.annotation.JsonProperty +import ru.touchin.push.message.provider.hpk.base.builders.Buildable + +internal data class AndroidLightSettings private constructor( + /** Breathing light color. */ + @JsonProperty("color") + val androidColor: AndroidColor, + /** Interval when a breathing light is on */ + val lightOnDuration: String, + /** Interval when a breathing light is off */ + val lightOffDuration: String, +) { + + class Validator { + + fun check(androidLightSettings: AndroidLightSettings) { + with(androidLightSettings) { + AndroidColor.validator.check(androidColor) + + require( + lightOnDuration.matches(LIGHT_DURATION_PATTERN) + ) { "light_on_duration pattern is wrong" } + require( + lightOffDuration.matches(LIGHT_DURATION_PATTERN) + ) { "light_off_duration pattern is wrong" } + } + } + + private companion object { + + val LIGHT_DURATION_PATTERN: Regex = Regex("\\d+|\\d+[sS]|\\d+.\\d{1,9}|\\d+.\\d{1,9}[sS]") + + } + + } + + class Builder : Buildable { + + fun build( + color: AndroidColor, + lightOnDuration: String, + lightOffDuration: String + ): AndroidLightSettings { + return AndroidLightSettings( + androidColor = color, + lightOnDuration = lightOnDuration, + lightOffDuration = lightOffDuration, + ) + } + + } + + companion object { + + val validator = Validator() + + fun builder() = Builder() + + } + +} diff --git a/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/dto/android/AndroidNotificationConfig.kt b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/dto/android/AndroidNotificationConfig.kt new file mode 100644 index 0000000..f947a0a --- /dev/null +++ b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/dto/android/AndroidNotificationConfig.kt @@ -0,0 +1,417 @@ +package ru.touchin.push.message.provider.hpk.clients.hms_hpk.dto.android + +import com.fasterxml.jackson.annotation.JsonProperty +import ru.touchin.push.message.provider.hpk.base.builders.Buildable +import ru.touchin.push.message.provider.hpk.clients.hms_hpk.dto.Notification +import ru.touchin.push.message.provider.hpk.clients.hms_hpk.enums.android.AndroidImportance +import ru.touchin.push.message.provider.hpk.clients.hms_hpk.enums.android.AndroidStyleType +import ru.touchin.push.message.provider.hpk.clients.hms_hpk.enums.android.AndroidVisibility + +internal data class AndroidNotificationConfig private constructor( + /** + * Title of an Android notification message. + * If the title parameter is set, the value of the [Notification.title] field is overwritten. + * */ + val title: String?, + /** + * Body of an Android notification message. + * If the body parameter is set, the value of the [Notification.body] field is overwritten. + * */ + val body: String?, + /** + * Custom app icon on the left of a notification message. + */ + val icon: String?, + /** Custom notification bar button color. */ + val color: String?, + val sound: String?, + /** Indicates whether to use the default ringtone. */ + val defaultSound: Boolean, + /** + * Message tag. + * Messages that use the same message tag in the same app will be overwritten by the latest message. + * */ + val tag: String?, + @JsonProperty("click_action") + val androidClickAction: AndroidClickAction?, + val bodyLocKey: String?, + val bodyLocArgs: Collection?, + val titleLocKey: String?, + val titleLocArgs: Collection?, + val multiLangKey: Map?, + /** Custom channel for displaying notification messages. */ + val channelId: String?, + /** Brief description of a notification message to an Android app. */ + val notifySummary: String?, + /** URL of the custom small image on the right of a notification message. */ + val image: String?, + /** Notification bar style. */ + @JsonProperty("style") + val androidStyleType: AndroidStyleType?, + /** Android notification message title in large text style. */ + val bigTitle: String?, + val bigBody: String?, + /** + * Unique notification ID of a message. + * If a message does not contain the ID or the ID is -1, the NC will generate a unique ID for the message. + * Different notification messages can use the same notification ID, so that new messages can overwrite old messages. + * */ + val notifyId: Int?, + /** + * Message group. + * For example, if 10 messages that contain the same value of group are sent to a device, + * the device displays only the latest message and the total number of messages received in the group, + * but does not display these 10 messages. + */ + val group: String?, + @JsonProperty("badge") + val androidBadgeNotification: AndroidBadgeNotification? = null, + val autoCancel: Boolean, + /** + * Time when Android notification messages are delivered, in the UTC timestamp format. + * If you send multiple messages at the same time, + * they will be sorted based on this value and displayed in the Android notification panel. + * Example: 2014-10-02T15:01:23.045123456Z + */ + @JsonProperty("when") + val sendAt: String?, + val localOnly: Boolean? = null, + /** + * Android notification message priority, which determines the message notification behavior of a user device. + */ + @JsonProperty("importance") + val androidImportance: AndroidImportance?, + /** Indicates whether to use the default vibration mode. */ + val useDefaultVibrate: Boolean, + /** Indicates whether to use the default breathing light. */ + val useDefaultLight: Boolean, + val vibrateConfig: Collection?, + /** Android notification message visibility. */ + @JsonProperty("visibility") + val androidVisibility: AndroidVisibility?, + @JsonProperty("light_settings") + val androidLightSettings: AndroidLightSettings?, + /** + * Indicates whether to display notification messages in the NC when your app is running in the foreground. + * If this parameter is not set, the default value true will be used, + * indicating that notification messages will be displayed in the NC when your app runs in the foreground. + * */ + val foregroundShow: Boolean, + val inboxContent: Collection?, + @JsonProperty("buttons") + val androidButtons: Collection?, + /** ID of the user-app relationship. */ + val profileId: String?, +) { + + class Validator { + + fun check(androidNotificationConfig: AndroidNotificationConfig, notification: Notification?) { + with(androidNotificationConfig) { + androidBadgeNotification?.let { AndroidBadgeNotification.validator.check(it) } + androidLightSettings?.also { AndroidLightSettings.validator.check(it) } + androidClickAction?.also { AndroidClickAction.validator.check(it) } + + require(!notification?.title.isNullOrBlank() || !title.isNullOrBlank()) { "title should be set" } + require(!notification?.body.isNullOrBlank() || !body.isNullOrBlank()) { "body should be set" } + + if (!color.isNullOrBlank()) { + require(color.matches(COLOR_PATTERN)) { "Wrong color format, color must be in the form #RRGGBB" } + } + if (!image.isNullOrBlank()) { + require(image.startsWith(HTTPS_URL_PATTERN)) { "notifyIcon must start with $HTTPS_URL_PATTERN" } + } + if (androidStyleType != null) { + when (androidStyleType) { + AndroidStyleType.DEFAULT -> { + // no verification + } + + AndroidStyleType.BIG_TEXT -> { + require( + !bigTitle.isNullOrBlank() && !bigBody.isNullOrBlank() + ) { "title and body are required when style is $androidStyleType" } + } + + AndroidStyleType.INBOX -> { + require( + !inboxContent.isNullOrEmpty() + ) { "inboxContent is required when style is $androidStyleType" } + require( + inboxContent.size <= INBOX_CONTENT_MAX_ITEMS + ) { "inboxContent must have at most $INBOX_CONTENT_MAX_ITEMS items" } + } + } + } + if (profileId != null) { + require( + profileId.length <= PROFILE_ID_MAX_LENGTH + ) { "profileId length cannot exceed $PROFILE_ID_MAX_LENGTH characters" } + } + } + } + + private companion object { + + val COLOR_PATTERN: Regex = Regex("^#[0-9a-fA-F]{6}$") + const val HTTPS_URL_PATTERN: String = "https" + const val INBOX_CONTENT_MAX_ITEMS: Byte = 5 + const val PROFILE_ID_MAX_LENGTH: Byte = 64 + + } + + } + + class Builder : Buildable { + + private var title: String? = null + private val body: String? = null + private var icon: String? = null + private var color: String? = null + private var sound: String? = null + private var defaultSound = false + private var tag: String? = null + private var bodyLocKey: String? = null + private val bodyLocArgs: MutableList = mutableListOf() + private var titleLocKey: String? = null + private val titleLocArgs: MutableList = mutableListOf() + private var multiLangkey: Map? = null + private var channelId: String? = null + private var notifySummary: String? = null + private var image: String? = null + private var androidStyleType: AndroidStyleType? = null + private var bigTitle: String? = null + private var bigBody: String? = null + private var notifyId: Int? = null + private var group: String? = null + private var androidBadgeNotification: AndroidBadgeNotification? = null + private var autoCancel = true + private var sendAt: String? = null + private var androidImportance: AndroidImportance? = null + private var useDefaultVibrate = false + private var useDefaultLight = false + private val vibrateConfig: MutableList = mutableListOf() + private var androidVisibility: AndroidVisibility? = null + private var androidLightSettings: AndroidLightSettings? = null + private var foregroundShow = false + private val inboxContent: MutableList = mutableListOf() + private val buttons: MutableList = mutableListOf() + private var profileId: String? = null + + fun setTitle(title: String): Builder { + this.title = title + return this + } + + fun setBody(body: String): Builder { + this.body = body + return this + } + + fun setIcon(icon: String): Builder { + this.icon = icon + return this + } + + fun setColor(color: String): Builder { + this.color = color + return this + } + + fun setSound(sound: String): Builder { + this.sound = sound + return this + } + + fun setDefaultSound(defaultSound: Boolean): Builder { + this.defaultSound = defaultSound + return this + } + + fun setTag(tag: String): Builder { + this.tag = tag + return this + } + + fun setBodyLocKey(bodyLocKey: String): Builder { + this.bodyLocKey = bodyLocKey + return this + } + + fun addBodyLocArgs(vararg arg: String): Builder { + bodyLocArgs.addAll(arg) + return this + } + + fun setTitleLocKey(titleLocKey: String): Builder { + this.titleLocKey = titleLocKey + return this + } + + fun addTitleLocArgs(vararg args: String): Builder { + titleLocArgs.addAll(args) + return this + } + + fun setMultiLangkey(multiLangkey: Map): Builder { + this.multiLangkey = multiLangkey + return this + } + + fun setChannelId(channelId: String): Builder { + this.channelId = channelId + return this + } + + fun setNotifySummary(notifySummary: String): Builder { + this.notifySummary = notifySummary + return this + } + + fun setImage(image: String): Builder { + this.image = image + return this + } + + fun setStyle(androidStyleType: AndroidStyleType): Builder { + this.androidStyleType = androidStyleType + return this + } + + fun setBigTitle(bigTitle: String): Builder { + this.bigTitle = bigTitle + return this + } + + fun setBigBody(bigBody: String): Builder { + this.bigBody = bigBody + return this + } + + fun setNotifyId(notifyId: Int): Builder { + this.notifyId = notifyId + return this + } + + fun setGroup(group: String): Builder { + this.group = group + return this + } + + fun setBadge(androidBadgeNotification: AndroidBadgeNotification): Builder { + this.androidBadgeNotification = androidBadgeNotification + return this + } + + fun setAutoCancel(autoCancel: Boolean): Builder { + this.autoCancel = autoCancel + return this + } + + fun sendAt(sendAt: String): Builder { + this.sendAt = sendAt + return this + } + + fun setImportance(androidImportance: AndroidImportance): Builder { + this.androidImportance = androidImportance + return this + } + + fun setUseDefaultVibrate(useDefaultVibrate: Boolean): Builder { + this.useDefaultVibrate = useDefaultVibrate + return this + } + + fun setUseDefaultLight(useDefaultLight: Boolean): Builder { + this.useDefaultLight = useDefaultLight + return this + } + + fun addVibrateConfig(vararg vibrateTimings: String): Builder { + vibrateConfig.addAll(vibrateTimings) + return this + } + + fun setAndroidVisibility(androidVisibility: AndroidVisibility): Builder { + this.androidVisibility = androidVisibility + return this + } + + fun setLightSettings(androidLightSettings: AndroidLightSettings): Builder { + this.androidLightSettings = androidLightSettings + return this + } + + fun setForegroundShow(foregroundShow: Boolean): Builder { + this.foregroundShow = foregroundShow + return this + } + + fun addInboxContent(vararg inboxContent: String): Builder { + this.inboxContent.addAll(inboxContent) + return this + } + + fun addButton(vararg button: AndroidButton): Builder { + buttons.addAll(button) + return this + } + + fun setProfileId(profileId: String): Builder { + this.profileId = profileId + return this + } + + fun build( + androidClickAction: AndroidClickAction, + ): AndroidNotificationConfig { + return AndroidNotificationConfig( + title = title, + body = body, + icon = icon, + color = color, + sound = sound, + defaultSound = defaultSound, + tag = tag, + androidClickAction = androidClickAction, + bodyLocKey = bodyLocKey, + bodyLocArgs = bodyLocArgs.takeIf(Collection<*>::isNotEmpty), + titleLocKey = titleLocKey, + titleLocArgs = titleLocArgs.takeIf(Collection<*>::isNotEmpty), + multiLangKey = multiLangkey, + channelId = channelId, + notifySummary = notifySummary, + image = image, + androidStyleType = androidStyleType, + bigTitle = bigTitle, + bigBody = bigBody, + notifyId = notifyId, + group = group, + androidBadgeNotification = androidBadgeNotification, + autoCancel = autoCancel, + sendAt = sendAt, + androidImportance = androidImportance, + useDefaultVibrate = useDefaultVibrate, + useDefaultLight = useDefaultLight, + vibrateConfig = vibrateConfig.takeIf(Collection<*>::isNotEmpty), + androidVisibility = androidVisibility, + androidLightSettings = androidLightSettings, + foregroundShow = foregroundShow, + inboxContent = inboxContent.takeIf(Collection<*>::isNotEmpty), + androidButtons = buttons.takeIf(Collection<*>::isNotEmpty), + profileId = profileId, + ) + } + + } + + companion object { + + val validator = Validator() + + fun builder() = Builder() + + } + +} diff --git a/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidActionType.kt b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidActionType.kt new file mode 100644 index 0000000..b6acf2d --- /dev/null +++ b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidActionType.kt @@ -0,0 +1,17 @@ +package ru.touchin.push.message.provider.hpk.clients.hms_hpk.enums.android + +import ru.touchin.push.message.provider.hpk.base.enums.ValueableSerializableEnum + +internal enum class AndroidActionType( + override val value: Short +) : ValueableSerializableEnum { + + OPEN_APP_HOME_PAGE(0), + OPEN_CUSTOM_APP_PAGE(1), + OPEN_WEB_PAGE(2), + DELETE_NOTIFICATION_MESSAGE(3), + + /** Only for Huawei devices */ + SHARE_NOTIFICATION_MESSAGE(4), + +} diff --git a/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidClickActionType.kt b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidClickActionType.kt new file mode 100644 index 0000000..edf1122 --- /dev/null +++ b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidClickActionType.kt @@ -0,0 +1,13 @@ +package ru.touchin.push.message.provider.hpk.clients.hms_hpk.enums.android + +import ru.touchin.push.message.provider.hpk.base.enums.ValueableSerializableEnum + +internal enum class AndroidClickActionType( + override val value: Short +) : ValueableSerializableEnum { + + CUSTOMIZE_ACTION(1), + OPEN_URL(2), + OPEN_APP(3), + +} diff --git a/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidFastAppTargetType.kt b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidFastAppTargetType.kt new file mode 100644 index 0000000..f0e083f --- /dev/null +++ b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidFastAppTargetType.kt @@ -0,0 +1,12 @@ +package ru.touchin.push.message.provider.hpk.clients.hms_hpk.enums.android + +import ru.touchin.push.message.provider.hpk.base.enums.ValueableSerializableEnum + +internal enum class AndroidFastAppTargetType( + override val value: Short +) : ValueableSerializableEnum { + + DEVELOPMENT(1), + PRODUCTION(2), + +} diff --git a/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidImportance.kt b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidImportance.kt new file mode 100644 index 0000000..0e957df --- /dev/null +++ b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidImportance.kt @@ -0,0 +1,13 @@ +package ru.touchin.push.message.provider.hpk.clients.hms_hpk.enums.android + +import ru.touchin.push.message.provider.hpk.base.enums.ValueableSerializableEnum + +internal enum class AndroidImportance( + override val value: String +) : ValueableSerializableEnum { + + LOW("LOW"), + NORMAL("NORMAL"), + HIGH("HIGH"), // TODO: check if this type is still supported by HMS HPK API + +} diff --git a/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidIntentType.kt b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidIntentType.kt new file mode 100644 index 0000000..a857f74 --- /dev/null +++ b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidIntentType.kt @@ -0,0 +1,12 @@ +package ru.touchin.push.message.provider.hpk.clients.hms_hpk.enums.android + +import ru.touchin.push.message.provider.hpk.base.enums.ValueableSerializableEnum + +enum class AndroidIntentType( + override val value: Short +) : ValueableSerializableEnum { + + INTENT(0), + ACTION(1), + +} diff --git a/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidStyleType.kt b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidStyleType.kt new file mode 100644 index 0000000..c9c8674 --- /dev/null +++ b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidStyleType.kt @@ -0,0 +1,13 @@ +package ru.touchin.push.message.provider.hpk.clients.hms_hpk.enums.android + +import ru.touchin.push.message.provider.hpk.base.enums.ValueableSerializableEnum + +enum class AndroidStyleType( + override val value: Short +) : ValueableSerializableEnum { + + DEFAULT(0), + BIG_TEXT(1), + INBOX(3), + +} diff --git a/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidTargetUserType.kt b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidTargetUserType.kt new file mode 100644 index 0000000..bdf5253 --- /dev/null +++ b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidTargetUserType.kt @@ -0,0 +1,13 @@ +package ru.touchin.push.message.provider.hpk.clients.hms_hpk.enums.android + +import ru.touchin.push.message.provider.hpk.base.enums.ValueableSerializableEnum + +internal enum class AndroidTargetUserType( + override val value: Short +) : ValueableSerializableEnum { + + TEST_USER(1), + FORMAL_USER(2), + VOIP_USER(3), + +} diff --git a/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidTopicOperation.kt b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidTopicOperation.kt new file mode 100644 index 0000000..2579cf2 --- /dev/null +++ b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidTopicOperation.kt @@ -0,0 +1,13 @@ +package ru.touchin.push.message.provider.hpk.clients.hms_hpk.enums.android + +import ru.touchin.push.message.provider.hpk.base.enums.ValueableSerializableEnum + +internal enum class AndroidTopicOperation( + override val value: String +) : ValueableSerializableEnum { + + SUBSCRIBE("subscribe"), + UNSUBSCRIBE("unsubscribe"), + LIST("list"), + +} diff --git a/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidUrgency.kt b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidUrgency.kt new file mode 100644 index 0000000..c6c0d31 --- /dev/null +++ b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidUrgency.kt @@ -0,0 +1,12 @@ +package ru.touchin.push.message.provider.hpk.clients.hms_hpk.enums.android + +import ru.touchin.push.message.provider.hpk.base.enums.ValueableSerializableEnum + +internal enum class AndroidUrgency( + override val value: String +) : ValueableSerializableEnum { + + HIGH("HIGH"), + NORMAL("NORMAL"), + +} diff --git a/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidVisibility.kt b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidVisibility.kt new file mode 100644 index 0000000..f7c6b32 --- /dev/null +++ b/push-message-provider-hpk/src/main/kotlin/ru/touchin/push/message/provider/hpk/clients/hms_hpk/enums/android/AndroidVisibility.kt @@ -0,0 +1,24 @@ +package ru.touchin.push.message.provider.hpk.clients.hms_hpk.enums.android + +import ru.touchin.push.message.provider.hpk.base.enums.ValueableSerializableEnum + +internal enum class AndroidVisibility( + override val value: String +) : ValueableSerializableEnum { + + /** The visibility is not specified. This value is equivalent to PRIVATE. */ + VISIBILITY_UNSPECIFIED("VISIBILITY_UNSPECIFIED"), + + /** + * If you have set a lock screen password and enabled Hide notification content under Settings > Notifications, + * the content of a received notification message is hidden on the lock screen. + * */ + PRIVATE("PRIVATE"), + + /** The content of a received notification message is displayed on the lock screen. */ + PUBLIC("PUBLIC"), + + /** A received notification message is not displayed on the lock screen. */ + SECRET("SECRET"), + +}