diff options
author | Tom Hennen <tom.hennen@gmail.com> | 2015-09-05 17:17:05 -0400 |
---|---|---|
committer | Tom Hennen <tom.hennen@gmail.com> | 2015-09-07 21:25:18 -0400 |
commit | 9fe8750ecba38e2c2033d8ef964775a40ecee921 (patch) | |
tree | fe526dbe47aa0ff30bd546f7bb774401955726fb /app/src/main | |
parent | 1d38db32d5cbb1a86276600bc06f660f9c521ec9 (diff) | |
download | AntennaPod-9fe8750ecba38e2c2033d8ef964775a40ecee921.zip |
changed method of tab use
Diffstat (limited to 'app/src/main')
3 files changed, 80 insertions, 40 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/EpisodesPagerAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/EpisodesPagerAdapter.java new file mode 100644 index 000000000..8114bc123 --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/adapter/EpisodesPagerAdapter.java @@ -0,0 +1,59 @@ +package de.danoeh.antennapod.adapter; + +import android.content.Context; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentPagerAdapter; + +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.activity.MainActivity; +import de.danoeh.antennapod.fragment.AllEpisodesFragment; +import de.danoeh.antennapod.fragment.NewEpisodesFragment; + +public class EpisodesPagerAdapter extends FragmentPagerAdapter { + + private final Context context; + + private String tabTags[] = new String[] {AllEpisodesFragment.TAG, NewEpisodesFragment.TAG}; + private String tabTitles[] = new String[tabTags.length]; + + public EpisodesPagerAdapter(FragmentManager fm, Context context) { + super(fm); + this.context = context; + tabTitles = new String[tabTags.length]; + for (int i = 0; i < tabTags.length; i++) { + String title = null; + switch (tabTags[i]) { + case AllEpisodesFragment.TAG: + title = context.getResources().getString(R.string.all_episodes_label); + break; + case NewEpisodesFragment.TAG: + title = context.getResources().getString(R.string.new_episodes_label); + break; + } + tabTitles[i] = title; + } + } + + @Override + public Fragment getItem(int position) { + String tag = tabTags[position]; + switch (tag) { + case AllEpisodesFragment.TAG: + return new AllEpisodesFragment(); + case NewEpisodesFragment.TAG: + return new NewEpisodesFragment(); + } + return null; + } + + @Override + public int getCount() { + return tabTags.length; + } + + @Override + public CharSequence getPageTitle(int position) { + return tabTitles[position]; + } +} diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesFragment.java index 698e1660b..a9ccd4cc1 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesFragment.java @@ -1,20 +1,21 @@ package de.danoeh.antennapod.fragment; import android.os.Bundle; +import android.support.design.widget.TabLayout; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTabHost; +import android.support.v4.view.ViewPager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import de.danoeh.antennapod.R; +import de.danoeh.antennapod.adapter.EpisodesPagerAdapter; public class EpisodesFragment extends Fragment { public static final String TAG = "EpisodesFragment"; - private FragmentTabHost mTabHost; - //Mandatory Constructor public EpisodesFragment() { } @@ -22,26 +23,18 @@ public class EpisodesFragment extends Fragment { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); - } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.episodes_fragment, container, false); + ViewPager pager = (ViewPager)rootView.findViewById(R.id.viewpager); + pager.setAdapter(new EpisodesPagerAdapter(getChildFragmentManager(), getActivity())); - - mTabHost = (FragmentTabHost) rootView.findViewById(android.R.id.tabhost); - mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent); - - - mTabHost.addTab(mTabHost.newTabSpec(NewEpisodesFragment.TAG).setIndicator( - getResources().getString(R.string.new_episodes_label)), - NewEpisodesFragment.class, null); - - mTabHost.addTab(mTabHost.newTabSpec(AllEpisodesFragment.TAG).setIndicator( - getResources().getString(R.string.all_episodes_label)), - AllEpisodesFragment.class, null); + // Give the TabLayout the ViewPager + TabLayout tabLayout = (TabLayout) rootView.findViewById(R.id.sliding_tabs); + tabLayout.setupWithViewPager(pager); return rootView; } diff --git a/app/src/main/res/layout/episodes_fragment.xml b/app/src/main/res/layout/episodes_fragment.xml index 70b288cdf..736a874b8 100644 --- a/app/src/main/res/layout/episodes_fragment.xml +++ b/app/src/main/res/layout/episodes_fragment.xml @@ -1,33 +1,21 @@ -<android.support.v4.app.FragmentTabHost +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:id="@android:id/tabhost" + xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="match_parent" + android:orientation="vertical"> - <LinearLayout - android:orientation="vertical" - android:layout_width="match_parent" - android:layout_height="match_parent"> - - <TabWidget - android:id="@android:id/tabs" - - android:orientation="horizontal" + <android.support.design.widget.TabLayout + android:id="@+id/sliding_tabs" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_weight="0"/> - - <FrameLayout - android:id="@android:id/tabcontent" - android:layout_width="0dp" - android:layout_height="0dp" - android:layout_weight="0"/> + app:tabMode="scrollable" /> - <FrameLayout - android:id="@+id/realtabcontent" + <android.support.v4.view.ViewPager + android:id="@+id/viewpager" android:layout_width="match_parent" - android:layout_height="0dp" - android:layout_weight="1"/> + android:layout_height="0px" + android:layout_weight="1" + android:background="@android:color/white" /> - </LinearLayout> -</android.support.v4.app.FragmentTabHost>
\ No newline at end of file +</LinearLayout>
\ No newline at end of file |