package de.danoeh.antennapod.fragment.gpodnet; import android.content.res.Resources; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentPagerAdapter; import androidx.viewpager.widget.ViewPager; import com.google.android.material.tabs.TabLayout; import de.danoeh.antennapod.R; /** * Main navigation hub for gpodder.net podcast directory */ public class GpodnetMainFragment extends Fragment { @Override 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); ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar); ViewPager viewPager = root.findViewById(R.id.viewpager); GpodnetPagerAdapter pagerAdapter = new GpodnetPagerAdapter(getChildFragmentManager(), getResources()); viewPager.setAdapter(pagerAdapter); // Give the TabLayout the ViewPager TabLayout tabLayout = root.findViewById(R.id.sliding_tabs); tabLayout.setupWithViewPager(viewPager); return root; } public class GpodnetPagerAdapter extends FragmentPagerAdapter { private static final int NUM_PAGES = 2; private static final int POS_TOPLIST = 0; private static final int POS_TAGS = 1; private static final int POS_SUGGESTIONS = 2; final Resources resources; public GpodnetPagerAdapter(FragmentManager fm, Resources resources) { super(fm); this.resources = resources; } @Override public Fragment getItem(int i) { Bundle arguments = new Bundle(); arguments.putBoolean(PodcastListFragment.ARGUMENT_HIDE_TOOLBAR, true); switch (i) { case POS_TAGS: return new TagListFragment(); case POS_TOPLIST: PodcastListFragment topListFragment = new PodcastTopListFragment(); topListFragment.setArguments(arguments); return topListFragment; case POS_SUGGESTIONS: PodcastListFragment suggestionsFragment = new SuggestionListFragment(); suggestionsFragment.setArguments(arguments); return suggestionsFragment; default: return null; } } @Override public CharSequence getPageTitle(int position) { switch (position) { case POS_TAGS: return getString(R.string.gpodnet_taglist_header); case POS_TOPLIST: return getString(R.string.gpodnet_toplist_header); case POS_SUGGESTIONS: return getString(R.string.gpodnet_suggestions_header); default: return super.getPageTitle(position); } } @Override public int getCount() { return NUM_PAGES; } } }