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

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

@ -84,7 +84,7 @@ public class RssfeedsActivity extends AppCompatActivity { @@ -84,7 +84,7 @@ public class RssfeedsActivity extends AppCompatActivity {
protected ApplicationSettings applicationSettings;
// Contained feeds and items fragments
protected RssfeedsFragment fragmentFeeds;
protected RssfeedsFragment fragmentLocalFeeds;
protected RemoteRssFragment fragmentRemoteFeeds;
@FragmentById(R.id.rssitems_fragment)
@ -120,10 +120,10 @@ public class RssfeedsActivity extends AppCompatActivity { @@ -120,10 +120,10 @@ public class RssfeedsActivity extends AppCompatActivity {
Fragment fragment = null;
if (position == RSS_FEEDS_LOCAL) {
fragment = fragmentFeeds;
fragment = RssfeedsFragment_.builder().build();
}
else if (position == RSS_FEEDS_REMOTE) {
fragment = fragmentRemoteFeeds;
fragment = RemoteRssFragment_.builder().build();
}
return fragment;
@ -163,15 +163,30 @@ public class RssfeedsActivity extends AppCompatActivity { @@ -163,15 +163,30 @@ public class RssfeedsActivity extends AppCompatActivity {
getSupportActionBar().setTitle(NavigationHelper.buildCondensedFontString(getString(R.string.rss_feeds)));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
fragmentFeeds = RssfeedsFragment_.builder().build();
fragmentRemoteFeeds = RemoteRssFragment_.builder().build();
PagerAdapter pagerAdapter = new PagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(pagerAdapter);
tabLayout.setupWithViewPager(viewPager);
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)
@OptionsItem(android.R.id.home)
protected void navigateUp() {
@ -190,7 +205,10 @@ public class RssfeedsActivity extends AppCompatActivity { @@ -190,7 +205,10 @@ public class RssfeedsActivity extends AppCompatActivity {
loaders.add(loader);
loadRssfeed(loader);
}
fragmentFeeds.update(loaders);
if (fragmentLocalFeeds != null) {
fragmentLocalFeeds.update(loaders);
}
}
/**
@ -221,7 +239,10 @@ public class RssfeedsActivity extends AppCompatActivity { @@ -221,7 +239,10 @@ public class RssfeedsActivity extends AppCompatActivity {
@UiThread
protected void handleRssfeedResult(RssfeedLoader loader, Channel channel, boolean hasError) {
loader.update(channel, hasError);
fragmentFeeds.notifyDataSetChanged();
if (fragmentLocalFeeds != null) {
fragmentLocalFeeds.notifyDataSetChanged();
}
}
/**
@ -324,9 +345,11 @@ public class RssfeedsActivity extends AppCompatActivity { @@ -324,9 +345,11 @@ public class RssfeedsActivity extends AppCompatActivity {
return;
}
if (fragmentRemoteFeeds != null) {
fragmentRemoteFeeds.updateRemoteItems(
selectedFilter == 0 ? recentItems : feeds.get(selectedFilter -1).getItems(),
false /* allow android to restore scroll position */ );
}
showRemoteChannelFilters();
}
@ -398,6 +421,8 @@ public class RssfeedsActivity extends AppCompatActivity { @@ -398,6 +421,8 @@ public class RssfeedsActivity extends AppCompatActivity {
});
feedLabels.addAll(feeds);
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 { @@ -77,20 +77,32 @@ public class RssfeedsFragment extends Fragment {
MainSettingsActivity_.intent(getActivity()).start();
}
protected RssfeedsActivity getRssActivity() {
return (RssfeedsActivity) getActivity();
}
@Override
public void onResume() {
super.onResume();
getRssActivity().onFragmentReady(this);
this.refreshScreen();
}
@Override
public void onDestroy() {
super.onDestroy();
getRssActivity().onFragmentDestroy(this);
}
@OptionsItem(R.id.action_refresh)
protected void refreshScreen() {
((RssfeedsActivity) getActivity()).refreshFeeds();
getRssActivity().refreshFeeds();
}
@ItemClick(R.id.rssfeeds_list)
protected void onFeedClicked(RssfeedLoader loader) {
((RssfeedsActivity) getActivity()).openRssfeed(loader, true);
getRssActivity().openRssfeed(loader, true);
}
/**

Loading…
Cancel
Save