Browse Source

remove withNullableControllerViewBinding

it seems async calls are not cancelled reliable so it was decided to always check for null bindings to avoid NPEs

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
Marcel Hibbe 2 years ago
parent
commit
b45794b0ca

+ 2 - 4
app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt

@@ -419,10 +419,8 @@ class ChatController(args: Bundle) :
                 }
             )
 
-            withNullableControllerViewBinding {
-                val itemTouchHelper = ItemTouchHelper(messageSwipeController)
-                itemTouchHelper.attachToRecyclerView(binding?.messagesListView)
-            }
+            val itemTouchHelper = ItemTouchHelper(messageSwipeController)
+            itemTouchHelper.attachToRecyclerView(binding?.messagesListView)
         }
     }
 

+ 15 - 27
app/src/main/java/com/nextcloud/talk/controllers/ContactsController.kt

@@ -452,22 +452,16 @@ class ContactsController(args: Bundle) :
                         adapter?.filterItems()
                     }
 
-                    withNullableControllerViewBinding {
-                        binding?.controllerGenericRv?.swipeRefreshLayout?.isRefreshing = false
-                    }
+                    binding?.controllerGenericRv?.swipeRefreshLayout?.isRefreshing = false
                 }
 
                 override fun onError(e: Throwable) {
-                    withNullableControllerViewBinding {
-                        binding?.controllerGenericRv?.swipeRefreshLayout?.isRefreshing = false
-                    }
+                    binding?.controllerGenericRv?.swipeRefreshLayout?.isRefreshing = false
                     dispose(contactsQueryDisposable)
                 }
 
                 override fun onComplete() {
-                    withNullableControllerViewBinding {
-                        binding?.controllerGenericRv?.swipeRefreshLayout?.isRefreshing = false
-                    }
+                    binding?.controllerGenericRv?.swipeRefreshLayout?.isRefreshing = false
                     dispose(contactsQueryDisposable)
                     alreadyFetching = false
                     disengageProgressBar()
@@ -699,9 +693,7 @@ class ContactsController(args: Bundle) :
             adapter?.updateDataSet(contactItems as List<Nothing>?)
         }
 
-        withNullableControllerViewBinding {
-            binding?.controllerGenericRv?.swipeRefreshLayout?.isEnabled = !adapter!!.hasFilter()
-        }
+        binding?.controllerGenericRv?.swipeRefreshLayout?.isEnabled = !adapter!!.hasFilter()
 
         return true
     }
@@ -929,25 +921,21 @@ class ContactsController(args: Bundle) :
     }
 
     private fun toggleConversationPrivacyLayout(showInitialLayout: Boolean) {
-        withNullableControllerViewBinding {
-            if (showInitialLayout) {
-                binding?.conversationPrivacyToggle?.initialRelativeLayout?.visibility = View.VISIBLE
-                binding?.conversationPrivacyToggle?.secondaryRelativeLayout?.visibility = View.GONE
-            } else {
-                binding?.conversationPrivacyToggle?.initialRelativeLayout?.visibility = View.GONE
-                binding?.conversationPrivacyToggle?.secondaryRelativeLayout?.visibility = View.VISIBLE
-            }
+        if (showInitialLayout) {
+            binding?.conversationPrivacyToggle?.initialRelativeLayout?.visibility = View.VISIBLE
+            binding?.conversationPrivacyToggle?.secondaryRelativeLayout?.visibility = View.GONE
+        } else {
+            binding?.conversationPrivacyToggle?.initialRelativeLayout?.visibility = View.GONE
+            binding?.conversationPrivacyToggle?.secondaryRelativeLayout?.visibility = View.VISIBLE
         }
     }
 
     private fun toggleConversationViaLinkVisibility(isPublicCall: Boolean) {
-        withNullableControllerViewBinding {
-            if (isPublicCall) {
-                binding?.joinConversationViaLink?.joinConversationViaLinkRelativeLayout?.visibility = View.GONE
-                updateGroupParticipantSelection()
-            } else {
-                binding?.joinConversationViaLink?.joinConversationViaLinkRelativeLayout?.visibility = View.VISIBLE
-            }
+        if (isPublicCall) {
+            binding?.joinConversationViaLink?.joinConversationViaLinkRelativeLayout?.visibility = View.GONE
+            updateGroupParticipantSelection()
+        } else {
+            binding?.joinConversationViaLink?.joinConversationViaLinkRelativeLayout?.visibility = View.VISIBLE
         }
     }
 

+ 10 - 26
app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.kt

@@ -409,9 +409,7 @@ class ConversationsListController(bundle: Bundle) :
                     adapter!!.setHeadersShown(true)
                     adapter!!.updateDataSet(searchableConversationItems, false)
                     adapter!!.showAllHeaders()
-                    withNullableControllerViewBinding {
-                        binding?.swipeRefreshLayoutView?.isEnabled = false
-                    }
+                    binding?.swipeRefreshLayoutView?.isEnabled = false
                     return true
                 }
 
@@ -424,9 +422,7 @@ class ConversationsListController(bundle: Bundle) :
                         searchHelper!!.cancelSearch()
                         binding?.swipeRefreshLayoutView?.isRefreshing = false
                     }
-                    withNullableControllerViewBinding {
-                        binding?.swipeRefreshLayoutView?.isEnabled = true
-                    }
+                    binding?.swipeRefreshLayoutView?.isEnabled = true
                     searchView!!.onActionViewCollapsed()
                     val mainActivity = getActivity() as MainActivity?
                     if (mainActivity != null) {
@@ -514,21 +510,15 @@ class ConversationsListController(bundle: Bundle) :
                 adapter!!.updateDataSet(conversationItems, false)
                 Handler().postDelayed({ checkToShowUnreadBubble() }, UNREAD_BUBBLE_DELAY.toLong())
                 fetchOpenConversations(apiVersion)
-                withNullableControllerViewBinding {
-                    binding?.swipeRefreshLayoutView?.isRefreshing = false
-                }
+                binding?.swipeRefreshLayoutView?.isRefreshing = false
             }, { throwable: Throwable ->
                 handleHttpExceptions(throwable)
-                withNullableControllerViewBinding {
-                    binding?.swipeRefreshLayoutView?.isRefreshing = false
-                    showErrorDialog()
-                }
+                binding?.swipeRefreshLayoutView?.isRefreshing = false
+                showErrorDialog()
                 dispose(roomsQueryDisposable)
             }) {
                 dispose(roomsQueryDisposable)
-                withNullableControllerViewBinding {
-                    binding?.swipeRefreshLayoutView?.isRefreshing = false
-                }
+                binding?.swipeRefreshLayoutView?.isRefreshing = false
                 isRefreshing = false
             }
     }
@@ -854,9 +844,7 @@ class ConversationsListController(bundle: Bundle) :
 
     @SuppressLint("CheckResult") // handled by helper
     private fun startMessageSearch(search: String?) {
-        withNullableControllerViewBinding {
-            binding?.swipeRefreshLayoutView?.isRefreshing = true
-        }
+        binding?.swipeRefreshLayoutView?.isRefreshing = true
         searchHelper?.startMessageSearch(search!!)
             ?.subscribeOn(Schedulers.io())
             ?.observeOn(AndroidSchedulers.mainThread())
@@ -1331,17 +1319,13 @@ class ConversationsListController(bundle: Bundle) :
                 binding?.recyclerView?.scrollToPosition(0)
             }
         }
-        withNullableControllerViewBinding {
-            binding?.swipeRefreshLayoutView?.isRefreshing = false
-        }
+        binding?.swipeRefreshLayoutView?.isRefreshing = false
     }
 
     private fun onMessageSearchError(throwable: Throwable) {
         handleHttpExceptions(throwable)
-        withNullableControllerViewBinding {
-            binding?.swipeRefreshLayoutView?.isRefreshing = false
-            showErrorDialog()
-        }
+        binding?.swipeRefreshLayoutView?.isRefreshing = false
+        showErrorDialog()
     }
 
     companion object {

+ 0 - 22
app/src/main/java/com/nextcloud/talk/controllers/base/BaseController.kt

@@ -54,7 +54,6 @@ import com.nextcloud.talk.controllers.ServerSelectionController
 import com.nextcloud.talk.controllers.SwitchAccountController
 import com.nextcloud.talk.controllers.WebViewLoginController
 import com.nextcloud.talk.controllers.base.providers.ActionBarProvider
-import com.nextcloud.talk.controllers.util.ControllerViewBindingDelegate
 import com.nextcloud.talk.databinding.ActivityMainBinding
 import com.nextcloud.talk.ui.theme.ViewThemeUtils
 import com.nextcloud.talk.utils.DisplayUtils
@@ -304,27 +303,6 @@ abstract class BaseController(@LayoutRes var layoutRes: Int, args: Bundle? = nul
         }
     }
 
-    /**
-     * Mainly intended to be used in async listeners that may be called after the controller has been destroyed.
-     *
-     * If you need to use this function to patch a NPE crash, something is wrong in the way that the async calls are
-     * handled, they should have been cancelled when the controller UI was destroyed (if their only purpose was
-     * updating UI).
-     */
-    @Suppress("Detekt.TooGenericExceptionCaught")
-    inline fun withNullableControllerViewBinding(block: () -> Unit) {
-        try {
-            block()
-        } catch (e: NullPointerException) {
-            // Handle only the exceptions we know about, let everything else pass through
-            if (e.stackTrace.firstOrNull()?.className == ControllerViewBindingDelegate::class.qualifiedName) {
-                Log.w("ControllerViewBinding", "Trying to update UI on a null ViewBinding.", e)
-            } else {
-                throw e
-            }
-        }
-    }
-
     open val appBarLayoutType: AppBarLayoutType
         get() = AppBarLayoutType.TOOLBAR
     val searchHint: String