Răsfoiți Sursa

Catch NPE on Profile view binding

Resolves: #1959

Signed-off-by: Tim Krüger <t@timkrueger.me>
Tim Krüger 3 ani în urmă
părinte
comite
5cb36d0801

+ 14 - 8
app/src/main/java/com/nextcloud/talk/controllers/ProfileController.kt

@@ -93,7 +93,6 @@ import retrofit2.Response
 import java.io.File
 import java.io.FileOutputStream
 import java.io.IOException
-import java.util.ArrayList
 import java.util.LinkedList
 import java.util.Locale
 import javax.inject.Inject
@@ -341,13 +340,20 @@ class ProfileController : NewBaseController(R.layout.controller_profile) {
         if (activity == null) {
             return
         }
-        binding.emptyList.emptyListViewHeadline.text = headline
-        binding.emptyList.emptyListViewText.text = message
-        binding.emptyList.emptyListIcon.setImageResource(errorResource)
-        binding.emptyList.emptyListIcon.visibility = View.VISIBLE
-        binding.emptyList.emptyListViewText.visibility = View.VISIBLE
-        binding.userinfoList.visibility = View.GONE
-        binding.loadingContent.visibility = View.GONE
+
+        try {
+            binding.emptyList.emptyListViewHeadline.text = headline
+            binding.emptyList.emptyListViewText.text = message
+            binding.emptyList.emptyListIcon.setImageResource(errorResource)
+            binding.emptyList.emptyListIcon.visibility = View.VISIBLE
+            binding.emptyList.emptyListViewText.visibility = View.VISIBLE
+            binding.userinfoList.visibility = View.GONE
+            binding.loadingContent.visibility = View.GONE
+        } catch (npe: NullPointerException) {
+            // view binding can be null
+            // since this is called asynchronously and UI might have been destroyed in the meantime
+            Log.i(TAG, "UI destroyed - view binding already gone")
+        }
     }
 
     private fun createUserInfoDetails(userInfo: UserProfileData?): List<UserInfoDetailsItem> {