firebase / codelab-friendlychat-android

Firebase FriendlyChat codelab
Apache License 2.0
246 stars 340 forks source link

LinearLayoutManager tends to crash when new image inserted #216

Open Bela-Szilagyi opened 2 years ago

Bela-Szilagyi commented 2 years ago

I can catch the exception using this wrapper, and then everything goes fine, but it is not the properr way... class LlmWrapper(context: Context) : LinearLayoutManager(context) { override fun onLayoutChildren(recycler: RecyclerView.Recycler?, state: RecyclerView.State?) { Log.i("olc", state.toString()) try { super.onLayoutChildren(recycler, state) } catch (e: Exception) { Log.e("olc", "$e.localizedMessage") } } }

AndreasKl commented 1 year ago

I was also able to reproduce this issue. To mitigate this issue I downgrading firebase UI components to 7.2.0

    implementation 'com.firebaseui:firebase-ui-auth:7.2.0'
    implementation 'com.firebaseui:firebase-ui-database:7.2.0'
landov commented 1 year ago

I also experience this with version 8.0.2.

Aniokrait commented 1 year ago

I also ran into the same issue with version 8.0.2. This commit removed notifyDataSetChanged() from FirebaseRecyclerAdapter, so the process of notifying the adapter about changes is now gone. This is the cause of RecyclerView and java.lang.IndexOutOfBoundsException: Inconsistency detected. Text submissions are reflected in the RecyclerView without any problems, however, images don’t work well because adapter.stopListening() is called during image selection at onPause.

A simple solution is to add the following code to FriendlyMessageAdapter:

override fun stopListening() {
    super.stopListening()
    notifyDataSetChanged()
}