diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/GpodnetMainFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/GpodnetMainFragment.java index 641e82b5a..ad815c3c9 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/GpodnetMainFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/GpodnetMainFragment.java @@ -1,11 +1,14 @@ package de.danoeh.antennapod.fragment.gpodnet; +import android.app.Activity; import android.os.Bundle; import android.view.LayoutInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import androidx.annotation.NonNull; +import androidx.appcompat.widget.SearchView; import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; import androidx.viewpager2.adapter.FragmentStateAdapter; @@ -15,6 +18,9 @@ import com.google.android.material.tabs.TabLayout; import com.google.android.material.tabs.TabLayoutMediator; import de.danoeh.antennapod.R; +import de.danoeh.antennapod.activity.MainActivity; +import de.danoeh.antennapod.discovery.GpodnetPodcastSearcher; +import de.danoeh.antennapod.fragment.OnlineSearchFragment; /** * Main navigation hub for gpodder.net podcast directory @@ -30,9 +36,7 @@ public class GpodnetMainFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); View root = inflater.inflate(R.layout.pager_fragment, container, false); - Toolbar toolbar = root.findViewById(R.id.toolbar); - toolbar.setTitle(R.string.gpodnet_main_label); - toolbar.setNavigationOnClickListener(v -> getParentFragmentManager().popBackStack()); + setupToolbar(root.findViewById(R.id.toolbar)); ViewPager2 viewPager = root.findViewById(R.id.viewpager); GpodnetPagerAdapter pagerAdapter = new GpodnetPagerAdapter(this); @@ -59,6 +63,33 @@ public class GpodnetMainFragment extends Fragment { return root; } + private void setupToolbar(Toolbar toolbar) { + toolbar.setTitle(R.string.gpodnet_main_label); + toolbar.setNavigationOnClickListener(v -> getParentFragmentManager().popBackStack()); + + toolbar.inflateMenu(R.menu.search); + MenuItem searchItem = toolbar.getMenu().findItem(R.id.action_search); + final SearchView sv = (SearchView) searchItem.getActionView(); + sv.setQueryHint(getString(R.string.gpodnet_search_hint)); + sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() { + @Override + public boolean onQueryTextSubmit(String query) { + Activity activity = getActivity(); + if (activity != null) { + searchItem.collapseActionView(); + ((MainActivity) activity).loadChildFragment( + OnlineSearchFragment.newInstance(GpodnetPodcastSearcher.class, query)); + } + return true; + } + + @Override + public boolean onQueryTextChange(String s) { + return false; + } + }); + } + public static class GpodnetPagerAdapter extends FragmentStateAdapter { GpodnetPagerAdapter(@NonNull Fragment fragment) { @@ -68,20 +99,14 @@ public class GpodnetMainFragment extends Fragment { @NonNull @Override public Fragment createFragment(int position) { - Bundle arguments = new Bundle(); - arguments.putBoolean(PodcastListFragment.ARGUMENT_HIDE_TOOLBAR, true); switch (position) { case POS_TAGS: return new TagListFragment(); case POS_TOPLIST: - PodcastListFragment topListFragment = new PodcastTopListFragment(); - topListFragment.setArguments(arguments); - return topListFragment; + return new PodcastTopListFragment(); default: case POS_SUGGESTIONS: - PodcastListFragment suggestionsFragment = new SuggestionListFragment(); - suggestionsFragment.setArguments(arguments); - return suggestionsFragment; + return new SuggestionListFragment(); } } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/PodcastListFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/PodcastListFragment.java index b3f56941b..e272b2869 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/PodcastListFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/PodcastListFragment.java @@ -33,7 +33,6 @@ import de.danoeh.antennapod.core.sync.gpoddernet.model.GpodnetPodcast; * Displays a list of GPodnetPodcast-Objects in a GridView */ public abstract class PodcastListFragment extends Fragment { - public static final String ARGUMENT_HIDE_TOOLBAR = "hideToolbar"; private static final String TAG = "PodcastListFragment"; private GridView gridView; @@ -44,8 +43,6 @@ public abstract class PodcastListFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View root = inflater.inflate(R.layout.gpodnet_podcast_list, container, false); - setupToolbar(root.findViewById(R.id.toolbar)); - gridView = root.findViewById(R.id.gridView); progressBar = root.findViewById(R.id.progressBar); txtvError = root.findViewById(R.id.txtvError); @@ -59,37 +56,6 @@ public abstract class PodcastListFragment extends Fragment { return root; } - private void setupToolbar(Toolbar toolbar) { - if (getArguments() != null && getArguments().getBoolean(ARGUMENT_HIDE_TOOLBAR, false)) { - toolbar.setVisibility(View.GONE); - return; - } - - toolbar.setTitle(R.string.gpodnet_main_label); - toolbar.setNavigationOnClickListener(v -> getParentFragmentManager().popBackStack()); - toolbar.inflateMenu(R.menu.gpodder_podcasts); - - MenuItem searchItem = toolbar.getMenu().findItem(R.id.action_search); - final SearchView sv = (SearchView) searchItem.getActionView(); - sv.setQueryHint(getString(R.string.gpodnet_search_hint)); - sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() { - @Override - public boolean onQueryTextSubmit(String s) { - sv.clearFocus(); - MainActivity activity = (MainActivity)getActivity(); - if (activity != null) { - activity.loadChildFragment(SearchListFragment.newInstance(s)); - } - return true; - } - - @Override - public boolean onQueryTextChange(String s) { - return false; - } - }); - } - private void onPodcastSelected(GpodnetPodcast selection) { Log.d(TAG, "Selected podcast: " + selection.toString()); Intent intent = new Intent(getActivity(), OnlineFeedViewActivity.class); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/SearchListFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/SearchListFragment.java deleted file mode 100644 index 72a752bf1..000000000 --- a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/SearchListFragment.java +++ /dev/null @@ -1,80 +0,0 @@ -package de.danoeh.antennapod.fragment.gpodnet; - -import android.os.Bundle; -import androidx.core.view.MenuItemCompat; -import androidx.appcompat.widget.SearchView; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; - -import de.danoeh.antennapod.core.sync.gpoddernet.GpodnetService; -import de.danoeh.antennapod.core.sync.gpoddernet.GpodnetServiceException; -import de.danoeh.antennapod.core.sync.gpoddernet.model.GpodnetPodcast; -import org.apache.commons.lang3.Validate; - -import de.danoeh.antennapod.R; - -import java.util.List; - -/** - * Performs a search on the gpodder.net directory and displays the results. - */ -public class SearchListFragment extends PodcastListFragment { - private static final String ARG_QUERY = "query"; - - private String query; - - public static SearchListFragment newInstance(String query) { - SearchListFragment fragment = new SearchListFragment(); - Bundle args = new Bundle(); - args.putString(ARG_QUERY, query); - fragment.setArguments(args); - return fragment; - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - if (getArguments() != null && getArguments().containsKey(ARG_QUERY)) { - this.query = getArguments().getString(ARG_QUERY); - } else { - this.query = ""; - } - } - - @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - super.onCreateOptionsMenu(menu, inflater); - // parent already inflated menu - MenuItem searchItem = menu.findItem(R.id.action_search); - final SearchView sv = (SearchView) searchItem.getActionView(); - sv.setQueryHint(getString(R.string.gpodnet_search_hint)); - sv.setQuery(query, false); - sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() { - @Override - public boolean onQueryTextSubmit(String s) { - sv.clearFocus(); - changeQuery(s); - return true; - } - - @Override - public boolean onQueryTextChange(String s) { - return false; - } - }); - } - - @Override - protected List loadPodcastData(GpodnetService service) throws GpodnetServiceException { - return service.searchPodcasts(query, 0); - } - - private void changeQuery(String query) { - Validate.notNull(query); - - this.query = query; - loadData(); - } -} diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/TagListFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/TagListFragment.java index 53a31b68d..2c41ee070 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/TagListFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/TagListFragment.java @@ -1,19 +1,11 @@ package de.danoeh.antennapod.fragment.gpodnet; -import android.app.Activity; import android.content.Context; import android.os.AsyncTask; import android.os.Bundle; -import androidx.fragment.app.ListFragment; -import androidx.core.view.MenuItemCompat; -import androidx.appcompat.widget.SearchView; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; import android.view.View; import android.widget.TextView; - -import de.danoeh.antennapod.R; +import androidx.fragment.app.ListFragment; import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.adapter.gpodnet.TagListAdapter; import de.danoeh.antennapod.core.preferences.GpodnetPreferences; @@ -27,37 +19,6 @@ import java.util.List; public class TagListFragment extends ListFragment { private static final int COUNT = 50; - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setHasOptionsMenu(true); - } - - @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - super.onCreateOptionsMenu(menu, inflater); - inflater.inflate(R.menu.gpodder_podcasts, menu); - MenuItem searchItem = menu.findItem(R.id.action_search); - final SearchView sv = (SearchView) searchItem.getActionView(); - sv.setQueryHint(getString(R.string.gpodnet_search_hint)); - sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() { - @Override - public boolean onQueryTextSubmit(String s) { - Activity activity = getActivity(); - if (activity != null) { - sv.clearFocus(); - ((MainActivity) activity).loadChildFragment(SearchListFragment.newInstance(s)); - } - return true; - } - - @Override - public boolean onQueryTextChange(String s) { - return false; - } - }); - } - @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); diff --git a/app/src/main/res/layout/gpodnet_podcast_list.xml b/app/src/main/res/layout/gpodnet_podcast_list.xml index ae0a400f1..a6918f8d4 100644 --- a/app/src/main/res/layout/gpodnet_podcast_list.xml +++ b/app/src/main/res/layout/gpodnet_podcast_list.xml @@ -2,18 +2,9 @@ - - - - - - - -