From 06a98a6da22b084ca99fc6ff8e5ee92ef9c6a3c3 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 9 Mar 2022 15:56:11 -0500 Subject: [PATCH] Move GONE/VISIBLE to the controller instead of the model --- .../conversations/ui/EnterJidDialog.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/EnterJidDialog.java b/src/main/java/eu/siacs/conversations/ui/EnterJidDialog.java index 696d61483..104d3f4db 100644 --- a/src/main/java/eu/siacs/conversations/ui/EnterJidDialog.java +++ b/src/main/java/eu/siacs/conversations/ui/EnterJidDialog.java @@ -152,6 +152,8 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected binding.gatewayList.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false)); binding.gatewayList.setAdapter(gatewayListAdapter); + gatewayListAdapter.setOnEmpty(() -> binding.gatewayList.setVisibility(View.GONE)); + gatewayListAdapter.setOnNonEmpty(() -> binding.gatewayList.setVisibility(View.VISIBLE)); binding.account.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override @@ -405,6 +407,8 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected protected List> gateways = new ArrayList(); protected int selected = 0; + protected Runnable onEmpty = () -> {}; + protected Runnable onNonEmpty = () -> {}; @Override public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { @@ -417,11 +421,7 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected viewHolder.setIndex(i); if(i == 0) { - if(getItemCount() < 2) { - binding.gatewayList.setVisibility(View.GONE); - } else { - viewHolder.useButton(R.string.account_settings_jabber_id); - } + viewHolder.useButton(R.string.account_settings_jabber_id); } else { viewHolder.useButton(getLabel(i)); } @@ -527,14 +527,23 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected return presence == null ? null : new Pair(gateway.second, presence); } + public void setOnEmpty(Runnable r) { + onEmpty = r; + } + + public void setOnNonEmpty(Runnable r) { + onNonEmpty = r; + } + public void clear() { - this.gateways.clear(); + gateways.clear(); + onEmpty.run(); notifyDataSetChanged(); setSelected(0); } public void add(Contact gateway, String prompt) { - binding.gatewayList.setVisibility(View.VISIBLE); + if (getItemCount() < 2) onNonEmpty.run(); this.gateways.add(new Pair<>(gateway, prompt)); Collections.sort(this.gateways, (x, y) -> getLabel(x.first).compareTo(getLabel(y.first))); notifyDataSetChanged();