Merge pull request #4677 from ByteHamster/gpodder-toolbar

Re-added toolbar to gpodder main fragment
This commit is contained in:
ByteHamster 2020-11-11 21:56:38 +01:00 committed by GitHub
commit 283dcfcc46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 188 deletions

View File

@ -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();
}
}

View File

@ -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);

View File

@ -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<GpodnetPodcast> loadPodcastData(GpodnetService service) throws GpodnetServiceException {
return service.searchPodcasts(query, 0);
}
private void changeQuery(String query) {
Validate.notNull(query);
this.query = query;
loadData();
}
}

View File

@ -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);

View File

@ -2,18 +2,9 @@
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:navigationIcon="?homeAsUpIndicator"
android:id="@+id/toolbar"/>
<GridView
android:id="@+id/gridView"
android:layout_width="match_parent"
@ -27,7 +18,7 @@
android:paddingTop="@dimen/list_vertical_padding"
android:stretchMode="columnWidth"
android:verticalSpacing="8dp"
android:layout_below="@id/toolbar"
android:layout_alignParentTop="true"
tools:listitem="@layout/gpodnet_podcast_listitem" />
<ProgressBar

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_search"
android:icon="?attr/action_search"
custom:showAsAction="collapseActionView|ifRoom"
custom:actionViewClass="androidx.appcompat.widget.SearchView"
android:title="@string/search_label"/>
</menu>