Move GONE/VISIBLE to the controller instead of the model
This commit is contained in:
parent
82bf15e040
commit
06a98a6da2
|
@ -152,6 +152,8 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected
|
||||||
|
|
||||||
binding.gatewayList.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false));
|
binding.gatewayList.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false));
|
||||||
binding.gatewayList.setAdapter(gatewayListAdapter);
|
binding.gatewayList.setAdapter(gatewayListAdapter);
|
||||||
|
gatewayListAdapter.setOnEmpty(() -> binding.gatewayList.setVisibility(View.GONE));
|
||||||
|
gatewayListAdapter.setOnNonEmpty(() -> binding.gatewayList.setVisibility(View.VISIBLE));
|
||||||
|
|
||||||
binding.account.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
binding.account.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -405,6 +407,8 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected
|
||||||
|
|
||||||
protected List<Pair<Contact,String>> gateways = new ArrayList();
|
protected List<Pair<Contact,String>> gateways = new ArrayList();
|
||||||
protected int selected = 0;
|
protected int selected = 0;
|
||||||
|
protected Runnable onEmpty = () -> {};
|
||||||
|
protected Runnable onNonEmpty = () -> {};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
||||||
|
@ -417,11 +421,7 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected
|
||||||
viewHolder.setIndex(i);
|
viewHolder.setIndex(i);
|
||||||
|
|
||||||
if(i == 0) {
|
if(i == 0) {
|
||||||
if(getItemCount() < 2) {
|
viewHolder.useButton(R.string.account_settings_jabber_id);
|
||||||
binding.gatewayList.setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
viewHolder.useButton(R.string.account_settings_jabber_id);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
viewHolder.useButton(getLabel(i));
|
viewHolder.useButton(getLabel(i));
|
||||||
}
|
}
|
||||||
|
@ -527,14 +527,23 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected
|
||||||
return presence == null ? null : new Pair(gateway.second, presence);
|
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() {
|
public void clear() {
|
||||||
this.gateways.clear();
|
gateways.clear();
|
||||||
|
onEmpty.run();
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
setSelected(0);
|
setSelected(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Contact gateway, String prompt) {
|
public void add(Contact gateway, String prompt) {
|
||||||
binding.gatewayList.setVisibility(View.VISIBLE);
|
if (getItemCount() < 2) onNonEmpty.run();
|
||||||
this.gateways.add(new Pair<>(gateway, prompt));
|
this.gateways.add(new Pair<>(gateway, prompt));
|
||||||
Collections.sort(this.gateways, (x, y) -> getLabel(x.first).compareTo(getLabel(y.first)));
|
Collections.sort(this.gateways, (x, y) -> getLabel(x.first).compareTo(getLabel(y.first)));
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
|
|
Loading…
Reference in a new issue