use of com.arlib.floatingsearchview.suggestions.model.SearchSuggestion in project floatingsearchview by arimorty.
the class FloatingSearchView method setupSuggestionSection.
private void setupSuggestionSection() {
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, true);
mSuggestionsList.setLayoutManager(layoutManager);
mSuggestionsList.setItemAnimator(null);
final GestureDetector gestureDetector = new GestureDetector(getContext(), new GestureDetectorListenerAdapter() {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
if (mHostActivity != null) {
Util.closeSoftKeyboard(mHostActivity);
}
return false;
}
});
mSuggestionsList.addOnItemTouchListener(new OnItemTouchListenerAdapter() {
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
gestureDetector.onTouchEvent(e);
return false;
}
});
mSuggestionsAdapter = new SearchSuggestionsAdapter(getContext(), mSuggestionsTextSizePx, new SearchSuggestionsAdapter.Listener() {
@Override
public void onItemSelected(SearchSuggestion item) {
mIsFocused = false;
if (mSearchListener != null) {
mSearchListener.onSuggestionClicked(item);
}
mSkipTextChangeEvent = true;
if (mIsTitleSet) {
setSearchBarTitle(item.getBody());
} else {
setSearchText(item.getBody());
}
setSearchFocusedInternal(false);
}
@Override
public void onMoveItemToSearchClicked(SearchSuggestion item) {
mSearchInput.setText(item.getBody());
//move cursor to end of text
mSearchInput.setSelection(mSearchInput.getText().length());
}
});
refreshShowMoveUpSuggestion();
mSuggestionsAdapter.setTextColor(this.mSuggestionTextColor);
mSuggestionsAdapter.setRightIconColor(this.mSuggestionRightIconColor);
mSuggestionsList.setAdapter(mSuggestionsAdapter);
int cardViewBottomPadding = Util.dpToPx(CARD_VIEW_CORNERS_AND_TOP_BOTTOM_SHADOW_HEIGHT);
//move up the suggestions section enough to cover the search bar
//card's bottom left and right corners
mSuggestionsSection.setTranslationY(-cardViewBottomPadding);
}
use of com.arlib.floatingsearchview.suggestions.model.SearchSuggestion in project floatingsearchview by arimorty.
the class SearchSuggestionsAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(RecyclerView.ViewHolder vh, int position) {
SearchSuggestionViewHolder viewHolder = (SearchSuggestionViewHolder) vh;
if (!mShowRightMoveUpBtn) {
viewHolder.rightIcon.setEnabled(false);
viewHolder.rightIcon.setVisibility(View.INVISIBLE);
} else {
viewHolder.rightIcon.setEnabled(true);
viewHolder.rightIcon.setVisibility(View.VISIBLE);
}
SearchSuggestion suggestionItem = mSearchSuggestions.get(position);
viewHolder.body.setText(suggestionItem.getBody());
if (mOnBindSuggestionCallback != null) {
mOnBindSuggestionCallback.onBindSuggestion(viewHolder.itemView, viewHolder.leftIcon, viewHolder.body, suggestionItem, position);
}
}
use of com.arlib.floatingsearchview.suggestions.model.SearchSuggestion in project Tusky by Vavassor.
the class MainActivity method setupSearchView.
private void setupSearchView() {
searchView.attachNavigationDrawerToMenuButton(drawer.getDrawerLayout());
// Setup content descriptions for the different elements in the search view.
final View leftAction = searchView.findViewById(R.id.left_action);
leftAction.setContentDescription(getString(R.string.action_open_drawer));
searchView.setOnFocusChangeListener(new FloatingSearchView.OnFocusChangeListener() {
@Override
public void onFocus() {
leftAction.setContentDescription(getString(R.string.action_close));
}
@Override
public void onFocusCleared() {
leftAction.setContentDescription(getString(R.string.action_open_drawer));
}
});
View clearButton = searchView.findViewById(R.id.clear_btn);
clearButton.setContentDescription(getString(R.string.action_clear));
searchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() {
@Override
public void onSearchTextChanged(String oldQuery, String newQuery) {
if (!oldQuery.equals("") && newQuery.equals("")) {
searchView.clearSuggestions();
return;
}
if (newQuery.length() < 3) {
return;
}
searchView.showProgress();
mastodonAPI.searchAccounts(newQuery, false, 5).enqueue(new Callback<List<Account>>() {
@Override
public void onResponse(Call<List<Account>> call, Response<List<Account>> response) {
if (response.isSuccessful()) {
searchView.swapSuggestions(response.body());
searchView.hideProgress();
} else {
searchView.hideProgress();
}
}
@Override
public void onFailure(Call<List<Account>> call, Throwable t) {
searchView.hideProgress();
}
});
}
});
searchView.setOnSearchListener(new FloatingSearchView.OnSearchListener() {
@Override
public void onSuggestionClicked(SearchSuggestion searchSuggestion) {
Account accountSuggestion = (Account) searchSuggestion;
Intent intent = new Intent(MainActivity.this, AccountActivity.class);
intent.putExtra("id", accountSuggestion.id);
startActivity(intent);
}
@Override
public void onSearchAction(String currentQuery) {
}
});
searchView.setOnBindSuggestionCallback(new SearchSuggestionsAdapter.OnBindSuggestionCallback() {
@Override
public void onBindSuggestion(View suggestionView, ImageView leftIcon, TextView textView, SearchSuggestion item, int itemPosition) {
Account accountSuggestion = ((Account) item);
Picasso.with(MainActivity.this).load(accountSuggestion.avatar).placeholder(R.drawable.avatar_default).into(leftIcon);
String searchStr = accountSuggestion.getDisplayName() + " " + accountSuggestion.username;
final SpannableStringBuilder str = new SpannableStringBuilder(searchStr);
str.setSpan(new StyleSpan(Typeface.BOLD), 0, accountSuggestion.getDisplayName().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(str);
textView.setMaxLines(1);
textView.setEllipsize(TextUtils.TruncateAt.END);
}
});
}
Aggregations