Skip to content
Snippets Groups Projects
Commit 154e1316 authored by Taras's avatar Taras
Browse files

override equals for post content to optimize payload calculation

parent fd9bce72
No related branches found
No related tags found
No related merge requests found
...@@ -21,7 +21,17 @@ sealed class PostContent(open val type: PostContentType) { ...@@ -21,7 +21,17 @@ sealed class PostContent(open val type: PostContentType) {
data class TextContent( data class TextContent(
val message: String, val message: String,
val messageSpanned: Spanned val messageSpanned: Spanned
) : PostContent(PostContentType.TEXT_CONTENT) ) : PostContent(PostContentType.TEXT_CONTENT) {
// to optimize payload calculation (spanned==spanned will return false and trigger unnecessary list update)
override fun equals(other: Any?): Boolean = this.message == (other as? TextContent)?.message
override fun hashCode(): Int {
var result = message.hashCode()
result = 31 * result + messageSpanned.hashCode()
return result
}
}
data class MediaContent( data class MediaContent(
override val type: PostContentType, override val type: PostContentType,
...@@ -32,6 +42,14 @@ data class MediaContent( ...@@ -32,6 +42,14 @@ data class MediaContent(
val thumbHash: String? val thumbHash: String?
) : PostContent(type) { ) : PostContent(type) {
override fun equals(other: Any?): Boolean =
this.type == (other as? MediaContent)?.type &&
this.caption == (other as? MediaContent)?.caption &&
this.mediaFileData == (other as? MediaContent)?.mediaFileData &&
this.thumbnailFileData == (other as? MediaContent)?.thumbnailFileData &&
this.thumbHash == (other as? MediaContent)?.thumbHash
fun thumbnailOrFullSize(width: Int) = thumbnailFileData?.let { fun thumbnailOrFullSize(width: Int) = thumbnailFileData?.let {
Size(width, (width / it.aspectRatio).toInt()) Size(width, (width / it.aspectRatio).toInt())
} ?: Size(width, (width / mediaFileData.aspectRatio).toInt()) } ?: Size(width, (width / mediaFileData.aspectRatio).toInt())
...@@ -39,6 +57,16 @@ data class MediaContent( ...@@ -39,6 +57,16 @@ data class MediaContent(
fun getMediaType(): MediaType = fun getMediaType(): MediaType =
if (type == PostContentType.VIDEO_CONTENT) MediaType.Video else MediaType.Image if (type == PostContentType.VIDEO_CONTENT) MediaType.Video else MediaType.Image
override fun hashCode(): Int {
var result = type.hashCode()
result = 31 * result + (caption?.hashCode() ?: 0)
result = 31 * result + (captionSpanned?.hashCode() ?: 0)
result = 31 * result + mediaFileData.hashCode()
result = 31 * result + (thumbnailFileData?.hashCode() ?: 0)
result = 31 * result + (thumbHash?.hashCode() ?: 0)
return result
}
} }
data class PollContent( data class PollContent(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment