Skip to content
This repository has been archived by the owner on Jun 7, 2020. It is now read-only.

[WIP][NEW] Show media size #2213

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<AttachmentUiModel>(itemView, listener, reactionListener) {

private val messageViews = listOf<View>(
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<View>(
itemView.audio_video_attachment,
itemView.play_button
itemView.audio_video_attachment,
itemView.play_button
)

private val quoteBarColor = ContextCompat.getColor(itemView.context, R.color.quoteBar)
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
7 changes: 7 additions & 0 deletions app/src/main/java/chat/rocket/android/helper/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions app/src/main/res/layout/item_message_attachment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,25 @@
tools:text="Some description"
tools:visibility="visible" />

<TextView
android:id="@+id/file_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:visibility="gone"
app:layout_constraintStart_toStartOf="@id/guideline"
app:layout_constraintTop_toBottomOf="@id/file_description"
tools:text="File info"
tools:visibility="visible" />

<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/image_attachment"
android:layout_width="0dp"
android:layout_height="150dp"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/guideline"
app:layout_constraintTop_toBottomOf="@id/file_description"
app:layout_constraintTop_toBottomOf="@id/file_info"
fresco:actualImageScaleType="centerCrop"
fresco:placeholderImage="@drawable/image_dummy"
tools:background="@drawable/image_dummy"
Expand Down Expand Up @@ -91,7 +102,7 @@
<TextView
android:id="@+id/text_file_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="55dp"
android:drawableStart="@drawable/ic_files_24dp"
android:drawablePadding="6dp"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
Expand Down