Merge pull request 'Don't show instance search results if there aren't any.' (#284) from nolan/Fedilab:instance-a11y into develop

Reviewed-on: https://codeberg.org/tom79/Fedilab/pulls/284
This commit is contained in:
Thomas 2022-07-30 10:36:02 +02:00
commit 7e2b1423a6
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.getInstances(query).observe(requireActivity(), instanceSocialList -> {
binding.loginInstance.setAdapter(null);
String[] instances = new String[instanceSocialList.instances.size()];
int j = 0;
for (InstanceSocial.Instance instance : instanceSocialList.instances) {
instances[j] = instance.name;
j++;
if (instanceSocialList.instances.isEmpty()) {
binding.loginInstance.dismissDropDown();
} else {
String[] instances = new String[instanceSocialList.instances.size()];
int j = 0;
for (InstanceSocial.Instance instance : instanceSocialList.instances) {
instances[j] = instance.name;
j++;
}
ArrayAdapter<String> adapter = new ArrayAdapter<>(requireActivity(),
android.R.layout.simple_list_item_1, instances);
binding.loginInstance.setAdapter(adapter);
if (binding.loginInstance.hasFocus() && !requireActivity().isFinishing())
binding.loginInstance.showDropDown();
}
ArrayAdapter<String> adapter =
new ArrayAdapter<>(requireActivity(), android.R.layout.simple_list_item_1, instances);
binding.loginInstance.setAdapter(adapter);
if (binding.loginInstance.hasFocus() && !requireActivity().isFinishing())
binding.loginInstance.showDropDown();
if (oldSearch != null && oldSearch.equals(binding.loginInstance.getText().toString())) {
binding.loginInstance.dismissDropDown();
}