diff options
author | Tom Hennen <tom.hennen@gmail.com> | 2015-09-05 17:41:37 -0400 |
---|---|---|
committer | Tom Hennen <tom.hennen@gmail.com> | 2015-09-07 21:25:18 -0400 |
commit | c63423c55829100d4579f6b251d2bb3aeee9221d (patch) | |
tree | c3019b662d789f4a72fb3bb974c53cc3494f3211 | |
parent | 9fe8750ecba38e2c2033d8ef964775a40ecee921 (diff) | |
download | AntennaPod-c63423c55829100d4579f6b251d2bb3aeee9221d.zip |
Collapsed All and New Episodes in to 'Episodes' using tabs
This is to make room for 'Favorites' in the future.
I kept the counter for 'New Episodes' and am displaying it next to 'Episodes'.
7 files changed, 43 insertions, 25 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java index 7f6cc1bda..ec73e3c47 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -45,12 +45,10 @@ import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.util.StorageUtils; import de.danoeh.antennapod.fragment.AddFeedFragment; -import de.danoeh.antennapod.fragment.AllEpisodesFragment; import de.danoeh.antennapod.fragment.DownloadsFragment; import de.danoeh.antennapod.fragment.EpisodesFragment; import de.danoeh.antennapod.fragment.ExternalPlayerFragment; import de.danoeh.antennapod.fragment.ItemlistFragment; -import de.danoeh.antennapod.fragment.NewEpisodesFragment; import de.danoeh.antennapod.fragment.PlaybackHistoryFragment; import de.danoeh.antennapod.fragment.QueueFragment; import de.danoeh.antennapod.menuhandler.NavDrawerActivity; @@ -84,8 +82,6 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity public static final String[] NAV_DRAWER_TAGS = { QueueFragment.TAG, EpisodesFragment.TAG, - NewEpisodesFragment.TAG, - AllEpisodesFragment.TAG, DownloadsFragment.TAG, PlaybackHistoryFragment.TAG, AddFeedFragment.TAG @@ -286,12 +282,6 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity case EpisodesFragment.TAG: fragment = new EpisodesFragment(); break; - case NewEpisodesFragment.TAG: - fragment = new NewEpisodesFragment(); - break; - case AllEpisodesFragment.TAG: - fragment = new AllEpisodesFragment(); - break; case DownloadsFragment.TAG: fragment = new DownloadsFragment(); break; @@ -301,6 +291,10 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity case AddFeedFragment.TAG: fragment = new AddFeedFragment(); break; + default: + // default to the queue + fragment = new QueueFragment(); + break; } currentTitle = navAdapter.getLabel(tag); getSupportActionBar().setTitle(currentTitle); @@ -543,7 +537,7 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity protected void onPostExecute(Void result) { super.onPostExecute(result); if(getSelectedNavListIndex() == position) { - loadFragment(NewEpisodesFragment.TAG, null); + loadFragment(EpisodesFragment.TAG, null); } } }; diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/EpisodesPagerAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/EpisodesPagerAdapter.java index 8114bc123..736b91e22 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/EpisodesPagerAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/EpisodesPagerAdapter.java @@ -14,7 +14,8 @@ public class EpisodesPagerAdapter extends FragmentPagerAdapter { private final Context context; - private String tabTags[] = new String[] {AllEpisodesFragment.TAG, NewEpisodesFragment.TAG}; + // this determines the order the tabs appear in + private String tabTags[] = new String[] {NewEpisodesFragment.TAG, AllEpisodesFragment.TAG}; private String tabTitles[] = new String[tabTags.length]; public EpisodesPagerAdapter(FragmentManager fm, Context context) { diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java index e3eb5d571..183c1a44e 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java @@ -216,7 +216,7 @@ public class NavListAdapter extends BaseAdapter } else { holder.count.setVisibility(View.GONE); } - } else if (tags.get(position).equals(NewEpisodesFragment.TAG)) { + } else if (tags.get(position).equals(EpisodesFragment.TAG)) { int unreadItems = itemAccess.getNumberOfNewItems(); if (unreadItems > 0) { holder.count.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java index 55b1c4cb1..27c20ff6f 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java @@ -270,16 +270,14 @@ public class AllEpisodesFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return onCreateViewHelper(inflater, container, savedInstanceState, - R.layout.all_episodes_fragment, R.string.all_episodes_label); + R.layout.all_episodes_fragment); } protected View onCreateViewHelper(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState, - int fragmentResource, - int titleString) { + int fragmentResource) { super.onCreateView(inflater, container, savedInstanceState); - ((MainActivity) getActivity()).getSupportActionBar().setTitle(titleString); View root = inflater.inflate(fragmentResource, container, false); 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 a9ccd4cc1..bab1c53c3 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,25 @@ package de.danoeh.antennapod.fragment; +import android.content.Context; +import android.content.SharedPreferences; 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.activity.MainActivity; import de.danoeh.antennapod.adapter.EpisodesPagerAdapter; public class EpisodesFragment extends Fragment { public static final String TAG = "EpisodesFragment"; + private static final String PREF_LAST_TAB_POSITION = "tab_position"; + private TabLayout tabLayout; + private ViewPager viewPager; //Mandatory Constructor public EpisodesFragment() { @@ -27,16 +32,38 @@ public class EpisodesFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + super.onCreateView(inflater, container, savedInstanceState); + ((MainActivity) getActivity()).getSupportActionBar().setTitle(R.string.episodes_label); View rootView = inflater.inflate(R.layout.episodes_fragment, container, false); - ViewPager pager = (ViewPager)rootView.findViewById(R.id.viewpager); - pager.setAdapter(new EpisodesPagerAdapter(getChildFragmentManager(), getActivity())); + viewPager = (ViewPager)rootView.findViewById(R.id.viewpager); + viewPager.setAdapter(new EpisodesPagerAdapter(getChildFragmentManager(), getActivity())); // Give the TabLayout the ViewPager - TabLayout tabLayout = (TabLayout) rootView.findViewById(R.id.sliding_tabs); - tabLayout.setupWithViewPager(pager); + tabLayout = (TabLayout) rootView.findViewById(R.id.sliding_tabs); + tabLayout.setupWithViewPager(viewPager); return rootView; } + @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); + } + } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/NewEpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/NewEpisodesFragment.java index b0ccbfbea..6c2271d79 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/NewEpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/NewEpisodesFragment.java @@ -63,7 +63,7 @@ public class NewEpisodesFragment extends AllEpisodesFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View root = super.onCreateViewHelper(inflater, container, savedInstanceState, - R.layout.new_episodes_fragment, R.string.new_episodes_label); + R.layout.new_episodes_fragment); listView.setRemoveListener(new DragSortListView.RemoveListener() { @Override diff --git a/core/src/main/res/values/arrays.xml b/core/src/main/res/values/arrays.xml index b621ae7f8..20eb79f84 100644 --- a/core/src/main/res/values/arrays.xml +++ b/core/src/main/res/values/arrays.xml @@ -121,8 +121,6 @@ <string-array name="nav_drawer_titles"> <item>@string/queue_label</item> <item>@string/episodes_label</item> - <item>@string/new_episodes_label</item> - <item>@string/all_episodes_label</item> <item>@string/downloads_label</item> <item>@string/playback_history_label</item> <item>@string/add_feed_label</item> |