# HG changeset patch # User Da Risk # Date 1368548665 -7200 # Node ID a1f3a20c87f8b610c17f1a03a01dbf491d0a54de # Parent 10851bc81cf273ec83813608ad48d27c46d39102 ContactList: Separate creation of ContactListAdapter and managment of the group list This is two separate things. getContactListAdapter is called in ContactListFragment.onActivityCreated() which is during a fragment transaction. Management of the group list calls FragmentPagerAdapter.notifyDataSetChanged() which repopulate the FragmentPagerAdapter and to do so calls FragmentManager.executePendingTransactions() in a recursive way and is not allowed (IllegalStateException). diff -r 10851bc81cf2 -r a1f3a20c87f8 src/com/beem/project/beem/ui/ContactList.java --- a/src/com/beem/project/beem/ui/ContactList.java Thu Mar 14 10:52:10 2013 +0100 +++ b/src/com/beem/project/beem/ui/ContactList.java Tue May 14 18:24:25 2013 +0200 @@ -243,23 +243,6 @@ if (contactListAdapter == null) { contactListAdapter = new ContactListAdapter(ContactList.this); contactListAdapters.put(group, contactListAdapter); - List realGroups = mListGroup.subList(1, mListGroup.size() - 1); - if (!mListGroup.contains(group)) { - boolean added = false; - // insert group in sorted list - for (ListIterator iterator = realGroups.listIterator(); iterator.hasNext();) { - String currentGroup = (String) iterator.next(); - if (currentGroup.compareTo(group) > 0) { - iterator.previous(); - iterator.add(group); - added = true; - break; - } - } - if (!added) - realGroups.add(group); - groupsPagesAdapter.notifyDataSetChanged(); - } } boolean hideDisconnected = mSettings.getBoolean(BeemApplication.SHOW_OFFLINE_CONTACTS_KEY, false); contactListAdapter.setOnlineOnly(hideDisconnected); @@ -348,6 +331,31 @@ } } + /** + * Add a new group in the GroupBanner. + * + * @param group the group to add + */ + private void addGroupInBanner(String group) { + List realGroups = mListGroup.subList(1, mListGroup.size() - 1); + if (!mListGroup.contains(group)) { + boolean added = false; + // insert group in sorted list + for (ListIterator iterator = realGroups.listIterator(); iterator.hasNext();) { + String currentGroup = (String) iterator.next(); + if (currentGroup.compareTo(group) > 0) { + iterator.previous(); + iterator.add(group); + added = true; + break; + } + } + if (!added) + realGroups.add(group); + groupsPagesAdapter.notifyDataSetChanged(); + } + } + /** * Listener on service event. */ @@ -453,6 +461,7 @@ @Override public void run() { + addGroupInBanner(group); ContactListAdapter contactListAdapter = getContactListAdapter(group); contactListAdapter.put(contact); } @@ -534,6 +543,7 @@ List groups = c.getGroups(); for (String currentGroup : groups) { + addGroupInBanner(currentGroup); ContactListAdapter cl = getContactListAdapter(currentGroup); cl.put(c); }