diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-01-27 14:43:44 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-01-27 14:43:44 +0000 |
commit | c0cb024eb99be74c36ea422df5731b09a0d5d570 (patch) | |
tree | 3692b327021b2e8dd73aa557721e0737c37b86e0 | |
parent | 968519b2ebd2569ed93a4afa6ed07ac46e86db5f (diff) | |
download | infinity-for-reddit-c0cb024eb99be74c36ea422df5731b09a0d5d570.tar infinity-for-reddit-c0cb024eb99be74c36ea422df5731b09a0d5d570.tar.gz infinity-for-reddit-c0cb024eb99be74c36ea422df5731b09a0d5d570.tar.bz2 infinity-for-reddit-c0cb024eb99be74c36ea422df5731b09a0d5d570.tar.lz infinity-for-reddit-c0cb024eb99be74c36ea422df5731b09a0d5d570.tar.xz infinity-for-reddit-c0cb024eb99be74c36ea422df5731b09a0d5d570.tar.zst infinity-for-reddit-c0cb024eb99be74c36ea422df5731b09a0d5d570.zip |
Fix always go to the first post in a post list in ViewPostDetailActivity.
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) { |