Merge pull request #2697 from nextcloud/bugfix/2691/fixMissingFileIcons

fix missing file icons in chat
This commit is contained in:
Marcel Hibbe 2023-01-18 11:07:48 +01:00 committed by GitHub
commit 18909232b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 89 additions and 69 deletions

View file

@ -106,29 +106,10 @@ abstract class PreviewMessageViewHolder(itemView: View?, payload: Any?) :
@Suppress("NestedBlockDepth", "ComplexMethod", "LongMethod") @Suppress("NestedBlockDepth", "ComplexMethod", "LongMethod")
override fun onBind(message: ChatMessage) { override fun onBind(message: ChatMessage) {
super.onBind(message) super.onBind(message)
image.minimumHeight = DisplayUtils.convertDpToPixel(MIN_IMAGE_HEIGHT, context).toInt()
time.text = dateUtils.getLocalTimeStringFromTimestamp(message.timestamp) 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!!) viewThemeUtils!!.platform.colorCircularProgressBar(progressBar!!)
clickView = image clickView = image
messageText.visibility = View.VISIBLE messageText.visibility = View.VISIBLE
@ -136,47 +117,7 @@ abstract class PreviewMessageViewHolder(itemView: View?, payload: Any?) :
fileViewerUtils = FileViewerUtils(context!!, message.activeUser!!) fileViewerUtils = FileViewerUtils(context!!, message.activeUser!!)
val fileName = message.selectedIndividualHashMap!![KEY_NAME] val fileName = message.selectedIndividualHashMap!![KEY_NAME]
messageText.text = fileName 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 && if (message.activeUser != null &&
message.activeUser!!.username != null && message.activeUser!!.username != null &&
message.activeUser!!.baseUrl != null message.activeUser!!.baseUrl != null
@ -228,6 +169,29 @@ abstract class PreviewMessageViewHolder(itemView: View?, payload: Any?) :
true, true,
viewThemeUtils!! 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) { private fun longClickOnReaction(chatMessage: ChatMessage) {
@ -239,6 +203,55 @@ abstract class PreviewMessageViewHolder(itemView: View?, payload: Any?) :
} }
override fun getPayloadForImageLoader(message: ChatMessage?): 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 return placeholder
} }
@ -255,10 +268,12 @@ abstract class PreviewMessageViewHolder(itemView: View?, payload: Any?) :
try { try {
inputStream.close() inputStream.close()
} catch (e: IOException) { } catch (e: IOException) {
val drawableResourceId = getDrawableResourceIdForMimeType("text/vcard") Log.e(TAG, "failed to close stream in getDrawableFromContactDetails", e)
drawable = ContextCompat.getDrawable(context, drawableResourceId)
} }
} }
if (drawable == null) {
drawable = ContextCompat.getDrawable(context!!, R.drawable.ic_mimetype_text_vcard)
}
return drawable return drawable
} }
@ -341,5 +356,6 @@ abstract class PreviewMessageViewHolder(itemView: View?, payload: Any?) :
const val ACTOR_TYPE_BOTS = "bots" const val ACTOR_TYPE_BOTS = "bots"
const val ACTOR_ID_CHANGELOG = "changelog" const val ACTOR_ID_CHANGELOG = "changelog"
const val KEY_NAME = "name" const val KEY_NAME = "name"
const val MIN_IMAGE_HEIGHT = 100F
} }
} }

View file

@ -621,8 +621,8 @@ class ChatController(args: Bundle) :
adapter = TalkMessagesListAdapter( adapter = TalkMessagesListAdapter(
senderId, senderId,
messageHolders, messageHolders,
ImageLoader { imageView, url, _ -> ImageLoader { imageView, url, placeholder ->
imageView.loadAvatarOrImagePreview(url!!, conversationUser, placeholder = payload as? Drawable) imageView.loadAvatarOrImagePreview(url!!, conversationUser, placeholder as Drawable?)
}, },
this this
) )

View file

@ -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 { 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) val requestBuilder = ImageRequest.Builder(context)
.data(url) .data(url)
.crossfade(true) .crossfade(true)
.target(this) .target(this)
.placeholder(placeholder) .placeholder(finalPlaceholder)
.error(placeholder) .error(finalPlaceholder)
.transformations(RoundedCornersTransformation(ROUNDING_PIXEL, ROUNDING_PIXEL, ROUNDING_PIXEL, ROUNDING_PIXEL)) .transformations(RoundedCornersTransformation(ROUNDING_PIXEL, ROUNDING_PIXEL, ROUNDING_PIXEL, ROUNDING_PIXEL))
if (url.startsWith(user.baseUrl!!) && if (url.startsWith(user.baseUrl!!) &&