From f429017122e825d7ffca3ecdf1b0abada59f572d Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Tue, 26 Jul 2022 15:19:59 -0500 Subject: [PATCH] Don't show instance search results if there aren't any. --- .../ui/fragment/login/FragmentLoginMain.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/login/FragmentLoginMain.java b/app/src/main/java/app/fedilab/android/ui/fragment/login/FragmentLoginMain.java index 0dc503d1d..5c1fdf061 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/login/FragmentLoginMain.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/login/FragmentLoginMain.java @@ -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 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 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(); }