Hopefully fix crash

This commit is contained in:
nielsandriesse 2020-08-24 09:11:48 +10:00
parent 457c4b75c9
commit 72999c7d12

View File

@ -23,11 +23,11 @@ class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks<L
get() = listAdapter.selectedContacts.map { it.address.serialize() } get() = listAdapter.selectedContacts.map { it.address.serialize() }
private val multiSelect: Boolean by lazy { private val multiSelect: Boolean by lazy {
activity!!.intent.getBooleanExtra(MULTI_SELECT, false) requireActivity().intent.getBooleanExtra(MULTI_SELECT, false)
} }
private val listAdapter by lazy { private val listAdapter by lazy {
val result = ContactSelectionListAdapter(activity!!, multiSelect) val result = ContactSelectionListAdapter(requireActivity(), multiSelect)
result.glide = GlideApp.with(this) result.glide = GlideApp.with(this)
result.contactClickListener = this result.contactClickListener = this
result result
@ -48,7 +48,7 @@ class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks<L
super.onActivityCreated(savedInstanceState) super.onActivityCreated(savedInstanceState)
recyclerView.layoutManager = LinearLayoutManager(activity) recyclerView.layoutManager = LinearLayoutManager(activity)
recyclerView.adapter = listAdapter recyclerView.adapter = listAdapter
swipeRefreshLayout.isEnabled = activity!!.intent.getBooleanExtra(REFRESHABLE, true) swipeRefreshLayout.isEnabled = requireActivity().intent.getBooleanExtra(REFRESHABLE, true)
} }
override fun onStart() { override fun onStart() {
@ -79,8 +79,8 @@ class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks<L
} }
override fun onCreateLoader(id: Int, args: Bundle?): Loader<List<ContactSelectionListItem>> { override fun onCreateLoader(id: Int, args: Bundle?): Loader<List<ContactSelectionListItem>> {
return ContactSelectionListLoader(activity!!, return ContactSelectionListLoader(requireActivity(),
activity!!.intent.getIntExtra(DISPLAY_MODE, ContactsCursorLoader.DisplayMode.FLAG_ALL), requireActivity().intent.getIntExtra(DISPLAY_MODE, ContactsCursorLoader.DisplayMode.FLAG_ALL),
cursorFilter) cursorFilter)
} }
@ -93,6 +93,7 @@ class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks<L
} }
private fun update(items: List<ContactSelectionListItem>) { private fun update(items: List<ContactSelectionListItem>) {
if (activity?.isDestroyed == true) { return }
listAdapter.items = items listAdapter.items = items
mainContentContainer.visibility = if (items.isEmpty()) View.GONE else View.VISIBLE mainContentContainer.visibility = if (items.isEmpty()) View.GONE else View.VISIBLE
emptyStateContainer.visibility = if (items.isEmpty()) View.VISIBLE else View.GONE emptyStateContainer.visibility = if (items.isEmpty()) View.VISIBLE else View.GONE