Sort gateways

This commit is contained in:
Stephen Paul Weber 2022-03-07 23:10:43 -05:00
parent 4444909d49
commit 58cf187f31
No known key found for this signature in database
GPG Key ID: D11C2911CE519CDE
1 changed files with 14 additions and 5 deletions

View File

@ -461,19 +461,27 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected
notifyItemChanged(i);
}
public String getLabel(Contact gateway) {
String type = getType(gateway);
if (type != null) return type;
return gateway.getDisplayName();
}
public String getLabel(int i) {
if (i == 0) return null;
String type = getType(i);
if (type != null) return type;
return gateways.get(i-1).first.getDisplayName();
return getLabel(this.gateways.get(i-1).first);
}
public String getType(int i) {
if (i == 0) return null;
for(Presence p : this.gateways.get(i-1).first.getPresences().getPresences()) {
return getType(this.gateways.get(i-1).first);
}
public String getType(Contact gateway) {
for(Presence p : gateway.getPresences().getPresences()) {
ServiceDiscoveryResult.Identity id;
if(p.getServiceDiscoveryResult() != null && (id = p.getServiceDiscoveryResult().getIdentity("gateway", null)) != null) {
return id.getType();
@ -528,6 +536,7 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected
public void add(Contact gateway, String prompt) {
binding.gatewayList.setVisibility(View.VISIBLE);
this.gateways.add(new Pair<>(gateway, prompt));
Collections.sort(this.gateways, (x, y) -> getLabel(x.first).compareTo(getLabel(y.first)));
notifyDataSetChanged();
}
}