Skip to content

Commit

Permalink
Fix Split chat not working on Livestreams
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerwin committed Sep 2, 2024
1 parent 29adb84 commit f2b6a6b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
23 changes: 20 additions & 3 deletions mod/app/src/main/java/bttv/SplitChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import bttv.settings.Settings;
import tv.twitch.android.app.core.ThemeManager;
import tv.twitch.android.shared.chat.adapter.item.ChatMessageViewHolder;
import tv.twitch.android.shared.chat.chomments.ChommentRecyclerItem.ChommentItemViewHolder;
import tv.twitch.android.shared.chat.messagefactory.adapteritem.UserNoticeRecyclerItem.UserNoticeViewHolder;

Expand Down Expand Up @@ -49,7 +50,8 @@ public static void setBackgroundColor(int position, RecyclerView.ViewHolder view
// so make sure not to do anything when
// not a ViewHolder used in Chat
if (
!(viewHolder instanceof ChommentItemViewHolder)
!(viewHolder instanceof ChatMessageViewHolder)
&& !(viewHolder instanceof ChommentItemViewHolder)
&& !(viewHolder instanceof UserNoticeViewHolder)
) {
Log.i(TAG, "viewHolder is not known: " + viewHolder.toString());
Expand All @@ -59,11 +61,26 @@ public static void setBackgroundColor(int position, RecyclerView.ViewHolder view
Context context = view.getContext();

// make sure we only change chat message items
// Other elements like redeems or Sub Anniversaries are ConstraintLayouts

// If view is a LinearLayout, check the childrens to find chat_message_item
if(view instanceof LinearLayout) {
Log.d(TAG, "view is LinearLayout: " + view.toString());
LinearLayout linearLayout = (LinearLayout) view;
for (int j = 0; j < linearLayout.getChildCount(); j++) {
View nestedChild = linearLayout.getChildAt(j);
if (nestedChild.getId() == ResUtil.getResourceId(context, "chat_message_item", "id")) {
Log.d(TAG, "found chat_message_item: " + nestedChild.toString());
view = nestedChild;
break;
}
}
}
boolean hasChatMessageId = view.getId() == ResUtil.getResourceId(context, "chat_message_item", "id");
boolean hasChommentRootId = view.getId() == ResUtil.getResourceId(context, "chomment_root_view", "id");

if (!hasChatMessageId && !hasChommentRootId) {
Log.i(TAG, "view skipped, as it's not a chat message or chomment" + viewHolder.toString());
if (!(hasChatMessageId || hasChommentRootId)) {
Log.i(TAG, "view skipped, as it's not a chat message or chomment, " + viewHolder.toString() + " ID: " + view.getId() + " View: " + view.toString() + " Expected ID: " + ResUtil.getResourceId(context, "chat_message_item", "id") + " or " + ResUtil.getResourceId(context, "chomment_root_view", "id"));
reset(view);
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package tv.twitch.android.shared.chat.adapter.item;

import android.view.View;

import androidx.annotation.NonNull;

import tv.twitch.android.core.adapters.AbstractTwitchRecyclerViewHolder;

public abstract class ChatMessageViewHolder extends AbstractTwitchRecyclerViewHolder {
public ChatMessageViewHolder(@NonNull View itemView) {
super(itemView);
}
}

0 comments on commit f2b6a6b

Please sign in to comment.