From 045f95326a0345c24a4ae88b650e80eee62f6364 Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Mon, 19 Jul 2021 22:30:02 +0200 Subject: [PATCH] Fix for crash on rendering media items 07-19 19:28:53.039 E/AndroidRuntime(12141): java.lang.NoSuchMethodError: No virtual method updateMessageBubble(Landroid/content/Context;Lim/vector/app/features/home/room/detail/timeline/item/AbsMessageItem$Holder;)V in class Lim/vector/app/features/home/room/detail/timeline/item/MessageImageVideoItem; or its super classes (declaration of 'im.vector.app.features.home.room.detail.timeline.item.MessageImageVideoItem' appears in base.apk) 07-19 19:28:53.039 E/AndroidRuntime(12141): at im.vector.app.features.home.room.detail.timeline.item.MessageImageVideoItem$bind$onImageSizeListener$1.onImageSizeUpdated(MessageImageVideoItem.kt:6) 07-19 19:28:53.039 E/AndroidRuntime(12141): at im.vector.app.features.media.ImageContentRenderer.render(ImageContentRenderer.kt:20) 07-19 19:28:53.039 E/AndroidRuntime(12141): at im.vector.app.features.home.room.detail.timeline.item.MessageImageVideoItem.bind(MessageImageVideoItem.kt:12) 07-19 19:28:53.039 E/AndroidRuntime(12141): at im.vector.app.features.home.room.detail.timeline.item.MessageImageVideoItem.bind(MessageImageVideoItem.kt:6) 07-19 19:28:53.039 E/AndroidRuntime(12141): at com.airbnb.epoxy.BaseEpoxyAdapter.onBindViewHolder(BaseEpoxyAdapter.java:25) Change-Id: Ic803b3bfb328ed3a56202df789500b162886250d --- .../app/core/ui/views/BubbleDependentView.kt | 60 ++++++++++--------- .../detail/timeline/item/AbsMessageItem.kt | 1 + .../detail/timeline/item/BaseEventItem.kt | 5 ++ .../detail/timeline/item/ReadReceiptsItem.kt | 8 +++ 4 files changed, 45 insertions(+), 29 deletions(-) diff --git a/vector/src/main/java/im/vector/app/core/ui/views/BubbleDependentView.kt b/vector/src/main/java/im/vector/app/core/ui/views/BubbleDependentView.kt index 68c4243add..ab9f96a707 100644 --- a/vector/src/main/java/im/vector/app/core/ui/views/BubbleDependentView.kt +++ b/vector/src/main/java/im/vector/app/core/ui/views/BubbleDependentView.kt @@ -7,27 +7,6 @@ import im.vector.app.features.themes.BubbleThemeUtils interface BubbleDependentView { - fun updateMessageBubble(context: Context, holder: H) { - val bubbleStyleSetting = BubbleThemeUtils.getBubbleStyle(context) - val bubbleStyle = when { - messageBubbleAllowed(context) -> { - bubbleStyleSetting - } - bubbleStyleSetting == BubbleThemeUtils.BUBBLE_STYLE_BOTH && pseudoBubbleAllowed() -> { - BubbleThemeUtils.BUBBLE_STYLE_BOTH_HIDDEN - } - bubbleStyleSetting == BubbleThemeUtils.BUBBLE_STYLE_START && pseudoBubbleAllowed() -> { - BubbleThemeUtils.BUBBLE_STYLE_START_HIDDEN - } - else -> { - BubbleThemeUtils.BUBBLE_STYLE_NONE - } - } - val reverseBubble = shouldReverseBubble() && BubbleThemeUtils.drawsDualSide(bubbleStyle) - - setBubbleLayout(holder, bubbleStyle, bubbleStyleSetting, reverseBubble) - } - fun messageBubbleAllowed(context: Context): Boolean { return false } @@ -41,15 +20,38 @@ interface BubbleDependentView { } fun setBubbleLayout(holder: H, bubbleStyle: String, bubbleStyleSetting: String, reverseBubble: Boolean) +} - fun setFlatRtl(layout: ViewGroup, direction: Int, childDirection: Int, depth: Int = 1) { - layout.layoutDirection = direction - for (child in layout.children) { - if (depth > 1 && child is ViewGroup) { - setFlatRtl(child, direction, childDirection, depth-1) - } else { - child.layoutDirection = childDirection - } +// This function belongs to BubbleDependentView, but turned out to raise a NoSuchMethodError since recently +// when called from an onImageSizeUpdated listener +fun updateMessageBubble(context: Context, view: BubbleDependentView, holder: H) { + val bubbleStyleSetting = BubbleThemeUtils.getBubbleStyle(context) + val bubbleStyle = when { + view.messageBubbleAllowed(context) -> { + bubbleStyleSetting + } + bubbleStyleSetting == BubbleThemeUtils.BUBBLE_STYLE_BOTH && view.pseudoBubbleAllowed() -> { + BubbleThemeUtils.BUBBLE_STYLE_BOTH_HIDDEN + } + bubbleStyleSetting == BubbleThemeUtils.BUBBLE_STYLE_START && view.pseudoBubbleAllowed() -> { + BubbleThemeUtils.BUBBLE_STYLE_START_HIDDEN + } + else -> { + BubbleThemeUtils.BUBBLE_STYLE_NONE + } + } + val reverseBubble = view.shouldReverseBubble() && BubbleThemeUtils.drawsDualSide(bubbleStyle) + + view.setBubbleLayout(holder, bubbleStyle, bubbleStyleSetting, reverseBubble) +} + +fun setFlatRtl(layout: ViewGroup, direction: Int, childDirection: Int, depth: Int = 1) { + layout.layoutDirection = direction + for (child in layout.children) { + if (depth > 1 && child is ViewGroup) { + setFlatRtl(child, direction, childDirection, depth-1) + } else { + child.layoutDirection = childDirection } } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt index 8c4e9632da..9c356b09be 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt @@ -39,6 +39,7 @@ import im.vector.app.R import im.vector.app.core.epoxy.ClickListener import im.vector.app.core.epoxy.onClick import im.vector.app.core.ui.views.SendStateImageView +import im.vector.app.core.ui.views.setFlatRtl import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.room.detail.timeline.MessageColorProvider import im.vector.app.features.home.room.detail.timeline.TimelineEventController diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/BaseEventItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/BaseEventItem.kt index 1e7a01c384..66672008c6 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/BaseEventItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/BaseEventItem.kt @@ -32,6 +32,7 @@ import im.vector.app.core.epoxy.VectorEpoxyHolder import im.vector.app.core.epoxy.VectorEpoxyModel import im.vector.app.core.platform.CheckableView import im.vector.app.core.ui.views.BubbleDependentView +import im.vector.app.core.ui.views.updateMessageBubble import im.vector.app.core.utils.DimensionConverter import im.vector.app.features.themes.BubbleThemeUtils @@ -129,4 +130,8 @@ abstract class BaseEventItem : VectorEpoxyModel */ } + + fun updateMessageBubble(context: Context, holder: H) { + return updateMessageBubble(context, this, holder) + } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/ReadReceiptsItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/ReadReceiptsItem.kt index 3510316f7b..1483853a99 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/ReadReceiptsItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/ReadReceiptsItem.kt @@ -16,6 +16,7 @@ package im.vector.app.features.home.room.detail.timeline.item +import android.content.Context import android.view.Gravity import android.view.View import android.widget.FrameLayout @@ -30,6 +31,8 @@ import im.vector.app.core.epoxy.VectorEpoxyHolder import im.vector.app.core.epoxy.onClick import im.vector.app.core.ui.views.BubbleDependentView import im.vector.app.core.ui.views.ReadReceiptsView +import im.vector.app.core.ui.views.setFlatRtl +import im.vector.app.core.ui.views.updateMessageBubble import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.themes.BubbleThemeUtils import timber.log.Timber @@ -105,4 +108,9 @@ abstract class ReadReceiptsItem : EpoxyModelWithHolder( // Also set rtl to have members fill from the natural side setFlatRtl(holder.readReceiptsView, if (dualBubbles) reverseDirection else defaultDirection, defaultDirection) } + + fun updateMessageBubble(context: Context, holder: Holder) { + return updateMessageBubble(context, this, holder) + } + }