1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-24 17:10:33 +00:00

setupTabs() if ageRestrictedContent pref changed

This commit is contained in:
Vincent Nagel 2020-03-15 22:27:44 -05:00
parent 430d4e1ccd
commit 9ede7a3c42

View File

@ -2,6 +2,7 @@ package org.schabi.newpipe.fragments;
import android.content.Context;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
@ -45,6 +46,9 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
private boolean hasTabsChanged = false;
private boolean previousShowAgeRestrictedContent;
private String showAgeRestrictedContentKey;
/*//////////////////////////////////////////////////////////////////////////
// Fragment's LifeCycle
//////////////////////////////////////////////////////////////////////////*/
@ -53,7 +57,6 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
tabsManager = TabsManager.getManager(activity);
tabsManager.setSavedTabsListener(() -> {
if (DEBUG) {
@ -66,6 +69,9 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
hasTabsChanged = true;
}
});
showAgeRestrictedContentKey = getString(R.string.show_age_restricted_content);
previousShowAgeRestrictedContent = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean(showAgeRestrictedContentKey, false);
}
@Override
@ -92,7 +98,11 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
public void onResume() {
super.onResume();
if (hasTabsChanged) {
boolean showAgeRestrictedContent = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean(showAgeRestrictedContentKey, false);
if (previousShowAgeRestrictedContent != showAgeRestrictedContent) {
previousShowAgeRestrictedContent = showAgeRestrictedContent;
setupTabs();
} else if (hasTabsChanged) {
setupTabs();
}
}