new attachments: gift, graffiti
fix NullPointerException on VkPhoto.kt text param
This commit is contained in:
@@ -150,9 +150,7 @@ object VkUtils {
|
||||
}
|
||||
BaseVkAttachmentItem.AttachmentType.GIFT -> {
|
||||
val gift = baseAttachment.gift ?: continue
|
||||
attachments += VkGift(
|
||||
link = gift.thumb_48
|
||||
)
|
||||
attachments += gift.asVkGift()
|
||||
}
|
||||
BaseVkAttachmentItem.AttachmentType.WALL -> {
|
||||
val wall = baseAttachment.wall ?: continue
|
||||
@@ -160,9 +158,7 @@ object VkUtils {
|
||||
}
|
||||
BaseVkAttachmentItem.AttachmentType.GRAFFITI -> {
|
||||
val graffiti = baseAttachment.graffiti ?: continue
|
||||
attachments += VkGraffiti(
|
||||
link = graffiti.url
|
||||
)
|
||||
attachments += graffiti.asVkGraffiti()
|
||||
}
|
||||
BaseVkAttachmentItem.AttachmentType.POLL -> {
|
||||
val poll = baseAttachment.poll ?: continue
|
||||
|
||||
@@ -5,7 +5,10 @@ import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Parcelize
|
||||
data class VkGift(
|
||||
val link: String
|
||||
val id: Int,
|
||||
val thumb256: String?,
|
||||
val thumb96: String?,
|
||||
val thumb48: String
|
||||
) : VkAttachment() {
|
||||
|
||||
@IgnoredOnParcel
|
||||
|
||||
@@ -5,7 +5,12 @@ import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Parcelize
|
||||
data class VkGraffiti(
|
||||
val link: String
|
||||
val id: Int,
|
||||
val ownerId: Int,
|
||||
val url: String,
|
||||
val width: Int,
|
||||
val height: Int,
|
||||
val accessKey: String
|
||||
) : VkAttachment() {
|
||||
|
||||
@IgnoredOnParcel
|
||||
|
||||
@@ -15,7 +15,7 @@ data class VkPhoto(
|
||||
val hasTags: Boolean,
|
||||
val accessKey: String?,
|
||||
val sizes: List<BaseVkPhoto.Size>,
|
||||
val text: String,
|
||||
val text: String?,
|
||||
val userId: Int?
|
||||
) : VkAttachment() {
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.meloda.fast.api.model.base.attachments
|
||||
|
||||
import android.os.Parcelable
|
||||
import com.meloda.fast.api.model.attachments.VkGift
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Parcelize
|
||||
@@ -9,4 +10,13 @@ data class BaseVkGift(
|
||||
val thumb_256: String?,
|
||||
val thumb_96: String?,
|
||||
val thumb_48: String
|
||||
) : Parcelable
|
||||
) : Parcelable {
|
||||
|
||||
fun asVkGift() = VkGift(
|
||||
id = id,
|
||||
thumb256 = thumb_256,
|
||||
thumb96 = thumb_96,
|
||||
thumb48 = thumb_48
|
||||
)
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.meloda.fast.api.model.base.attachments
|
||||
|
||||
import android.os.Parcelable
|
||||
import com.meloda.fast.api.model.attachments.VkGraffiti
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Parcelize
|
||||
@@ -11,4 +12,15 @@ data class BaseVkGraffiti(
|
||||
val width: Int,
|
||||
val height: Int,
|
||||
val access_key: String
|
||||
) : Parcelable
|
||||
) : Parcelable {
|
||||
|
||||
fun asVkGraffiti() = VkGraffiti(
|
||||
id = id,
|
||||
ownerId = owner_id,
|
||||
url = url,
|
||||
width = width,
|
||||
height = height,
|
||||
accessKey = access_key
|
||||
)
|
||||
|
||||
}
|
||||
@@ -13,7 +13,7 @@ data class BaseVkPhoto(
|
||||
val has_tags: Boolean,
|
||||
val access_key: String?,
|
||||
val sizes: List<Size>,
|
||||
val text: String,
|
||||
val text: String?,
|
||||
val user_id: Int?,
|
||||
val lat: Double?,
|
||||
val long: Double?,
|
||||
|
||||
@@ -66,6 +66,10 @@ class AttachmentInflater constructor(
|
||||
when (val attachment = attachments[0]) {
|
||||
is VkSticker -> return sticker(attachment)
|
||||
is VkWall -> return wall(attachment)
|
||||
is VkVoiceMessage -> return voice(attachment)
|
||||
is VkCall -> return call(attachment)
|
||||
is VkGraffiti -> return graffiti(attachment)
|
||||
is VkGift -> return gift(attachment)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,8 +98,6 @@ class AttachmentInflater constructor(
|
||||
is VkAudio -> audio(attachment)
|
||||
is VkFile -> file(attachment)
|
||||
is VkLink -> link(attachment)
|
||||
is VkVoiceMessage -> voice(attachment)
|
||||
is VkCall -> call(attachment)
|
||||
|
||||
else -> Log.e(
|
||||
"Attachment inflater",
|
||||
@@ -370,4 +372,38 @@ class AttachmentInflater constructor(
|
||||
binding.state.text = callState
|
||||
}
|
||||
|
||||
private fun graffiti(graffiti: VkGraffiti) {
|
||||
val binding = ItemMessageAttachmentGraffitiBinding.inflate(inflater, container, true)
|
||||
|
||||
val url = graffiti.url
|
||||
|
||||
val heightCoefficient = graffiti.height / AndroidUtils.px(140)
|
||||
|
||||
with(binding.image) {
|
||||
layoutParams = LinearLayoutCompat.LayoutParams(
|
||||
AndroidUtils.px(140).roundToInt(),
|
||||
(graffiti.height / heightCoefficient).roundToInt()
|
||||
)
|
||||
|
||||
load(url) { crossfade(150) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun gift(gift: VkGift) {
|
||||
val binding = ItemMessageAttachmentGiftBinding.inflate(inflater, container, true)
|
||||
|
||||
val url = gift.thumb256 ?: gift.thumb96 ?: gift.thumb48
|
||||
|
||||
with(binding.image) {
|
||||
shapeAppearanceModel = shapeAppearanceModel.withCornerSize { AndroidUtils.px(12) }
|
||||
|
||||
layoutParams = LinearLayoutCompat.LayoutParams(
|
||||
AndroidUtils.px(140).roundToInt(),
|
||||
AndroidUtils.px(140).roundToInt()
|
||||
)
|
||||
|
||||
load(url) { crossfade(150) }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.google.android.material.imageview.ShapeableImageView
|
||||
android:id="@+id/image"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
</layout>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.google.android.material.imageview.ShapeableImageView
|
||||
android:id="@+id/image"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
</layout>
|
||||
Reference in New Issue
Block a user