Add chip when searching for specific feed (#4522)

This commit is contained in:
Ezequiel 2020-10-13 17:05:26 -03:00 committed by GitHub
parent e5e149a9df
commit cb1af5dbac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 7 deletions

View File

@ -130,7 +130,7 @@ public abstract class EpisodesListFragment extends Fragment {
}
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.episodes, menu);
MenuItemUtils.setupSearchItem(menu, (MainActivity) getActivity(), 0);
MenuItemUtils.setupSearchItem(menu, (MainActivity) getActivity(), 0, "");
isUpdatingFeeds = MenuItemUtils.updateRefreshMenuItem(menu, R.id.refresh_item, updateRefreshMenuItemChecker);
}

View File

@ -252,7 +252,11 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
optionsMenu = menu;
FeedMenuHandler.onCreateOptionsMenu(inflater, menu);
iconTintManager.updateTint();
MenuItemUtils.setupSearchItem(menu, (MainActivity) getActivity(), feedID);
if (feed != null) {
MenuItemUtils.setupSearchItem(menu, (MainActivity) getActivity(), feedID, feed.getTitle());
} else {
MenuItemUtils.setupSearchItem(menu, (MainActivity) getActivity(), feedID, "");
}
if (feed == null || feed.getLink() == null) {
menu.findItem(R.id.share_link_item).setVisible(false);
menu.findItem(R.id.visit_website_item).setVisible(false);

View File

@ -246,7 +246,7 @@ public class QueueFragment extends Fragment {
super.onCreateOptionsMenu(menu, inflater);
if (queue != null) {
inflater.inflate(R.menu.queue, menu);
MenuItemUtils.setupSearchItem(menu, (MainActivity) getActivity(), 0);
MenuItemUtils.setupSearchItem(menu, (MainActivity) getActivity(), 0, "");
MenuItemUtils.refreshLockItem(getActivity(), menu);
// Show Lock Item only if queue is sorted manually

View File

@ -17,6 +17,9 @@ import androidx.appcompat.widget.SearchView;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.chip.Chip;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.adapter.EpisodeItemListAdapter;
@ -53,6 +56,7 @@ public class SearchFragment extends Fragment {
private static final String TAG = "SearchFragment";
private static final String ARG_QUERY = "query";
private static final String ARG_FEED = "feed";
private static final String ARG_FEED_NAME = "feedName";
private EpisodeItemListAdapter adapter;
private FeedSearchResultAdapter adapterFeeds;
@ -61,6 +65,7 @@ public class SearchFragment extends Fragment {
private EmptyViewHandler emptyViewHandler;
private EpisodeItemListRecyclerView recyclerView;
private List<FeedItem> results;
private Chip chip;
/**
* Create a new SearchFragment that searches all feeds.
@ -80,9 +85,10 @@ public class SearchFragment extends Fragment {
/**
* Create a new SearchFragment that searches one specific feed.
*/
public static SearchFragment newInstance(String query, long feed) {
public static SearchFragment newInstance(String query, long feed, String feedTitle) {
SearchFragment fragment = newInstance(query);
fragment.getArguments().putLong(ARG_FEED, feed);
fragment.getArguments().putString(ARG_FEED_NAME, feedTitle);
return fragment;
}
@ -133,6 +139,12 @@ public class SearchFragment extends Fragment {
emptyViewHandler.setIcon(R.attr.action_search);
emptyViewHandler.setTitle(R.string.search_status_no_results);
EventBus.getDefault().register(this);
chip = layout.findViewById(R.id.feed_title_chip);
chip.setOnCloseIconClickListener(v -> {
getArguments().putLong(ARG_FEED, 0);
search();
});
return layout;
}
@ -262,8 +274,10 @@ public class SearchFragment extends Fragment {
adapter.updateItems(results.first);
if (getArguments().getLong(ARG_FEED, 0) == 0) {
adapterFeeds.updateData(results.second);
chip.setVisibility(View.GONE);
} else {
adapterFeeds.updateData(Collections.emptyList());
chip.setText(getArguments().getString(ARG_FEED_NAME, ""));
}
String query = getArguments().getString(ARG_QUERY);
emptyViewHandler.setMessage(getString(R.string.no_results_for_query, query));

View File

@ -30,7 +30,7 @@ public class MenuItemUtils extends de.danoeh.antennapod.core.menuhandler.MenuIte
ta.recycle();
}
public static void setupSearchItem(Menu menu, MainActivity activity, long feedId) {
public static void setupSearchItem(Menu menu, MainActivity activity, long feedId, String feedTitle) {
MenuItem searchItem = menu.findItem(R.id.action_search);
final SearchView sv = (SearchView) searchItem.getActionView();
sv.setQueryHint(activity.getString(R.string.search_label));
@ -38,7 +38,7 @@ public class MenuItemUtils extends de.danoeh.antennapod.core.menuhandler.MenuIte
@Override
public boolean onQueryTextSubmit(String s) {
sv.clearFocus();
activity.loadChildFragment(SearchFragment.newInstance(s, feedId));
activity.loadChildFragment(SearchFragment.newInstance(s, feedId, feedTitle));
searchItem.collapseActionView();
return true;
}

View File

@ -14,6 +14,15 @@
app:title="@string/search_label"
android:id="@+id/toolbar"/>
<com.google.android.material.chip.Chip
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/toolbar"
android:id="@+id/feed_title_chip"
android:layout_marginLeft="10dp"
android:layout_marginRight="0dp"
app:closeIconVisible="true"/>
<ProgressBar
android:layout_centerInParent="true"
android:id="@+id/progressBar"
@ -23,7 +32,7 @@
android:layout_gravity="center"/>
<androidx.recyclerview.widget.RecyclerView
android:layout_below="@id/toolbar"
android:layout_below="@id/feed_title_chip"
android:id="@+id/recyclerViewFeeds"
android:layout_width="match_parent"
android:layout_height="wrap_content"