From 59b94a1744252c3c70de003755922b5d5443f582 Mon Sep 17 00:00:00 2001
From: Anton Chekulaev <metaphore@bk.ru>
Date: Mon, 24 Aug 2020 11:43:09 +1000
Subject: [PATCH 1/2] Update ContactSelectionListFragment.kt

Manual loader destruction and logging for the loader callback activity check.
---
 .../fragments/ContactSelectionListFragment.kt    | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/org/thoughtcrime/securesms/loki/fragments/ContactSelectionListFragment.kt b/src/org/thoughtcrime/securesms/loki/fragments/ContactSelectionListFragment.kt
index b3e2932848..5ccbe020f4 100644
--- a/src/org/thoughtcrime/securesms/loki/fragments/ContactSelectionListFragment.kt
+++ b/src/org/thoughtcrime/securesms/loki/fragments/ContactSelectionListFragment.kt
@@ -55,6 +55,11 @@ class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks<L
         super.onStart()
         LoaderManager.getInstance(this).initLoader(0, null, this)
     }
+    
+    override fun onStop() {
+        super.onStop()
+        LoaderManager.getInstance(this).destroyLoader(0)
+    }
 
     override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
         return inflater.inflate(R.layout.contact_selection_list_fragment, container, false)
@@ -92,8 +97,13 @@ class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks<L
         update(listOf())
     }
 
-    private fun update(items: List<ContactSelectionListItem>) {
-        if (activity?.isDestroyed == true) { return }
+    private fun update(items: List<ContactSelectionListItem>) {        
+        if (activity?.isDestroyed == true) {
+            Log.e(ContactSelectionListFragment::class.java.name,
+                    "Received a loader callback after the fragment was detached from an activity.",
+                    IllegalStateException())
+            return
+        }
         listAdapter.items = items
         mainContentContainer.visibility = if (items.isEmpty()) View.GONE else View.VISIBLE
         emptyStateContainer.visibility = if (items.isEmpty()) View.VISIBLE else View.GONE
@@ -110,4 +120,4 @@ class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks<L
     override fun onContactDeselected(contact: Recipient) {
         onContactSelectedListener?.onContactDeselected(contact.address.serialize())
     }
-}
\ No newline at end of file
+}

From 61b3cca246b282850d8bb1b86e5087ec425c6d86 Mon Sep 17 00:00:00 2001
From: Anton Chekulaev <metaphore@bk.ru>
Date: Mon, 24 Aug 2020 11:46:50 +1000
Subject: [PATCH 2/2] Missed import.

---
 .../securesms/loki/fragments/ContactSelectionListFragment.kt     | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/org/thoughtcrime/securesms/loki/fragments/ContactSelectionListFragment.kt b/src/org/thoughtcrime/securesms/loki/fragments/ContactSelectionListFragment.kt
index 5ccbe020f4..1285b65198 100644
--- a/src/org/thoughtcrime/securesms/loki/fragments/ContactSelectionListFragment.kt
+++ b/src/org/thoughtcrime/securesms/loki/fragments/ContactSelectionListFragment.kt
@@ -12,6 +12,7 @@ import android.view.ViewGroup
 import kotlinx.android.synthetic.main.contact_selection_list_fragment.*
 import network.loki.messenger.R
 import org.thoughtcrime.securesms.contacts.ContactsCursorLoader
+import org.thoughtcrime.securesms.logging.Log
 import org.thoughtcrime.securesms.mms.GlideApp
 import org.thoughtcrime.securesms.recipients.Recipient