Browse Source

- fix crashes on activity recreation because android is just awful

pull/526/head
Twig N 5 years ago
parent
commit
10c1bf76b6
  1. 15
      app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java
  2. 45
      app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java
  3. 16
      app/src/main/java/org/transdroid/core/gui/rss/RssfeedsFragment.java

15
app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java

@ -75,10 +75,23 @@ public class RemoteRssFragment extends Fragment {
torrentsList.setFastScrollEnabled(true); torrentsList.setFastScrollEnabled(true);
} }
protected RssfeedsActivity getRssActivity() {
return (RssfeedsActivity) getActivity();
}
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
((RssfeedsActivity) getActivity()).refreshRemoteFeeds();
getRssActivity().onFragmentReady(this);
getRssActivity().refreshRemoteFeeds();
}
@Override
public void onDestroy() {
super.onDestroy();
getRssActivity().onFragmentDestroy(this);
} }
/** /**

45
app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java

@ -84,7 +84,7 @@ public class RssfeedsActivity extends AppCompatActivity {
protected ApplicationSettings applicationSettings; protected ApplicationSettings applicationSettings;
// Contained feeds and items fragments // Contained feeds and items fragments
protected RssfeedsFragment fragmentFeeds; protected RssfeedsFragment fragmentLocalFeeds;
protected RemoteRssFragment fragmentRemoteFeeds; protected RemoteRssFragment fragmentRemoteFeeds;
@FragmentById(R.id.rssitems_fragment) @FragmentById(R.id.rssitems_fragment)
@ -120,10 +120,10 @@ public class RssfeedsActivity extends AppCompatActivity {
Fragment fragment = null; Fragment fragment = null;
if (position == RSS_FEEDS_LOCAL) { if (position == RSS_FEEDS_LOCAL) {
fragment = fragmentFeeds; fragment = RssfeedsFragment_.builder().build();
} }
else if (position == RSS_FEEDS_REMOTE) { else if (position == RSS_FEEDS_REMOTE) {
fragment = fragmentRemoteFeeds; fragment = RemoteRssFragment_.builder().build();
} }
return fragment; return fragment;
@ -163,15 +163,30 @@ public class RssfeedsActivity extends AppCompatActivity {
getSupportActionBar().setTitle(NavigationHelper.buildCondensedFontString(getString(R.string.rss_feeds))); getSupportActionBar().setTitle(NavigationHelper.buildCondensedFontString(getString(R.string.rss_feeds)));
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
fragmentFeeds = RssfeedsFragment_.builder().build();
fragmentRemoteFeeds = RemoteRssFragment_.builder().build();
PagerAdapter pagerAdapter = new PagerAdapter(getSupportFragmentManager()); PagerAdapter pagerAdapter = new PagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(pagerAdapter); viewPager.setAdapter(pagerAdapter);
tabLayout.setupWithViewPager(viewPager); tabLayout.setupWithViewPager(viewPager);
viewPager.setCurrentItem(0); viewPager.setCurrentItem(0);
} }
public void onFragmentReady(Fragment fragment) {
if (fragment instanceof RssfeedsFragment) {
fragmentLocalFeeds = (RssfeedsFragment) fragment;
}
else if (fragment instanceof RemoteRssFragment) {
fragmentRemoteFeeds = (RemoteRssFragment) fragment;
}
}
public void onFragmentDestroy(Fragment fragment) {
if (fragment instanceof RssfeedsFragment) {
fragmentLocalFeeds = null;
}
else if (fragment instanceof RemoteRssFragment) {
fragmentRemoteFeeds = null;
}
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @TargetApi(Build.VERSION_CODES.HONEYCOMB)
@OptionsItem(android.R.id.home) @OptionsItem(android.R.id.home)
protected void navigateUp() { protected void navigateUp() {
@ -190,7 +205,10 @@ public class RssfeedsActivity extends AppCompatActivity {
loaders.add(loader); loaders.add(loader);
loadRssfeed(loader); loadRssfeed(loader);
} }
fragmentFeeds.update(loaders);
if (fragmentLocalFeeds != null) {
fragmentLocalFeeds.update(loaders);
}
} }
/** /**
@ -221,7 +239,10 @@ public class RssfeedsActivity extends AppCompatActivity {
@UiThread @UiThread
protected void handleRssfeedResult(RssfeedLoader loader, Channel channel, boolean hasError) { protected void handleRssfeedResult(RssfeedLoader loader, Channel channel, boolean hasError) {
loader.update(channel, hasError); loader.update(channel, hasError);
fragmentFeeds.notifyDataSetChanged();
if (fragmentLocalFeeds != null) {
fragmentLocalFeeds.notifyDataSetChanged();
}
} }
/** /**
@ -324,9 +345,11 @@ public class RssfeedsActivity extends AppCompatActivity {
return; return;
} }
fragmentRemoteFeeds.updateRemoteItems( if (fragmentRemoteFeeds != null) {
fragmentRemoteFeeds.updateRemoteItems(
selectedFilter == 0 ? recentItems : feeds.get(selectedFilter -1).getItems(), selectedFilter == 0 ? recentItems : feeds.get(selectedFilter -1).getItems(),
false /* allow android to restore scroll position */ ); false /* allow android to restore scroll position */ );
}
showRemoteChannelFilters(); showRemoteChannelFilters();
} }
@ -398,6 +421,8 @@ public class RssfeedsActivity extends AppCompatActivity {
}); });
feedLabels.addAll(feeds); feedLabels.addAll(feeds);
fragmentRemoteFeeds.updateChannelFilters(feedLabels); if (fragmentRemoteFeeds != null) {
fragmentRemoteFeeds.updateChannelFilters(feedLabels);
}
} }
} }

16
app/src/main/java/org/transdroid/core/gui/rss/RssfeedsFragment.java

@ -77,20 +77,32 @@ public class RssfeedsFragment extends Fragment {
MainSettingsActivity_.intent(getActivity()).start(); MainSettingsActivity_.intent(getActivity()).start();
} }
protected RssfeedsActivity getRssActivity() {
return (RssfeedsActivity) getActivity();
}
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
getRssActivity().onFragmentReady(this);
this.refreshScreen(); this.refreshScreen();
} }
@Override
public void onDestroy() {
super.onDestroy();
getRssActivity().onFragmentDestroy(this);
}
@OptionsItem(R.id.action_refresh) @OptionsItem(R.id.action_refresh)
protected void refreshScreen() { protected void refreshScreen() {
((RssfeedsActivity) getActivity()).refreshFeeds(); getRssActivity().refreshFeeds();
} }
@ItemClick(R.id.rssfeeds_list) @ItemClick(R.id.rssfeeds_list)
protected void onFeedClicked(RssfeedLoader loader) { protected void onFeedClicked(RssfeedLoader loader) {
((RssfeedsActivity) getActivity()).openRssfeed(loader, true); getRssActivity().openRssfeed(loader, true);
} }
/** /**

Loading…
Cancel
Save