summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorTom Hennen <tom.hennen@gmail.com>2015-09-07 21:21:53 -0400
committerTom Hennen <tom.hennen@gmail.com>2015-09-07 21:25:19 -0400
commitb7ad88d70ff03880c4613608dc6a40d198133430 (patch)
tree2851a841bca182a77fdf1f1f9ef7573e572a0652 /app/src/main
parent6ae33e1c5d5b90aef86a7f4bc437acd74f008137 (diff)
downloadAntennaPod-b7ad88d70ff03880c4613608dc6a40d198133430.zip
tabs fill all space and are remembered
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/de/danoeh/antennapod/fragment/DownloadsFragment.java37
-rw-r--r--app/src/main/java/de/danoeh/antennapod/fragment/EpisodesFragment.java4
-rw-r--r--app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/GpodnetMainFragment.java37
-rw-r--r--app/src/main/res/layout/pager_fragment.xml3
4 files changed, 68 insertions, 13 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/DownloadsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/DownloadsFragment.java
index f56cb1ff6..52a38ccb9 100644
--- a/app/src/main/java/de/danoeh/antennapod/fragment/DownloadsFragment.java
+++ b/app/src/main/java/de/danoeh/antennapod/fragment/DownloadsFragment.java
@@ -1,5 +1,7 @@
package de.danoeh.antennapod.fragment;
+import android.content.Context;
+import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
@@ -26,20 +28,23 @@ public class DownloadsFragment extends Fragment {
public static final int POS_COMPLETED = 1;
public static final int POS_LOG = 2;
- private ViewPager pager;
+ private static final String PREF_LAST_TAB_POSITION = "tab_position";
+
+ private ViewPager viewPager;
+ private TabLayout tabLayout;
@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);
- pager = (ViewPager)root.findViewById(R.id.viewpager);
+ viewPager = (ViewPager)root.findViewById(R.id.viewpager);
DownloadsPagerAdapter pagerAdapter = new DownloadsPagerAdapter(getChildFragmentManager(), getResources());
- pager.setAdapter(pagerAdapter);
+ viewPager.setAdapter(pagerAdapter);
// Give the TabLayout the ViewPager
- TabLayout tabLayout = (TabLayout) root.findViewById(R.id.sliding_tabs);
- tabLayout.setupWithViewPager(pager);
+ tabLayout = (TabLayout) root.findViewById(R.id.sliding_tabs);
+ tabLayout.setupWithViewPager(viewPager);
return root;
}
@@ -49,10 +54,30 @@ public class DownloadsFragment extends Fragment {
super.onViewCreated(view, savedInstanceState);
if (getArguments() != null) {
int tab = getArguments().getInt(ARG_SELECTED_TAB);
- pager.setCurrentItem(tab, false);
+ viewPager.setCurrentItem(tab, false);
}
}
+ @Override
+ public void onPause() {
+ super.onPause();
+ // save our tab selection
+ SharedPreferences prefs = getActivity().getSharedPreferences(TAG, Context.MODE_PRIVATE);
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putInt(PREF_LAST_TAB_POSITION, tabLayout.getSelectedTabPosition());
+ editor.apply();
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
+
+ // restore our last position
+ SharedPreferences prefs = getActivity().getSharedPreferences(TAG, Context.MODE_PRIVATE);
+ int lastPosition = prefs.getInt(PREF_LAST_TAB_POSITION, 0);
+ viewPager.setCurrentItem(lastPosition);
+ }
+
public class DownloadsPagerAdapter extends FragmentPagerAdapter {
Resources resources;
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 15a78d7e5..231c161a2 100644
--- a/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesFragment.java
+++ b/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesFragment.java
@@ -104,9 +104,9 @@ public class EpisodesFragment extends Fragment {
public CharSequence getPageTitle(int position) {
switch (position) {
case POS_ALL_EPISODES:
- return resources.getString(R.string.all_episodes_label);
+ return resources.getString(R.string.all_episodes_short_label);
case POS_NEW_EPISODES:
- return resources.getString(R.string.new_episodes_label);
+ return resources.getString(R.string.new_episodes_short_label);
default:
return super.getPageTitle(position);
}
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 34383eff1..aff5069c6 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,5 +1,7 @@
package de.danoeh.antennapod.fragment.gpodnet;
+import android.content.Context;
+import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
@@ -18,22 +20,49 @@ import de.danoeh.antennapod.R;
*/
public class GpodnetMainFragment extends Fragment {
+ public static final String TAG = "GpodnetMainFragment";
+
+ private static final String PREF_LAST_TAB_POSITION = "tab_position";
+ private TabLayout tabLayout;
+ private ViewPager viewPager;
+
@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);
- ViewPager pager = (ViewPager)root.findViewById(R.id.viewpager);
+ viewPager = (ViewPager)root.findViewById(R.id.viewpager);
GpodnetPagerAdapter pagerAdapter = new GpodnetPagerAdapter(getChildFragmentManager(), getResources());
- pager.setAdapter(pagerAdapter);
+ viewPager.setAdapter(pagerAdapter);
// Give the TabLayout the ViewPager
- TabLayout tabLayout = (TabLayout) root.findViewById(R.id.sliding_tabs);
- tabLayout.setupWithViewPager(pager);
+ tabLayout = (TabLayout) root.findViewById(R.id.sliding_tabs);
+ tabLayout.setupWithViewPager(viewPager);
return root;
}
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ // save our tab selection
+ SharedPreferences prefs = getActivity().getSharedPreferences(TAG, Context.MODE_PRIVATE);
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putInt(PREF_LAST_TAB_POSITION, tabLayout.getSelectedTabPosition());
+ editor.apply();
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
+
+ // restore our last position
+ SharedPreferences prefs = getActivity().getSharedPreferences(TAG, Context.MODE_PRIVATE);
+ int lastPosition = prefs.getInt(PREF_LAST_TAB_POSITION, 0);
+ viewPager.setCurrentItem(lastPosition);
+ }
+
public class GpodnetPagerAdapter extends FragmentPagerAdapter {
diff --git a/app/src/main/res/layout/pager_fragment.xml b/app/src/main/res/layout/pager_fragment.xml
index cb866e86a..54b711b1c 100644
--- a/app/src/main/res/layout/pager_fragment.xml
+++ b/app/src/main/res/layout/pager_fragment.xml
@@ -11,7 +11,8 @@
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- app:tabMode="scrollable" />
+ app:tabGravity="fill"
+ app:tabMode="fixed" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"