split roster by different accounts
This commit is contained in:
parent
54ac152019
commit
510f93ce78
|
@ -81,6 +81,7 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -1620,11 +1621,13 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
|
|||
|
||||
class ExpandableListItemAdapter extends ListItemAdapter implements ExpandableListAdapter {
|
||||
|
||||
private List<ListItem.Tag> tags = new ArrayList<>();
|
||||
private String generalTagName = activity.getString(R.string.contact_tag_general);
|
||||
private ListItem.Tag generalTag = new ListItem.Tag(generalTagName, UIHelper.getColorForName(generalTagName,true));
|
||||
private ListItem.Tag generalTag = new ListItem.Tag(generalTagName, UIHelper.getColorForName(generalTagName, true));
|
||||
|
||||
private Map<ListItem.Tag, List<ListItem>> groupedItems = new HashMap<>();
|
||||
private List<Object> tagsAndAccounts = new ArrayList<>();
|
||||
private Set<Account> expandedAccounts = new HashSet<>();
|
||||
|
||||
private Map<Account, Map<ListItem.Tag, List<ListItem>>> groupedItems = new HashMap<>();
|
||||
|
||||
public ExpandableListItemAdapter(XmppActivity activity, List<ListItem> objects) {
|
||||
super(activity, objects);
|
||||
|
@ -1633,46 +1636,66 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
|
|||
@Override
|
||||
public void onChanged() {
|
||||
if (activity instanceof StartConversationActivity && ((StartConversationActivity) activity).groupingEnabled) {
|
||||
tags.clear();
|
||||
tags.addAll(mTagsAdapter.tags);
|
||||
tagsAndAccounts.clear();
|
||||
|
||||
for (int i=tags.size()-1;i>=0;i--) {
|
||||
if (UIHelper.isStatusTag(activity, tags.get(i))) {
|
||||
tags.remove(tags.get(i));
|
||||
List<Account> accounts = xmppConnectionService.getAccounts();
|
||||
|
||||
List<ListItem.Tag> tags = new ArrayList<>();
|
||||
for (ListItem.Tag tag : mTagsAdapter.tags) {
|
||||
if (!UIHelper.isStatusTag(activity, tag)) {
|
||||
tags.add(tag);
|
||||
}
|
||||
}
|
||||
|
||||
groupedItems.clear();
|
||||
|
||||
boolean generalTagAdded = false;
|
||||
|
||||
for (int i=0;i<ExpandableListItemAdapter.super.getCount();i++) {
|
||||
ListItem item = getItem(i);
|
||||
List<ListItem.Tag> itemTags = item.getTags(activity);
|
||||
|
||||
if (itemTags.size() == 0 || (itemTags.size() == 1 && UIHelper.isStatusTag(activity, itemTags.get(0)))) {
|
||||
if (!generalTagAdded) {
|
||||
tags.add(0, generalTag);
|
||||
generalTagAdded = true;
|
||||
}
|
||||
|
||||
List<ListItem> group = groupedItems.computeIfAbsent(generalTag, tag -> new ArrayList<>());
|
||||
group.add(item);
|
||||
} else {
|
||||
for (ListItem.Tag itemTag : itemTags) {
|
||||
if (UIHelper.isStatusTag(activity, itemTag)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
List<ListItem> group = groupedItems.computeIfAbsent(itemTag, tag -> new ArrayList<>());
|
||||
group.add(item);
|
||||
}
|
||||
for (Account account : accounts) {
|
||||
if (accounts.size() > 1) {
|
||||
tagsAndAccounts.add(account);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=tags.size()-1;i>=0;i--) {
|
||||
if (groupedItems.get(tags.get(i)) == null) {
|
||||
tags.remove(tags.get(i));
|
||||
if (expandedAccounts.contains(account) || accounts.size() == 1) {
|
||||
boolean generalTagAdded = false;
|
||||
int initialPosition = tagsAndAccounts.size();
|
||||
|
||||
tagsAndAccounts.addAll(tags);
|
||||
|
||||
Map<ListItem.Tag, List<ListItem>> groupedItems = new HashMap<>();
|
||||
|
||||
for (int i = 0; i < ExpandableListItemAdapter.super.getCount(); i++) {
|
||||
ListItem item = getItem(i);
|
||||
List<ListItem.Tag> itemTags = item.getTags(activity);
|
||||
|
||||
if (itemTags.size() == 0 || (itemTags.size() == 1 && UIHelper.isStatusTag(activity, itemTags.get(0)))) {
|
||||
if (!generalTagAdded) {
|
||||
tagsAndAccounts.add(initialPosition, generalTag);
|
||||
generalTagAdded = true;
|
||||
}
|
||||
|
||||
List<ListItem> group = groupedItems.computeIfAbsent(generalTag, tag -> new ArrayList<>());
|
||||
group.add(item);
|
||||
} else {
|
||||
for (ListItem.Tag itemTag : itemTags) {
|
||||
if (UIHelper.isStatusTag(activity, itemTag)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
List<ListItem> group = groupedItems.computeIfAbsent(itemTag, tag -> new ArrayList<>());
|
||||
group.add(item);
|
||||
|
||||
android.util.Log.e("27fd add", group.size() + " " + itemTag.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = tagsAndAccounts.size() - 1; i >= initialPosition; i--) {
|
||||
ListItem.Tag tag = (ListItem.Tag) tagsAndAccounts.get(i);
|
||||
if (groupedItems.get(tag) == null) {
|
||||
tagsAndAccounts.remove(tagsAndAccounts.lastIndexOf(tag));
|
||||
}
|
||||
}
|
||||
|
||||
ExpandableListItemAdapter.this.groupedItems.put(account, groupedItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1682,50 +1705,68 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
|
|||
|
||||
@Override
|
||||
public int getGroupCount() {
|
||||
return tags.size();
|
||||
return tagsAndAccounts.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getChildrenCount(int groupPosition) {
|
||||
return groupedItems.get(tags.get(groupPosition)).size();
|
||||
return getChildsList(groupPosition).size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getGroup(int groupPosition) {
|
||||
return tags.get(groupPosition);
|
||||
return tagsAndAccounts.get(groupPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getChild(int groupPosition, int childPosition) {
|
||||
return groupedItems.get(tags.get(groupPosition)).get(childPosition);
|
||||
return getChildsList(groupPosition).get(childPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getGroupId(int groupPosition) {
|
||||
return tags.get(groupPosition).hashCode();
|
||||
return tagsAndAccounts.get(groupPosition).hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getChildId(int groupPosition, int childPosition) {
|
||||
return groupedItems.get(tags.get(groupPosition)).get(childPosition).getJid().hashCode();
|
||||
return getChildsList(groupPosition).get(childPosition).getJid().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
|
||||
ListItem.Tag tag = tags.get(groupPosition);
|
||||
Object obj = tagsAndAccounts.get(groupPosition);
|
||||
|
||||
View v = activity.getLayoutInflater().inflate(R.layout.contact_group, parent, false);
|
||||
View v;
|
||||
if (obj instanceof ListItem.Tag) {
|
||||
ListItem.Tag tag = (ListItem.Tag) obj;
|
||||
|
||||
TextView tv = v.findViewById(R.id.text);
|
||||
tv.setText(activity.getString(R.string.contact_tag_with_total, tag.getName(), getChildrenCount(groupPosition)));
|
||||
tv.setBackgroundColor(tag.getColor());
|
||||
v = activity.getLayoutInflater().inflate(R.layout.contact_group, parent, false);
|
||||
|
||||
TextView tv = v.findViewById(R.id.text);
|
||||
tv.setText(activity.getString(R.string.contact_tag_with_total, tag.getName(), getChildrenCount(groupPosition)));
|
||||
tv.setBackgroundColor(tag.getColor());
|
||||
} else {
|
||||
Account acc = (Account) obj;
|
||||
|
||||
v = activity.getLayoutInflater().inflate(R.layout.contact_account, parent, false);
|
||||
|
||||
TextView tv = v.findViewById(R.id.text);
|
||||
tv.setText(acc.getJid().toString());
|
||||
|
||||
if (acc.isOnlineAndConnected()) {
|
||||
tv.setBackgroundColor(StyledAttributes.getColor(activity, R.attr.TextColorOnline));
|
||||
} else {
|
||||
tv.setBackgroundColor(StyledAttributes.getColor(activity, android.R.attr.textColorSecondary));
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
|
||||
ListItem item = groupedItems.get(tags.get(groupPosition)).get(childPosition);
|
||||
ListItem item = getChildsList(groupPosition).get(childPosition);
|
||||
return super.getView(super.getPosition(item), convertView, parent);
|
||||
}
|
||||
|
||||
|
@ -1736,12 +1777,20 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
|
|||
|
||||
@Override
|
||||
public void onGroupExpanded(int groupPosition) {
|
||||
|
||||
Object tagOrAccount = tagsAndAccounts.get(groupPosition);
|
||||
if (tagOrAccount instanceof Account) {
|
||||
expandedAccounts.add((Account) tagOrAccount);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGroupCollapsed(int groupPosition) {
|
||||
|
||||
Object tagOrAccount = tagsAndAccounts.get(groupPosition);
|
||||
if (tagOrAccount instanceof Account) {
|
||||
expandedAccounts.remove((Account) tagOrAccount);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1753,5 +1802,28 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
|
|||
public long getCombinedGroupId(long groupId) {
|
||||
return (groupId & 0x7FFFFFFF) << 32;
|
||||
}
|
||||
|
||||
private List<ListItem> getChildsList(int groupPosition) {
|
||||
Object tagOrAccount = tagsAndAccounts.get(groupPosition);
|
||||
if (tagOrAccount instanceof Account) {
|
||||
return Collections.emptyList();
|
||||
} else {
|
||||
Account account = null;
|
||||
|
||||
for (int i = groupPosition; i >= 0; i--) {
|
||||
Object item = tagsAndAccounts.get(i);
|
||||
if (item instanceof Account) {
|
||||
account = (Account) item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (account == null) {
|
||||
return groupedItems.get(xmppConnectionService.getAccounts().get(0)).get((ListItem.Tag) tagOrAccount);
|
||||
} else {
|
||||
return groupedItems.get(account).get((ListItem.Tag) tagOrAccount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
23
src/main/res/layout/contact_account.xml
Normal file
23
src/main/res/layout/contact_account.xml
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="8dp"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:layout_marginStart="40dp"
|
||||
android:layout_marginEnd="16dp" />
|
||||
|
||||
<View
|
||||
android:id="@+id/divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1px"
|
||||
android:background="?color_background_tertiary" />
|
||||
|
||||
</FrameLayout>
|
Loading…
Reference in a new issue