소스 검색

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

Signed-off-by: Dariusz Olszewski <starypatyk@users.noreply.github.com>
Dariusz Olszewski 3 년 전
부모
커밋
606c6b0b9e

+ 8 - 0
app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java

@@ -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);

+ 4 - 0
app/src/main/java/com/nextcloud/talk/controllers/base/ButterKnifeController.kt

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