private void showSearchSuggestions() { BusProvider.getInstance().post(new ShowSearchSuggestionsEvent(getQuery())); mSuggestionsAdapter.setOnItemClickListener(this); mSuggestionsAdapter.setOnItemLongClickListener(this); mSuggestionsAdapter.setOnSearchSuggestionCompleteClickListener(this); CustomLinearLayoutManager layoutManager = new CustomLinearLayoutManager(getContext()); // LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); mRecyclerView.setLayoutManager(layoutManager); mDividerItemDecoration = new DividerItemDecoration(ContextCompat.getDrawable(getContext(), R.drawable.divider)); mRecyclerView.addItemDecoration(mDividerItemDecoration); // mRecyclerView.setItemAnimator(new SlideInUpAnimator()); mRecyclerView.setAdapter(mSuggestionsAdapter); if (mSuggestionsAdapter.getItemCount() > 0) { mRecyclerView.setVisibility(View.VISIBLE); mDividerView.setVisibility(View.VISIBLE); } else { mRecyclerView.setVisibility(View.GONE); mDividerView.setVisibility(View.GONE); } mBackgroundCoverFrameLayout.setVisibility(View.VISIBLE); setUpLeftDrawable(true); mAreSearchSuggestionsVisible = true; }
// region SuggestionsAdapter.OnItemClickListener Methods @Override public void onItemClick(int position, View view) { TextView suggestionTextView = (TextView) view.findViewById(R.id.suggestion_tv); String suggestion = suggestionTextView.getText().toString(); hideSearchSuggestions(); BusProvider.getInstance().post(new SearchPerformedEvent(suggestion)); }
@OnTextChanged(R.id.search_et) public void onSearchEditTextTextChanged(CharSequence text) { if (text.length() > 0) { mMicrophoneImageView.setVisibility(View.GONE); mClearImageView.setVisibility(View.VISIBLE); } else { mClearImageView.setVisibility(View.GONE); mMicrophoneImageView.setVisibility(View.VISIBLE); } if (mIsSearchEditTextFocused) { mSuggestionsAdapter.setCurrentQuery(text.toString()); BusProvider.getInstance().post(new ShowSearchSuggestionsEvent(text.toString())); } mFilterImageView.setVisibility(View.GONE); }
@OnClick(R.id.left_drawable_iv) public void leftDrawableImageViewClicked() { if (mAreSearchSuggestionsVisible) { hideSearchSuggestions(); } else { LeftDrawableClickedEvent.Type type = null; switch (mLeftDrawableType) { case 0: type = LeftDrawableClickedEvent.Type.MENU; break; case 1: type = LeftDrawableClickedEvent.Type.BACK; break; case 2: type = LeftDrawableClickedEvent.Type.SEARCH; mSearchEditText.requestFocus(); default: break; } BusProvider.getInstance().post(new LeftDrawableClickedEvent(type)); } }
@Override public void onClick(View v) { BusProvider.getInstance().post(new FilterClickedEvent()); }
@Override public void onPause() { super.onPause(); BusProvider.getInstance().unregister(this); }
@Override public void onResume() { super.onResume(); BusProvider.getInstance().register(this); }