simplifying base models

new attachments
This commit is contained in:
2021-09-24 10:55:07 +03:00
parent 56fb93d2e4
commit e127501889
68 changed files with 1933 additions and 1559 deletions
+159 -224
View File
@@ -13,27 +13,22 @@ import com.meloda.fast.api.model.VkUser
import com.meloda.fast.api.model.attachments.*
import com.meloda.fast.api.model.base.BaseVkMessage
import com.meloda.fast.api.model.base.attachments.BaseVkAttachmentItem
import com.meloda.fast.api.network.VkErrors
object VkUtils {
fun isValidationRequired(throwable: Throwable): Boolean {
if (throwable !is VKException) return false
return throwable.error == VkErrors.NEED_VALIDATION
fun prepareMessageText(text: String, forConversations: Boolean? = null): String {
return text.apply {
if (forConversations == true) replace("\n", "")
replace("&amp", "&")
}
}
fun isCaptchaRequired(throwable: Throwable): Boolean {
if (throwable !is VKException) return false
return throwable.error == VkErrors.NEED_CAPTCHA
}
fun isPreviousMessageSentFiveMinutesAgo(prevMessage: VkMessage?, message: VkMessage?) =
prevMessage != null && message != null && (message.date - prevMessage.date >= 300)
fun prepareMessageText(text: String?): String? {
if (text == null) return null
return text
.replace("\n", " ")
.replace("&amp", "&")
}
fun isPreviousMessageFromDifferentSender(prevMessage: VkMessage?, message: VkMessage?) =
prevMessage != null && message != null && prevMessage.fromId != message.fromId
fun parseForwards(baseForwards: List<BaseVkMessage>?): List<VkMessage>? {
if (baseForwards.isNullOrEmpty()) return null
@@ -64,21 +59,15 @@ object VkUtils {
}
BaseVkAttachmentItem.AttachmentType.AUDIO -> {
val audio = baseAttachment.audio ?: continue
attachments += VkAudio(
link = audio.url
)
attachments += audio.asVkAudio()
}
BaseVkAttachmentItem.AttachmentType.FILE -> {
val file = baseAttachment.file ?: continue
attachments += VkFile(
link = file.url
)
attachments += file.asVkFile()
}
BaseVkAttachmentItem.AttachmentType.LINK -> {
val link = baseAttachment.link ?: continue
attachments += VkLink(
link = link.url
)
attachments += link.asVkLink()
}
BaseVkAttachmentItem.AttachmentType.MINI_APP -> {
val miniApp = baseAttachment.miniApp ?: continue
@@ -89,7 +78,7 @@ object VkUtils {
BaseVkAttachmentItem.AttachmentType.VOICE -> {
val voiceMessage = baseAttachment.voiceMessage ?: continue
attachments += VkVoiceMessage(
link = voiceMessage.linkMp3
link = voiceMessage.link_mp3
)
}
BaseVkAttachmentItem.AttachmentType.STICKER -> {
@@ -99,14 +88,12 @@ object VkUtils {
BaseVkAttachmentItem.AttachmentType.GIFT -> {
val gift = baseAttachment.gift ?: continue
attachments += VkGift(
link = gift.thumb48
link = gift.thumb_48
)
}
BaseVkAttachmentItem.AttachmentType.WALL -> {
val wall = baseAttachment.wall ?: continue
attachments += VkWall(
id = wall.id
)
attachments += wall.asVkWall()
}
BaseVkAttachmentItem.AttachmentType.GRAFFITI -> {
val graffiti = baseAttachment.graffiti ?: continue
@@ -129,15 +116,27 @@ object VkUtils {
BaseVkAttachmentItem.AttachmentType.CALL -> {
val call = baseAttachment.call ?: continue
attachments += VkCall(
initiatorId = call.initiatorId
initiatorId = call.initiator_id
)
}
BaseVkAttachmentItem.AttachmentType.GROUP_CALL_IN_PROGRESS -> {
val groupCall = baseAttachment.groupCall ?: continue
attachments += VkGroupCall(
initiatorId = groupCall.initiatorId
initiatorId = groupCall.initiator_id
)
}
BaseVkAttachmentItem.AttachmentType.CURATOR -> {
val curator = baseAttachment.curator ?: continue
attachments += curator.asVkCurator()
}
BaseVkAttachmentItem.AttachmentType.EVENT -> {
val event = baseAttachment.event ?: continue
attachments += event.asVkEvent()
}
BaseVkAttachmentItem.AttachmentType.STORY -> {
val story = baseAttachment.story ?: continue
attachments += story.asVkStory()
}
else -> continue
}
}
@@ -145,177 +144,12 @@ object VkUtils {
return attachments
}
fun getActionConversationText(
message: VkMessage,
youPrefix: String,
profiles: HashMap<Int, VkUser>? = null,
groups: HashMap<Int, VkGroup>? = null,
messageUser: VkUser? = null,
messageGroup: VkGroup? = null
): String? {
return when (message.getPreparedAction()) {
VkMessage.Action.CHAT_CREATE -> {
val text = message.actionText ?: return null
val prefix = when {
message.fromId == UserConfig.userId -> youPrefix
message.isGroup() -> messageGroup?.name
message.isUser() -> messageUser?.toString()
else -> return null
} ?: return null
"$prefix created «$text»"
}
VkMessage.Action.CHAT_TITLE_UPDATE -> {
val text = message.actionText ?: return null
val prefix = when {
message.fromId == UserConfig.userId -> youPrefix
message.isGroup() -> messageGroup?.name
message.isUser() -> messageUser?.toString()
else -> return null
} ?: return null
"$prefix renamed chat to «$text»"
}
VkMessage.Action.CHAT_PHOTO_UPDATE -> {
val prefix = when {
message.fromId == UserConfig.userId -> youPrefix
message.isGroup() -> messageGroup?.name
message.isUser() -> messageUser?.toString()
else -> return null
} ?: return null
"$prefix updated the chat photo"
}
VkMessage.Action.CHAT_PHOTO_REMOVE -> {
val prefix = when {
message.fromId == UserConfig.userId -> youPrefix
message.isGroup() -> messageGroup?.name
message.isUser() -> messageUser?.toString()
else -> return null
} ?: return null
"$prefix deleted the chat photo"
}
VkMessage.Action.CHAT_KICK_USER -> {
val memberId = message.actionMemberId ?: return null
val isUser = memberId > 0
val isGroup = memberId < 0
val actionUser = profiles?.get(memberId)
val actionGroup = groups?.get(memberId)
if (isUser && actionUser == null) return null
if (isGroup && actionGroup == null) return null
if (memberId == message.fromId) {
val prefix = if (memberId == UserConfig.userId) youPrefix
else actionUser.toString()
"$prefix left the chat"
} else {
val prefix =
if (message.fromId == UserConfig.userId) youPrefix
else messageUser?.toString() ?: messageGroup?.toString() ?: "..."
val postfix =
if (memberId == UserConfig.userId) youPrefix.lowercase()
else actionUser.toString()
"$prefix kicked $postfix"
}
}
VkMessage.Action.CHAT_INVITE_USER -> {
val memberId = message.actionMemberId ?: 0
val isUser = memberId > 0
val isGroup = memberId < 0
val actionUser = profiles?.get(memberId)
val actionGroup = groups?.get(memberId)
if (isUser && actionUser == null) return null
if (isGroup && actionGroup == null) return null
if (memberId == message.fromId) {
val prefix = if (memberId == UserConfig.userId) youPrefix
else actionUser.toString()
"$prefix returned the chat"
} else {
val prefix = if (message.fromId == UserConfig.userId) youPrefix
else messageUser?.toString() ?: messageGroup?.toString() ?: "..."
val postfix =
if (memberId == UserConfig.userId) youPrefix.lowercase()
else actionUser.toString()
"$prefix invited $postfix"
}
}
VkMessage.Action.CHAT_INVITE_USER_BY_LINK -> {
val prefix = when {
message.fromId == UserConfig.userId -> youPrefix
message.isUser() -> messageUser?.toString()
else -> return null
} ?: return null
"$prefix joined the chat via link"
}
VkMessage.Action.CHAT_INVITE_USER_BY_CALL_LINK -> {
val prefix = when {
message.fromId == UserConfig.userId -> youPrefix
message.isUser() -> messageUser?.toString()
else -> return null
} ?: return null
"$prefix joined the call via link"
}
VkMessage.Action.CHAT_PIN_MESSAGE -> {
val prefix = when {
message.fromId == UserConfig.userId -> youPrefix
message.isGroup() -> messageGroup?.name
message.isUser() -> messageUser?.toString()
else -> return null
} ?: return null
val actionMessage = message.actionMessage
"$prefix pinned message ${if (actionMessage == null) "" else "«$actionMessage»"}".trim()
}
VkMessage.Action.CHAT_UNPIN_MESSAGE -> {
val prefix = when {
message.fromId == UserConfig.userId -> youPrefix
message.isGroup() -> messageGroup?.name
message.isUser() -> messageUser?.toString()
else -> return null
} ?: return null
"$prefix unpinned message"
}
VkMessage.Action.CHAT_SCREENSHOT -> {
val prefix = when {
message.fromId == UserConfig.userId -> youPrefix
message.isGroup() -> messageGroup?.name
message.isUser() -> messageUser?.toString()
else -> return null
} ?: return null
"$prefix took a screenshot"
}
VkMessage.Action.CHAT_STYLE_UPDATE -> {
val prefix = when {
message.fromId == UserConfig.userId -> youPrefix
message.isUser() -> messageUser?.toString()
else -> return null
} ?: return null
"$prefix changed chat theme"
}
null -> null
else -> "[${message.action}]"
}
}
fun getActionMessageText(
context: Context,
message: VkMessage,
youPrefix: String,
profiles: HashMap<Int, VkUser>? = null,
groups: HashMap<Int, VkGroup>? = null,
profiles: Map<Int, VkUser>? = null,
groups: Map<Int, VkGroup>? = null,
messageUser: VkUser? = null,
messageGroup: VkGroup? = null
): SpannableString? {
@@ -330,7 +164,8 @@ object VkUtils {
else -> return null
} ?: return null
val spanText = "$prefix created «$text»"
val spanText =
context.getString(R.string.message_action_chat_created, prefix, text)
SpannableString(spanText).also {
it.setSpan(StyleSpan(Typeface.BOLD), 0, prefix.length, 0)
@@ -351,8 +186,8 @@ object VkUtils {
else -> return null
} ?: return null
val spanText = "$prefix renamed chat to «$text»"
val spanText =
context.getString(R.string.message_action_chat_renamed, prefix, text)
val startIndex = spanText.indexOf(text)
SpannableString(spanText).also {
@@ -370,7 +205,9 @@ object VkUtils {
else -> return null
} ?: return null
val spanText = "$prefix updated the chat photo"
val spanText =
context.getString(R.string.message_action_chat_photo_update, prefix)
SpannableString(spanText).also {
it.setSpan(StyleSpan(Typeface.BOLD), 0, prefix.length, 0)
}
@@ -383,7 +220,9 @@ object VkUtils {
else -> return null
} ?: return null
val spanText = "$prefix deleted the chat photo"
val spanText =
context.getString(R.string.message_action_chat_photo_remove, prefix)
SpannableString(spanText).also {
it.setSpan(StyleSpan(Typeface.BOLD), 0, prefix.length, 0)
}
@@ -402,7 +241,10 @@ object VkUtils {
if (memberId == message.fromId) {
val prefix = if (memberId == UserConfig.userId) youPrefix
else actionUser.toString()
val spanText = "$prefix left the chat"
val spanText =
context.getString(R.string.message_action_chat_user_left, prefix)
SpannableString(spanText).also {
it.setSpan(StyleSpan(Typeface.BOLD), 0, prefix.length, 0)
}
@@ -410,11 +252,17 @@ object VkUtils {
val prefix =
if (message.fromId == UserConfig.userId) youPrefix
else messageUser?.toString() ?: messageGroup?.toString() ?: "..."
val postfix =
if (memberId == UserConfig.userId) youPrefix.lowercase()
else actionUser.toString()
val spanText = "$prefix kicked $postfix"
val spanText =
context.getString(
R.string.message_action_chat_user_kicked,
prefix,
postfix
)
val startIndex = spanText.indexOf(postfix)
SpannableString(spanText).also {
@@ -439,18 +287,27 @@ object VkUtils {
if (memberId == message.fromId) {
val prefix = if (memberId == UserConfig.userId) youPrefix
else actionUser.toString()
val spanText = "$prefix returned the chat"
val spanText =
context.getString(R.string.message_action_chat_user_returned, prefix)
SpannableString(spanText).also {
it.setSpan(StyleSpan(Typeface.BOLD), 0, prefix.length, 0)
}
} else {
val prefix = if (message.fromId == UserConfig.userId) youPrefix
else messageUser?.toString() ?: messageGroup?.toString() ?: "..."
val postfix =
if (memberId == UserConfig.userId) youPrefix.lowercase()
else actionUser.toString()
val spanText = "$prefix invited $postfix"
val spanText =
context.getString(
R.string.message_action_chat_user_invited,
prefix,
postfix
)
val startIndex = spanText.indexOf(postfix)
SpannableString(spanText).also {
@@ -468,7 +325,9 @@ object VkUtils {
else -> return null
} ?: return null
val spanText = "$prefix joined the chat via link"
val spanText =
context.getString(R.string.message_action_chat_user_joined_by_link, prefix)
SpannableString(spanText).also {
it.setSpan(StyleSpan(Typeface.BOLD), 0, prefix.length, 0)
}
@@ -480,7 +339,9 @@ object VkUtils {
else -> return null
} ?: return null
val spanText = "$prefix joined the call via link"
val spanText =
context.getString(R.string.message_action_chat_user_joined_by_call_link, prefix)
SpannableString(spanText).also {
it.setSpan(StyleSpan(Typeface.BOLD), 0, prefix.length, 0)
}
@@ -493,16 +354,11 @@ object VkUtils {
else -> return null
} ?: return null
val actionMessage = message.actionMessage ?: return null
val spanText = "$prefix pinned message «$actionMessage»"
val startIndex = spanText.indexOf(actionMessage)
val spanText =
context.getString(R.string.message_action_chat_pin_message, prefix).trim()
SpannableString(spanText).also {
it.setSpan(StyleSpan(Typeface.BOLD), 0, prefix.length, 0)
it.setSpan(
StyleSpan(Typeface.BOLD), startIndex, startIndex + actionMessage.length, 0
)
}
}
VkMessage.Action.CHAT_UNPIN_MESSAGE -> {
@@ -513,7 +369,9 @@ object VkUtils {
else -> return null
} ?: return null
val spanText = "$prefix unpinned message"
val spanText =
context.getString(R.string.message_action_chat_unpin_message, prefix)
SpannableString(spanText).also {
it.setSpan(StyleSpan(Typeface.BOLD), 0, prefix.length, 0)
}
@@ -526,7 +384,9 @@ object VkUtils {
else -> return null
} ?: return null
val spanText = "$prefix took a screenshot"
val spanText =
context.getString(R.string.message_action_chat_screenshot, prefix)
SpannableString(spanText).also {
it.setSpan(StyleSpan(Typeface.BOLD), 0, prefix.length, 0)
}
@@ -538,7 +398,9 @@ object VkUtils {
else -> return null
} ?: return null
val spanText = "$prefix changed chat theme"
val spanText =
context.getString(R.string.message_action_chat_style_update, prefix)
SpannableString(spanText).also {
it.setSpan(StyleSpan(Typeface.BOLD), 0, prefix.length, 0)
}
@@ -548,6 +410,26 @@ object VkUtils {
}
}
fun getActionConversationText(
context: Context,
message: VkMessage,
youPrefix: String,
profiles: HashMap<Int, VkUser>? = null,
groups: HashMap<Int, VkGroup>? = null,
messageUser: VkUser? = null,
messageGroup: VkGroup? = null
): String? {
return getActionMessageText(
context = context,
message = message,
youPrefix = youPrefix,
profiles = profiles,
groups = groups,
messageUser = messageUser,
messageGroup = messageGroup
)?.toString()
}
fun getForwardsConversationText(context: Context, message: VkMessage): String? {
if (message.forwards.isNullOrEmpty()) return null
@@ -570,10 +452,19 @@ object VkUtils {
return message.attachments?.let { attachments ->
if (attachments.size == 1) {
getAttachmentTypeByClass(attachments[0])?.let { getAttachmentTextByType(it) }
getAttachmentTypeByClass(attachments[0])?.let {
getAttachmentTextByType(
context,
it
)
}
} else {
if (isAttachmentsHaveOneType(attachments)) {
getAttachmentTypeByClass(attachments[0])?.let { getAttachmentTextByType(it) }
getAttachmentTypeByClass(attachments[0])?.let {
getAttachmentTextByType(
context, it, attachments.size
)
}
} else {
context.getString(R.string.message_attachments_many)
}
@@ -622,6 +513,8 @@ object VkUtils {
BaseVkAttachmentItem.AttachmentType.WALL_REPLY -> R.drawable.ic_attachment_wall_reply
BaseVkAttachmentItem.AttachmentType.CALL -> R.drawable.ic_attachment_call
BaseVkAttachmentItem.AttachmentType.GROUP_CALL_IN_PROGRESS -> R.drawable.ic_attachment_group_call
BaseVkAttachmentItem.AttachmentType.STORY -> R.drawable.ic_attachment_story
else -> return null
}
return ContextCompat.getDrawable(context, resId)
@@ -657,14 +550,56 @@ object VkUtils {
is VkWallReply -> BaseVkAttachmentItem.AttachmentType.WALL_REPLY
is VkCall -> BaseVkAttachmentItem.AttachmentType.CALL
is VkGroupCall -> BaseVkAttachmentItem.AttachmentType.GROUP_CALL_IN_PROGRESS
is VkEvent -> BaseVkAttachmentItem.AttachmentType.EVENT
is VkCurator -> BaseVkAttachmentItem.AttachmentType.CURATOR
is VkStory -> BaseVkAttachmentItem.AttachmentType.STORY
else -> null
}
}
fun getAttachmentTextByType(attachmentType: BaseVkAttachmentItem.AttachmentType): String? {
fun getAttachmentTextByType(
context: Context,
attachmentType: BaseVkAttachmentItem.AttachmentType,
size: Int = 1
): String {
return when (attachmentType) {
BaseVkAttachmentItem.AttachmentType.PHOTO ->
context.resources.getQuantityString(R.plurals.attachment_photos, size, size)
BaseVkAttachmentItem.AttachmentType.VIDEO ->
context.resources.getQuantityString(R.plurals.attachment_videos, size, size)
BaseVkAttachmentItem.AttachmentType.AUDIO ->
context.resources.getQuantityString(R.plurals.attachment_audios, size, size)
BaseVkAttachmentItem.AttachmentType.FILE ->
context.resources.getQuantityString(R.plurals.attachment_files, size, size)
BaseVkAttachmentItem.AttachmentType.LINK ->
context.resources.getString(R.string.message_attachments_link)
BaseVkAttachmentItem.AttachmentType.VOICE ->
context.resources.getString(R.string.message_attachments_voice)
BaseVkAttachmentItem.AttachmentType.MINI_APP ->
context.resources.getString(R.string.message_attachments_mini_app)
BaseVkAttachmentItem.AttachmentType.STICKER ->
context.resources.getString(R.string.message_attachments_sticker)
BaseVkAttachmentItem.AttachmentType.GIFT ->
context.resources.getString(R.string.message_attachments_gift)
BaseVkAttachmentItem.AttachmentType.WALL ->
context.resources.getString(R.string.message_attachments_wall)
BaseVkAttachmentItem.AttachmentType.GRAFFITI ->
context.resources.getString(R.string.message_attachments_graffiti)
BaseVkAttachmentItem.AttachmentType.POLL ->
context.resources.getString(R.string.message_attachments_poll)
BaseVkAttachmentItem.AttachmentType.WALL_REPLY ->
context.resources.getString(R.string.message_attachments_wall_reply)
BaseVkAttachmentItem.AttachmentType.CALL ->
context.resources.getString(R.string.message_attachments_call)
BaseVkAttachmentItem.AttachmentType.GROUP_CALL_IN_PROGRESS ->
context.resources.getString(R.string.message_attachments_call_in_progress)
BaseVkAttachmentItem.AttachmentType.EVENT ->
context.resources.getString(R.string.message_attachments_event)
BaseVkAttachmentItem.AttachmentType.CURATOR ->
context.resources.getString(R.string.message_attachments_curator)
BaseVkAttachmentItem.AttachmentType.STORY ->
context.resources.getString(R.string.message_attachments_story)
else -> attachmentType.value
}
}
}
@@ -5,7 +5,11 @@ import kotlinx.parcelize.Parcelize
@Parcelize
data class VkAudio(
val link: String
val id: Int,
val title: String,
val artist: String,
val url: String,
val duration: Int
) : VkAttachment() {
@IgnoredOnParcel
@@ -0,0 +1,8 @@
package com.meloda.fast.api.model.attachments
import kotlinx.parcelize.Parcelize
@Parcelize
data class VkCurator(
val id: Int
) : VkAttachment()
@@ -0,0 +1,8 @@
package com.meloda.fast.api.model.attachments
import kotlinx.parcelize.Parcelize
@Parcelize
data class VkEvent(
val id: Int
) : VkAttachment()
@@ -5,7 +5,11 @@ import kotlinx.parcelize.Parcelize
@Parcelize
data class VkFile(
val link: String
val id: Int,
val title: String,
val ext: String,
val size: Int,
val url: String
) : VkAttachment() {
@IgnoredOnParcel
@@ -5,7 +5,12 @@ import kotlinx.parcelize.Parcelize
@Parcelize
data class VkLink(
val link: String
val url: String,
val title: String?,
val caption: String?,
val photo: VkPhoto?,
val target: String,
val isFavorite: Boolean
) : VkAttachment() {
@IgnoredOnParcel
@@ -1,6 +1,6 @@
package com.meloda.fast.api.model.attachments
import com.meloda.fast.api.model.base.attachments.Size
import com.meloda.fast.api.model.base.attachments.BaseVkPhoto
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize
@@ -12,7 +12,7 @@ data class VkPhoto(
val ownerId: Int,
val hasTags: Boolean,
val accessKey: String?,
val sizes: List<Size>,
val sizes: List<BaseVkPhoto.Size>,
val text: String,
val userId: Int?
) : VkAttachment() {
@@ -20,7 +20,7 @@ data class VkPhoto(
@IgnoredOnParcel
val className: String = this::class.java.name
fun sizeOfType(type: Char): Size? {
fun sizeOfType(type: Char): BaseVkPhoto.Size? {
for (size in sizes) {
if (size.type == type.toString())
return size
@@ -1,7 +1,6 @@
package com.meloda.fast.api.model.attachments
import com.meloda.fast.api.model.base.attachments.BaseVkSticker
import com.meloda.fast.api.model.base.attachments.StickerSize
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize
@@ -16,7 +15,7 @@ data class VkSticker(
@IgnoredOnParcel
val className: String = this::class.java.name
fun urlForSize(@StickerSize size: Int): String? {
fun urlForSize(size: Int): String? {
for (image in images) {
if (image.width == size) return image.url
}
@@ -0,0 +1,11 @@
package com.meloda.fast.api.model.attachments
import kotlinx.parcelize.Parcelize
@Parcelize
data class VkStory(
val id: Int,
val ownerId: Int,
val date: Int,
val photo: VkPhoto
) : VkAttachment()
@@ -8,7 +8,7 @@ import kotlinx.parcelize.Parcelize
data class VkVideo(
val id: Int,
val images: List<BaseVkVideo.Image>,
val firstFrames: List<BaseVkVideo.FirstFrame>
val firstFrames: List<BaseVkVideo.FirstFrame>?
) : VkAttachment() {
@IgnoredOnParcel
@@ -1,11 +1,23 @@
package com.meloda.fast.api.model.attachments
import com.meloda.fast.api.model.base.attachments.BaseVkAttachmentItem
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize
@Parcelize
data class VkWall(
val id: Int
val id: Int,
val fromId: Int,
val toId: Int,
val date: Int,
val text: String,
val attachments: List<BaseVkAttachmentItem>?,
val comments: Int,
val likes: Int,
val reposts: Int,
val views: Int,
val isFavorite: Boolean,
val accessKey: String
) : VkAttachment() {
@IgnoredOnParcel
@@ -1,90 +1,70 @@
package com.meloda.fast.api.model.base
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import com.meloda.fast.api.model.VkConversation
import com.meloda.fast.api.model.VkMessage
import com.meloda.fast.api.model.base.attachments.BaseVkGroupCall
import kotlinx.parcelize.Parcelize
@Parcelize
data class BaseVkConversation(
val peer: Peer,
@SerializedName("last_message_id")
val lastMessageId: Int,
@SerializedName("in_read")
val inRead: Int,
@SerializedName("out_read")
val outRead: Int,
@SerializedName("sort_id")
val sortId: SortId,
@SerializedName("last_conversation_message_id")
val lastConversationMessageId: Int,
@SerializedName("is_marked_unread")
val isMarkedUnread: Boolean,
val last_message_id: Int,
val in_read: Int,
val out_read: Int,
val sort_id: SortId,
val last_conversation_message_id: Int,
val is_marked_unread: Boolean,
val important: Boolean,
@SerializedName("push_settings")
val pushSettings: PushSettings,
@SerializedName("can_write")
val canWrite: CanWrite,
@SerializedName("can_send_money")
val canSendMoney: Boolean,
@SerializedName("can_receive_money")
val canReceiveMoney: Boolean,
@SerializedName("chat_settings")
val chatSettings: ChatSettings?,
@SerializedName("call_in_progress")
val callInProgress: CallInProgress?,
@SerializedName("unread_count")
val unreadCount: Int?
val push_settings: PushSettings,
val can_write: CanWrite,
val can_send_money: Boolean,
val can_receive_money: Boolean,
val chat_settings: ChatSettings?,
val call_in_progress: CallInProgress?,
val unread_count: Int?
) : Parcelable {
fun asVkConversation(lastMessage: VkMessage? = null) = VkConversation(
id = peer.id,
title = chatSettings?.title,
photo200 = chatSettings?.photo?.photo200,
title = chat_settings?.title,
photo200 = chat_settings?.photo?.photo_200,
type = peer.type,
callInProgress = callInProgress != null,
isPhantom = chatSettings?.isDisappearing == true,
lastConversationMessageId = lastConversationMessageId,
inRead = inRead,
outRead = outRead,
isMarkedUnread = isMarkedUnread,
lastMessageId = lastMessageId,
unreadCount = unreadCount,
membersCount = chatSettings?.membersCount,
ownerId = chatSettings?.ownerId,
isPinned = sortId.majorId > 0
callInProgress = call_in_progress != null,
isPhantom = chat_settings?.is_disappearing == true,
lastConversationMessageId = last_conversation_message_id,
inRead = in_read,
outRead = out_read,
isMarkedUnread = is_marked_unread,
lastMessageId = last_message_id,
unreadCount = unread_count,
membersCount = chat_settings?.members_count,
ownerId = chat_settings?.owner_id,
isPinned = sort_id.major_id > 0
).apply {
this.lastMessage = lastMessage
this.pinnedMessage = chatSettings?.pinnedMessage?.asVkMessage()
this.pinnedMessage = chat_settings?.pinned_message?.asVkMessage()
}
@Parcelize
data class Peer(
val id: Int,
val type: String,
@SerializedName("local_id")
val localId: Int
val local_id: Int
) : Parcelable
@Parcelize
data class SortId(
@SerializedName("major_id")
val majorId: Int,
@SerializedName("minor_id")
val minorId: Int
val major_id: Int,
val minor_id: Int
) : Parcelable
@Parcelize
data class PushSettings(
@SerializedName("disabled_forever")
val disabledForever: Boolean,
@SerializedName("no_sound")
val noSound: Boolean,
@SerializedName("disabled_mentions")
val disabledMentions: Boolean,
@SerializedName("disabled_mass_mentions")
val disabledMassMentions: Boolean
val disabled_forever: Boolean,
val no_sound: Boolean,
val disabled_mentions: Boolean,
val disabled_mass_mentions: Boolean
) : Parcelable
@Parcelize
@@ -94,75 +74,50 @@ data class BaseVkConversation(
@Parcelize
data class ChatSettings(
@SerializedName("owner_id")
val ownerId: Int,
val owner_id: Int,
val title: String,
val state: String,
val acl: Acl,
@SerializedName("members_count")
val membersCount: Int,
@SerializedName("friends_count")
val friendsCount: Int,
val members_count: Int,
val friends_count: Int,
val photo: Photo?,
@SerializedName("admin_ids")
val adminsIds: List<Int>,
@SerializedName("active_ids")
val activeIds: List<Int>,
@SerializedName("is_group_channel")
val isGroupChannel: Boolean,
@SerializedName("is_disappearing")
val isDisappearing: Boolean,
@SerializedName("is_service")
val isService: Boolean,
val admin_ids: List<Int>,
val active_ids: List<Int>,
val is_group_channel: Boolean,
val is_disappearing: Boolean,
val is_service: Boolean,
val theme: String?,
@SerializedName("pinned_message")
val pinnedMessage: BaseVkMessage?
val pinned_message: BaseVkMessage?
) : Parcelable {
@Parcelize
data class Acl(
@SerializedName("can_change_info")
val canChangeInfo: Boolean,
@SerializedName("can_change_invite_link")
val canChangeInviteLink: Boolean,
@SerializedName("can_change_pin")
val canChangePin: Boolean,
@SerializedName("can_invite")
val canInvite: Boolean,
@SerializedName("can_promote_users")
val canPromoteUsers: Boolean,
@SerializedName("can_see_invite_link")
val canSeeInviteLink: Boolean,
@SerializedName("can_moderate")
val canModerate: Boolean,
@SerializedName("can_copy_chat")
val canCopyChat: Boolean,
@SerializedName("can_call")
val canCall: Boolean,
@SerializedName("can_use_mass_mentions")
val canUseMassMentions: Boolean,
@SerializedName("can_change_style")
val canChangeStyle: Boolean
val can_change_info: Boolean,
val can_change_invite_link: Boolean,
val can_change_pin: Boolean,
val can_invite: Boolean,
val can_promote_users: Boolean,
val can_see_invite_link: Boolean,
val can_moderate: Boolean,
val can_copy_chat: Boolean,
val can_call: Boolean,
val can_use_mass_mentions: Boolean,
val can_change_style: Boolean
) : Parcelable
@Parcelize
data class Photo(
@SerializedName("photo_50")
val photo50: String?,
@SerializedName("photo_100")
val photo100: String?,
@SerializedName("photo_200")
val photo200: String?,
@SerializedName("is_default_photo")
val isDefaultPhoto: Boolean
val photo_50: String?,
val photo_100: String?,
val photo_200: String?,
val is_default_photo: Boolean
) : Parcelable
}
@Parcelize
data class CallInProgress(
val participants: Participants,
@SerializedName("join_link")
val joinLink: String
val participants: BaseVkGroupCall.Participants,
val join_link: String
) : Parcelable {
@Parcelize
@@ -1,7 +1,6 @@
package com.meloda.fast.api.model.base
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import com.meloda.fast.api.model.VkGroup
import kotlinx.parcelize.Parcelize
@@ -9,33 +8,24 @@ import kotlinx.parcelize.Parcelize
data class BaseVkGroup(
val id: Int,
val name: String,
@SerializedName("screen_name")
val screenName: String,
@SerializedName("is_closed")
val isClosed: Int,
val screen_name: String,
val is_closed: Int,
val type: String,
@SerializedName("is_admin")
val isAdmin: Int,
@SerializedName("is_member")
val isMember: Int,
@SerializedName("is_advertiser")
val isAdvertiser: Int,
@SerializedName("photo_50")
val photo50: String?,
@SerializedName("photo_100")
val photo100: String?,
@SerializedName("photo_200")
val photo200: String?,
@SerializedName("members_count")
val membersCount: Int?
val is_admin: Int,
val is_member: Int,
val is_advertiser: Int,
val photo_50: String?,
val photo_100: String?,
val photo_200: String?,
val members_count: Int?
) : Parcelable {
fun asVkGroup() = VkGroup(
id = -id,
name = name,
screenName = screenName,
photo200 = photo200,
membersCount = membersCount
screenName = screen_name,
photo200 = photo_200,
membersCount = members_count
)
}
@@ -1,7 +1,6 @@
package com.meloda.fast.api.model.base
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import com.meloda.fast.api.VkUtils
import com.meloda.fast.api.model.VkMessage
import com.meloda.fast.api.model.base.attachments.BaseVkAttachmentItem
@@ -10,23 +9,17 @@ import kotlinx.parcelize.Parcelize
@Parcelize
data class BaseVkMessage(
val date: Int,
@SerializedName("from_id")
val fromId: Int,
val from_id: Int,
val id: Int,
val out: Int,
@SerializedName("peer_id")
val peerId: Int,
val peer_id: Int,
val text: String,
@SerializedName("conversation_message_id")
val conversationMessageId: Int,
@SerializedName("fwd_messages")
val fwdMessages: List<BaseVkMessage>? = listOf(),
val conversation_message_id: Int,
val fwd_messages: List<BaseVkMessage>? = listOf(),
val important: Boolean,
@SerializedName("random_id")
val randomId: Int,
val random_id: Int,
val attachments: List<BaseVkAttachmentItem> = listOf(),
@SerializedName("is_hidden")
val isHidden: Boolean,
val is_hidden: Boolean,
val payload: String,
val geo: Geo?,
val action: Action?,
@@ -37,20 +30,20 @@ data class BaseVkMessage(
id = id,
text = if (text.isBlank()) null else text,
isOut = out == 1,
peerId = peerId,
fromId = fromId,
peerId = peer_id,
fromId = from_id,
date = date,
randomId = randomId,
randomId = random_id,
action = action?.type,
actionMemberId = action?.memberId,
actionMemberId = action?.member_id,
actionText = action?.text,
actionConversationMessageId = action?.conversationMessageId,
actionConversationMessageId = action?.conversation_message_id,
actionMessage = action?.message,
geoType = geo?.type,
important = important
).also {
it.attachments = VkUtils.parseAttachments(attachments)
it.forwards = VkUtils.parseForwards(fwdMessages)
it.forwards = VkUtils.parseForwards(fwd_messages)
}
@Parcelize
@@ -71,11 +64,9 @@ data class BaseVkMessage(
@Parcelize
data class Action(
val type: String,
@SerializedName("member_id")
val memberId: Int?,
val member_id: Int?,
val text: String?,
@SerializedName("conversation_message_id")
val conversationMessageId: Int?,
val conversation_message_id: Int?,
val message: String?
) : Parcelable
@@ -1,35 +1,24 @@
package com.meloda.fast.api.model.base
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import com.meloda.fast.api.model.VkUser
import kotlinx.parcelize.Parcelize
@Parcelize
data class BaseVkUser(
val id: Int,
@SerializedName("first_name")
val firstName: String,
@SerializedName("last_name")
val lastName: String,
@SerializedName("can_access_closed")
val canAccessClosed: Boolean,
@SerializedName("is_closed")
val isClosed: Boolean,
@SerializedName("can_invite_to_chats")
val canInviteToChats: Boolean,
val first_name: String,
val last_name: String,
val can_access_closed: Boolean,
val is_closed: Boolean,
val can_invite_to_chats: Boolean,
val sex: Int?,
@SerializedName("photo_50")
val photo50: String?,
@SerializedName("photo_100")
val photo100: String?,
@SerializedName("photo_200")
val photo200: String?,
val photo_50: String?,
val photo_100: String?,
val photo_200: String?,
val online: Int?,
@SerializedName("online_info")
val onlineInfo: OnlineInfo?,
@SerializedName("screen_name")
val screenName: String
val online_info: OnlineInfo?,
val screen_name: String
//...other fields
) : Parcelable {
@@ -37,24 +26,20 @@ data class BaseVkUser(
data class OnlineInfo(
val visible: Boolean,
val status: String,
@SerializedName("last_seen")
val lastSeen: Int?,
@SerializedName("is_online")
val isOnline: Boolean?,
@SerializedName("online_mobile")
val isOnlineMobile: Boolean?,
@SerializedName("app_id")
val appId: Int?
val last_seen: Int?,
val is_online: Boolean?,
val online_mobile: Boolean?,
val app_id: Int?
) : Parcelable
fun asVkUser() = VkUser(
id = id,
firstName = firstName,
lastName = lastName,
firstName = first_name,
lastName = last_name,
online = online == 1,
photo200 = photo200,
lastSeen = onlineInfo?.lastSeen,
lastSeenStatus = onlineInfo?.status
photo200 = photo_200,
lastSeen = online_info?.last_seen,
lastSeenStatus = online_info?.status
)
}
@@ -1,6 +1,7 @@
package com.meloda.fast.api.model.base.attachments
import android.os.Parcelable
import android.util.Log
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize
@@ -26,12 +27,16 @@ data class BaseVkAttachmentItem(
val wallReply: BaseVkWallReply?,
val call: BaseVkCall?,
@SerializedName("group_call_in_progress")
val groupCall: BaseVkGroupCall?
val groupCall: BaseVkGroupCall?,
val curator: BaseVkCurator?,
val event: BaseVkEvent?,
val story: BaseVkStory?
) : Parcelable {
fun getPreparedType() = AttachmentType.parse(type)
enum class AttachmentType(val value: String) {
enum class AttachmentType(var value: String) {
UNKNOWN("unknown"),
PHOTO("photo"),
VIDEO("video"),
AUDIO("audio"),
@@ -46,11 +51,22 @@ data class BaseVkAttachmentItem(
POLL("poll"),
WALL_REPLY("wall_reply"),
CALL("call"),
GROUP_CALL_IN_PROGRESS("group_call_in_progress")
GROUP_CALL_IN_PROGRESS("group_call_in_progress"),
CURATOR("curator"),
EVENT("event"),
STORY("story")
;
companion object {
fun parse(value: String) = values().firstOrNull { it.value == value }
fun parse(value: String): AttachmentType? {
val parsedValue = values().firstOrNull { it.value == value } ?: UNKNOWN
if (parsedValue == UNKNOWN) {
Log.e("AttachmentType", "Unknown attachment type: $value")
}
return parsedValue
}
}
}
@@ -1,7 +1,7 @@
package com.meloda.fast.api.model.base.attachments
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import com.meloda.fast.api.model.attachments.VkAudio
import kotlinx.parcelize.Parcelize
@Parcelize
@@ -12,37 +12,33 @@ data class BaseVkAudio(
val duration: Int,
val url: String,
val date: Int,
@SerializedName("owner_id")
val ownerId: Int,
@SerializedName("access_key")
val accessKey: String,
@SerializedName("is_explicit")
val isExplicit: Boolean,
@SerializedName("is_focus_track")
val isFocusTrack: Boolean,
@SerializedName("is_licensed")
val isLicensed: Boolean,
@SerializedName("track_code")
val trackCode: String,
@SerializedName("genre_id")
val genreId: Int,
val owner_id: Int,
val access_key: String,
val is_explicit: Boolean,
val is_focus_track: Boolean,
val is_licensed: Boolean,
val track_code: String,
val genre_id: Int,
val album: Album,
@SerializedName("short_videos_allowed")
val shortVideosAllowed: Boolean,
@SerializedName("stories_allowed")
val storiesAllowed: Boolean,
@SerializedName("stories_cover_allowed")
val storiesCoverAllowed: Boolean
val short_videos_allowed: Boolean,
val stories_allowed: Boolean,
val stories_cover_allowed: Boolean
) : BaseVkAttachment() {
fun asVkAudio() = VkAudio(
id = id,
title = title,
artist = artist,
url = url,
duration = duration
)
@Parcelize
data class Album(
val id: Int,
val title: String,
@SerializedName("owner_id")
val ownerId: Int,
@SerializedName("access_key")
val accessKey: String,
val owner_id: Int,
val access_key: String,
val thumb: Thumb
) : Parcelable {
@@ -50,22 +46,13 @@ data class BaseVkAudio(
data class Thumb(
val width: Int,
val height: Int,
@SerializedName("photo_34")
val photo34: String,
@SerializedName("photo_68")
val photo68: String,
@SerializedName("photo_135")
val photo135: String,
@SerializedName("photo_270")
val photo270: String,
@SerializedName("photo_300")
val photo300: String,
@SerializedName("photo_600")
val photo600: String,
@SerializedName("photo_1200")
val photo1200: String
val photo_34: String,
val photo_68: String,
val photo_135: String,
val photo_270: String,
val photo_300: String,
val photo_600: String,
val photo_1200: String
) : Parcelable
}
}
@@ -1,15 +1,12 @@
package com.meloda.fast.api.model.base.attachments
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize
@Parcelize
data class BaseVkCall(
@SerializedName("initiator_id")
val initiatorId: Int,
@SerializedName("receiver_id")
val receiverId: Int,
val initiator_id: Int,
val receiver_id: Int,
val state: String,
val time: Int,
val duration: Int,
@@ -0,0 +1,27 @@
package com.meloda.fast.api.model.base.attachments
import android.os.Parcelable
import com.meloda.fast.api.model.attachments.VkCurator
import kotlinx.parcelize.Parcelize
@Parcelize
data class BaseVkCurator(
val id: Int,
val name: String,
val description: String,
val url: String,
val photo: List<Photo>
) : BaseVkAttachment() {
fun asVkCurator() = VkCurator(
id = id
)
@Parcelize
data class Photo(
val height: Int,
val url: String,
val width: String
) : Parcelable
}
@@ -0,0 +1,22 @@
package com.meloda.fast.api.model.base.attachments
import com.meloda.fast.api.model.attachments.VkEvent
import kotlinx.parcelize.Parcelize
@Parcelize
data class BaseVkEvent(
val button_text: String,
val id: Int,
val is_favorite: Boolean,
val text: String,
val address: String,
val friends: List<Int> = listOf(),
val member_status: Int,
val time: Int
) : BaseVkAttachment() {
fun asVkEvent() = VkEvent(
id = id
)
}
@@ -1,14 +1,13 @@
package com.meloda.fast.api.model.base.attachments
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import com.meloda.fast.api.model.attachments.VkFile
import kotlinx.parcelize.Parcelize
@Parcelize
data class BaseVkFile(
val id: Int,
@SerializedName("owner_id")
val ownerId: Int,
val owner_id: Int,
val title: String,
val size: Int,
val ext: String,
@@ -16,14 +15,19 @@ data class BaseVkFile(
val type: Int,
val url: String,
val preview: Preview?,
@SerializedName("is_licensed")
val isLicensed: Int,
@SerializedName("access_key")
val accessKey: String,
@SerializedName("web_preview_url")
val webPreviewUrl: String?
val ic_licensed: Int,
val access_key: String,
val web_preview_url: String?
) : BaseVkAttachment() {
fun asVkFile() = VkFile(
id = id,
title = title,
ext = ext,
url = url,
size = size
)
@Parcelize
data class Preview(
val photo: Photo?,
@@ -31,15 +35,24 @@ data class BaseVkFile(
) : Parcelable {
@Parcelize
data class Photo(val sizes: List<Size>) : Parcelable
data class Photo(val sizes: List<Size>) : Parcelable {
@Parcelize
data class Size(
val height: Int,
val width: Int,
val type: String,
val src: String
) : Parcelable
}
@Parcelize
data class Video(
val src: String,
val width: Int,
val height: Int,
@SerializedName("file_size")
val fileSize: Int
val file_size: Int
) : Parcelable
}
@@ -1,16 +1,12 @@
package com.meloda.fast.api.model.base.attachments
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize
@Parcelize
data class BaseVkGift(
val id: Int,
@SerializedName("thumb_256")
val thumb256: String?,
@SerializedName("thumb_96")
val thumb96: String?,
@SerializedName("thumb_48")
val thumb48: String
val thumb_256: String?,
val thumb_96: String?,
val thumb_48: String
) : Parcelable
@@ -1,17 +1,14 @@
package com.meloda.fast.api.model.base.attachments
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize
@Parcelize
data class BaseVkGraffiti(
val id: Int,
@SerializedName("owner_id")
val ownerId: Int,
val owner_id: Int,
val url: String,
val width: Int,
val height: Int,
@SerializedName("access_key")
val accessKey: String
val access_key: String
) : Parcelable
@@ -1,15 +1,12 @@
package com.meloda.fast.api.model.base.attachments
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize
@Parcelize
data class BaseVkGroupCall(
@SerializedName("initiator_id")
val initiatorId: Int,
@SerializedName("join_link")
val joinLink: String,
val initiator_id: Int,
val join_link: String,
val participants: Participants
) : Parcelable {
@@ -1,15 +1,25 @@
package com.meloda.fast.api.model.base.attachments
import com.google.gson.annotations.SerializedName
import com.meloda.fast.api.model.attachments.VkLink
import kotlinx.parcelize.Parcelize
@Parcelize
data class BaseVkLink(
val url: String,
val title: String,
val caption: String,
val photo: BaseVkPhoto,
val title: String?,
val caption: String?,
val photo: BaseVkPhoto?,
val target: String,
@SerializedName("is_favorite")
val isFavorite: Boolean
) : BaseVkAttachment()
val is_favorite: Boolean
) : BaseVkAttachment() {
fun asVkLink() = VkLink(
url = url,
title = title,
caption = caption,
photo = photo?.asVkPhoto(),
target = target,
isFavorite = is_favorite
)
}
@@ -10,8 +10,7 @@ data class BaseVkMiniApp(
val description: String,
val app: App,
val images: List<Image>?,
@SerializedName("button_text")
val buttonText: String
val button_text: String
) : Parcelable {
@Parcelize
@@ -1,47 +1,43 @@
package com.meloda.fast.api.model.base.attachments
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import com.meloda.fast.api.model.attachments.VkPhoto
import kotlinx.parcelize.Parcelize
@Parcelize
data class BaseVkPhoto(
@SerializedName("album_id")
val albumId: Int,
val album_id: Int,
val date: Int,
val id: Int,
@SerializedName("owner_id")
val ownerId: Int,
@SerializedName("has_tags")
val hasTags: Boolean,
@SerializedName("access_key")
val accessKey: String?,
val owner_id: Int,
val has_tags: Boolean,
val access_key: String?,
val sizes: List<Size>,
val text: String,
@SerializedName("user_id")
val userId: Int?
val user_id: Int?,
val lat: Double?,
val long: Double?,
val post_id: Int?
) : BaseVkAttachment() {
fun asVkPhoto() = VkPhoto(
albumId = albumId,
albumId = album_id,
date = date,
id = id,
ownerId = ownerId,
hasTags = hasTags,
accessKey = accessKey,
ownerId = owner_id,
hasTags = has_tags,
accessKey = access_key,
sizes = sizes,
text = text,
userId = userId
userId = user_id
)
}
@Parcelize
data class Size(
val height: Int,
val width: Int,
val type: String,
val url: String
) : Parcelable
@Parcelize
data class Size(
val height: Int,
val width: Int,
val type: String,
@SerializedName("url", alternate = ["src"])
val url: String,
) : Parcelable
}
@@ -1,7 +1,6 @@
package com.meloda.fast.api.model.base.attachments
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize
@Parcelize
@@ -11,30 +10,20 @@ data class BaseVkPoll(
val votes: Int,
val anonymous: Boolean,
val closed: Boolean,
@SerializedName("end_date")
val endDate: Int,
@SerializedName("is_board")
val isBoard: Boolean,
@SerializedName("can_vote")
val canVote: Boolean,
@SerializedName("can_edit")
val canEdit: Boolean,
@SerializedName("can_report")
val canReport: Boolean,
@SerializedName("can_share")
val canShare: Boolean,
val end_date: Int,
val is_board: Boolean,
val can_vote: Boolean,
val can_edit: Boolean,
val can_report: Boolean,
val can_share: Boolean,
val created: Int,
@SerializedName("owner_id")
val ownerId: Int,
val owner_id: Int,
val question: String,
@SerializedName("disable_unvote")
val disableUnVote: Boolean,
val disable_unvote: Boolean,
val friends: List<Friend>?,
@SerializedName("embed_hash")
val embedHash: String,
val embed_hash: String,
val answers: List<Answer>,
@SerializedName("author_id")
val authorId: Int,
val author_id: Int,
val background: Background?
) : Parcelable {
@@ -1,30 +1,24 @@
package com.meloda.fast.api.model.base.attachments
import android.os.Parcelable
import androidx.annotation.IntDef
import com.google.gson.annotations.SerializedName
import com.meloda.fast.api.model.attachments.VkSticker
import kotlinx.parcelize.Parcelize
@Parcelize
data class BaseVkSticker(
@SerializedName("product_id")
val productId: Int,
@SerializedName("sticker_id")
val stickerId: Int,
val product_id: Int,
val sticker_id: Int,
val images: List<Image>,
@SerializedName("images_with_background")
val imagesWithBackground: List<Image>,
@SerializedName("animation_url")
val animationUrl: String?,
val images_with_background: List<Image>,
val animation_url: String?,
val animations: List<Animation>?
) : Parcelable {
fun asVkSticker() = VkSticker(
id = stickerId,
productId = productId,
id = sticker_id,
productId = product_id,
images = images,
backgroundImages = imagesWithBackground
backgroundImages = images_with_background
)
@Parcelize
@@ -41,6 +35,3 @@ data class BaseVkSticker(
) : Parcelable
}
@IntDef(64, 128, 256, 352)
annotation class StickerSize
@@ -0,0 +1,52 @@
package com.meloda.fast.api.model.base.attachments
import android.os.Parcelable
import com.meloda.fast.api.model.attachments.VkStory
import kotlinx.parcelize.Parcelize
@Parcelize
data class BaseVkStory(
val id: Int,
val owner_id: Int,
val access_key: String,
val can_comment: Int,
val can_reply: Int,
val can_like: Boolean,
val can_share: Int,
val can_hide: Int,
val date: Int,
val expires_at: Int,
val is_ads: Boolean,
val photo: BaseVkPhoto,
val replies: Replies,
val is_one_time: Boolean,
val track_code: String,
val type: String,
val views: Int,
val likes_count: Int,
val reaction_set_id: String,
val is_restricted: Boolean,
val no_sound: Boolean,
val need_mute: Boolean,
val mute_reply: Boolean,
val can_ask: Int,
val can_ask_anonymous: Int,
val preloading_enabled: Boolean,
val narratives_count: Int,
val can_use_in_narrative: Boolean
) : BaseVkAttachment() {
fun asVkStory() = VkStory(
id = id,
ownerId = owner_id,
date = date,
photo = photo.asVkPhoto()
)
@Parcelize
data class Replies(
val count: Int,
val new: Int
) : Parcelable
}
@@ -1,11 +1,9 @@
package com.meloda.fast.api.model.base.attachments
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import com.meloda.fast.api.model.attachments.VkVideo
import kotlinx.parcelize.Parcelize
//not all fields
@Parcelize
data class BaseVkVideo(
val id: Int,
@@ -20,45 +18,30 @@ data class BaseVkVideo(
val added: Int,
val type: String,
val views: Int,
@SerializedName("can_comment")
val canComment: Int,
@SerializedName("can_edit")
val canEdit: Int,
@SerializedName("can_like")
val canLike: Int,
@SerializedName("can_repost")
val canRepost: Int,
@SerializedName("can_subscribe")
val canSubscribe: Int,
@SerializedName("can_add_to_faves")
val canAddToFaves: Int,
@SerializedName("can_add")
val canAdd: Int,
@SerializedName("can_attach_link")
val canAttachLink: Int,
@SerializedName("access_key")
val accessKey: String,
@SerializedName("owner_id")
val ownerId: Int,
@SerializedName("ov_id")
val ovId: String,
@SerializedName("is_favorite")
val isFavorite: Boolean,
@SerializedName("track_code")
val trackCode: String,
val can_comment: Int,
val can_edit: Int,
val can_like: Int,
val can_repost: Int,
val can_subscribe: Int,
val can_add_to_faves: Int,
val can_add: Int,
val can_attach_link: Int,
val access_key: String,
val owner_id: Int,
val ov_id: String,
val is_favorite: Boolean,
val track_code: String,
val image: List<Image>,
@SerializedName("first_frame")
val firstFrame: List<FirstFrame>,
val first_frame: List<FirstFrame>,
val files: File,
@SerializedName("timeline_thumbs")
val timelineThumbs: TimelineThumbs
//ads
val timeline_thumbs: TimelineThumbs,
val ads: Ads
) : BaseVkAttachment() {
fun asVkVideo() = VkVideo(
id = id,
images = image,
firstFrames = firstFrame
firstFrames = first_frame
)
@Parcelize
@@ -66,8 +49,7 @@ data class BaseVkVideo(
val height: Int,
val width: Int,
val url: String,
@SerializedName("with_padding")
val withPadding: Int
val with_padding: Int
) : Parcelable
@Parcelize
@@ -86,34 +68,62 @@ data class BaseVkVideo(
val mp4_1080: String?,
val mp4_1440: String?,
val hls: String,
@SerializedName("dash_uni")
val dashUni: String,
@SerializedName("dash_sep")
val dashSep: String,
@SerializedName("hls_ondemand")
val hlsOnDemand: String,
@SerializedName("dash_ondemand")
val dashOnDemand: String,
@SerializedName("failover_host")
val failOverHost: String
val dash_uni: String,
val dash_sep: String,
val hls_ondemand: String,
val dash_ondemand: String,
val failover_host: String
) : Parcelable
@Parcelize
data class TimelineThumbs(
@SerializedName("count_per_image")
val countPerImage: Int,
@SerializedName("count_per_row")
val countPerRow: Int,
@SerializedName("count_total")
val countTotal: Int,
@SerializedName("frame_height")
val frameHeight: Int,
@SerializedName("frame_width")
val frameWidth: Float,
val count_per_image: Int,
val count_per_row: Int,
val count_total: Int,
val frame_height: Int,
val frame_width: Float,
val links: List<String>,
@SerializedName("is_uv")
val isUv: Boolean,
val is_uv: Boolean,
val frequency: Int
) : Parcelable
@Parcelize
data class Ads(
val slot_id: Int,
val timeout: Int,
val can_play: Int,
val params: Params,
val sections: List<String>,
val midroll_percents: List<Float>
) : Parcelable {
@Parcelize
data class Params(
val vk_id: Int,
val duration: Int,
val video_id: String,
val pl: Int,
val content_id: String,
val lang: Int,
val puid1: String,
val puid2: Int,
val puid3: Int,
val puid5: Int,
val puid6: Int,
val puid7: Int,
val puid9: Int,
val puid10: Int,
val puid12: Int,
val puid13: Int,
val puid14: Int,
val puid15: Int,
val puid18: Int,
val puid21: Int,
val sign: String,
val groupId: Int,
val vk_catid: Int,
val is_xz_video: Int
) : Parcelable
}
}
@@ -1,23 +1,17 @@
package com.meloda.fast.api.model.base.attachments
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize
@Parcelize
data class BaseVkVoiceMessage(
val id: Int,
@SerializedName("owner_id")
val ownerId: Int,
val owner_id: Int,
val duration: Int,
val waveform: List<Int>,
@SerializedName("link_ogg")
val linkOgg: String,
@SerializedName("link_mp3")
val linkMp3: String,
@SerializedName("access_key")
val accessKey: String,
@SerializedName("transcript_state")
val transcriptState: String,
val link_ogg: String,
val link_mp3: String,
val access_key: String,
val transcript_state: String,
val transcript: String
) : Parcelable
@@ -1,34 +1,43 @@
package com.meloda.fast.api.model.base.attachments
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import com.meloda.fast.api.model.attachments.VkWall
import kotlinx.parcelize.Parcelize
@Parcelize
data class BaseVkWall(
val id: Int,
@SerializedName("from_id")
val fromId: Int,
@SerializedName("to_id")
val toId: Int,
val from_id: Int,
val to_id: Int,
val date: Int,
val text: String,
val attachments: List<BaseVkAttachmentItem>?,
@SerializedName("post_source")
val postSource: PostSource,
val post_source: PostSource,
val comments: Comments,
val likes: Likes,
val reposts: Reposts,
val views: Views,
@SerializedName("is_favorite")
val isFavorite: Boolean,
val is_favorite: Boolean,
val donut: Donut,
@SerializedName("access_key")
val accessKey: String,
@SerializedName("short_text_rate")
val shortTextRate: Double
val access_key: String,
val short_text_rate: Double
) : Parcelable {
fun asVkWall() = VkWall(
id = id,
fromId = from_id,
toId = to_id,
date = date,
text = text,
attachments = attachments,
comments = comments.count,
likes = likes.count,
reposts = reposts.count,
views = views.count,
isFavorite = is_favorite,
accessKey = access_key
)
@Parcelize
data class PostSource(
val type: String,
@@ -38,28 +47,22 @@ data class BaseVkWall(
@Parcelize
data class Comments(
val count: Int,
@SerializedName("can_post")
val canPost: Int,
@SerializedName("groups_can_post")
val groupsCanPost: Boolean
val can_post: Int,
val groups_can_post: Boolean
) : Parcelable
@Parcelize
data class Likes(
val count: Int,
@SerializedName("user_likes")
val userLikes: Int,
@SerializedName("can_like")
val canLike: Int,
@SerializedName("can_publish")
val canPublish: Int,
val user_likes: Int,
val can_like: Int,
val can_publish: Int,
) : Parcelable
@Parcelize
data class Reposts(
val count: Int,
@SerializedName("user_reposted")
val userReposted: Int
val user_reposted: Int
) : Parcelable
@Parcelize
@@ -69,8 +72,7 @@ data class BaseVkWall(
@Parcelize
data class Donut(
@SerializedName("is_donut")
val isDonut: Boolean
val is_donut: Boolean
) : Parcelable
}
@@ -1,39 +1,29 @@
package com.meloda.fast.api.model.base.attachments
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize
@Parcelize
data class BaseVkWallReply(
val id: Int,
@SerializedName("from_id")
val fromId: Int,
val from_id: Int,
val date: Int,
val text: String,
@SerializedName("post_id")
val postId: Int,
@SerializedName("owner_id")
val ownerId: Int,
@SerializedName("parents_stack")
val parentsStack: List<Int>,
val post_id: Int,
val owner_id: Int,
val parents_stack: List<Int>,
val likes: Likes,
@SerializedName("reply_to_user")
val replyToUser: Int?,
@SerializedName("reply_to_comment")
val replyToComment: Int?
val reply_to_user: Int?,
val reply_to_comment: Int?
) : Parcelable {
@Parcelize
data class Likes(
val count: Int,
@SerializedName("can_like")
val canLike: Int,
@SerializedName("user_likes")
val userLikes: Int,
@SerializedName("can_publish")
val canPublish: Int
val can_like: Int,
val user_likes: Int,
val can_publish: Int
) : Parcelable
}
@@ -77,18 +77,21 @@ internal class ResultCall<T>(proxy: Call<T>) : CallDelegate<T, Answer<T>>(proxy)
) : Callback<T> {
override fun onResponse(call: Call<T>, response: Response<T>) {
var isVkException = true
val result: Answer<T> =
if (response.isSuccessful) {
val baseBody = response.body()
if (baseBody !is ApiResponse<*>) Answer.Success(baseBody as T)
else {
val body = baseBody as ApiResponse<*>
if (body.error != null) Answer.Error(body.error)
else Answer.Success(body as T)
if (body.error != null) {
Answer.Error(body.error)
} else Answer.Success(body as T)
}
} else Answer.Error(IOException(response.errorBody()?.string() ?: ""))
if (result is Answer.Error) if (checkErrors(call, result)) return
if (result is Answer.Error && isVkException) if (checkErrors(call, result)) return
callback.onResponse(proxy, Response.success(result))