Skip to content

Commit 8b224bd

Browse files
committed
Rewrite SendAnimation to Kotlin
1 parent 1357ae5 commit 8b224bd

File tree

2 files changed

+130
-80
lines changed

2 files changed

+130
-80
lines changed

library/src/main/java/com/pengrad/telegrambot/request/SendAnimation.java

Lines changed: 0 additions & 80 deletions
This file was deleted.
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
package com.pengrad.telegrambot.request
2+
3+
import com.pengrad.telegrambot.model.MessageEntity
4+
import com.pengrad.telegrambot.model.request.ParseMode
5+
import com.pengrad.telegrambot.utility.kotlin.optionalRequestParameter
6+
import java.io.File
7+
8+
class SendAnimation(
9+
chatId: Long? = null,
10+
channelUsername: String? = null,
11+
12+
animationUrl: String? = null,
13+
animationFile: File? = null,
14+
animationBytes: ByteArray? = null
15+
) : AbstractThumbnailedMultipartRequest<SendAnimation>(
16+
chatId = chatId,
17+
channelUsername = channelUsername,
18+
19+
contentParameterName = "animation",
20+
contentUrl = animationUrl,
21+
contentFile = animationFile,
22+
contentBytes = animationBytes,
23+
24+
defaultFileName = ContentTypes.GIF_FILE_NAME,
25+
defaultContentType = ContentTypes.GIF_MIME_TYPE
26+
) {
27+
28+
29+
constructor(chatId: Long, animationUrl: String) : this(
30+
chatId = chatId,
31+
channelUsername = null,
32+
animationUrl = animationUrl
33+
)
34+
35+
constructor(channelUsername: String, animationUrl: String) : this(
36+
chatId = null,
37+
channelUsername = channelUsername,
38+
animationUrl = animationUrl
39+
)
40+
41+
42+
constructor(chatId: Long, animationFile: File) : this(
43+
chatId = chatId,
44+
channelUsername = null,
45+
animationFile = animationFile
46+
)
47+
48+
constructor(channelUsername: String, animationFile: File) : this(
49+
chatId = null,
50+
channelUsername = channelUsername,
51+
animationFile = animationFile
52+
)
53+
54+
55+
constructor(chatId: Long, animationBytes: ByteArray) : this(
56+
chatId = chatId,
57+
channelUsername = null,
58+
animationBytes = animationBytes
59+
)
60+
61+
constructor(channelUsername: String, animationBytes: ByteArray) : this(
62+
chatId = null,
63+
channelUsername = channelUsername,
64+
animationBytes = animationBytes
65+
)
66+
67+
68+
@Deprecated("Use constructor with chatId or channelUsername instead", ReplaceWith("SendAnimation(chatId, animation)"))
69+
constructor(chatId: Any, animation: String) : this(
70+
chatId = (chatId as? Number)?.toLong(),
71+
channelUsername = chatId as? String,
72+
animationUrl = animation
73+
) {
74+
checkDeprecatedConstructorParameters()
75+
}
76+
77+
@Deprecated("Use constructor with chatId or channelUsername instead", ReplaceWith("SendAnimation(chatId, animation)"))
78+
constructor(chatId: Any, animation: File) : this(
79+
chatId = (chatId as? Number)?.toLong(),
80+
channelUsername = chatId as? String,
81+
animationFile = animation
82+
) {
83+
checkDeprecatedConstructorParameters()
84+
}
85+
86+
@Deprecated("Use constructor with chatId or channelUsername instead", ReplaceWith("SendAnimation(chatId, animation)"))
87+
constructor(chatId: Any, animation: ByteArray) : this(
88+
chatId = (chatId as? Number)?.toLong(),
89+
channelUsername = chatId as? String,
90+
animationBytes = animation
91+
) {
92+
checkDeprecatedConstructorParameters()
93+
}
94+
95+
@Suppress("NOTHING_TO_INLINE")
96+
private inline fun checkDeprecatedConstructorParameters() {
97+
if (this.chatId == null && this.channelUsername == null) {
98+
throw IllegalArgumentException("chatId parameter must be either Long or String")
99+
}
100+
}
101+
102+
var caption: String? by optionalRequestParameter()
103+
var parseMode: ParseMode? by optionalRequestParameter()
104+
var captionEntities: List<MessageEntity>? by optionalRequestParameter()
105+
var showCaptionAboveMedia: Boolean? by optionalRequestParameter()
106+
var hasSpoiler: Boolean? by optionalRequestParameter()
107+
108+
var duration: Int? by optionalRequestParameter()
109+
var width: Int? by optionalRequestParameter()
110+
var height: Int? by optionalRequestParameter()
111+
112+
fun caption(caption: String) = apply { this.caption = caption }
113+
114+
fun parseMode(parseMode: ParseMode) = apply { this.parseMode = parseMode }
115+
116+
fun captionEntities(captionEntities: List<MessageEntity>) = apply { this.captionEntities = captionEntities }
117+
118+
fun captionEntities(vararg captionEntities: MessageEntity) = apply { this.captionEntities = captionEntities.toList() }
119+
120+
fun showCaptionAboveMedia(showCaptionAboveMedia: Boolean) = apply { this.showCaptionAboveMedia = showCaptionAboveMedia }
121+
122+
fun hasSpoiler(hasSpoiler: Boolean) = apply { this.hasSpoiler = hasSpoiler }
123+
124+
fun duration(duration: Int) = apply { this.duration = duration }
125+
126+
fun width(width: Int) = apply { this.width = width }
127+
128+
fun height(height: Int) = apply { this.height = height }
129+
130+
}

0 commit comments

Comments
 (0)