Avoid NullPointerException when server response arrives after the view was unbound.

Signed-off-by: Dariusz Olszewski <starypatyk@users.noreply.github.com>
This commit is contained in:
Dariusz Olszewski 2022-01-22 20:42:04 +01:00 committed by Marcel Hibbe
parent 505bcdfe20
commit 606c6b0b9e
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
2 changed files with 12 additions and 0 deletions

View File

@ -525,6 +525,14 @@ public class ConversationsListController extends BaseController implements Searc
.subscribe(roomsOverall -> {
Log.d(TAG, "fetchData - getRooms - got response: " + startNanoTime);
// This is invoked asynchronously, when server returns a response the view might have been
// unbound in the meantime. Check if the view is still there.
// FIXME - does it make sense to update internal data structures even when view has been unbound?
if (!viewIsBound()) {
Log.d(TAG, "fetchData - getRooms - view is not bound: " + startNanoTime);
return;
}
if (adapterWasNull) {
adapterWasNull = false;
loadingContent.setVisibility(View.GONE);

View File

@ -55,4 +55,8 @@ abstract class ButterKnifeController : Controller {
unbinder!!.unbind()
unbinder = null
}
protected fun viewIsBound() : Boolean {
return unbinder != null
}
}