diff --git a/app/src/main/kotlin/com/meloda/fast/api/UserConfig.kt b/app/src/main/kotlin/com/meloda/fast/api/UserConfig.kt index 3d882c2c..e40a107e 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/UserConfig.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/UserConfig.kt @@ -1,5 +1,6 @@ package com.meloda.fast.api +import com.meloda.fast.api.model.VkUser import com.meloda.fast.common.AppGlobal object UserConfig { @@ -30,4 +31,6 @@ object UserConfig { fun isLoggedIn() = userId > 0 && accessToken.isNotBlank() + var vkUser: VkUser? = null + } \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/VkUtils.kt b/app/src/main/kotlin/com/meloda/fast/api/VkUtils.kt new file mode 100644 index 00000000..e714f6da --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/VkUtils.kt @@ -0,0 +1,357 @@ +package com.meloda.fast.api + +import android.content.Context +import com.meloda.fast.R +import com.meloda.fast.api.model.VkGroup +import com.meloda.fast.api.model.VkMessage +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 + +object VkUtils { + + fun parseForwards(baseForwards: List?): List? { + if (baseForwards.isNullOrEmpty()) return null + + val forwards = mutableListOf() + + for (baseForward in baseForwards) { + forwards += baseForward.asVkMessage() + } + + return forwards + } + + fun parseAttachments(baseAttachments: List?): List? { + if (baseAttachments.isNullOrEmpty()) return null + + val attachments = mutableListOf() + + for (baseAttachment in baseAttachments) { + when (baseAttachment.getPreparedType()) { + BaseVkAttachmentItem.AttachmentType.PHOTO -> { + val photo = baseAttachment.photo ?: continue + attachments += VkPhoto( + link = photo.sizes[0].url + ) + } + BaseVkAttachmentItem.AttachmentType.VIDEO -> { + val video = baseAttachment.video ?: continue + attachments += VkVideo( + link = video.player + ) + } + BaseVkAttachmentItem.AttachmentType.AUDIO -> { + val audio = baseAttachment.audio ?: continue + attachments += VkAudio( + link = audio.url + ) + } + BaseVkAttachmentItem.AttachmentType.FILE -> { + val file = baseAttachment.file ?: continue + attachments += VkFile( + link = file.url + ) + } + BaseVkAttachmentItem.AttachmentType.LINK -> { + val link = baseAttachment.link ?: continue + attachments += VkLink( + link = link.url + ) + } + BaseVkAttachmentItem.AttachmentType.MINI_APP -> { + val miniApp = baseAttachment.miniApp ?: continue + attachments += VkMiniApp( + link = miniApp.app.shareUrl + ) + } + BaseVkAttachmentItem.AttachmentType.VOICE -> { + val voiceMessage = baseAttachment.voiceMessage ?: continue + attachments += VkVoiceMessage( + link = voiceMessage.linkMp3 + ) + } + BaseVkAttachmentItem.AttachmentType.STICKER -> { + val sticker = baseAttachment.sticker ?: continue + attachments += VkSticker( + link = sticker.images[0].url + ) + } + BaseVkAttachmentItem.AttachmentType.GIFT -> { + val gift = baseAttachment.gift ?: continue + attachments += VkGift( + link = gift.thumb48 + ) + } + BaseVkAttachmentItem.AttachmentType.WALL -> { + val wall = baseAttachment.wall ?: continue + attachments += VkWall( + id = wall.id + ) + } + BaseVkAttachmentItem.AttachmentType.GRAFFITI -> { + val graffiti = baseAttachment.graffiti ?: continue + attachments += VkGraffiti( + link = graffiti.url + ) + } + BaseVkAttachmentItem.AttachmentType.POLL -> { + val poll = baseAttachment.poll ?: continue + attachments += VkPoll( + id = poll.id + ) + } + BaseVkAttachmentItem.AttachmentType.WALL_REPLY -> { + val wallReply = baseAttachment.wallReply ?: continue + attachments += VkWallReply( + id = wallReply.id + ) + } + BaseVkAttachmentItem.AttachmentType.CALL -> { + val call = baseAttachment.call ?: continue + attachments += VkCall( + initiatorId = call.initiatorId + ) + } + else -> continue + } + } + + return attachments + } + + fun getActionConversationText( + message: VkMessage, + youPrefix: String, + profiles: HashMap? = null, + groups: HashMap? = 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) +// val actionUser = profiles?.find { it.id == memberId } +// val actionGroup = groups?.find { it.id == 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) +// val actionUser = profiles?.find { it.id == memberId } +// val actionGroup = groups?.find { it.id == 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 ?: return null + + "$prefix pinned message «$actionMessage»" + } + 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" + } + null -> null + else -> "[${message.action}]" + } + } + + fun getForwardsConversationText(context: Context, message: VkMessage): String? { + if (message.forwards.isNullOrEmpty()) return null + + return message.forwards?.let { forwards -> + context.getString( + if (forwards.size == 1) R.string.forwarded_message + else R.string.forwarded_messages + ) + } + } + + fun getAttachmentConversationText(context: Context, message: VkMessage): String? { + message.geoType?.let { + return when (it) { + "point" -> context.getString(R.string.message_geo_point) + else -> context.getString(R.string.message_geo) + } + } + if (message.attachments.isNullOrEmpty()) return null + + return message.attachments?.let { attachments -> + if (attachments.size == 1) { + getAttachmentTypeByClass(attachments[0])?.let { getAttachmentTextByType(it) } + } else { + if (isAttachmentsHaveOneType(attachments)) { + getAttachmentTypeByClass(attachments[0])?.let { getAttachmentTextByType(it) } + } else { + context.getString(R.string.message_attachments_many) + } + } + } + } + + fun isAttachmentsHaveOneType(attachments: List): Boolean { + if (attachments.isEmpty()) return true + if (attachments.size == 1) return true + + val firstType = getAttachmentTypeByClass(attachments[0]) + for (i in 1 until attachments.size) { + val type = getAttachmentTypeByClass(attachments[i]) + if (type != firstType) return false + } + + return true + } + + fun getAttachmentTypeByClass(attachment: VkAttachment): BaseVkAttachmentItem.AttachmentType? { + return when (attachment) { + is VkPhoto -> BaseVkAttachmentItem.AttachmentType.PHOTO + is VkVideo -> BaseVkAttachmentItem.AttachmentType.VIDEO + is VkAudio -> BaseVkAttachmentItem.AttachmentType.AUDIO + is VkFile -> BaseVkAttachmentItem.AttachmentType.FILE + is VkLink -> BaseVkAttachmentItem.AttachmentType.LINK + is VkMiniApp -> BaseVkAttachmentItem.AttachmentType.MINI_APP + is VkVoiceMessage -> BaseVkAttachmentItem.AttachmentType.VOICE + is VkSticker -> BaseVkAttachmentItem.AttachmentType.STICKER + is VkGift -> BaseVkAttachmentItem.AttachmentType.GIFT + is VkWall -> BaseVkAttachmentItem.AttachmentType.WALL + is VkGraffiti -> BaseVkAttachmentItem.AttachmentType.GRAFFITI + is VkPoll -> BaseVkAttachmentItem.AttachmentType.POLL + is VkWallReply -> BaseVkAttachmentItem.AttachmentType.WALL_REPLY + is VkCall -> BaseVkAttachmentItem.AttachmentType.CALL + else -> null + } + } + + fun getAttachmentTextByType(attachmentType: BaseVkAttachmentItem.AttachmentType): String? { + return when (attachmentType) { + else -> attachmentType.value + } + } + +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/datasource/ConversationsDataSource.kt b/app/src/main/kotlin/com/meloda/fast/api/datasource/ConversationsDataSource.kt index 6b488183..1b78db0e 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/datasource/ConversationsDataSource.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/datasource/ConversationsDataSource.kt @@ -11,7 +11,7 @@ class ConversationsDataSource @Inject constructor( private val dao: ConversationsDao ) { - suspend fun getAllChats(params: ConversationsGetRequest) = repo.getAllChats(params) + suspend fun getAllChats(params: ConversationsGetRequest) = repo.getAllChats(params.map) suspend fun storeConversations(conversations: List) = dao.insert(conversations) diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/VkConversation.kt b/app/src/main/kotlin/com/meloda/fast/api/model/VkConversation.kt index ead41a76..2c9f450d 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/VkConversation.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/VkConversation.kt @@ -9,7 +9,15 @@ data class VkConversation( @PrimaryKey(autoGenerate = false) val id: Int, val title: String?, + val photo200: String?, + val type: String, + val callInProgress: Boolean ) { @Ignore var lastMessage: VkMessage? = null + + fun isChat() = type == "chat" + fun isUser() = type == "user" + fun isGroup() = type == "group" + } diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/VkGroup.kt b/app/src/main/kotlin/com/meloda/fast/api/model/VkGroup.kt new file mode 100644 index 00000000..6a7cabbc --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/model/VkGroup.kt @@ -0,0 +1,17 @@ +package com.meloda.fast.api.model + +import androidx.room.Entity +import androidx.room.PrimaryKey + +@Entity(tableName = "groups") +data class VkGroup( + @PrimaryKey(autoGenerate = false) + val id: Int, + val name: String, + val screenName: String, + val photo200: String? +) { + + override fun toString() = name.trim() + +} diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/VkMessage.kt b/app/src/main/kotlin/com/meloda/fast/api/model/VkMessage.kt index c53396b3..59121406 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/VkMessage.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/VkMessage.kt @@ -1,7 +1,9 @@ package com.meloda.fast.api.model import androidx.room.Entity +import androidx.room.Ignore import androidx.room.PrimaryKey +import com.meloda.fast.api.model.attachments.VkAttachment @Entity(tableName = "messages") data class VkMessage( @@ -11,9 +13,48 @@ data class VkMessage( val isOut: Boolean, val peerId: Int, val fromId: Int, - val date: Int + val date: Int, + val action: String?, + val actionMemberId: Int?, + val actionText: String?, + val actionConversationMessageId: Int?, + val actionMessage: String?, + val geoType: String? ) { + @Ignore + var forwards: List? = null + @Ignore + var attachments: List? = null + fun isUser() = id > 0 + + fun isGroup() = id < 0 + + fun getPreparedAction(): Action? { + if (action == null) return null + return Action.parse(action) + } + + enum class Action(val value: String) { + CHAT_CREATE("chat_create"), + CHAT_PHOTO_UPDATE("chat_photo_update"), + CHAT_PHOTO_REMOVE("chat_photo_remove"), + CHAT_TITLE_UPDATE("chat_title_update"), + CHAT_PIN_MESSAGE("chat_pin_message"), + CHAT_UNPIN_MESSAGE("chat_unpin_message"), + CHAT_INVITE_USER("chat_invite_user"), + CHAT_INVITE_USER_BY_LINK("chat_invite_user_by_link"), + CHAT_KICK_USER("chat_kick_user"), + CHAT_SCREENSHOT("chat_screenshot"), + + // TODO: 9/11/2021 catch this shit + CHAT_INVITE_USER_BY_CALL("chat_invite_user_by_call"), + CHAT_INVITE_USER_BY_CALL_LINK("chat_invite_user_by_call_join_link"); + + companion object { + fun parse(value: String) = values().first { it.value == value } + } + } } diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/VkUser.kt b/app/src/main/kotlin/com/meloda/fast/api/model/VkUser.kt index 0873961c..5e28b35c 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/VkUser.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/VkUser.kt @@ -8,5 +8,11 @@ data class VkUser( @PrimaryKey(autoGenerate = false) val id: Int, val firstName: String, - val lastName: String -) \ No newline at end of file + val lastName: String, + val online: Boolean, + val photo200: String? +) { + + override fun toString() = "$firstName $lastName".trim() + +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/attachments/BaseVKAttachmentItem.kt b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/BaseVKAttachmentItem.kt deleted file mode 100644 index 8808bc4a..00000000 --- a/app/src/main/kotlin/com/meloda/fast/api/model/attachments/BaseVKAttachmentItem.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.meloda.fast.api.model.attachments - -import android.os.Parcelable -import kotlinx.parcelize.Parcelize - -@Parcelize -data class BaseVKAttachmentItem( - val type: String, - val photo: VKPhotoAttachment?, - val video: VKVideoAttachment?, - val audio: VKAudioAttachment?, - val doc: VKFileAttachment?, - val link: VKLinkAttachment? -) : Parcelable - -abstract class BaseVKAttachment : Parcelable \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkAttachment.kt b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkAttachment.kt new file mode 100644 index 00000000..5c6ce70c --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkAttachment.kt @@ -0,0 +1,3 @@ +package com.meloda.fast.api.model.attachments + +abstract class VkAttachment \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkAudio.kt b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkAudio.kt new file mode 100644 index 00000000..5a5ec10a --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkAudio.kt @@ -0,0 +1,5 @@ +package com.meloda.fast.api.model.attachments + +data class VkAudio( + val link: String +) : VkAttachment() \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkCall.kt b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkCall.kt new file mode 100644 index 00000000..5c418b22 --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkCall.kt @@ -0,0 +1,5 @@ +package com.meloda.fast.api.model.attachments + +data class VkCall( + val initiatorId: Int +) : VkAttachment() \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkFile.kt b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkFile.kt new file mode 100644 index 00000000..e8eaaa23 --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkFile.kt @@ -0,0 +1,5 @@ +package com.meloda.fast.api.model.attachments + +data class VkFile( + val link: String +) : VkAttachment() \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkGift.kt b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkGift.kt new file mode 100644 index 00000000..75f08967 --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkGift.kt @@ -0,0 +1,5 @@ +package com.meloda.fast.api.model.attachments + +data class VkGift( + val link: String +) : VkAttachment() diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkGraffiti.kt b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkGraffiti.kt new file mode 100644 index 00000000..7f7ddebc --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkGraffiti.kt @@ -0,0 +1,5 @@ +package com.meloda.fast.api.model.attachments + +data class VkGraffiti( + val link: String +) : VkAttachment() \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkLink.kt b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkLink.kt new file mode 100644 index 00000000..6e68af59 --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkLink.kt @@ -0,0 +1,5 @@ +package com.meloda.fast.api.model.attachments + +data class VkLink( + val link: String +) : VkAttachment() diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkMiniApp.kt b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkMiniApp.kt new file mode 100644 index 00000000..781ba12e --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkMiniApp.kt @@ -0,0 +1,5 @@ +package com.meloda.fast.api.model.attachments + +data class VkMiniApp( + val link: String +) : VkAttachment() diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkPhoto.kt b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkPhoto.kt new file mode 100644 index 00000000..2e1579ba --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkPhoto.kt @@ -0,0 +1,5 @@ +package com.meloda.fast.api.model.attachments + +data class VkPhoto( + val link: String +) : VkAttachment() \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkPoll.kt b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkPoll.kt new file mode 100644 index 00000000..ec8742a0 --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkPoll.kt @@ -0,0 +1,5 @@ +package com.meloda.fast.api.model.attachments + +data class VkPoll( + val id: Int +) : VkAttachment() \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkSticker.kt b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkSticker.kt new file mode 100644 index 00000000..43aeefdc --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkSticker.kt @@ -0,0 +1,5 @@ +package com.meloda.fast.api.model.attachments + +data class VkSticker( + val link: String +) : VkAttachment() diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkVideo.kt b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkVideo.kt new file mode 100644 index 00000000..77c0d427 --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkVideo.kt @@ -0,0 +1,5 @@ +package com.meloda.fast.api.model.attachments + +data class VkVideo( + val link: String +) : VkAttachment() \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkVoiceMessage.kt b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkVoiceMessage.kt new file mode 100644 index 00000000..e701a35f --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkVoiceMessage.kt @@ -0,0 +1,5 @@ +package com.meloda.fast.api.model.attachments + +data class VkVoiceMessage( + val link: String +) : VkAttachment() diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkWall.kt b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkWall.kt new file mode 100644 index 00000000..e2f54efe --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkWall.kt @@ -0,0 +1,5 @@ +package com.meloda.fast.api.model.attachments + +data class VkWall( + val id: Int +) : VkAttachment() \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkWallReply.kt b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkWallReply.kt new file mode 100644 index 00000000..6930c369 --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VkWallReply.kt @@ -0,0 +1,5 @@ +package com.meloda.fast.api.model.attachments + +data class VkWallReply( + val id: Int +) : VkAttachment() \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/base/BaseVkConversation.kt b/app/src/main/kotlin/com/meloda/fast/api/model/base/BaseVkConversation.kt index db8de3ee..444b6cff 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/base/BaseVkConversation.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/base/BaseVkConversation.kt @@ -31,12 +31,17 @@ data class BaseVkConversation( @SerializedName("can_receive_money") val canReceiveMoney: Boolean, @SerializedName("chat_settings") - val chatSettings: ChatSettings? + val chatSettings: ChatSettings?, + @SerializedName("call_in_progress") + val callInProgress: CallInProgress? ) : Parcelable { fun asVkConversation(lastMessage: VkMessage? = null) = VkConversation( id = peer.id, title = chatSettings?.title, + photo200 = chatSettings?.photo?.photo200, + type = peer.type, + callInProgress = callInProgress != null ).apply { this.lastMessage = lastMessage } @Parcelize @@ -83,7 +88,7 @@ data class BaseVkConversation( val membersCount: Int, @SerializedName("friends_count") val friendsCount: Int, - val photo: Photo, + val photo: Photo?, @SerializedName("admin_ids") val adminsIds: List, @SerializedName("active_ids") @@ -93,7 +98,8 @@ data class BaseVkConversation( @SerializedName("is_disappearing") val isDisappearing: Boolean, @SerializedName("is_service") - val isService: Boolean + val isService: Boolean, + val theme: String ) : Parcelable { @Parcelize @@ -125,13 +131,28 @@ data class BaseVkConversation( @Parcelize data class Photo( @SerializedName("photo_50") - val photo50: String, + val photo50: String?, @SerializedName("photo_100") - val photo100: String, + val photo100: String?, @SerializedName("photo_200") - val photo200: String, + val photo200: String?, @SerializedName("is_default_photo") val isDefaultPhoto: Boolean ) : Parcelable } + + @Parcelize + data class CallInProgress( + val participants: Participants, + @SerializedName("join_link") + val joinLink: String + ) : Parcelable { + + @Parcelize + data class Participants( + val list: List, + val count: Int + ) : Parcelable + + } } \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/base/BaseVkGroup.kt b/app/src/main/kotlin/com/meloda/fast/api/model/base/BaseVkGroup.kt new file mode 100644 index 00000000..0bf754c3 --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/model/base/BaseVkGroup.kt @@ -0,0 +1,38 @@ +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 + +@Parcelize +data class BaseVkGroup( + val id: Int, + val name: String, + @SerializedName("screen_name") + val screenName: String, + @SerializedName("is_closed") + val isClosed: 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? +) : Parcelable { + + fun asVkGroup() = VkGroup( + id = -id, + name = name, + screenName = screenName, + photo200 = photo200 + ) + +} diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/base/BaseVkMessage.kt b/app/src/main/kotlin/com/meloda/fast/api/model/base/BaseVkMessage.kt index bdedf2ec..0c698b82 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/base/BaseVkMessage.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/base/BaseVkMessage.kt @@ -2,9 +2,10 @@ 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 import kotlinx.parcelize.Parcelize -import kotlinx.parcelize.RawValue @Parcelize data class BaseVkMessage( @@ -19,25 +20,36 @@ data class BaseVkMessage( @SerializedName("conversation_message_id") val conversationMessageId: Int, @SerializedName("fwd_messages") - val fwdMessages: List = listOf(), + val fwdMessages: List? = listOf(), val important: Boolean, @SerializedName("random_id") val randomId: Int, - val attachments: @RawValue List = listOf(), + val attachments: List = listOf(), @SerializedName("is_hidden") val isHidden: Boolean, val payload: String, - val geo: Geo? + val geo: Geo?, + val action: Action?, + val ttl: Int ) : Parcelable { fun asVkMessage() = VkMessage( id = id, - text = text, + text = if (text.isBlank()) null else text, isOut = out == 1, peerId = peerId, fromId = fromId, - date = date - ) + date = date, + action = action?.type, + actionMemberId = action?.memberId, + actionText = action?.text, + actionConversationMessageId = action?.conversationMessageId, + actionMessage = action?.message, + geoType = geo?.type + ).also { + it.attachments = VkUtils.parseAttachments(attachments) + it.forwards = VkUtils.parseForwards(fwdMessages) + } @Parcelize data class Geo( @@ -54,4 +66,15 @@ data class BaseVkMessage( data class Place(val country: String, val city: String, val title: String) : Parcelable } + @Parcelize + data class Action( + val type: String, + @SerializedName("member_id") + val memberId: Int?, + val text: String?, + @SerializedName("conversation_message_id") + val conversationMessageId: Int?, + val message: String? + ) : Parcelable + } diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/base/BaseVkUser.kt b/app/src/main/kotlin/com/meloda/fast/api/model/base/BaseVkUser.kt index e38cba7e..bc7ceac9 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/base/BaseVkUser.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/base/BaseVkUser.kt @@ -50,7 +50,9 @@ data class BaseVkUser( fun asVkUser() = VkUser( id = id, firstName = firstName, - lastName = lastName + lastName = lastName, + online = online == 1, + photo200 = photo200 ) } diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkAttachmentItem.kt b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkAttachmentItem.kt new file mode 100644 index 00000000..f887b3be --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkAttachmentItem.kt @@ -0,0 +1,56 @@ +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 BaseVkAttachmentItem( + val type: String, + val photo: BaseVkPhoto?, + val video: BaseVkVideo?, + val audio: BaseVkAudio?, + @SerializedName("doc") + val file: BaseVkFile?, + val link: BaseVkLink?, + @SerializedName("mini_app") + val miniApp: BaseVkMiniApp?, + @SerializedName("audio_message") + val voiceMessage: BaseVkVoiceMessage?, + val sticker: BaseVkSticker?, + val gift: BaseVkGift?, + val wall: BaseVkWall?, + val graffiti: BaseVkGraffiti?, + val poll: BaseVkPoll?, + @SerializedName("wall_reply") + val wallReply: BaseVkWallReply?, + val call: BaseVkCall? +) : Parcelable { + + fun getPreparedType() = AttachmentType.parse(type) + + enum class AttachmentType(val value: String) { + PHOTO("photo"), + VIDEO("video"), + AUDIO("audio"), + FILE("doc"), + LINK("link"), + VOICE("audio_message"), + MINI_APP("mini_app"), + STICKER("sticker"), + GIFT("gift"), + WALL("wall"), + GRAFFITI("graffiti"), + POLL("poll"), + WALL_REPLY("wall_reply"), + CALL("call") + ; + + companion object { + fun parse(value: String) = values().firstOrNull { it.value == value } + } + } + +} + +abstract class BaseVkAttachment : Parcelable \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VKAudioAttachment.kt b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkAudio.kt similarity index 94% rename from app/src/main/kotlin/com/meloda/fast/api/model/attachments/VKAudioAttachment.kt rename to app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkAudio.kt index c4e3423b..e25a276f 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VKAudioAttachment.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkAudio.kt @@ -1,11 +1,11 @@ -package com.meloda.fast.api.model.attachments +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 VKAudioAttachment( +data class BaseVkAudio( val id: Int, val title: String, val artist: String, @@ -33,7 +33,7 @@ data class VKAudioAttachment( val storiesAllowed: Boolean, @SerializedName("stories_cover_allowed") val storiesCoverAllowed: Boolean -) : BaseVKAttachment() { +) : BaseVkAttachment() { @Parcelize data class Album( diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkCall.kt b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkCall.kt new file mode 100644 index 00000000..70cd1b80 --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkCall.kt @@ -0,0 +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 BaseVkCall( + @SerializedName("initiator_id") + val initiatorId: Int, + @SerializedName("receiver_id") + val receiverId: Int, + val state: String, + val time: Int, + val duration: Int, + val video: Boolean +) : Parcelable \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VKFileAttachment.kt b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkFile.kt similarity index 90% rename from app/src/main/kotlin/com/meloda/fast/api/model/attachments/VKFileAttachment.kt rename to app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkFile.kt index f2515255..1791b814 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VKFileAttachment.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkFile.kt @@ -1,11 +1,11 @@ -package com.meloda.fast.api.model.attachments +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 VKFileAttachment( +data class BaseVkFile( val id: Int, @SerializedName("owner_id") val ownerId: Int, @@ -22,7 +22,7 @@ data class VKFileAttachment( val accessKey: String, @SerializedName("web_preview_url") val webPreviewUrl: String? -) : BaseVKAttachment() { +) : BaseVkAttachment() { @Parcelize data class Preview( diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkGift.kt b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkGift.kt new file mode 100644 index 00000000..bba4b6ea --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkGift.kt @@ -0,0 +1,16 @@ +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 +) : Parcelable \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkGraffiti.kt b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkGraffiti.kt new file mode 100644 index 00000000..d044e3fe --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkGraffiti.kt @@ -0,0 +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 BaseVkGraffiti( + val id: Int, + @SerializedName("owner_id") + val ownerId: Int, + val url: String, + val width: Int, + val height: Int, + @SerializedName("access_key") + val accessKey: String +) : Parcelable \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VKLinkAttachment.kt b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkLink.kt similarity index 65% rename from app/src/main/kotlin/com/meloda/fast/api/model/attachments/VKLinkAttachment.kt rename to app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkLink.kt index a65be339..baee2679 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VKLinkAttachment.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkLink.kt @@ -1,15 +1,15 @@ -package com.meloda.fast.api.model.attachments +package com.meloda.fast.api.model.base.attachments import com.google.gson.annotations.SerializedName import kotlinx.parcelize.Parcelize @Parcelize -data class VKLinkAttachment( +data class BaseVkLink( val url: String, val title: String, val caption: String, - val photo: VKPhotoAttachment, + val photo: BaseVkPhoto, val target: String, @SerializedName("is_favorite") val isFavorite: Boolean -) : BaseVKAttachment() \ No newline at end of file +) : BaseVkAttachment() \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkMiniApp.kt b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkMiniApp.kt new file mode 100644 index 00000000..4c91922b --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkMiniApp.kt @@ -0,0 +1,67 @@ +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 BaseVkMiniApp( + val title: String, + val description: String, + val app: App, + val images: List?, + @SerializedName("button_text") + val buttonText: String +) : Parcelable { + + @Parcelize + data class App( + val type: String, + val id: Int, + val title: String, + @SerializedName("author_owner_id") + val authorOwnerId: Int, + @SerializedName("are_notifications_enabled") + val areNotificationsEnabled: Boolean, + @SerializedName("is_favorite") + val isFavorite: Boolean, + @SerializedName("is_installed") + val isInstalled: Boolean, + @SerializedName("track_code") + val trackCode: String, + @SerializedName("share_url") + val shareUrl: String, + @SerializedName("webview_url") + val webViewUrl: String, + @SerializedName("hide_tabbar") + val hideTabBar: Int, + @SerializedName("icon_75") + val icon75: String?, + @SerializedName("icon_139") + val icon139: String?, + @SerializedName("icon_150") + val icon150: String?, + @SerializedName("icon_278") + val icon278: String?, + @SerializedName("icon_576") + val icon576: String?, + @SerializedName("open_in_external_browser") + val openInExternalBrowser: Boolean, + @SerializedName("need_policy_confirmation") + val needPolicyConfirmation: Boolean, + @SerializedName("is_vkui_internal") + val isVkUiInternal: Boolean, + @SerializedName("has_vk_connect") + val hasVkConnect: Boolean, + @SerializedName("need_show_bottom_menu_tooltip_on_close") + val needShowBottomMenuTooltipOnClose: Boolean + ) : Parcelable + + @Parcelize + data class Image( + val height: Int, + val width: Int, + val url: String + ) : Parcelable + +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VKPhotoAttachment.kt b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkPhoto.kt similarity index 87% rename from app/src/main/kotlin/com/meloda/fast/api/model/attachments/VKPhotoAttachment.kt rename to app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkPhoto.kt index a62e4e49..9cb21093 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VKPhotoAttachment.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkPhoto.kt @@ -1,11 +1,11 @@ -package com.meloda.fast.api.model.attachments +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 VKPhotoAttachment( +data class BaseVkPhoto( @SerializedName("album_id") val albumId: Int, val date: Int, @@ -20,7 +20,7 @@ data class VKPhotoAttachment( val text: String, @SerializedName("user_id") val userId: Int? -) : BaseVKAttachment() +) : BaseVkAttachment() @Parcelize data class Size( diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkPoll.kt b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkPoll.kt new file mode 100644 index 00000000..c41aa349 --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkPoll.kt @@ -0,0 +1,72 @@ +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 BaseVkPoll( + val multiple: Boolean, + val id: Int, + 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 created: Int, + @SerializedName("owner_id") + val ownerId: Int, + val question: String, + @SerializedName("disable_unvote") + val disableUnVote: Boolean, + val friends: List?, + @SerializedName("embed_hash") + val embedHash: String, + val answers: List, + @SerializedName("author_id") + val authorId: Int, + val background: Background? +) : Parcelable { + + @Parcelize + data class Friend( + val id: Int + ) : Parcelable + + @Parcelize + data class Answer( + val id: Int, + val rate: Double, + val text: String, + val votes: Int + ) : Parcelable + + @Parcelize + data class Background( + val angle: Int, + val color: String, + val id: Int, + val name: String, + val type: String, + val points: List + ) : Parcelable { + + @Parcelize + data class Point( + val color: String, + val position: Double + ) : Parcelable + + } + +} diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkSticker.kt b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkSticker.kt new file mode 100644 index 00000000..14dfb4a0 --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkSticker.kt @@ -0,0 +1,35 @@ +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 BaseVkSticker( + @SerializedName("product_id") + val productId: Int, + @SerializedName("sticker_id") + val stickerId: Int, + val images: List, + @SerializedName("images_with_background") + val imagesWithBackground: List, + @SerializedName("animation_url") + val animationUrl: String?, + val animations: List? +) : Parcelable { + + @Parcelize + data class Image( + val width: Int, + val height: Int, + val url: String + ) : Parcelable + + @Parcelize + data class Animation( + val type: String, + val url: String + ) : Parcelable + + +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VKVideoAttachment.kt b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkVideo.kt similarity index 89% rename from app/src/main/kotlin/com/meloda/fast/api/model/attachments/VKVideoAttachment.kt rename to app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkVideo.kt index a6782687..707193dd 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/attachments/VKVideoAttachment.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkVideo.kt @@ -1,11 +1,11 @@ -package com.meloda.fast.api.model.attachments +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 VKVideoAttachment( +data class BaseVkVideo( val id: Int, val title: String, val width: Int, @@ -47,11 +47,11 @@ data class VKVideoAttachment( val image: List, @SerializedName("first_frame") val firstFrame: List, - val files: List, + val files: File, @SerializedName("timeline_thumbs") val timelineThumbs: TimelineThumbs //ads -) : BaseVKAttachment() { +) : BaseVkAttachment() { @Parcelize data class Image( @@ -71,12 +71,12 @@ data class VKVideoAttachment( @Parcelize data class File( - val mp4_240: String, - val mp4_360: String, - val mp4_480: String, - val mp4_720: String, - val mp4_1080: String, - val mp4_1440: String, + val mp4_240: String?, + val mp4_360: String?, + val mp4_480: String?, + val mp4_720: String?, + val mp4_1080: String?, + val mp4_1440: String?, val hls: String, @SerializedName("dash_uni") val dashUni: String, diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkVoiceMessage.kt b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkVoiceMessage.kt new file mode 100644 index 00000000..745fe162 --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkVoiceMessage.kt @@ -0,0 +1,23 @@ +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 duration: Int, + val waveform: List, + @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 transcript: String +) : Parcelable \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkWall.kt b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkWall.kt new file mode 100644 index 00000000..8637ccce --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkWall.kt @@ -0,0 +1,76 @@ +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 BaseVkWall( + val id: Int, + @SerializedName("from_id") + val fromId: Int, + @SerializedName("to_id") + val toId: Int, + val date: Int, + val text: String, + val attachments: List?, + @SerializedName("post_source") + val postSource: PostSource, + val comments: Comments, + val likes: Likes, + val reposts: Reposts, + val views: Views, + @SerializedName("is_favorite") + val isFavorite: Boolean, + val donut: Donut, + @SerializedName("access_key") + val accessKey: String, + @SerializedName("short_text_rate") + val shortTextRate: Double +) : Parcelable { + + @Parcelize + data class PostSource( + val type: String, + val platform: String + ) : Parcelable + + @Parcelize + data class Comments( + val count: Int, + @SerializedName("can_post") + val canPost: Int, + @SerializedName("groups_can_post") + val groupsCanPost: 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, + ) : Parcelable + + @Parcelize + data class Reposts( + val count: Int, + @SerializedName("user_reposted") + val userReposted: Int + ) : Parcelable + + @Parcelize + data class Views( + val count: Int + ) : Parcelable + + @Parcelize + data class Donut( + @SerializedName("is_donut") + val isDonut: Boolean + ) : Parcelable + +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkWallReply.kt b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkWallReply.kt new file mode 100644 index 00000000..5ec039be --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/api/model/base/attachments/BaseVkWallReply.kt @@ -0,0 +1,39 @@ +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 date: Int, + val text: String, + @SerializedName("post_id") + val postId: Int, + @SerializedName("owner_id") + val ownerId: Int, + @SerializedName("parents_stack") + val parentsStack: List, + val likes: Likes, + @SerializedName("reply_to_user") + val replyToUser: Int?, + @SerializedName("reply_to_comment") + val replyToComment: 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 + ) : Parcelable + +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKAttachments.kt b/app/src/main/kotlin/com/meloda/fast/api/model/old/VKAttachments.kt index d74563c3..6286bb6d 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKAttachments.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/old/VKAttachments.kt @@ -18,20 +18,20 @@ object VKAttachments { val jsonObject = attachment.optJSONObject(type.value) ?: continue when (type) { - Type.PHOTO -> attachments.add(VKPhoto(jsonObject)) - Type.AUDIO -> attachments.add(VKAudio(jsonObject)) - Type.VIDEO -> attachments.add(VKVideo(jsonObject)) - Type.DOCUMENT -> attachments.add(VKDocument(jsonObject)) - Type.STICKER -> attachments.add(VKSticker(jsonObject)) - Type.LINK -> attachments.add(VKLink(jsonObject)) - Type.GIFT -> attachments.add(VKGift(jsonObject)) - Type.VOICE_MESSAGE -> attachments.add(VKAudioMessage(jsonObject)) - Type.GRAFFITI -> attachments.add(VKGraffiti(jsonObject)) - Type.POLL -> attachments.add(VKPoll(jsonObject)) +// Type.PHOTO -> attachments.add(oldVKPhoto(jsonObject)) +// Type.AUDIO -> attachments.add(oldVKAudio(jsonObject)) +// Type.VIDEO -> attachments.add(oldVKVideo(jsonObject)) +// Type.DOCUMENT -> attachments.add(oldVKDocument(jsonObject)) +// Type.STICKER -> attachments.add(oldVKSticker(jsonObject)) +// Type.LINK -> attachments.add(oldVKLink(jsonObject)) +// Type.GIFT -> attachments.add(VKGift(jsonObject)) +// Type.VOICE_MESSAGE -> attachments.add(oldVKAudioMessage(jsonObject)) +// Type.GRAFFITI -> attachments.add(VKGraffiti(jsonObject)) + Type.POLL -> attachments.add(oldVKPoll(jsonObject)) Type.CALL -> attachments.add(VKCall(jsonObject)) - Type.WALL_POST -> attachments.add(VKWall(jsonObject)) - Type.WALL_REPLY -> attachments.add(VKComment(jsonObject)) - Type.GEOLOCATION -> attachments.add(VKGeolocation(jsonObject)) +// Type.WALL_POST -> attachments.add(VKWall(jsonObject)) + Type.WALL_REPLY -> attachments.add(oldVKComment(jsonObject)) +// Type.GEOLOCATION -> attachments.add(oldVKGeolocation(jsonObject)) else -> continue } } diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKLongPollHistory.kt b/app/src/main/kotlin/com/meloda/fast/api/model/old/VKLongPollHistory.kt index a4bf14a6..11219a6b 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKLongPollHistory.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/old/VKLongPollHistory.kt @@ -9,6 +9,6 @@ class VKLongPollHistory : VKModel() { private val lpMessages: ArrayList? = null private val messages: ArrayList? = null private val profiles: ArrayList? = null - private val groups: ArrayList? = null //TODO: использовать + private val groups: ArrayList? = null //TODO: использовать } \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKAudio.kt b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKAudio.kt similarity index 95% rename from app/src/main/kotlin/com/meloda/fast/api/model/old/VKAudio.kt rename to app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKAudio.kt index c66e456b..8ee77511 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKAudio.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKAudio.kt @@ -2,7 +2,7 @@ package com.meloda.fast.api.model.old import org.json.JSONObject -class VKAudio() : VKModel() { +class oldVKAudio() : VKModel() { companion object { const val serialVersionUID: Long = 1L diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKAudioMessage.kt b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKAudioMessage.kt similarity index 94% rename from app/src/main/kotlin/com/meloda/fast/api/model/old/VKAudioMessage.kt rename to app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKAudioMessage.kt index cf0690e3..0d17f961 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKAudioMessage.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKAudioMessage.kt @@ -2,7 +2,7 @@ package com.meloda.fast.api.model.old import org.json.JSONObject -class VKAudioMessage() : VKModel() { +class oldVKAudioMessage() : VKModel() { companion object { const val serialVersionUID: Long = 1L diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKComment.kt b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKComment.kt similarity index 77% rename from app/src/main/kotlin/com/meloda/fast/api/model/old/VKComment.kt rename to app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKComment.kt index 018f33de..9cc11bcc 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKComment.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKComment.kt @@ -2,7 +2,7 @@ package com.meloda.fast.api.model.old import org.json.JSONObject -class VKComment() : VKModel() { //https://vk.com/dev/objects/comment +class oldVKComment() : VKModel() { //https://vk.com/dev/objects/comment companion object { const val serialVersionUID: Long = 1L diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKConversation.kt b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKConversation.kt index 951e90be..56f01e67 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKConversation.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKConversation.kt @@ -10,7 +10,7 @@ class oldVKConversation() : VKModel(), Cloneable { const val serialVersionUID: Long = 1L var profiles = arrayListOf() - var groups = arrayListOf() + var groups = arrayListOf() var conversationsCount: Int = 0 @@ -56,7 +56,7 @@ class oldVKConversation() : VKModel(), Cloneable { var peerUser: oldVKUser? = null - var peerGroup: VKGroup? = null + var peerGroup: oldVKGroup? = null constructor(o: JSONObject) : this() { inReadMessageId = o.optInt("in_read") diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKDocument.kt b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKDocument.kt similarity index 90% rename from app/src/main/kotlin/com/meloda/fast/api/model/old/VKDocument.kt rename to app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKDocument.kt index 83a4ec14..88ff6170 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKDocument.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKDocument.kt @@ -4,7 +4,7 @@ import org.json.JSONObject import java.io.Serializable import java.util.* -class VKDocument() : VKModel() { +class oldVKDocument() : VKModel() { override val attachmentType = VKAttachments.Type.DOCUMENT @@ -47,13 +47,13 @@ class VKDocument() : VKModel() { inner class Photo(o: JSONObject) : Serializable { - var sizes: ArrayList? = null + var sizes: ArrayList? = null init { o.optJSONArray("sizes")?.let { - val sizes = ArrayList() + val sizes = ArrayList() for (i in 0 until it.length()) { - sizes.add(VKPhotoSize(it.optJSONObject(i))) + sizes.add(oldVKPhotoSize(it.optJSONObject(i))) } this.sizes = sizes } diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKGeolocation.kt b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKGeolocation.kt similarity index 86% rename from app/src/main/kotlin/com/meloda/fast/api/model/old/VKGeolocation.kt rename to app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKGeolocation.kt index 3715f101..ad912543 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKGeolocation.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKGeolocation.kt @@ -2,7 +2,7 @@ package com.meloda.fast.api.model.old import org.json.JSONObject -class VKGeolocation() : VKModel() { +class oldVKGeolocation() : VKModel() { companion object { const val serialVersionUID: Long = 1L diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKGift.kt b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKGift.kt similarity index 94% rename from app/src/main/kotlin/com/meloda/fast/api/model/old/VKGift.kt rename to app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKGift.kt index 3bb9b73d..693e1c76 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKGift.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKGift.kt @@ -2,7 +2,7 @@ package com.meloda.fast.api.model.old import org.json.JSONObject -class VKGift() : VKModel() { +class oldVKGift() : VKModel() { companion object { const val serialVersionUID: Long = 1L diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKGraffiti.kt b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKGraffiti.kt similarity index 94% rename from app/src/main/kotlin/com/meloda/fast/api/model/old/VKGraffiti.kt rename to app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKGraffiti.kt index e6dba70b..d439565b 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKGraffiti.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKGraffiti.kt @@ -2,7 +2,7 @@ package com.meloda.fast.api.model.old import org.json.JSONObject -class VKGraffiti() : VKModel() { +class oldVKGraffiti() : VKModel() { companion object { const val serialVersionUID: Long = 1L diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKGroup.kt b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKGroup.kt similarity index 85% rename from app/src/main/kotlin/com/meloda/fast/api/model/old/VKGroup.kt rename to app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKGroup.kt index a60f06a1..d2ededfa 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKGroup.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKGroup.kt @@ -3,7 +3,7 @@ package com.meloda.fast.api.model.old import org.json.JSONArray import org.json.JSONObject -open class VKGroup() : VKModel() { +open class oldVKGroup() : VKModel() { override val attachmentType = VKAttachments.Type.NONE @@ -11,11 +11,11 @@ open class VKGroup() : VKModel() { const val serialVersionUID: Long = 1L - fun parse(array: JSONArray): ArrayList { - val groups = ArrayList() + fun parse(array: JSONArray): ArrayList { + val groups = ArrayList() for (i in 0 until array.length()) { - groups.add(VKGroup(array.optJSONObject(i))) + groups.add(oldVKGroup(array.optJSONObject(i))) } return groups } diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKLink.kt b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKLink.kt similarity index 92% rename from app/src/main/kotlin/com/meloda/fast/api/model/old/VKLink.kt rename to app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKLink.kt index 605fa4ca..e11c3ba8 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKLink.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKLink.kt @@ -3,7 +3,7 @@ package com.meloda.fast.api.model.old import org.json.JSONObject import java.io.Serializable -class VKLink() : VKModel() { +class oldVKLink() : VKModel() { companion object { const val serialVersionUID: Long = 1L @@ -17,7 +17,7 @@ class VKLink() : VKModel() { var description: String = "" var previewPage: String = "" var previewUrl: String = "" - var photo: VKPhoto? = null + var photo: oldVKPhoto? = null var button: Button? = null constructor(o: JSONObject): this() { @@ -29,7 +29,7 @@ class VKLink() : VKModel() { previewUrl = o.optString("preview_url") o.optJSONObject("photo")?.let { - photo = VKPhoto(it) + photo = oldVKPhoto(it) } o.optJSONObject("button")?.let { diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKMessage.kt b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKMessage.kt index bcd8da1d..00519819 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKMessage.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKMessage.kt @@ -1,7 +1,7 @@ package com.meloda.fast.api.model.old import android.util.ArrayMap -import com.meloda.fast.api.VKUtil +import com.meloda.fast.api.oldVKUtil import org.json.JSONObject open class oldVKMessage() : VKModel() { @@ -11,7 +11,7 @@ open class oldVKMessage() : VKModel() { companion object { var profiles = arrayListOf() - var groups = arrayListOf() + var groups = arrayListOf() var conversations = arrayListOf() const val serialVersionUID: Long = 1L @@ -101,11 +101,11 @@ open class oldVKMessage() : VKModel() { var replyMessage: oldVKMessage? = null - var action: VKMessageAction? = null + var action: oldVKMessageAction? = null var fromUser: oldVKUser? = null - var fromGroup: VKGroup? = null + var fromGroup: oldVKGroup? = null constructor(o: JSONObject) : this() { id = o.optInt("id", -1) @@ -115,7 +115,7 @@ open class oldVKMessage() : VKModel() { editTime = o.optInt("edit_time", -1) isOut = o.optInt("out") == 1 - text = VKUtil.prepareMessageText(o.optString("text")) + text = oldVKUtil.prepareMessageText(o.optString("text")) randomId = o.optInt("random_id", -1) conversationMessageId = o.optInt("conversation_message_id", -1) @@ -138,7 +138,7 @@ open class oldVKMessage() : VKModel() { } o.optJSONObject("action")?.let { - action = VKMessageAction(it) + action = oldVKMessageAction(it) } } diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKMessageAction.kt b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKMessageAction.kt similarity index 97% rename from app/src/main/kotlin/com/meloda/fast/api/model/old/VKMessageAction.kt rename to app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKMessageAction.kt index e875ad65..cdd3e473 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKMessageAction.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKMessageAction.kt @@ -2,7 +2,7 @@ package com.meloda.fast.api.model.old import org.json.JSONObject -class VKMessageAction() : VKModel() { +class oldVKMessageAction() : VKModel() { companion object { const val serialVersionUID: Long = 1L diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKPhoto.kt b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKPhoto.kt similarity index 80% rename from app/src/main/kotlin/com/meloda/fast/api/model/old/VKPhoto.kt rename to app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKPhoto.kt index 0fe72342..0e9c8fcb 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKPhoto.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKPhoto.kt @@ -3,7 +3,7 @@ package com.meloda.fast.api.model.old import org.json.JSONObject import java.util.* -class VKPhoto() : VKModel() { +class oldVKPhoto() : VKModel() { companion object { const val serialVersionUID: Long = 1L @@ -18,7 +18,7 @@ class VKPhoto() : VKModel() { var date: Int = 0 var width: Int = 0 var height: Int = 0 - var sizes: ArrayList? = null + var sizes: ArrayList? = null constructor(o: JSONObject) : this() { id = o.optInt("id", -1) @@ -30,9 +30,9 @@ class VKPhoto() : VKModel() { height = o.optInt("height") o.optJSONArray("sizes")?.let { - val sizes = ArrayList() + val sizes = ArrayList() for (i in 0 until it.length()) { - sizes.add(VKPhotoSize(it.optJSONObject(i))) + sizes.add(oldVKPhotoSize(it.optJSONObject(i))) } this.sizes = sizes } diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKPhotoSize.kt b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKPhotoSize.kt similarity index 88% rename from app/src/main/kotlin/com/meloda/fast/api/model/old/VKPhotoSize.kt rename to app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKPhotoSize.kt index 94cd6c70..675bf6b7 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKPhotoSize.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKPhotoSize.kt @@ -2,7 +2,7 @@ package com.meloda.fast.api.model.old import org.json.JSONObject -class VKPhotoSize(o: JSONObject) : VKModel() { +class oldVKPhotoSize(o: JSONObject) : VKModel() { companion object { const val serialVersionUID: Long = 1L diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKPoll.kt b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKPoll.kt similarity index 97% rename from app/src/main/kotlin/com/meloda/fast/api/model/old/VKPoll.kt rename to app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKPoll.kt index 0d5cd9eb..4427243b 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKPoll.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKPoll.kt @@ -2,7 +2,7 @@ package com.meloda.fast.api.model.old import org.json.JSONObject -class VKPoll() : VKModel() { +class oldVKPoll() : VKModel() { companion object { const val serialVersionUID: Long = 1L diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKSticker.kt b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKSticker.kt similarity index 96% rename from app/src/main/kotlin/com/meloda/fast/api/model/old/VKSticker.kt rename to app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKSticker.kt index 5fd582e1..954340f8 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKSticker.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKSticker.kt @@ -3,7 +3,7 @@ package com.meloda.fast.api.model.old import org.json.JSONObject import java.util.* -class VKSticker() : VKModel() { +class oldVKSticker() : VKModel() { companion object { const val serialVersionUID: Long = 1L diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKVideo.kt b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKVideo.kt similarity index 98% rename from app/src/main/kotlin/com/meloda/fast/api/model/old/VKVideo.kt rename to app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKVideo.kt index 4bf58508..8423c877 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKVideo.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKVideo.kt @@ -4,7 +4,7 @@ import com.meloda.fast.api.model.old.VKAttachments import com.meloda.fast.api.model.old.VKModel import org.json.JSONObject -class VKVideo() : VKModel() { +class oldVKVideo() : VKModel() { companion object { const val serialVersionUID: Long = 1L diff --git a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKWall.kt b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKWall.kt similarity index 79% rename from app/src/main/kotlin/com/meloda/fast/api/model/old/VKWall.kt rename to app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKWall.kt index 469426fa..640ffc85 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/model/old/VKWall.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/model/old/oldVKWall.kt @@ -2,7 +2,7 @@ package com.meloda.fast.api.model.old import org.json.JSONObject -class VKWall() : VKModel() { //https://vk.com/dev/objects/post +class oldVKWall() : VKModel() { //https://vk.com/dev/objects/post companion object { const val serialVersionUID: Long = 1L diff --git a/app/src/main/kotlin/com/meloda/fast/api/network/repo/ConversationsRepo.kt b/app/src/main/kotlin/com/meloda/fast/api/network/repo/ConversationsRepo.kt index 62ee65b8..882d8ee9 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/network/repo/ConversationsRepo.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/network/repo/ConversationsRepo.kt @@ -3,14 +3,15 @@ package com.meloda.fast.api.network.repo import com.meloda.fast.api.base.ApiResponse import com.meloda.fast.api.network.Answer import com.meloda.fast.api.network.VKUrls -import com.meloda.fast.api.network.request.ConversationsGetRequest import com.meloda.fast.api.network.response.ConversationsGetResponse -import retrofit2.http.Body +import retrofit2.http.FieldMap +import retrofit2.http.FormUrlEncoded import retrofit2.http.POST interface ConversationsRepo { + @FormUrlEncoded @POST(VKUrls.Conversations.get) - suspend fun getAllChats(@Body params: ConversationsGetRequest): Answer> + suspend fun getAllChats(@FieldMap params: Map): Answer> } \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/network/repo/UsersRepo.kt b/app/src/main/kotlin/com/meloda/fast/api/network/repo/UsersRepo.kt index 3a705312..4df465d4 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/network/repo/UsersRepo.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/network/repo/UsersRepo.kt @@ -4,12 +4,16 @@ import com.meloda.fast.api.base.ApiResponse import com.meloda.fast.api.model.base.BaseVkUser import com.meloda.fast.api.network.Answer import com.meloda.fast.api.network.VKUrls -import retrofit2.http.GET -import retrofit2.http.QueryMap +import retrofit2.http.FieldMap +import retrofit2.http.FormUrlEncoded +import retrofit2.http.POST interface UsersRepo { - @GET(VKUrls.Users.getById) - suspend fun getById(@QueryMap params: Map): Answer>> + @FormUrlEncoded + @POST(VKUrls.Users.getById) + suspend fun getById( + @FieldMap params: Map? + ): Answer>> } \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/network/request/ConversationsRequest.kt b/app/src/main/kotlin/com/meloda/fast/api/network/request/ConversationsRequest.kt index 46a3275e..f612d7e5 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/network/request/ConversationsRequest.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/network/request/ConversationsRequest.kt @@ -13,4 +13,16 @@ data class ConversationsGetRequest( val extended: Boolean? = true, @SerializedName("start_message_id") val startMessageId: Int? = null -) : Parcelable \ No newline at end of file +) : Parcelable { + + val map + get() = mutableMapOf( + "fields" to fields, + "filter" to filter + ).apply { + count?.let { this["count"] = it.toString() } + offset?.let { this["offset"] = it.toString() } + extended?.let { this["extended"] = it.toString() } + startMessageId?.let { this["start_message_id"] = it.toString() } + } +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/network/request/UsersRequest.kt b/app/src/main/kotlin/com/meloda/fast/api/network/request/UsersRequest.kt index adeb00f8..053fc785 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/network/request/UsersRequest.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/network/request/UsersRequest.kt @@ -5,17 +5,17 @@ import kotlinx.parcelize.Parcelize @Parcelize data class UsersGetRequest( - val usersIds: List, + val usersIds: List? = null, val fields: String? = null, val nomCase: String? = null ) : Parcelable { val map - get() = mutableMapOf( - "user_ids" to usersIds.joinToString { it.toString() } - ).apply { - fields?.let { this["fields"] = it } - nomCase?.let { this["nom_case"] = it } - } + get() = mutableMapOf() + .apply { + usersIds?.let { this["user_ids"] = it.joinToString { id -> id.toString() } } + fields?.let { this["fields"] = it } + nomCase?.let { this["nom_case"] = it } + } } \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/api/network/response/ConversationsResponse.kt b/app/src/main/kotlin/com/meloda/fast/api/network/response/ConversationsResponse.kt index f4cce0a3..ce9bc2f6 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/network/response/ConversationsResponse.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/network/response/ConversationsResponse.kt @@ -3,7 +3,9 @@ package com.meloda.fast.api.network.response import android.os.Parcelable import com.google.gson.annotations.SerializedName import com.meloda.fast.api.model.base.BaseVkConversation +import com.meloda.fast.api.model.base.BaseVkGroup import com.meloda.fast.api.model.base.BaseVkMessage +import com.meloda.fast.api.model.base.BaseVkUser import kotlinx.parcelize.Parcelize @Parcelize @@ -11,7 +13,9 @@ data class ConversationsGetResponse( val count: Int, val items: List, @SerializedName("unread_count") - val unreadCount: Int? + val unreadCount: Int?, + val profiles: List?, + val groups: List? ) : Parcelable @Parcelize diff --git a/app/src/main/kotlin/com/meloda/fast/api/VKUtil.kt b/app/src/main/kotlin/com/meloda/fast/api/oldVKUtil.kt similarity index 91% rename from app/src/main/kotlin/com/meloda/fast/api/VKUtil.kt rename to app/src/main/kotlin/com/meloda/fast/api/oldVKUtil.kt index c7e22979..c2bc1aa5 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/VKUtil.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/oldVKUtil.kt @@ -10,7 +10,7 @@ import java.text.SimpleDateFormat import java.util.* // TODO: 8/31/2021 review -object VKUtil { +object oldVKUtil { private const val TAG = "VKUtil" @@ -122,7 +122,7 @@ object VKUtil { fun getTitle( conversation: oldVKConversation, peerUser: oldVKUser?, - peerGroup: VKGroup? + peerGroup: oldVKGroup? ): String { return when { conversation.isUser() -> peerUser?.let { return it.toString() } ?: "" @@ -140,7 +140,7 @@ object VKUtil { fun getMessageTitle( message: oldVKMessage, fromUser: oldVKUser?, - fromGroup: VKGroup? + fromGroup: oldVKGroup? ): String { return when { message.isFromUser() -> { @@ -158,7 +158,7 @@ object VKUtil { fun getAvatar( conversation: oldVKConversation, peerUser: oldVKUser?, - peerGroup: VKGroup? + peerGroup: oldVKGroup? ): String { return when { conversation.isUser() -> { @@ -180,7 +180,7 @@ object VKUtil { fun getUserAvatar( message: oldVKMessage, fromUser: oldVKUser?, - fromGroup: VKGroup? + fromGroup: oldVKGroup? ): String { return when { message.isFromUser() -> { @@ -211,7 +211,7 @@ object VKUtil { return "" } - fun getGroupPhoto(group: VKGroup): String { + fun getGroupPhoto(group: oldVKGroup): String { if (group.photo200.isEmpty()) { if (group.photo100.isEmpty()) { if (group.photo50.isEmpty()) { @@ -286,19 +286,19 @@ object VKUtil { } if (it.has("source_act")) { - message.action = VKMessageAction().also { action -> + message.action = oldVKMessageAction().also { action -> action.type = - VKMessageAction.Type.fromString(it.optString("source_act")) + oldVKMessageAction.Type.fromString(it.optString("source_act")) when (action.type) { - VKMessageAction.Type.CHAT_CREATE -> { + oldVKMessageAction.Type.CHAT_CREATE -> { action.text = it.optString("source_text") } - VKMessageAction.Type.TITLE_UPDATE -> { + oldVKMessageAction.Type.TITLE_UPDATE -> { action.oldText = it.optString("source_old_text") action.text = it.optString("source_text") } - VKMessageAction.Type.PIN_MESSAGE -> { + oldVKMessageAction.Type.PIN_MESSAGE -> { action.memberId = it.optInt("source_mid") action.conversationMessageId = it.optInt("source_chat_local_id") @@ -306,14 +306,14 @@ object VKUtil { action.message = oldVKMessage(message) } } - VKMessageAction.Type.UNPIN_MESSAGE -> { + oldVKMessageAction.Type.UNPIN_MESSAGE -> { action.memberId = it.optInt("source_mid") action.conversationMessageId = it.optInt("source_chat_local_id") } - VKMessageAction.Type.INVITE_USER, - VKMessageAction.Type.KICK_USER, - VKMessageAction.Type.SCREENSHOT, - VKMessageAction.Type.INVITE_USER_BY_CALL -> { + oldVKMessageAction.Type.INVITE_USER, + oldVKMessageAction.Type.KICK_USER, + oldVKMessageAction.Type.SCREENSHOT, + oldVKMessageAction.Type.INVITE_USER_BY_CALL -> { action.memberId = it.optInt("source_mid") } } diff --git a/app/src/main/kotlin/com/meloda/fast/database/AppDatabase.kt b/app/src/main/kotlin/com/meloda/fast/database/AppDatabase.kt index ea6abb31..523e3adf 100644 --- a/app/src/main/kotlin/com/meloda/fast/database/AppDatabase.kt +++ b/app/src/main/kotlin/com/meloda/fast/database/AppDatabase.kt @@ -3,9 +3,11 @@ package com.meloda.fast.database import androidx.room.Database import androidx.room.RoomDatabase import com.meloda.fast.api.model.VkConversation +import com.meloda.fast.api.model.VkGroup import com.meloda.fast.api.model.VkMessage import com.meloda.fast.api.model.VkUser import com.meloda.fast.database.dao.ConversationsDao +import com.meloda.fast.database.dao.GroupsDao import com.meloda.fast.database.dao.MessagesDao import com.meloda.fast.database.dao.UsersDao @@ -13,9 +15,10 @@ import com.meloda.fast.database.dao.UsersDao entities = [ VkConversation::class, VkMessage::class, - VkUser::class + VkUser::class, + VkGroup::class ], - version = 1, + version = 8, exportSchema = false ) abstract class AppDatabase : RoomDatabase() { @@ -23,5 +26,6 @@ abstract class AppDatabase : RoomDatabase() { abstract fun conversationsDao(): ConversationsDao abstract fun messagesDao(): MessagesDao abstract fun usersDao(): UsersDao + abstract fun groupsDao(): GroupsDao } \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/database/dao/ConversationsDao.kt b/app/src/main/kotlin/com/meloda/fast/database/dao/ConversationsDao.kt index 01c1589a..218dcd15 100644 --- a/app/src/main/kotlin/com/meloda/fast/database/dao/ConversationsDao.kt +++ b/app/src/main/kotlin/com/meloda/fast/database/dao/ConversationsDao.kt @@ -1,8 +1,20 @@ package com.meloda.fast.database.dao import androidx.room.Dao +import androidx.room.Insert +import androidx.room.OnConflictStrategy +import androidx.room.Query import com.meloda.fast.api.model.VkConversation @Dao -interface ConversationsDao : KindaDao { +interface ConversationsDao { + + @Query("SELECT * FROM conversations") + suspend fun getAll(): List + + @Insert(onConflict = OnConflictStrategy.REPLACE) + suspend fun insert(values: List) + + suspend fun insert(values: Array) = insert(values.toList()) + } \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/database/dao/GroupsDao.kt b/app/src/main/kotlin/com/meloda/fast/database/dao/GroupsDao.kt new file mode 100644 index 00000000..963c7b22 --- /dev/null +++ b/app/src/main/kotlin/com/meloda/fast/database/dao/GroupsDao.kt @@ -0,0 +1,23 @@ +package com.meloda.fast.database.dao + +import androidx.room.Dao +import androidx.room.Insert +import androidx.room.OnConflictStrategy +import androidx.room.Query +import com.meloda.fast.api.model.VkGroup + +@Dao +interface GroupsDao { + + @Query("SELECT * FROM groups") + suspend fun getAll(): List + + @Query("SELECT * FROM groups WHERE id = :id") + suspend fun getById(id: Int): VkGroup? + + @Insert(onConflict = OnConflictStrategy.REPLACE) + suspend fun insert(values: List) + + suspend fun insert(values: Array) = insert(values.toList()) + +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/database/dao/UsersDao.kt b/app/src/main/kotlin/com/meloda/fast/database/dao/UsersDao.kt index 819bec91..0d7801b1 100644 --- a/app/src/main/kotlin/com/meloda/fast/database/dao/UsersDao.kt +++ b/app/src/main/kotlin/com/meloda/fast/database/dao/UsersDao.kt @@ -9,12 +9,15 @@ import com.meloda.fast.api.model.VkUser @Dao interface UsersDao { - @Insert(onConflict = OnConflictStrategy.REPLACE) - suspend fun insert(values: List) - @Query("SELECT * FROM users") suspend fun getAll(): List + @Query("SELECT * FROM users WHERE id = :id") + suspend fun getById(id: Int): VkUser? + + @Insert(onConflict = OnConflictStrategy.REPLACE) + suspend fun insert(values: List) + suspend fun insert(values: Array) = insert(values.toList()) } \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/database/old/storage/ChatsStorage.kt b/app/src/main/kotlin/com/meloda/fast/database/old/storage/ChatsStorage.kt index 2c01c18c..ea799adf 100644 --- a/app/src/main/kotlin/com/meloda/fast/database/old/storage/ChatsStorage.kt +++ b/app/src/main/kotlin/com/meloda/fast/database/old/storage/ChatsStorage.kt @@ -26,7 +26,7 @@ import com.meloda.fast.database.old.DatabaseKeys.UNREAD_COUNT import com.meloda.fast.database.old.DatabaseUtils.TABLE_CHATS import com.meloda.fast.database.old.base.Storage import com.meloda.fast.api.model.old.oldVKConversation -import com.meloda.fast.api.VKUtil +import com.meloda.fast.api.oldVKUtil import org.json.JSONObject @WorkerThread @@ -86,7 +86,7 @@ class ChatsStorage : Storage() { values.put( PHOTOS, - VKUtil.putPhotosToJson( + oldVKUtil.putPhotosToJson( value.photo50, value.photo100, value.photo200 @@ -130,7 +130,7 @@ class ChatsStorage : Storage() { val lastMessage = messagesStorage.getMessageById(conversation.lastMessageId) if (lastMessage != null) conversation.lastMessage = lastMessage - val photos = VKUtil.parseJsonPhotos(JSONObject(CacheStorage.getString(cursor, PHOTOS))) + val photos = oldVKUtil.parseJsonPhotos(JSONObject(CacheStorage.getString(cursor, PHOTOS))) conversation.photo50 = photos[0] conversation.photo100 = photos[1] conversation.photo200 = photos[2] diff --git a/app/src/main/kotlin/com/meloda/fast/database/old/storage/GroupsStorage.kt b/app/src/main/kotlin/com/meloda/fast/database/old/storage/GroupsStorage.kt index 4350fc1d..1c779bcd 100644 --- a/app/src/main/kotlin/com/meloda/fast/database/old/storage/GroupsStorage.kt +++ b/app/src/main/kotlin/com/meloda/fast/database/old/storage/GroupsStorage.kt @@ -17,19 +17,19 @@ import com.meloda.fast.database.old.DatabaseKeys.SCREEN_NAME import com.meloda.fast.database.old.DatabaseKeys.TYPE import com.meloda.fast.database.old.DatabaseUtils.TABLE_GROUPS import com.meloda.fast.database.old.base.Storage -import com.meloda.fast.api.model.old.VKGroup -import com.meloda.fast.api.VKUtil +import com.meloda.fast.api.model.old.oldVKGroup +import com.meloda.fast.api.oldVKUtil import org.json.JSONObject -class GroupsStorage : Storage() { +class GroupsStorage : Storage() { override val tag = "GroupsStorage" @WorkerThread - fun getGroups(ids: IntArray): ArrayList { + fun getGroups(ids: IntArray): ArrayList { val cursor = CacheStorage.selectCursor(TABLE_GROUPS, GROUP_ID, ids) - val groups = ArrayList(cursor.count) + val groups = ArrayList(cursor.count) while (cursor.moveToNext()) groups.add(parseValue(cursor)) cursor.close() @@ -37,15 +37,15 @@ class GroupsStorage : Storage() { } @WorkerThread - fun getGroup(userId: Int): VKGroup? { + fun getGroup(userId: Int): oldVKGroup? { val group = getGroups(intArrayOf(userId)) return if (group.isNotEmpty()) group[0] else null } - override fun getAllValues(): ArrayList { + override fun getAllValues(): ArrayList { val cursor = CacheStorage.selectCursor(TABLE_GROUPS) - val groups = ArrayList() + val groups = ArrayList() while (cursor.moveToNext()) groups.add(parseValue(cursor)) @@ -54,7 +54,7 @@ class GroupsStorage : Storage() { return groups } - override fun insertValues(values: ArrayList, params: Bundle?) { + override fun insertValues(values: ArrayList, params: Bundle?) { if (values.isEmpty()) return database.beginTransaction() @@ -75,7 +75,7 @@ class GroupsStorage : Storage() { Log.d(tag, "Successful cached groups") } - override fun cacheValue(values: ContentValues, value: VKGroup, params: Bundle?) { + override fun cacheValue(values: ContentValues, value: oldVKGroup, params: Bundle?) { values.put(GROUP_ID, value.id) values.put(NAME, value.name) values.put(SCREEN_NAME, value.screenName) @@ -84,22 +84,22 @@ class GroupsStorage : Storage() { values.put(TYPE, value.type.value) val photos = - VKUtil.putPhotosToJson(value.photo50, value.photo100, value.photo200).toString() + oldVKUtil.putPhotosToJson(value.photo50, value.photo100, value.photo200).toString() values.put(PHOTOS, photos) } - override fun parseValue(cursor: Cursor): VKGroup { - val group = VKGroup() + override fun parseValue(cursor: Cursor): oldVKGroup { + val group = oldVKGroup() group.id = getInt(cursor, GROUP_ID) group.name = getString(cursor, NAME) group.screenName = getString(cursor, SCREEN_NAME) group.isClosed = getInt(cursor, IS_CLOSED) == 1 group.deactivated = getString(cursor, DEACTIVATED) - group.type = VKGroup.Type.fromString(getString(cursor, TYPE)) + group.type = oldVKGroup.Type.fromString(getString(cursor, TYPE)) - val photos = VKUtil.parseJsonPhotos(JSONObject(getString(cursor, PHOTOS))) + val photos = oldVKUtil.parseJsonPhotos(JSONObject(getString(cursor, PHOTOS))) group.photo50 = photos[0] group.photo100 = photos[1] diff --git a/app/src/main/kotlin/com/meloda/fast/database/old/storage/MessagesStorage.kt b/app/src/main/kotlin/com/meloda/fast/database/old/storage/MessagesStorage.kt index 8895031f..f84f6822 100644 --- a/app/src/main/kotlin/com/meloda/fast/database/old/storage/MessagesStorage.kt +++ b/app/src/main/kotlin/com/meloda/fast/database/old/storage/MessagesStorage.kt @@ -24,7 +24,7 @@ import com.meloda.fast.database.old.DatabaseUtils.TABLE_MESSAGES import com.meloda.fast.database.old.base.Storage import com.meloda.fast.util.Utils import com.meloda.fast.api.model.old.oldVKMessage -import com.meloda.fast.api.model.old.VKMessageAction +import com.meloda.fast.api.model.old.oldVKMessageAction import com.meloda.fast.api.model.old.VKModel import java.util.stream.Collectors @@ -153,7 +153,7 @@ class MessagesStorage : Storage() { if (replyMessage != null) message.replyMessage = replyMessage val blobAction = Utils.deserialize(CacheStorage.getBlob(cursor, ACTION)) - if (blobAction != null) message.action = blobAction as VKMessageAction + if (blobAction != null) message.action = blobAction as oldVKMessageAction val stringFwdMessages = CacheStorage.getString(cursor, FWD_MESSAGES) if (stringFwdMessages != null) { diff --git a/app/src/main/kotlin/com/meloda/fast/database/old/storage/UsersStorage.kt b/app/src/main/kotlin/com/meloda/fast/database/old/storage/UsersStorage.kt index 44f5857d..11a7ab96 100644 --- a/app/src/main/kotlin/com/meloda/fast/database/old/storage/UsersStorage.kt +++ b/app/src/main/kotlin/com/meloda/fast/database/old/storage/UsersStorage.kt @@ -6,7 +6,7 @@ import android.os.Bundle import android.util.Log import androidx.annotation.WorkerThread import com.meloda.fast.api.UserConfig -import com.meloda.fast.api.VKUtil +import com.meloda.fast.api.oldVKUtil import com.meloda.fast.api.model.old.oldVKUser import com.meloda.fast.database.old.CacheStorage import com.meloda.fast.database.old.DatabaseKeys.DEACTIVATED @@ -135,7 +135,7 @@ class UsersStorage : Storage() { values.put( PHOTOS, - VKUtil.putPhotosToJson( + oldVKUtil.putPhotosToJson( value.photo50, value.photo100, value.photo200 @@ -159,7 +159,7 @@ class UsersStorage : Storage() { user.lastSeen = CacheStorage.getInt(cursor, LAST_SEEN) val photos = - VKUtil.parseJsonPhotos(JSONObject(CacheStorage.getString(cursor, PHOTOS))) + oldVKUtil.parseJsonPhotos(JSONObject(CacheStorage.getString(cursor, PHOTOS))) user.photo50 = photos[0] user.photo100 = photos[1] diff --git a/app/src/main/kotlin/com/meloda/fast/di/DatabaseModule.kt b/app/src/main/kotlin/com/meloda/fast/di/DatabaseModule.kt index d05327e6..8b3900d9 100644 --- a/app/src/main/kotlin/com/meloda/fast/di/DatabaseModule.kt +++ b/app/src/main/kotlin/com/meloda/fast/di/DatabaseModule.kt @@ -3,6 +3,7 @@ package com.meloda.fast.di import com.meloda.fast.common.AppGlobal import com.meloda.fast.database.AppDatabase import com.meloda.fast.database.dao.ConversationsDao +import com.meloda.fast.database.dao.GroupsDao import com.meloda.fast.database.dao.MessagesDao import com.meloda.fast.database.dao.UsersDao import dagger.Module @@ -35,4 +36,9 @@ object DatabaseModule { fun provideMessagesDao(appDatabase: AppDatabase): MessagesDao = appDatabase.messagesDao() + @Provides + @Singleton + fun provideGroupsDao(appDatabase: AppDatabase): GroupsDao = + appDatabase.groupsDao() + } \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/extensions/Extensions.kt b/app/src/main/kotlin/com/meloda/fast/extensions/Extensions.kt index 64acf668..c93ae89c 100644 --- a/app/src/main/kotlin/com/meloda/fast/extensions/Extensions.kt +++ b/app/src/main/kotlin/com/meloda/fast/extensions/Extensions.kt @@ -1,3 +1 @@ -package com.meloda.fast.extensions - -fun Boolean.toApiStyle() = (if (this) 1 else 0).toString() \ No newline at end of file +package com.meloda.fast.extensions \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/screens/login/LoginViewModel.kt b/app/src/main/kotlin/com/meloda/fast/screens/login/LoginViewModel.kt index f603c24b..23b6ff06 100644 --- a/app/src/main/kotlin/com/meloda/fast/screens/login/LoginViewModel.kt +++ b/app/src/main/kotlin/com/meloda/fast/screens/login/LoginViewModel.kt @@ -5,7 +5,7 @@ import androidx.lifecycle.viewModelScope import com.meloda.fast.api.UserConfig import com.meloda.fast.api.VKConstants import com.meloda.fast.api.VKException -import com.meloda.fast.api.VKUtil +import com.meloda.fast.api.oldVKUtil import com.meloda.fast.api.datasource.AuthDataSource import com.meloda.fast.api.network.request.RequestAuthDirect import com.meloda.fast.base.viewmodel.BaseViewModel @@ -61,13 +61,13 @@ class LoginViewModel @Inject constructor( twoFaCode?.let { sendEvent(CodeSent) } - if (VKUtil.isValidationRequired(it)) { + if (oldVKUtil.isValidationRequired(it)) { it.validationSid?.let { sid -> sendEvent(ValidationRequired(validationSid = sid)) sendSms(sid) } - } else if (VKUtil.isCaptchaRequired(it)) { + } else if (oldVKUtil.isCaptchaRequired(it)) { it.captcha?.let { captcha -> sendEvent(CaptchaRequired(captcha.first to captcha.second)) } diff --git a/app/src/main/kotlin/com/meloda/fast/screens/messages/ConversationsAdapter.kt b/app/src/main/kotlin/com/meloda/fast/screens/messages/ConversationsAdapter.kt index a252c260..b09f9b19 100644 --- a/app/src/main/kotlin/com/meloda/fast/screens/messages/ConversationsAdapter.kt +++ b/app/src/main/kotlin/com/meloda/fast/screens/messages/ConversationsAdapter.kt @@ -1,17 +1,142 @@ package com.meloda.fast.screens.messages import android.content.Context +import android.graphics.Color +import android.graphics.drawable.ColorDrawable +import android.text.SpannableString +import android.text.style.ForegroundColorSpan import android.view.ViewGroup +import androidx.core.content.ContextCompat +import androidx.core.view.isVisible import androidx.recyclerview.widget.DiffUtil +import coil.load +import com.meloda.fast.R +import com.meloda.fast.api.UserConfig +import com.meloda.fast.api.VkUtils import com.meloda.fast.api.model.VkConversation +import com.meloda.fast.api.model.VkGroup +import com.meloda.fast.api.model.VkUser import com.meloda.fast.base.adapter.BaseAdapter import com.meloda.fast.base.adapter.BindingHolder import com.meloda.fast.databinding.ItemConversationBinding +import java.text.SimpleDateFormat -class ConversationsAdapter(context: Context, values: MutableList) : - BaseAdapter( - context, values, COMPARATOR - ) { +class ConversationsAdapter constructor( + context: Context, + values: MutableList, + val profiles: HashMap = hashMapOf(), + val groups: HashMap = hashMapOf() +) : BaseAdapter( + context, values, COMPARATOR +) { + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = + ItemHolder(ItemConversationBinding.inflate(inflater, parent, false)) + + inner class ItemHolder(binding: ItemConversationBinding) : + BindingHolder(binding) { + + private val dateColor = ContextCompat.getColor(context, R.color.date) + private val youPrefix = context.getString(R.string.you_message_prefix) + + override fun bind(position: Int) { + val conversation = getItem(position) + val message = conversation.lastMessage ?: return + + val chatUser: VkUser? = if (conversation.isUser()) { + profiles[conversation.id] +// profiles.find { it.id == conversation.id } + } else null + + val messageUser: VkUser? = if (message.isUser()) { + profiles[message.fromId] +// profiles.find { it.id == message.fromId } + } else null + + val chatGroup: VkGroup? = if (conversation.isGroup()) { + groups[conversation.id] +// groups.find { it.id == conversation.id } + } else null + + val messageGroup: VkGroup? = if (message.isGroup()) { + groups[message.fromId] +// groups.find { it.id == message.fromId } + } else null + + val avatar = when { + chatUser != null && !chatUser.photo200.isNullOrBlank() -> chatUser.photo200 + chatGroup != null && !chatGroup.photo200.isNullOrBlank() -> chatGroup.photo200 + !conversation.photo200.isNullOrBlank() -> conversation.photo200 + else -> null + } + + if (avatar == null) { + binding.avatar.setImageDrawable(ColorDrawable(Color.RED)) + } else { + binding.avatar.load(avatar) { crossfade(200) } + } + + binding.online.isVisible = chatUser?.online == true + + val actionMessage = VkUtils.getActionConversationText( + message = message, + youPrefix = youPrefix, + profiles = profiles, + groups = groups, + messageUser = messageUser, + messageGroup = messageGroup + ) + + val attachmentsMessage = VkUtils.getAttachmentConversationText( + context = context, + message = message + ) + + val forwardsMessage = VkUtils.getForwardsConversationText( + context = context, + message = message + ) + + val messageText = if (actionMessage != null || + attachmentsMessage != null || + forwardsMessage != null + ) "" + else message.text ?: "no_message" + + val coloredMessage = actionMessage ?: attachmentsMessage ?: forwardsMessage ?: "" + + var prefix = when { + actionMessage != null -> "" + message.isOut -> "$youPrefix: " + messageUser != null && messageUser.firstName.isNotBlank() -> "${messageUser.firstName}: " + messageGroup != null && messageGroup.toString() + .isNotBlank() -> "${messageGroup.name}: " + else -> "" + } + + if (!conversation.isChat() && !message.isOut || conversation.id == UserConfig.userId) prefix = + "" + +// if (conversation.isChat() || message.isOut) { + val spanText = "$prefix$coloredMessage $messageText".trim() + + val spanMessage = SpannableString(spanText) + spanMessage.setSpan( + ForegroundColorSpan(dateColor), 0, + prefix.length + coloredMessage.length, + 0 + ) + binding.message.text = spanMessage +// } else { +// binding.message.text = messageText +// } + + binding.title.text = + getItem(position).title ?: chatUser?.toString() ?: chatGroup?.name ?: "..." + + binding.date.text = SimpleDateFormat("HH:mm").format(message.date * 1000) + } + } companion object { private val COMPARATOR = object : DiffUtil.ItemCallback() { @@ -27,15 +152,4 @@ class ConversationsAdapter(context: Context, values: MutableList } } - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = - ItemHolder(ItemConversationBinding.inflate(inflater, parent, false)) - - inner class ItemHolder(binding: ItemConversationBinding) : - BindingHolder(binding) { - - override fun bind(position: Int) { - binding.title.text = getItem(position).title ?: "HUI" - } - } - } \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/screens/messages/ConversationsFragment.kt b/app/src/main/kotlin/com/meloda/fast/screens/messages/ConversationsFragment.kt index f33b54ab..65d88939 100644 --- a/app/src/main/kotlin/com/meloda/fast/screens/messages/ConversationsFragment.kt +++ b/app/src/main/kotlin/com/meloda/fast/screens/messages/ConversationsFragment.kt @@ -32,6 +32,8 @@ class ConversationsFragment : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + viewModel.loadProfileUser() + prepareViews() adapter = ConversationsAdapter(requireContext(), mutableListOf()) @@ -43,7 +45,7 @@ class ConversationsFragment : override fun onEvent(event: VKEvent) { super.onEvent(event) when (event) { - is ConversationsLoaded -> refreshConversations(event.conversations) + is ConversationsLoaded -> refreshConversations(event) is StartProgressEvent -> onProgressStarted() is StopProgressEvent -> onProgressStopped() } @@ -91,10 +93,14 @@ class ConversationsFragment : } } - private fun refreshConversations(conversations: List) { - fillRecyclerView(conversations) + private fun refreshConversations(event: ConversationsLoaded) { +// adapter.profiles.clear() + adapter.profiles += event.profiles - viewModel.loadSomeUsers(listOf(1, 2, 3, 362877006)) +// adapter.groups.clear() + adapter.groups += event.groups + + fillRecyclerView(event.conversations) } private fun fillRecyclerView(values: List) { diff --git a/app/src/main/kotlin/com/meloda/fast/screens/messages/ConversationsViewModel.kt b/app/src/main/kotlin/com/meloda/fast/screens/messages/ConversationsViewModel.kt index de68058d..59030797 100644 --- a/app/src/main/kotlin/com/meloda/fast/screens/messages/ConversationsViewModel.kt +++ b/app/src/main/kotlin/com/meloda/fast/screens/messages/ConversationsViewModel.kt @@ -1,10 +1,13 @@ package com.meloda.fast.screens.messages import androidx.lifecycle.viewModelScope +import com.meloda.fast.api.UserConfig import com.meloda.fast.api.VKConstants import com.meloda.fast.api.datasource.ConversationsDataSource import com.meloda.fast.api.datasource.UsersDataSource import com.meloda.fast.api.model.VkConversation +import com.meloda.fast.api.model.VkGroup +import com.meloda.fast.api.model.VkUser import com.meloda.fast.api.network.request.ConversationsGetRequest import com.meloda.fast.api.network.request.UsersGetRequest import com.meloda.fast.base.viewmodel.BaseViewModel @@ -14,6 +17,7 @@ import com.meloda.fast.base.viewmodel.VKEvent import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch +import java.util.* import javax.inject.Inject @HiltViewModel @@ -27,12 +31,27 @@ class ConversationsViewModel @Inject constructor( dataSource.getAllChats( ConversationsGetRequest( count = 30, +// offset = 37, + extended = true, fields = "${VKConstants.USER_FIELDS},${VKConstants.GROUP_FIELDS}" ) ) }, onAnswer = { it.response?.let { response -> + val profiles = hashMapOf() + response.profiles?.forEach { baseUser -> + baseUser.asVkUser().let { user -> profiles[user.id] = user } + } + + val groups = hashMapOf() + response.groups?.forEach { baseGroup -> + baseGroup.asVkGroup().let { group -> groups[group.id] = group } + } + +// val profiles = response.profiles?.map { profile -> profile.asVkUser() } ?: listOf() +// val groups = response.groups?.map { group -> group.asVkGroup() } ?: listOf() + sendEvent( ConversationsLoaded( count = response.count, @@ -41,14 +60,16 @@ class ConversationsViewModel @Inject constructor( items.conversation.asVkConversation( items.lastMessage.asVkMessage() ) - } + }, + profiles = profiles, + groups = groups ) ) } }, onError = { val er = it - val i = 0 + throw it }, onStart = { sendEvent(StartProgressEvent) @@ -58,34 +79,25 @@ class ConversationsViewModel @Inject constructor( }) } - fun loadSomeUsers(usersIds: List) = viewModelScope.launch { + fun loadProfileUser() = viewModelScope.launch { makeJob({ - usersDataSource.getById( - UsersGetRequest( - usersIds = usersIds, - fields = "sex" - ) - ) + usersDataSource.getById(UsersGetRequest(fields = "online,photo_200")) }, onAnswer = { - val argh = it - val i = 0 it.response?.let { r -> - val users = r.map { user -> user.asVkUser() } - + val users = r.map { u -> u.asVkUser() } usersDataSource.storeUsers(users) - } - }, - onError = { - val e = it - val i = 0 - }) + UserConfig.vkUser = users[0] + } + }) } } data class ConversationsLoaded( val count: Int, val unreadCount: Int, - val conversations: List + val conversations: List, + val profiles: HashMap, + val groups: HashMap ) : VKEvent() \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/util/VKUtils.kt b/app/src/main/kotlin/com/meloda/fast/util/VKUtils.kt index 8686cc88..a3b4aa6f 100644 --- a/app/src/main/kotlin/com/meloda/fast/util/VKUtils.kt +++ b/app/src/main/kotlin/com/meloda/fast/util/VKUtils.kt @@ -4,7 +4,7 @@ import android.content.Context import android.graphics.drawable.Drawable import androidx.core.content.ContextCompat import com.meloda.fast.R -import com.meloda.fast.api.VKUtil +import com.meloda.fast.api.oldVKUtil import com.meloda.fast.api.model.old.* import com.meloda.fast.common.AppGlobal import com.meloda.fast.extensions.ContextExtensions.color @@ -31,7 +31,7 @@ object VKUtils { } else { r.getString( R.string.user_last_seen_at, - VKUtil.getLastSeenTime(user.lastSeen * 1000L) + oldVKUtil.getLastSeenTime(user.lastSeen * 1000L) ) } } @@ -195,11 +195,11 @@ object VKUtils { var result = "" when (it.type) { - VKMessageAction.Type.CHAT_CREATE -> result = context.getString( + oldVKMessageAction.Type.CHAT_CREATE -> result = context.getString( R.string.message_action_created_chat, "" ) - VKMessageAction.Type.INVITE_USER -> result = + oldVKMessageAction.Type.INVITE_USER -> result = if (lastMessage.fromId == lastMessage.action!!.memberId) { context.getString(R.string.message_action_returned_to_chat, "") } else { @@ -207,11 +207,11 @@ object VKUtils { // val invited = MemoryCache.getUserById(lastMessage.action!!.memberId) // context.getString(R.string.message_action_invited_user, invited) } - VKMessageAction.Type.INVITE_USER_BY_LINK -> result = context.getString( + oldVKMessageAction.Type.INVITE_USER_BY_LINK -> result = context.getString( R.string.message_action_invited_by_link, "" ) - VKMessageAction.Type.KICK_USER -> result = + oldVKMessageAction.Type.KICK_USER -> result = if (lastMessage.fromId == lastMessage.action!!.memberId) { context.getString(R.string.message_action_left_from_chat, "") } else { @@ -219,23 +219,23 @@ object VKUtils { // val kicked = MemoryCache.getUserById(lastMessage.action!!.memberId) // context.getString(R.string.message_action_kicked_user, kicked) } - VKMessageAction.Type.PHOTO_REMOVE -> result = context.getString( + oldVKMessageAction.Type.PHOTO_REMOVE -> result = context.getString( R.string.message_action_removed_photo, "" ) - VKMessageAction.Type.PHOTO_UPDATE -> result = context.getString( + oldVKMessageAction.Type.PHOTO_UPDATE -> result = context.getString( R.string.message_action_updated_photo, "" ) - VKMessageAction.Type.PIN_MESSAGE -> result = context.getString( + oldVKMessageAction.Type.PIN_MESSAGE -> result = context.getString( R.string.message_action_pinned_message, "" ) - VKMessageAction.Type.UNPIN_MESSAGE -> result = context.getString( + oldVKMessageAction.Type.UNPIN_MESSAGE -> result = context.getString( R.string.message_action_unpinned_message, "" ) - VKMessageAction.Type.TITLE_UPDATE -> result = context.getString( + oldVKMessageAction.Type.TITLE_UPDATE -> result = context.getString( R.string.message_action_updated_title, "" ) diff --git a/app/src/main/res/font/google_sans_regular.ttf b/app/src/main/res/font/google_sans_regular.ttf index e017417b..f8fa337c 100644 Binary files a/app/src/main/res/font/google_sans_regular.ttf and b/app/src/main/res/font/google_sans_regular.ttf differ diff --git a/app/src/main/res/layout/fragment_conversations.xml b/app/src/main/res/layout/fragment_conversations.xml index 4c3f8723..7681f86b 100644 --- a/app/src/main/res/layout/fragment_conversations.xml +++ b/app/src/main/res/layout/fragment_conversations.xml @@ -8,8 +8,7 @@ + android:layout_height="match_parent"> + tools:listitem="@layout/item_conversation_old" /> - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_main.xml b/app/src/main/res/layout/fragment_main.xml index 72cff9af..1441837d 100644 --- a/app/src/main/res/layout/fragment_main.xml +++ b/app/src/main/res/layout/fragment_main.xml @@ -9,14 +9,14 @@ + android:layout_height="match_parent" /> - + xmlns:tools="http://schemas.android.com/tools"> - + android:layout_height="wrap_content" + android:layout_marginHorizontal="24dp" + android:layout_marginVertical="10dp" + android:orientation="horizontal"> + android:layout_width="56dp" + android:layout_height="56dp"> - + + + + + + + + + - - - - - - - - - - - - - - + android:layout_weight="1" + android:fontFamily="@font/google_sans_regular" + android:maxLines="2" + android:textColor="#201A1A" + android:textSize="22sp" + tools:text="Title" /> - + + + + + + + - - - + - + - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/item_conversation_old.xml b/app/src/main/res/layout/item_conversation_old.xml new file mode 100644 index 00000000..236c3e6d --- /dev/null +++ b/app/src/main/res/layout/item_conversation_old.xml @@ -0,0 +1,186 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-v31/colors.xml b/app/src/main/res/values-v31/colors.xml index bdde9573..1f96aee1 100644 --- a/app/src/main/res/values-v31/colors.xml +++ b/app/src/main/res/values-v31/colors.xml @@ -1,16 +1,19 @@ - @android:color/system_accent1_10 - @android:color/system_accent1_10 - @android:color/system_accent1_10 + @android:color/system_neutral1_50 + @android:color/system_neutral1_50 + @android:color/system_neutral1_50 @android:color/system_accent1_500 @android:color/system_accent3_500 @android:color/system_accent3_200 @android:color/system_accent1_10 + @android:color/system_accent3_200 + @android:color/system_neutral2_500 + @android:color/system_neutral1_900 - @android:color/system_accent1_10 + @android:color/system_neutral1_50 #E0E0E0 diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 1152bcb5..70ece8a2 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -15,6 +15,10 @@ #99000000 + #00ff00 + #212121 + #000000 + #ff000000 #DE000000 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a2e533dc..1d7613d4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -158,5 +158,10 @@ Conversations Code Input code from sms + You + Geolocation + Point + Message + Messages