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).
--- 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<String> realGroups = mListGroup.subList(1, mListGroup.size() - 1);
- if (!mListGroup.contains(group)) {
- boolean added = false;
- // insert group in sorted list
- for (ListIterator<String> 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<String> realGroups = mListGroup.subList(1, mListGroup.size() - 1);
+ if (!mListGroup.contains(group)) {
+ boolean added = false;
+ // insert group in sorted list
+ for (ListIterator<String> 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<String> groups = c.getGroups();
for (String currentGroup : groups) {
+ addGroupInBanner(currentGroup);
ContactListAdapter cl = getContactListAdapter(currentGroup);
cl.put(c);
}