Fix (#4148) Issues on theme change

* fixed themeChange crashes

* fixed comments

* Overlooked the title bar
This commit is contained in:
Aditya-Srivastav 2021-01-11 19:51:44 +05:30 committed by GitHub
parent 2d884b44ca
commit c4bd23f7a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 9 deletions

View file

@ -38,6 +38,10 @@ public class BookmarkListRootFragment extends CommonsDaggerSupportFragment imple
@BindView(R.id.explore_container)
FrameLayout container;
public BookmarkListRootFragment(){
//empty constructor necessary otherwise crashes on recreate
}
public BookmarkListRootFragment(Bundle bundle, BookmarksPagerAdapter bookmarksPagerAdapter) {
String title = bundle.getString("categoryName");
int order = bundle.getInt("order");
@ -65,7 +69,9 @@ public class BookmarkListRootFragment extends CommonsDaggerSupportFragment imple
@Override
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
setFragment(listFragment, mediaDetails);
if(savedInstanceState==null) {
setFragment(listFragment, mediaDetails);
}
}
public void setFragment(Fragment fragment, Fragment otherFragment) {

View file

@ -113,7 +113,11 @@ public class MainActivity extends BaseActivity
setTitle(getString(R.string.explore_tab_title_mobile));
setUpLoggedOutPager();
} else {
setTitle(getString(R.string.contributions_fragment));
if(savedInstanceState == null){
//starting a fresh fragment.
setTitle(getString(R.string.contributions_fragment));
loadFragment(ContributionsFragment.newInstance(),false);
}
setUpPager();
initMain();
}
@ -124,30 +128,31 @@ public class MainActivity extends BaseActivity
}
private void setUpPager() {
loadFragment(ContributionsFragment.newInstance());
tabLayout.setOnNavigationItemSelectedListener(item -> {
if (!item.getTitle().equals("More")) {
// do not change title for more fragment
setTitle(item.getTitle());
}
Fragment fragment = NavTab.of(item.getOrder()).newInstance();
return loadFragment(fragment);
return loadFragment(fragment,true);
});
}
private void setUpLoggedOutPager() {
loadFragment(ExploreFragment.newInstance());
loadFragment(ExploreFragment.newInstance(),false);
tabLayout.setOnNavigationItemSelectedListener(item -> {
if (!item.getTitle().equals("More")) {
// do not change title for more fragment
setTitle(item.getTitle());
}
Fragment fragment = NavTabLoggedOut.of(item.getOrder()).newInstance();
return loadFragment(fragment);
return loadFragment(fragment,true);
});
}
private boolean loadFragment(Fragment fragment) {
private boolean loadFragment(Fragment fragment,boolean showBottom ) {
//showBottom so that we do not show the bottom tray again when constructing
//from the saved instance state.
if (fragment instanceof ContributionsFragment) {
if (activeFragment == ActiveFragment.CONTRIBUTIONS) { // Do nothing if same tab
return true;
@ -172,7 +177,7 @@ public class MainActivity extends BaseActivity
}
bookmarkFragment = (BookmarkFragment) fragment;
activeFragment = ActiveFragment.BOOKMARK;
} else if (fragment == null) {
} else if (fragment == null && showBottom) {
if (applicationKvStore.getBoolean("login_skipped") == true) { // If logged out, more sheet is different
MoreBottomSheetLoggedOutFragment bottomSheet = new MoreBottomSheetLoggedOutFragment();
bottomSheet.show(getSupportFragmentManager(),

View file

@ -34,6 +34,10 @@ public class ExploreListRootFragment extends CommonsDaggerSupportFragment implem
@BindView(R.id.explore_container)
FrameLayout container;
public ExploreListRootFragment(){
//empty constructor necessary otherwise crashes on recreate
}
public ExploreListRootFragment(Bundle bundle) {
String title = bundle.getString("categoryName");
listFragment = new CategoriesMediaFragment();
@ -55,7 +59,9 @@ public class ExploreListRootFragment extends CommonsDaggerSupportFragment implem
@Override
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
setFragment(listFragment, mediaDetails);
if(savedInstanceState == null) {
setFragment(listFragment, mediaDetails);
}
}
public void setFragment(Fragment fragment, Fragment otherFragment) {