Skip to content

Commit f4447f4

Browse files
authored
fix: split chat issues (#688)
1 parent ea9b0bc commit f4447f4

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

mod/app/src/main/java/bttv/SplitChat.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import bttv.settings.Settings;
1414
import tv.twitch.android.app.core.ThemeManager;
15+
import tv.twitch.android.shared.chat.adapter.item.ChatMessageViewHolder;
1516
import tv.twitch.android.shared.chat.chomments.ChommentRecyclerItem.ChommentItemViewHolder;
1617
import tv.twitch.android.shared.chat.messagefactory.adapteritem.UserNoticeRecyclerItem.UserNoticeViewHolder;
1718

@@ -49,7 +50,8 @@ public static void setBackgroundColor(int position, RecyclerView.ViewHolder view
4950
// so make sure not to do anything when
5051
// not a ViewHolder used in Chat
5152
if (
52-
!(viewHolder instanceof ChommentItemViewHolder)
53+
!(viewHolder instanceof ChatMessageViewHolder)
54+
&& !(viewHolder instanceof ChommentItemViewHolder)
5355
&& !(viewHolder instanceof UserNoticeViewHolder)
5456
) {
5557
Log.i(TAG, "viewHolder is not known: " + viewHolder.toString());
@@ -58,12 +60,30 @@ public static void setBackgroundColor(int position, RecyclerView.ViewHolder view
5860
View view = viewHolder.itemView;
5961
Context context = view.getContext();
6062

61-
// make sure we only change chat message items
62-
boolean hasChatMessageId = view.getId() == ResUtil.getResourceId(context, "chat_message_item", "id");
63-
boolean hasChommentRootId = view.getId() == ResUtil.getResourceId(context, "chomment_root_view", "id");
63+
// make sure we only change chat message items,
64+
// which are LinearLayouts with chat_message_item children.
65+
// Anything else is ignored.
66+
int chatMessageItemResId = ResUtil.getResourceId(context, "chat_message_item", "id");
67+
int chommentRootViewResId = ResUtil.getResourceId(context, "chomment_root_view", "id");
68+
if(view instanceof LinearLayout) {
69+
Log.d(TAG, "view is LinearLayout: " + view.toString());
70+
LinearLayout linearLayout = (LinearLayout) view;
71+
for (int j = 0; j < linearLayout.getChildCount(); j++) {
72+
View nestedChild = linearLayout.getChildAt(j);
73+
if (nestedChild.getId() == chatMessageItemResId) {
74+
Log.d(TAG, "found chat_message_item: " + nestedChild.toString());
75+
view = nestedChild;
76+
// Increase width of linearLayout to match parent to color the whole item
77+
linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
78+
break;
79+
}
80+
}
81+
}
82+
boolean hasChatMessageId = view.getId() == chatMessageItemResId;
83+
boolean hasChommentRootId = view.getId() == chommentRootViewResId;
6484

65-
if (!hasChatMessageId && !hasChommentRootId) {
66-
Log.i(TAG, "view skipped, as it's not a chat message or chomment" + viewHolder.toString());
85+
if (!(hasChatMessageId || hasChommentRootId)) {
86+
Log.d(TAG, "view skipped, as it's not a chat message or chomment, " + viewHolder.toString() + " ID: " + view.getId() + " View: " + view.toString() + " Expected ID: " + chatMessageItemResId + " or " + chommentRootViewResId);
6787
reset(view);
6888
return;
6989
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package tv.twitch.android.shared.chat.adapter.item;
2+
3+
import android.view.View;
4+
5+
import androidx.annotation.NonNull;
6+
7+
import tv.twitch.android.core.adapters.AbstractTwitchRecyclerViewHolder;
8+
9+
public abstract class ChatMessageViewHolder extends AbstractTwitchRecyclerViewHolder {
10+
public ChatMessageViewHolder(@NonNull View itemView) {
11+
super(itemView);
12+
}
13+
}

0 commit comments

Comments
 (0)