Skip to content

Commit

Permalink
Merge pull request #2699 from nextcloud/backport/2697/stable-15.1
Browse files Browse the repository at this point in the history
[stable-15.1] fix missing file icons in chat
  • Loading branch information
mahibi authored Jan 18, 2023
2 parents 2b24ee0 + 880a84e commit f0d78d1
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,77 +106,18 @@ abstract class PreviewMessageViewHolder(itemView: View?, payload: Any?) :
@Suppress("NestedBlockDepth", "ComplexMethod", "LongMethod")
override fun onBind(message: ChatMessage) {
super.onBind(message)
image.minimumHeight = DisplayUtils.convertDpToPixel(MIN_IMAGE_HEIGHT, context).toInt()

time.text = dateUtils.getLocalTimeStringFromTimestamp(message.timestamp)
if (userAvatar != null) {
if (message.isGrouped || message.isOneToOneConversation) {
if (message.isOneToOneConversation) {
userAvatar.visibility = View.GONE
} else {
userAvatar.visibility = View.INVISIBLE
}
} else {
userAvatar.visibility = View.VISIBLE
userAvatar.setOnClickListener { v: View ->
if (payload is MessagePayload) {
(payload as MessagePayload).profileBottomSheet.showFor(
message.actorId!!,
v.context
)
}
}
if (ACTOR_TYPE_BOTS == message.actorType && ACTOR_ID_CHANGELOG == message.actorId) {
userAvatar.loadChangelogBotAvatar()
}
}
}

viewThemeUtils!!.platform.colorCircularProgressBar(progressBar!!)
clickView = image
messageText.visibility = View.VISIBLE
if (message.getCalculateMessageType() === ChatMessage.MessageType.SINGLE_NC_ATTACHMENT_MESSAGE) {
fileViewerUtils = FileViewerUtils(context!!, message.activeUser!!)
val fileName = message.selectedIndividualHashMap!![KEY_NAME]
messageText.text = fileName
if (message.selectedIndividualHashMap!!.containsKey(KEY_CONTACT_NAME)) {
previewContainer.visibility = View.GONE
previewContactName.text = message.selectedIndividualHashMap!![KEY_CONTACT_NAME]
progressBar = previewContactProgressBar
messageText.visibility = View.INVISIBLE
clickView = previewContactContainer
viewThemeUtils!!.talk.colorContactChatItemBackground(previewContactContainer)
viewThemeUtils!!.talk.colorContactChatItemName(previewContactName)
viewThemeUtils!!.platform.colorCircularProgressBarOnPrimaryContainer(previewContactProgressBar!!)
} else {
previewContainer.visibility = View.VISIBLE
previewContactContainer.visibility = View.GONE
}
if (message.selectedIndividualHashMap!!.containsKey(KEY_CONTACT_PHOTO)) {
image = previewContactPhoto
placeholder = getDrawableFromContactDetails(
context,
message.selectedIndividualHashMap!![KEY_CONTACT_PHOTO]
)
} else if (message.selectedIndividualHashMap!!.containsKey(KEY_MIMETYPE)) {
val mimetype = message.selectedIndividualHashMap!![KEY_MIMETYPE]
val drawableResourceId = getDrawableResourceIdForMimeType(mimetype)
val drawable = ContextCompat.getDrawable(context!!, drawableResourceId)
if (drawable != null &&
(
drawableResourceId == R.drawable.ic_mimetype_folder ||
drawableResourceId == R.drawable.ic_mimetype_package_x_generic
)
) {
drawable.setColorFilter(
viewThemeUtils!!.getScheme(image.context).primary,
PorterDuff.Mode.SRC_ATOP
)
}
placeholder = drawable
} else {
fetchFileInformation(
"/" + message.selectedIndividualHashMap!![KEY_PATH],
message.activeUser
)
}

if (message.activeUser != null &&
message.activeUser!!.username != null &&
message.activeUser!!.baseUrl != null
Expand Down Expand Up @@ -228,6 +169,29 @@ abstract class PreviewMessageViewHolder(itemView: View?, payload: Any?) :
true,
viewThemeUtils!!
)

if (userAvatar != null) {
if (message.isGrouped || message.isOneToOneConversation) {
if (message.isOneToOneConversation) {
userAvatar.visibility = View.GONE
} else {
userAvatar.visibility = View.INVISIBLE
}
} else {
userAvatar.visibility = View.VISIBLE
userAvatar.setOnClickListener { v: View ->
if (payload is MessagePayload) {
(payload as MessagePayload).profileBottomSheet.showFor(
message.actorId!!,
v.context
)
}
}
if (ACTOR_TYPE_BOTS == message.actorType && ACTOR_ID_CHANGELOG == message.actorId) {
userAvatar.loadChangelogBotAvatar()
}
}
}
}

private fun longClickOnReaction(chatMessage: ChatMessage) {
Expand All @@ -239,6 +203,55 @@ abstract class PreviewMessageViewHolder(itemView: View?, payload: Any?) :
}

override fun getPayloadForImageLoader(message: ChatMessage?): Any? {
if (message!!.selectedIndividualHashMap!!.containsKey(KEY_CONTACT_NAME)) {
previewContainer.visibility = View.GONE
previewContactContainer.visibility = View.VISIBLE
previewContactName.text = message.selectedIndividualHashMap!![KEY_CONTACT_NAME]
progressBar = previewContactProgressBar
messageText.visibility = View.INVISIBLE
clickView = previewContactContainer
viewThemeUtils!!.talk.colorContactChatItemBackground(previewContactContainer)
viewThemeUtils!!.talk.colorContactChatItemName(previewContactName)
viewThemeUtils!!.platform.colorCircularProgressBarOnPrimaryContainer(previewContactProgressBar!!)

if (message.selectedIndividualHashMap!!.containsKey(KEY_CONTACT_PHOTO)) {
image = previewContactPhoto
placeholder = getDrawableFromContactDetails(
context,
message.selectedIndividualHashMap!![KEY_CONTACT_PHOTO]
)
} else {
image = previewContactPhoto
image.setImageDrawable(ContextCompat.getDrawable(context!!, R.drawable.ic_mimetype_text_vcard))
}
} else {
previewContainer.visibility = View.VISIBLE
previewContactContainer.visibility = View.GONE
}

if (message.selectedIndividualHashMap!!.containsKey(KEY_MIMETYPE)) {
val mimetype = message.selectedIndividualHashMap!![KEY_MIMETYPE]
val drawableResourceId = getDrawableResourceIdForMimeType(mimetype)
val drawable = ContextCompat.getDrawable(context!!, drawableResourceId)
if (drawable != null &&
(
drawableResourceId == R.drawable.ic_mimetype_folder ||
drawableResourceId == R.drawable.ic_mimetype_package_x_generic
)
) {
drawable.setColorFilter(
viewThemeUtils!!.getScheme(image.context).primary,
PorterDuff.Mode.SRC_ATOP
)
}
placeholder = drawable
} else {
fetchFileInformation(
"/" + message.selectedIndividualHashMap!![KEY_PATH],
message.activeUser
)
}

return placeholder
}

Expand All @@ -255,10 +268,12 @@ abstract class PreviewMessageViewHolder(itemView: View?, payload: Any?) :
try {
inputStream.close()
} catch (e: IOException) {
val drawableResourceId = getDrawableResourceIdForMimeType("text/vcard")
drawable = ContextCompat.getDrawable(context, drawableResourceId)
Log.e(TAG, "failed to close stream in getDrawableFromContactDetails", e)
}
}
if (drawable == null) {
drawable = ContextCompat.getDrawable(context!!, R.drawable.ic_mimetype_text_vcard)
}
return drawable
}

Expand Down Expand Up @@ -341,5 +356,6 @@ abstract class PreviewMessageViewHolder(itemView: View?, payload: Any?) :
const val ACTOR_TYPE_BOTS = "bots"
const val ACTOR_ID_CHANGELOG = "changelog"
const val KEY_NAME = "name"
const val MIN_IMAGE_HEIGHT = 100F
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,8 @@ class ChatController(args: Bundle) :
adapter = TalkMessagesListAdapter(
senderId,
messageHolders,
ImageLoader { imageView, url, _ ->
imageView.loadAvatarOrImagePreview(url!!, conversationUser, placeholder = payload as? Drawable)
ImageLoader { imageView, url, placeholder ->
imageView.loadAvatarOrImagePreview(url!!, conversationUser, placeholder as Drawable?)
},
this
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,17 @@ fun ImageView.loadThumbnail(url: String, user: User): io.reactivex.disposables.D
}

fun ImageView.loadImage(url: String, user: User, placeholder: Drawable? = null): io.reactivex.disposables.Disposable {
var finalPlaceholder = placeholder
if (finalPlaceholder == null) {
finalPlaceholder = ContextCompat.getDrawable(context!!, R.drawable.ic_mimetype_file)
}

val requestBuilder = ImageRequest.Builder(context)
.data(url)
.crossfade(true)
.target(this)
.placeholder(placeholder)
.error(placeholder)
.placeholder(finalPlaceholder)
.error(finalPlaceholder)
.transformations(RoundedCornersTransformation(ROUNDING_PIXEL, ROUNDING_PIXEL, ROUNDING_PIXEL, ROUNDING_PIXEL))

if (url.startsWith(user.baseUrl!!) &&
Expand Down

0 comments on commit f0d78d1

Please sign in to comment.