Search in sources :

Example 1 with AvailableAttributeAdapter

use of me.devsaki.hentoid.adapters.AvailableAttributeAdapter in project Hentoid by avluis.

the class SearchBottomSheetFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.include_search_filter_category, container, false);
    AttributeType mainAttr = selectedAttributeTypes.get(0);
    // Image that displays current metadata type icon (e.g. face icon for character)
    ImageView tagWaitImage = requireViewById(rootView, R.id.tag_wait_image);
    tagWaitImage.setImageResource(mainAttr.getIcon());
    // Image that displays current metadata type title (e.g. "Character search")
    TextView tagWaitTitle = requireViewById(rootView, R.id.tag_wait_title);
    tagWaitTitle.setText(getString(R.string.search_category, StringHelper.capitalizeString(getString(mainAttr.getDisplayName()))));
    tagWaitPanel = requireViewById(rootView, R.id.tag_wait_panel);
    tagWaitMessage = requireViewById(rootView, R.id.tag_wait_description);
    RecyclerView attributeMosaic = requireViewById(rootView, R.id.tag_suggestion);
    FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(this.getContext());
    // layoutManager.setAlignContent(AlignContent.FLEX_START); <-- not supported
    layoutManager.setAlignItems(AlignItems.STRETCH);
    layoutManager.setFlexWrap(FlexWrap.WRAP);
    attributeMosaic.setLayoutManager(layoutManager);
    attributeAdapter = new AvailableAttributeAdapter();
    attributeAdapter.setOnScrollToEndListener(this::loadMore);
    attributeAdapter.setOnClickListener(this::onAttributeChosen);
    attributeMosaic.setAdapter(attributeAdapter);
    tagSearchView = requireViewById(rootView, R.id.tag_filter);
    // Associate searchable configuration with the SearchView
    tagSearchView.setSearchableInfo(getSearchableInfo(requireActivity()));
    List<String> attrTypesNames = Stream.of(selectedAttributeTypes).map(AttributeType::getDisplayName).map(this::getString).toList();
    tagSearchView.setQueryHint(getResources().getString(R.string.search_prompt, android.text.TextUtils.join(", ", attrTypesNames)));
    tagSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String s) {
            if (!s.isEmpty())
                searchMasterData(s);
            tagSearchView.clearFocus();
            return true;
        }

        @Override
        public boolean onQueryTextChange(String s) {
            searchMasterDataDebouncer.submit(s);
            return true;
        }
    });
    return rootView;
}
Also used : SearchView(androidx.appcompat.widget.SearchView) AvailableAttributeAdapter(me.devsaki.hentoid.adapters.AvailableAttributeAdapter) AttributeType(me.devsaki.hentoid.enums.AttributeType) FlexboxLayoutManager(com.google.android.flexbox.FlexboxLayoutManager) TextView(android.widget.TextView) RecyclerView(androidx.recyclerview.widget.RecyclerView) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) SearchView(androidx.appcompat.widget.SearchView) TextView(android.widget.TextView)

Aggregations

View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 SearchView (androidx.appcompat.widget.SearchView)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 FlexboxLayoutManager (com.google.android.flexbox.FlexboxLayoutManager)1 AvailableAttributeAdapter (me.devsaki.hentoid.adapters.AvailableAttributeAdapter)1 AttributeType (me.devsaki.hentoid.enums.AttributeType)1