FirebaseUI-Android
FirebaseUI-Android copied to clipboard
FirestoreRecyclerAdapter jumps position when updating the first document
- Android device: Google Pixel 2 XL
- Android OS version: 10
- Google Play Services version: 18.1.0
- Firebase/Play Services SDK version: 21.5.0
- FirebaseUI version: 6.3.0
Steps to reproduce:
- make a recyclerview connected to firestore that displays a list of shopping items showing item names only
- the shopping items change to crossed out when clicked on
- the shopping items are ordered by uncrossed first
- if your list contains about 20 elements go to the top and cross out the first item
Observed Results:
- the recyclerview will scroll down to the crossed out item
- does not happen when crossing any of the items except the first one
Expected Results:
- the crossed out item should just fly down and the list should not move
Relevant Code:
ShoppingAdapter.kt https://hastebin.com/okezanasak.m
@BirdmanTunes do you have any scroll listeners attached to your adapter or anything else that affects scrolling? There's nothing in FirebaseUI that controls scroll position so I would be surprised if this was a bug in the library.
Nope, there is no code that attaches a scroll listener, it's just a basic recyclerview setup for firestore, this is how i attach my adapter, it's just default stuff except i have a decoration on it
val layoutManagerNote = LinearLayoutManager(this)
recyclerview_bottom_group.setHasFixedSize(false)
recyclerview_bottom_group.layoutManager = layoutManagerNote
val itemDecoration = DividerItemDecoration(
recyclerview_bottom_group.context,
layoutManagerNote.orientation
)
itemDecoration.setDrawable(
ContextCompat.getDrawable(
this,
R.drawable.divider_gray
)!!
)
recyclerview_bottom_group.addItemDecoration(
itemDecoration
)
val queryForShoppingItems = firebaseFirestore.collection("listOfNotes/" + documentReference?.id + "/shoppingItems").orderBy("checked", Query.Direction.ASCENDING)
val optionsForShoppingItems: FirestoreRecyclerOptions<ShoppingItem> =
FirestoreRecyclerOptions.Builder<ShoppingItem>()
.setQuery(queryForShoppingItems, ShoppingItem::class.java)
.build()
shoppingAdapterGroup = ShoppingAdapterGroup(optionsForShoppingItems, this)
recyclerview_bottom_group.adapter = shoppingAdapterGroup
shoppingAdapterGroup?.startListening()
I forgot to show, this is how i update the item
shoppingAdapterGroup?.setClickListener(object: ShoppingAdapterGroup.OnItemClickListener {
override fun onItemClick(documentSnapshot: DocumentSnapshot?, position: Int) {
val shoppingItem = documentSnapshot?.toObject(ShoppingItem::class.java)
val updatedFields = HashMap<String, Any>()
updatedFields["checked"] = !shoppingItem?.checked!!
}
})