From 41c7239a8c0e9d5ca2c6910979b3a57a2fe16c2c Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Fri, 12 Apr 2019 09:46:11 +0100 Subject: [PATCH] Members list: fix crash and handle correct lifecycle. --- .../ui/CollectionMembersListFragment.kt | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/etesync/syncadapter/ui/CollectionMembersListFragment.kt b/app/src/main/java/com/etesync/syncadapter/ui/CollectionMembersListFragment.kt index 5ac00d85..fb6f3c31 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/CollectionMembersListFragment.kt +++ b/app/src/main/java/com/etesync/syncadapter/ui/CollectionMembersListFragment.kt @@ -28,6 +28,7 @@ class CollectionMembersListFragment : ListFragment(), AdapterView.OnItemClickLis private lateinit var account: Account private lateinit var info: CollectionInfo private lateinit var journalEntity: JournalEntity + private var members: List? = null private var asyncTask: Future? = null private var emptyTextView: TextView? = null @@ -57,15 +58,10 @@ class CollectionMembersListFragment : ListFragment(), AdapterView.OnItemClickLis val journalsManager = JournalManager(httpClient, HttpUrl.get(settings.uri!!)!!) val journal = JournalManager.Journal.fakeWithUid(journalEntity.uid) - val members = journalsManager.listMembers(journal) + members = journalsManager.listMembers(journal) uiThread { - val listAdapter = MembersListAdapter(context!!) - setListAdapter(listAdapter) - - listAdapter.addAll(members) - - emptyTextView!!.setText(R.string.collection_members_list_empty) + setListAdapterMembers(members!!) } } catch (e: Exception) { uiThread { @@ -75,6 +71,25 @@ class CollectionMembersListFragment : ListFragment(), AdapterView.OnItemClickLis } } + private fun setListAdapterMembers(members: List) { + val context = context + if (context != null) { + val listAdapter = MembersListAdapter(context) + setListAdapter(listAdapter) + + listAdapter.addAll(members) + + emptyTextView!!.setText(R.string.collection_members_list_empty) + } + } + + override fun onResume() { + super.onResume() + if (members != null) { + setListAdapterMembers(members!!) + } + } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState)