From 95daff285f9db20a5b75cc8c9dedbff3e827f97a Mon Sep 17 00:00:00 2001 From: Adizbek Date: Tue, 9 Apr 2019 18:07:20 +0500 Subject: [PATCH 1/5] Show media size --- .../chatroom/adapter/AttachmentViewHolder.kt | 57 +++++++++++++++---- .../chat/rocket/android/helper/Constants.kt | 7 +++ .../res/layout/item_message_attachment.xml | 15 ++++- 3 files changed, 67 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/chat/rocket/android/chatroom/adapter/AttachmentViewHolder.kt b/app/src/main/java/chat/rocket/android/chatroom/adapter/AttachmentViewHolder.kt index 2c5ed9fdb8..b04f5639b0 100644 --- a/app/src/main/java/chat/rocket/android/chatroom/adapter/AttachmentViewHolder.kt +++ b/app/src/main/java/chat/rocket/android/chatroom/adapter/AttachmentViewHolder.kt @@ -13,6 +13,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import chat.rocket.android.R import chat.rocket.android.chatroom.uimodel.AttachmentUiModel import chat.rocket.android.emoji.EmojiReactionListener +import chat.rocket.android.helper.DataMeasure import chat.rocket.android.helper.ImageHelper import chat.rocket.android.player.PlayerActivity import chat.rocket.android.util.extensions.content @@ -25,21 +26,21 @@ import kotlinx.android.synthetic.main.item_message_attachment.view.* import timber.log.Timber class AttachmentViewHolder( - itemView: View, - listener: ActionsListener, - reactionListener: EmojiReactionListener? = null, - var actionAttachmentOnClickListener: ActionAttachmentOnClickListener + itemView: View, + listener: ActionsListener, + reactionListener: EmojiReactionListener? = null, + var actionAttachmentOnClickListener: ActionAttachmentOnClickListener ) : BaseViewHolder(itemView, listener, reactionListener) { private val messageViews = listOf( - itemView.text_sender, - itemView.text_message_time, - itemView.text_content, - itemView.text_view_more + itemView.text_sender, + itemView.text_message_time, + itemView.text_content, + itemView.text_view_more ) private val audioVideoViews = listOf( - itemView.audio_video_attachment, - itemView.play_button + itemView.audio_video_attachment, + itemView.play_button ) private val quoteBarColor = ContextCompat.getColor(itemView.context, R.color.quoteBar) @@ -65,6 +66,30 @@ class AttachmentViewHolder( data.hasFile -> bindFile(data) } + file_info.isVisible = data.hasAudioOrVideo || data.hasImage + + when { + data.hasVideo -> file_info.text = data.rawData.videoSize?.toDataSize() + data.hasAudio -> file_info.text = data.rawData.audioSize?.toDataSize() + data.hasImage -> file_info.text = data.rawData.imageSize?.toDataSize() + } + + // File description - self describing + + // Message attachment + + // Author + + // If not media or message, show the text with quote bar + + // If it has titleLink and is not "type = file" show the title/titleLink on this field. + + // Fields + + // Actions + + // Quote bar + // File description - self describing file_description.isVisible = data.hasDescription file_description.text = data.description @@ -299,6 +324,18 @@ class AttachmentViewHolder( } } +private fun Long.toDataSize(): String { + var size = this.toFloat() + + return when { + size > DataMeasure.GIGABYTE -> String.format("%.2f Gb", size / DataMeasure.GIGABYTE) + size > DataMeasure.MEGABYTE -> String.format("%.2f Mb", size / DataMeasure.MEGABYTE) + size > DataMeasure.KILOBYTE -> String.format("%.2f Kb", size / DataMeasure.KILOBYTE) + else -> "$this b" + } + +} + interface ActionAttachmentOnClickListener { fun onActionClicked(view: View, action: Action) } \ No newline at end of file diff --git a/app/src/main/java/chat/rocket/android/helper/Constants.kt b/app/src/main/java/chat/rocket/android/helper/Constants.kt index 7dbeb08ec2..36c66e0365 100644 --- a/app/src/main/java/chat/rocket/android/helper/Constants.kt +++ b/app/src/main/java/chat/rocket/android/helper/Constants.kt @@ -12,6 +12,13 @@ object Constants { const val CHATROOM_LIVE_CHAT = 3 } +object DataMeasure { + const val BYTE = 1 + const val KILOBYTE = 1024 + const val MEGABYTE = KILOBYTE * 1024 + const val GIGABYTE = MEGABYTE * 1024 +} + object ChatRoomsSortOrder { const val ALPHABETICAL: Int = 0 const val ACTIVITY: Int = 1 diff --git a/app/src/main/res/layout/item_message_attachment.xml b/app/src/main/res/layout/item_message_attachment.xml index 0ffb5ca0d4..48eabe82f3 100644 --- a/app/src/main/res/layout/item_message_attachment.xml +++ b/app/src/main/res/layout/item_message_attachment.xml @@ -43,6 +43,17 @@ tools:text="Some description" tools:visibility="visible" /> + + Date: Sat, 4 May 2019 04:30:55 +0500 Subject: [PATCH 2/5] Update to latest version. --- .../android/chatroom/adapter/AttachmentViewHolder.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/chat/rocket/android/chatroom/adapter/AttachmentViewHolder.kt b/app/src/main/java/chat/rocket/android/chatroom/adapter/AttachmentViewHolder.kt index b04f5639b0..e05177c75c 100644 --- a/app/src/main/java/chat/rocket/android/chatroom/adapter/AttachmentViewHolder.kt +++ b/app/src/main/java/chat/rocket/android/chatroom/adapter/AttachmentViewHolder.kt @@ -13,7 +13,6 @@ import androidx.recyclerview.widget.LinearLayoutManager import chat.rocket.android.R import chat.rocket.android.chatroom.uimodel.AttachmentUiModel import chat.rocket.android.emoji.EmojiReactionListener -import chat.rocket.android.helper.DataMeasure import chat.rocket.android.helper.ImageHelper import chat.rocket.android.player.PlayerActivity import chat.rocket.android.util.extensions.content @@ -324,6 +323,13 @@ class AttachmentViewHolder( } } +object DataMeasure { + const val BYTE = 1 + const val KILOBYTE = 1024 + const val MEGABYTE = KILOBYTE * 1024 + const val GIGABYTE = MEGABYTE * 1024 +} + private fun Long.toDataSize(): String { var size = this.toFloat() From 9faf092c83e2b6f9fe8c47b5dab35bda6b49eaec Mon Sep 17 00:00:00 2001 From: Adizbek Date: Sat, 4 May 2019 04:31:52 +0500 Subject: [PATCH 3/5] Fix code formatting. --- .../chatroom/adapter/AttachmentViewHolder.kt | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/chat/rocket/android/chatroom/adapter/AttachmentViewHolder.kt b/app/src/main/java/chat/rocket/android/chatroom/adapter/AttachmentViewHolder.kt index e05177c75c..a27225e391 100644 --- a/app/src/main/java/chat/rocket/android/chatroom/adapter/AttachmentViewHolder.kt +++ b/app/src/main/java/chat/rocket/android/chatroom/adapter/AttachmentViewHolder.kt @@ -25,21 +25,21 @@ import kotlinx.android.synthetic.main.item_message_attachment.view.* import timber.log.Timber class AttachmentViewHolder( - itemView: View, - listener: ActionsListener, - reactionListener: EmojiReactionListener? = null, - var actionAttachmentOnClickListener: ActionAttachmentOnClickListener + itemView: View, + listener: ActionsListener, + reactionListener: EmojiReactionListener? = null, + var actionAttachmentOnClickListener: ActionAttachmentOnClickListener ) : BaseViewHolder(itemView, listener, reactionListener) { private val messageViews = listOf( - itemView.text_sender, - itemView.text_message_time, - itemView.text_content, - itemView.text_view_more + itemView.text_sender, + itemView.text_message_time, + itemView.text_content, + itemView.text_view_more ) private val audioVideoViews = listOf( - itemView.audio_video_attachment, - itemView.play_button + itemView.audio_video_attachment, + itemView.play_button ) private val quoteBarColor = ContextCompat.getColor(itemView.context, R.color.quoteBar) @@ -154,9 +154,9 @@ class AttachmentViewHolder( image_attachment.controller = controller image_attachment.setOnClickListener { ImageHelper.openImage( - context, - data.imageUrl!!, - data.title?.toString() + context, + data.imageUrl!!, + data.title?.toString() ) } @@ -213,7 +213,7 @@ class AttachmentViewHolder( text_content.addOnLayoutChangeListener(object : View.OnLayoutChangeListener { override fun onLayoutChange(v: View, left: Int, top: Int, right: Int, bottom: Int, - oldLeft: Int, oldTop: Int, oldRight: Int, oldBottom: Int) { + oldLeft: Int, oldTop: Int, oldRight: Int, oldBottom: Int) { val textMeasuredHeight = bottom - top if (collapsedHeight >= textMeasuredHeight) { text_view_more.isVisible = false @@ -222,13 +222,13 @@ class AttachmentViewHolder( } val expandAnimation = ValueAnimator - .ofInt(collapsedHeight, textMeasuredHeight) - .setDuration(300) + .ofInt(collapsedHeight, textMeasuredHeight) + .setDuration(300) expandAnimation.interpolator = LinearInterpolator() val collapseAnimation = ValueAnimator - .ofInt(textMeasuredHeight, collapsedHeight) - .setDuration(300) + .ofInt(textMeasuredHeight, collapsedHeight) + .setDuration(300) collapseAnimation.interpolator = LinearInterpolator() expandAnimation.addUpdateListener { @@ -307,10 +307,10 @@ class AttachmentViewHolder( attachment_text.isVisible = data.hasText attachment_text.text = data.text actions_list.layoutManager = LinearLayoutManager(itemView.context, - when (alignment) { - "horizontal" -> LinearLayoutManager.HORIZONTAL - else -> LinearLayoutManager.VERTICAL //Default - }, false) + when (alignment) { + "horizontal" -> LinearLayoutManager.HORIZONTAL + else -> LinearLayoutManager.VERTICAL //Default + }, false) actions_list.adapter = ActionsListAdapter(actions, actionAttachmentOnClickListener) } } @@ -331,7 +331,7 @@ object DataMeasure { } private fun Long.toDataSize(): String { - var size = this.toFloat() + val size = this.toFloat() return when { size > DataMeasure.GIGABYTE -> String.format("%.2f Gb", size / DataMeasure.GIGABYTE) From d131696ab4a7aef054916e0456ba0991b2ccc0a7 Mon Sep 17 00:00:00 2001 From: Adizbek Date: Sat, 4 May 2019 04:36:00 +0500 Subject: [PATCH 4/5] Fix code formatting. --- .../chatroom/adapter/AttachmentViewHolder.kt | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/app/src/main/java/chat/rocket/android/chatroom/adapter/AttachmentViewHolder.kt b/app/src/main/java/chat/rocket/android/chatroom/adapter/AttachmentViewHolder.kt index a27225e391..b4129e483f 100644 --- a/app/src/main/java/chat/rocket/android/chatroom/adapter/AttachmentViewHolder.kt +++ b/app/src/main/java/chat/rocket/android/chatroom/adapter/AttachmentViewHolder.kt @@ -73,22 +73,6 @@ class AttachmentViewHolder( data.hasImage -> file_info.text = data.rawData.imageSize?.toDataSize() } - // File description - self describing - - // Message attachment - - // Author - - // If not media or message, show the text with quote bar - - // If it has titleLink and is not "type = file" show the title/titleLink on this field. - - // Fields - - // Actions - - // Quote bar - // File description - self describing file_description.isVisible = data.hasDescription file_description.text = data.description From 4b9fd6a6f61b48ce34cf7a966f54046c33b92cfd Mon Sep 17 00:00:00 2001 From: Adizbek Date: Sat, 4 May 2019 04:36:38 +0500 Subject: [PATCH 5/5] Fix code formatting. --- .../android/chatroom/adapter/AttachmentViewHolder.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/chat/rocket/android/chatroom/adapter/AttachmentViewHolder.kt b/app/src/main/java/chat/rocket/android/chatroom/adapter/AttachmentViewHolder.kt index b4129e483f..fa653ad4d2 100644 --- a/app/src/main/java/chat/rocket/android/chatroom/adapter/AttachmentViewHolder.kt +++ b/app/src/main/java/chat/rocket/android/chatroom/adapter/AttachmentViewHolder.kt @@ -197,7 +197,7 @@ class AttachmentViewHolder( text_content.addOnLayoutChangeListener(object : View.OnLayoutChangeListener { override fun onLayoutChange(v: View, left: Int, top: Int, right: Int, bottom: Int, - oldLeft: Int, oldTop: Int, oldRight: Int, oldBottom: Int) { + oldLeft: Int, oldTop: Int, oldRight: Int, oldBottom: Int) { val textMeasuredHeight = bottom - top if (collapsedHeight >= textMeasuredHeight) { text_view_more.isVisible = false @@ -206,13 +206,13 @@ class AttachmentViewHolder( } val expandAnimation = ValueAnimator - .ofInt(collapsedHeight, textMeasuredHeight) - .setDuration(300) + .ofInt(collapsedHeight, textMeasuredHeight) + .setDuration(300) expandAnimation.interpolator = LinearInterpolator() val collapseAnimation = ValueAnimator - .ofInt(textMeasuredHeight, collapsedHeight) - .setDuration(300) + .ofInt(textMeasuredHeight, collapsedHeight) + .setDuration(300) collapseAnimation.interpolator = LinearInterpolator() expandAnimation.addUpdateListener {