Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when chat roomstate changes #280

Merged
merged 3 commits into from
Dec 18, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions app/src/main/java/com/perflyst/twire/chat/ChatManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -435,15 +435,23 @@ private void handleNotice(IRCMessage message) {
* If the roomstate has changed since last check variables are changed and the chatfragment is notified
*/
private void handleRoomstate(IRCMessage message) {
boolean newR9k = message.tags.get("r9k").equals("1");
boolean newSlow = !message.tags.get("slow").equals("0");
boolean newSub = message.tags.get("subs-only").equals("1");
// If the one of the roomstate types have changed notify the chatfragment
if (chatIsR9kmode != newR9k || chatIsSlowmode != newSlow || chatIsSubsonlymode != newSub) {
chatIsR9kmode = newR9k;
chatIsSlowmode = newSlow;
chatIsSubsonlymode = newSub;
boolean roomstateChanged = false;

if( message.tags.get("r9k") != null) {
chatIsR9kmode = message.tags.get("r9k").equals("1");
roomstateChanged = true;
}
if( message.tags.get("slow") != null) {
chatIsSlowmode = !message.tags.get("slow").equals("0");
roomstateChanged = true;
}
if( message.tags.get("subs-only") != null) {
chatIsSubsonlymode = message.tags.get("subs-only").equals("1");
roomstateChanged = true;
}

// If the one of the roomstate types have changed notify the chatfragment
if (roomstateChanged) {
onProgressUpdate(new ProgressUpdate(ProgressUpdate.UpdateType.ON_ROOMSTATE_CHANGE));
}
samfundev marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/res/layout/fragment_chat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,21 @@
android:layout_height="match_parent"
android:layout_gravity="end">

<View
android:id="@+id/roomstate_anchor"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />

samfundev marked this conversation as resolved.
Show resolved Hide resolved
<ImageView
android:id="@+id/slowmode_ic"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_toStartOf="@id/roomstate_anchor"
android:layout_toLeftOf="@id/roomstate_anchor"
android:visibility="gone"
app:srcCompat="@drawable/ic_roomstate_slowmode"
app:tint="?attr/chatRoomstateIconColor" />
Expand Down