Don't show instance search results if there aren't any.

This commit is contained in:
Nolan Darilek 2022-07-26 15:19:59 -05:00
parent 1fcefad951
commit f429017122
1 changed files with 14 additions and 10 deletions

View File

@ -104,17 +104,21 @@ public class FragmentLoginMain extends Fragment {
InstanceSocialVM instanceSocialVM = new ViewModelProvider(FragmentLoginMain.this).get(InstanceSocialVM.class); InstanceSocialVM instanceSocialVM = new ViewModelProvider(FragmentLoginMain.this).get(InstanceSocialVM.class);
instanceSocialVM.getInstances(query).observe(requireActivity(), instanceSocialList -> { instanceSocialVM.getInstances(query).observe(requireActivity(), instanceSocialList -> {
binding.loginInstance.setAdapter(null); binding.loginInstance.setAdapter(null);
if (instanceSocialList.instances.isEmpty()) {
binding.loginInstance.dismissDropDown();
} else {
String[] instances = new String[instanceSocialList.instances.size()]; String[] instances = new String[instanceSocialList.instances.size()];
int j = 0; int j = 0;
for (InstanceSocial.Instance instance : instanceSocialList.instances) { for (InstanceSocial.Instance instance : instanceSocialList.instances) {
instances[j] = instance.name; instances[j] = instance.name;
j++; j++;
} }
ArrayAdapter<String> adapter = ArrayAdapter<String> adapter = new ArrayAdapter<>(requireActivity(),
new ArrayAdapter<>(requireActivity(), android.R.layout.simple_list_item_1, instances); android.R.layout.simple_list_item_1, instances);
binding.loginInstance.setAdapter(adapter); binding.loginInstance.setAdapter(adapter);
if (binding.loginInstance.hasFocus() && !requireActivity().isFinishing()) if (binding.loginInstance.hasFocus() && !requireActivity().isFinishing())
binding.loginInstance.showDropDown(); binding.loginInstance.showDropDown();
}
if (oldSearch != null && oldSearch.equals(binding.loginInstance.getText().toString())) { if (oldSearch != null && oldSearch.equals(binding.loginInstance.getText().toString())) {
binding.loginInstance.dismissDropDown(); binding.loginInstance.dismissDropDown();
} }