From 6ea6389939ca3de26b511648a5cff293ce8d8fc0 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Wed, 28 Nov 2018 12:36:12 +0100 Subject: [PATCH] Workaround for a crash while rotating the device --- .../linphone/chat/ChatMessagesFragment.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/linphone/chat/ChatMessagesFragment.java b/app/src/main/java/org/linphone/chat/ChatMessagesFragment.java index 87e0d49fc..444bed35b 100644 --- a/app/src/main/java/org/linphone/chat/ChatMessagesFragment.java +++ b/app/src/main/java/org/linphone/chat/ChatMessagesFragment.java @@ -39,6 +39,7 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import android.text.Editable; import android.text.TextWatcher; +import android.util.AttributeSet; import android.view.ContextMenu; import android.view.LayoutInflater; import android.view.MenuInflater; @@ -48,7 +49,6 @@ import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.view.WindowManager; import android.view.inputmethod.InputMethodManager; -import android.widget.Adapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; @@ -57,7 +57,6 @@ import android.widget.LinearLayout; import android.widget.TextView; import org.linphone.LinphoneManager; -import org.linphone.core.ChatMessageListenerStub; import org.linphone.settings.LinphonePreferences; import org.linphone.LinphoneService; import org.linphone.utils.FileUtils; @@ -269,7 +268,7 @@ public class ChatMessagesFragment extends Fragment implements ChatRoomListener, mChatEventsList = view.findViewById(R.id.chat_message_list); mSelectionHelper = new SelectableHelper(view, this); - layoutManager = new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, true); + layoutManager = new LinphoneLinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, true); mChatEventsList.setLayoutManager(layoutManager); mChatScrollListener = new ChatScrollListener(layoutManager) { @@ -1179,4 +1178,20 @@ public class ChatMessagesFragment extends Fragment implements ChatRoomListener, public void onContactsUpdated() { getContactsForParticipants(); } + + // This is a workaround to prevent a crash from happening while rotating the device + private class LinphoneLinearLayoutManager extends LinearLayoutManager { + public LinphoneLinearLayoutManager(Context context, int orientation, boolean reverseLayout) { + super(context, orientation, reverseLayout); + } + + @Override + public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) { + try { + super.onLayoutChildren(recycler, state); + } catch (IndexOutOfBoundsException e) { + Log.e("InvalidIndexOutOfBound Exception, probably while rotating the device"); + } + } + } }