diff options
author | Martin Fietz <Martin.Fietz@gmail.com> | 2015-07-10 13:18:04 +0200 |
---|---|---|
committer | Martin Fietz <Martin.Fietz@gmail.com> | 2015-07-11 19:33:57 +0200 |
commit | b8b36b4ee8aee817b3d9b79fa0bfe314dd581081 (patch) | |
tree | cf84154110e6eba4721e0d50b9f2fa32b96f65a7 /app | |
parent | 8516ca126780d088ed3b1e4f3c241b16f18e77ad (diff) | |
download | AntennaPod-b8b36b4ee8aee817b3d9b79fa0bfe314dd581081.zip |
Load fragment used in last session correctly.
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java | 47 | ||||
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/fragment/SearchFragment.java | 2 |
2 files changed, 16 insertions, 33 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 acb56dcb4..c4fc54d73 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -100,7 +100,6 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity private ActionBarDrawerToggle drawerToggle; private CharSequence currentTitle; - private String currentFragment; private ProgressDialog pd; @@ -171,9 +170,9 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity String lastFragment = getLastNavFragment(); if(ArrayUtils.contains(NAV_DRAWER_TAGS, lastFragment)) { loadFragment(lastFragment, null); + } else { + loadFeedFragmentById(Integer.valueOf(lastFragment), null); } - // else: lastFragment contains feed id - drawer data is not loaded yet, - // so loading is postponed until then } externalPlayerFragment = new ExternalPlayerFragment(); transaction.replace(R.id.playerFragment, externalPlayerFragment); @@ -191,7 +190,6 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity } else { edit.remove(PREF_LAST_FRAGMENT_TAG); } - currentFragment = tag; edit.commit(); } @@ -312,32 +310,20 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity return; } Feed feed = itemAccess.getItem(relPos); - long feedId = feed.getId(); + loadFeedFragmentById(feed.getId(), args); + } + + public void loadFeedFragmentById(long feedId, Bundle args) { Fragment fragment = ItemlistFragment.newInstance(feedId); if(args != null) { fragment.setArguments(args); } - saveLastNavFragment(String.valueOf(feed.getId())); + saveLastNavFragment(String.valueOf(feedId)); currentTitle = ""; getSupportActionBar().setTitle(currentTitle); loadFragment(fragment); } - public void loadFeedFragmentById(long feedId) { - if (navDrawerData != null) { - int relPos = -1; - List<Feed> feeds = navDrawerData.feeds; - for (int i = 0; relPos < 0 && i < feeds.size(); i++) { - if (feeds.get(i).getId() == feedId) { - relPos = i; - } - } - if(relPos >= 0) { - loadFeedFragmentByPosition(relPos, null); - } - } - } - private void loadFragment(Fragment fragment) { FragmentManager fragmentManager = getSupportFragmentManager(); // clear back stack @@ -377,15 +363,19 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity } private int getSelectedNavListIndex() { - String lastFragment = getLastNavFragment(); - int tagIndex = navAdapter.getTags().indexOf(lastFragment); + String currentFragment = getLastNavFragment(); + if(currentFragment == null) { + // should not happen, but better safe than sorry + return -1; + } + int tagIndex = navAdapter.getTags().indexOf(currentFragment); if(tagIndex >= 0) { return tagIndex; - } else if(ArrayUtils.contains(NAV_DRAWER_TAGS, lastFragment)) { + } else if(ArrayUtils.contains(NAV_DRAWER_TAGS, currentFragment)) { // the fragment was just hidden return -1; } else { // last fragment was not a list, but a feed - long feedId = Long.parseLong(lastFragment); + long feedId = Long.parseLong(currentFragment); if (navDrawerData != null) { List<Feed> feeds = navDrawerData.feeds; for (int i = 0; i < feeds.size(); i++) { @@ -618,13 +608,6 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity navDrawerData = result; navAdapter.notifyDataSetChanged(); - String lastFragment = getLastNavFragment(); - if(currentFragment != lastFragment && - !ArrayUtils.contains(NAV_DRAWER_TAGS, lastFragment)) { - long feedId = Long.valueOf(lastFragment); - loadFeedFragmentById(feedId); - } - if (handleIntent) { handleNavIntent(); } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/SearchFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/SearchFragment.java index fc6225409..975493ce9 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/SearchFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/SearchFragment.java @@ -120,7 +120,7 @@ public class SearchFragment extends ListFragment { SearchResult result = (SearchResult) l.getAdapter().getItem(position); FeedComponent comp = result.getComponent(); if (comp.getClass() == Feed.class) { - ((MainActivity) getActivity()).loadFeedFragmentById(comp.getId()); + ((MainActivity) getActivity()).loadFeedFragmentById(comp.getId(), null); } else { if (comp.getClass() == FeedItem.class) { FeedItem item = (FeedItem) comp; |