call adapter methods in UI thread

otherwise sometimes this exception was thrown:

IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling androidx.recyclerview.widget.RecyclerView
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2021-09-03 12:25:46 +02:00
parent a488b9738e
commit 2f35ae19fc
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B

View File

@ -195,7 +195,6 @@ abstract class BrowserController(args: Bundle) :
}
override fun listingResult(davResponse: DavResponse) {
adapter!!.clear()
recyclerViewItems = ArrayList()
if (davResponse.getData() != null) {
val objectList = davResponse.getData() as List<BrowserFile>
@ -210,9 +209,10 @@ abstract class BrowserController(args: Bundle) :
FileSortOrder.getFileSortOrder(appPreferences?.sorting).sortCloudFiles(recyclerViewItems)
adapter!!.addItems(0, recyclerViewItems)
if (activity != null) {
activity!!.runOnUiThread {
adapter!!.clear()
adapter!!.addItems(0, recyclerViewItems)
adapter!!.notifyDataSetChanged()
changeEnabledStatusForBarItems(true)
}
@ -247,8 +247,12 @@ abstract class BrowserController(args: Bundle) :
selectedPaths.remove(file.parent!! + "/")
file = File(file.parent!!)
}
if (activity != null) {
activity!!.runOnUiThread {
adapter!!.notifyDataSetChanged()
}
}
}
override fun onItemClick(view: View, position: Int): Boolean {
val browserFile = (adapter!!.getItem(position) as BrowserFileItem).model