1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-15 19:27:31 +00:00

Fix tapping search input not showing keyboard the first time

This commit is contained in:
Ammar Githam 2021-04-28 23:16:35 +09:00
parent 67b8bd9a2f
commit 6df5bc056c

View File

@ -22,7 +22,6 @@ import androidx.navigation.fragment.NavHostFragment;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.tabs.TabLayoutMediator; import com.google.android.material.tabs.TabLayoutMediator;
import com.google.android.material.textfield.TextInputLayout;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -45,8 +44,6 @@ public class SearchFragment extends Fragment implements SearchCategoryFragment.O
private LinearLayoutCompat root; private LinearLayoutCompat root;
private boolean shouldRefresh = true; private boolean shouldRefresh = true;
@Nullable @Nullable
private TextInputLayout searchInputLayout;
@Nullable
private EditText searchInput; private EditText searchInput;
@Nullable @Nullable
private MainActivity mainActivity; private MainActivity mainActivity;
@ -122,15 +119,14 @@ public class SearchFragment extends Fragment implements SearchCategoryFragment.O
if (mainActivity != null) { if (mainActivity != null) {
mainActivity.showSearchView(); mainActivity.showSearchView();
} }
if (searchInputLayout != null) { // if (searchInputLayout != null) {
searchInputLayout.requestFocus(); // searchInputLayout.requestFocus();
} // }
} }
private void init(@Nullable final Bundle savedInstanceState) { private void init(@Nullable final Bundle savedInstanceState) {
if (mainActivity == null) return; if (mainActivity == null) return;
searchInputLayout = mainActivity.showSearchView(); searchInput = mainActivity.showSearchView().getEditText();
searchInput = searchInputLayout.getEditText();
setupObservers(); setupObservers();
setupViewPager(); setupViewPager();
setupSearchInput(savedInstanceState); setupSearchInput(savedInstanceState);
@ -151,7 +147,7 @@ public class SearchFragment extends Fragment implements SearchCategoryFragment.O
searchInput.setText(savedQuery); searchInput.setText(savedQuery);
triggerEmptyQuery = false; triggerEmptyQuery = false;
} }
searchInput.requestFocus(); // searchInput.requestFocus();
if (triggerEmptyQuery) { if (triggerEmptyQuery) {
viewModel.submitQuery(""); viewModel.submitQuery("");
} }
@ -235,7 +231,7 @@ public class SearchFragment extends Fragment implements SearchCategoryFragment.O
liveData.removeObserver(this); liveData.removeObserver(this);
break; break;
case ERROR: case ERROR:
Snackbar.make(binding.getRoot(), R.string.error, Snackbar.LENGTH_SHORT); Snackbar.make(binding.getRoot(), R.string.error, Snackbar.LENGTH_SHORT).show();
liveData.removeObserver(this); liveData.removeObserver(this);
break; break;
case LOADING: case LOADING: