Fixed bug where fragments wouldn't update their preferences if they changed
This commit is contained in:
parent
58d8cb6a36
commit
f05312e915
@ -32,6 +32,7 @@ import android.support.annotation.IdRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
@ -131,6 +132,9 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
|
||||
private static final String INTENT_PANIC_TRIGGER = "info.guardianproject.panic.action.TRIGGER";
|
||||
|
||||
private static final String TAG_BOOKMARK_FRAGMENT = "TAG_BOOKMARK_FRAGMENT";
|
||||
private static final String TAG_TABS_FRAGMENT = "TAG_TABS_FRAGMENT";
|
||||
|
||||
// Static Layout
|
||||
@Bind(Window.ID_ANDROID_CONTENT) View mRoot;
|
||||
@Bind(R.id.drawer_layout) DrawerLayout mDrawerLayout;
|
||||
@ -316,8 +320,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
final FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
fragmentManager
|
||||
.beginTransaction()
|
||||
.replace(containerId, tabsFragment)
|
||||
.replace(R.id.right_drawer, bookmarksFragment)
|
||||
.replace(containerId, tabsFragment, TAG_TABS_FRAGMENT)
|
||||
.replace(R.id.right_drawer, bookmarksFragment, TAG_BOOKMARK_FRAGMENT)
|
||||
.commit();
|
||||
if (mShowTabsInDrawer) {
|
||||
mToolbarLayout.removeView(findViewById(R.id.tabs_toolbar_container));
|
||||
@ -575,6 +579,18 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
changeToolbarBackground(mWebpageBitmap, null);
|
||||
} else if (!isIncognito() && currentView != null && !mDarkTheme) {
|
||||
changeToolbarBackground(currentView.getFavicon(), null);
|
||||
} else if (!isIncognito() && !mDarkTheme && mWebpageBitmap != null) {
|
||||
changeToolbarBackground(mWebpageBitmap, null);
|
||||
}
|
||||
|
||||
FragmentManager manager = getSupportFragmentManager();
|
||||
Fragment tabsFragment = manager.findFragmentByTag(TAG_TABS_FRAGMENT);
|
||||
if (tabsFragment instanceof TabsFragment) {
|
||||
((TabsFragment) tabsFragment).reinitializePreferences();
|
||||
}
|
||||
Fragment bookmarksFragment = manager.findFragmentByTag(TAG_BOOKMARK_FRAGMENT);
|
||||
if (bookmarksFragment instanceof BookmarksFragment) {
|
||||
((BookmarksFragment) bookmarksFragment).reinitializePreferences();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package acr.browser.lightning.fragment;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
@ -91,6 +92,8 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
||||
// Colors
|
||||
private int mIconColor, mScrollIndex;
|
||||
|
||||
private boolean mIsIncognito;
|
||||
|
||||
private Observable<BookmarkViewAdapter> initBookmarkManager() {
|
||||
return Observable.create(new Action<BookmarkViewAdapter>() {
|
||||
@Override
|
||||
@ -109,8 +112,8 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
||||
final Bundle arguments = getArguments();
|
||||
final Context context = getContext();
|
||||
mTabsManager = ((UIController) context).getTabModel();
|
||||
boolean isIncognito = arguments.getBoolean(INCOGNITO_MODE, false);
|
||||
boolean darkTheme = mPreferenceManager.getUseTheme() != 0 || isIncognito;
|
||||
mIsIncognito = arguments.getBoolean(INCOGNITO_MODE, false);
|
||||
boolean darkTheme = mPreferenceManager.getUseTheme() != 0 || mIsIncognito;
|
||||
mWebpageBitmap = ThemeUtils.getThemedBitmap(context, R.drawable.ic_webpage, darkTheme);
|
||||
mFolderBitmap = ThemeUtils.getThemedBitmap(context, R.drawable.ic_folder, darkTheme);
|
||||
mIconColor = darkTheme ? ThemeUtils.getIconDarkThemeColor(context) :
|
||||
@ -196,6 +199,18 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
||||
mEventBus.unregister(this);
|
||||
}
|
||||
|
||||
public void reinitializePreferences() {
|
||||
Activity activity = getActivity();
|
||||
if (activity == null) {
|
||||
return;
|
||||
}
|
||||
boolean darkTheme = mPreferenceManager.getUseTheme() != 0 || mIsIncognito;
|
||||
mWebpageBitmap = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_webpage, darkTheme);
|
||||
mFolderBitmap = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_folder, darkTheme);
|
||||
mIconColor = darkTheme ? ThemeUtils.getIconDarkThemeColor(activity) :
|
||||
ThemeUtils.getIconLightThemeColor(activity);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void addBookmark(@NonNull final BrowserEvents.BookmarkAdded event) {
|
||||
updateBookmarkIndicator(event.url);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package acr.browser.lightning.fragment;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
@ -182,6 +183,22 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
|
||||
mBus.unregister(this);
|
||||
}
|
||||
|
||||
public void reinitializePreferences() {
|
||||
Activity activity = getActivity();
|
||||
if (activity == null) {
|
||||
return;
|
||||
}
|
||||
mDarkTheme = mPreferences.getUseTheme() != 0 || mIsIncognito;
|
||||
mColorMode = mPreferences.getColorModeEnabled();
|
||||
mColorMode &= !mDarkTheme;
|
||||
mIconColor = mDarkTheme ?
|
||||
ThemeUtils.getIconDarkThemeColor(activity) :
|
||||
ThemeUtils.getIconLightThemeColor(activity);
|
||||
if (mTabsAdapter != null) {
|
||||
mTabsAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(@NonNull View v) {
|
||||
switch (v.getId()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user