Search in sources :

Example 1 with FeedSearchResultAdapter

use of de.danoeh.antennapod.adapter.FeedSearchResultAdapter in project AntennaPod by AntennaPod.

the class SearchFragment method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View layout = inflater.inflate(R.layout.search_fragment, container, false);
    setupToolbar(layout.findViewById(R.id.toolbar));
    progressBar = layout.findViewById(R.id.progressBar);
    recyclerView = layout.findViewById(R.id.recyclerView);
    recyclerView.setRecycledViewPool(((MainActivity) getActivity()).getRecycledViewPool());
    adapter = new EpisodeItemListAdapter((MainActivity) getActivity());
    recyclerView.setAdapter(adapter);
    RecyclerView recyclerViewFeeds = layout.findViewById(R.id.recyclerViewFeeds);
    LinearLayoutManager layoutManagerFeeds = new LinearLayoutManager(getActivity());
    layoutManagerFeeds.setOrientation(RecyclerView.HORIZONTAL);
    recyclerViewFeeds.setLayoutManager(layoutManagerFeeds);
    adapterFeeds = new FeedSearchResultAdapter((MainActivity) getActivity());
    recyclerViewFeeds.setAdapter(adapterFeeds);
    emptyViewHandler = new EmptyViewHandler(getContext());
    emptyViewHandler.attachToRecyclerView(recyclerView);
    emptyViewHandler.setIcon(R.drawable.ic_search);
    emptyViewHandler.setTitle(R.string.search_status_no_results);
    emptyViewHandler.setMessage(R.string.type_to_search);
    EventBus.getDefault().register(this);
    chip = layout.findViewById(R.id.feed_title_chip);
    chip.setOnCloseIconClickListener(v -> {
        getArguments().putLong(ARG_FEED, 0);
        searchWithProgressBar();
    });
    chip.setVisibility((getArguments().getLong(ARG_FEED, 0) == 0) ? View.GONE : View.VISIBLE);
    chip.setText(getArguments().getString(ARG_FEED_NAME, ""));
    if (getArguments().getString(ARG_QUERY, null) != null) {
        search();
    }
    searchView.setOnQueryTextFocusChangeListener((view, hasFocus) -> {
        if (hasFocus) {
            showInputMethod(view.findFocus());
        }
    });
    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
                InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(recyclerView.getWindowToken(), 0);
            }
        }
    });
    return layout;
}
Also used : FeedSearchResultAdapter(de.danoeh.antennapod.adapter.FeedSearchResultAdapter) EmptyViewHandler(de.danoeh.antennapod.view.EmptyViewHandler) EpisodeItemListRecyclerView(de.danoeh.antennapod.view.EpisodeItemListRecyclerView) RecyclerView(androidx.recyclerview.widget.RecyclerView) InputMethodManager(android.view.inputmethod.InputMethodManager) MainActivity(de.danoeh.antennapod.activity.MainActivity) EpisodeItemListAdapter(de.danoeh.antennapod.adapter.EpisodeItemListAdapter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) EpisodeItemListRecyclerView(de.danoeh.antennapod.view.EpisodeItemListRecyclerView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) SearchView(androidx.appcompat.widget.SearchView) Nullable(androidx.annotation.Nullable)

Aggregations

View (android.view.View)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1 Nullable (androidx.annotation.Nullable)1 SearchView (androidx.appcompat.widget.SearchView)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 MainActivity (de.danoeh.antennapod.activity.MainActivity)1 EpisodeItemListAdapter (de.danoeh.antennapod.adapter.EpisodeItemListAdapter)1 FeedSearchResultAdapter (de.danoeh.antennapod.adapter.FeedSearchResultAdapter)1 EmptyViewHandler (de.danoeh.antennapod.view.EmptyViewHandler)1 EpisodeItemListRecyclerView (de.danoeh.antennapod.view.EpisodeItemListRecyclerView)1