diff options
Diffstat (limited to 'app')
2 files changed, 22 insertions, 9 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java index b13a49a7..3e395af8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java @@ -187,7 +187,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS } }); - checkNewAccountAndBindView(); + checkNewAccountAndBindView(savedInstanceState); } public void setTitle(String title) { @@ -225,7 +225,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS applyFABTheme(fab); } - private void checkNewAccountAndBindView() { + private void checkNewAccountAndBindView(Bundle savedInstanceState) { if (mNewAccountName != null) { if (mAccountName == null || !mAccountName.equals(mNewAccountName)) { SwitchAccount.switchAccount(mRedditDataRoomDatabase, mCurrentAccountSharedPreferences, @@ -235,19 +235,22 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS mNewAccountName = null; - bindView(); + bindView(savedInstanceState); }); } else { - bindView(); + bindView(savedInstanceState); } } else { - bindView(); + bindView(savedInstanceState); } } - private void bindView() { + private void bindView(Bundle savedInstanceState) { sectionsPagerAdapter = new SectionsPagerAdapter(this); viewPager2.setAdapter(sectionsPagerAdapter); + if (savedInstanceState == null) { + viewPager2.setCurrentItem(getIntent().getIntExtra(EXTRA_POST_LIST_POSITION, 0), false); + } } private void editComment(String commentAuthor, String commentContentMarkdown, int position) { @@ -411,10 +414,14 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS public Fragment createFragment(int position) { ViewPostDetailFragment fragment = new ViewPostDetailFragment(); Bundle bundle = new Bundle(); - if (posts == null) { - bundle.putParcelable(ViewPostDetailFragment.EXTRA_POST_DATA, post); - } else { + if (posts != null) { bundle.putParcelable(ViewPostDetailFragment.EXTRA_POST_DATA, posts.get(position)); + } else { + if (post == null) { + bundle.putString(ViewPostDetailFragment.EXTRA_POST_ID, getIntent().getStringExtra(EXTRA_POST_ID)); + } else { + bundle.putParcelable(ViewPostDetailFragment.EXTRA_POST_DATA, post); + } } fragment.setArguments(bundle); return fragment; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java index 5e41fdec..18b95b8b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java @@ -1006,6 +1006,12 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic Bridge.clear(this); } + @Override + public void onDestroy() { + EventBus.getDefault().unregister(this); + super.onDestroy(); + } + @SuppressLint("RestrictedApi") protected boolean applyMenuItemTheme(Menu menu) { if (mCustomThemeWrapper != null) { |