Browse Source

Fixed bug where fragments wouldn't update their preferences if they changed

master
Anthony Restaino 9 years ago
parent
commit
f05312e915
  1. 20
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 19
      app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java
  3. 17
      app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java

20
app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java

@ -32,6 +32,7 @@ import android.support.annotation.IdRes;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.annotation.StringRes; import android.support.annotation.StringRes;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v4.view.GravityCompat; 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 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 // Static Layout
@Bind(Window.ID_ANDROID_CONTENT) View mRoot; @Bind(Window.ID_ANDROID_CONTENT) View mRoot;
@Bind(R.id.drawer_layout) DrawerLayout mDrawerLayout; @Bind(R.id.drawer_layout) DrawerLayout mDrawerLayout;
@ -316,8 +320,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
final FragmentManager fragmentManager = getSupportFragmentManager(); final FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager fragmentManager
.beginTransaction() .beginTransaction()
.replace(containerId, tabsFragment) .replace(containerId, tabsFragment, TAG_TABS_FRAGMENT)
.replace(R.id.right_drawer, bookmarksFragment) .replace(R.id.right_drawer, bookmarksFragment, TAG_BOOKMARK_FRAGMENT)
.commit(); .commit();
if (mShowTabsInDrawer) { if (mShowTabsInDrawer) {
mToolbarLayout.removeView(findViewById(R.id.tabs_toolbar_container)); mToolbarLayout.removeView(findViewById(R.id.tabs_toolbar_container));
@ -575,6 +579,18 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
changeToolbarBackground(mWebpageBitmap, null); changeToolbarBackground(mWebpageBitmap, null);
} else if (!isIncognito() && currentView != null && !mDarkTheme) { } else if (!isIncognito() && currentView != null && !mDarkTheme) {
changeToolbarBackground(currentView.getFavicon(), null); 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();
} }

19
app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java

@ -1,5 +1,6 @@
package acr.browser.lightning.fragment; package acr.browser.lightning.fragment;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
@ -91,6 +92,8 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
// Colors // Colors
private int mIconColor, mScrollIndex; private int mIconColor, mScrollIndex;
private boolean mIsIncognito;
private Observable<BookmarkViewAdapter> initBookmarkManager() { private Observable<BookmarkViewAdapter> initBookmarkManager() {
return Observable.create(new Action<BookmarkViewAdapter>() { return Observable.create(new Action<BookmarkViewAdapter>() {
@Override @Override
@ -109,8 +112,8 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
final Bundle arguments = getArguments(); final Bundle arguments = getArguments();
final Context context = getContext(); final Context context = getContext();
mTabsManager = ((UIController) context).getTabModel(); mTabsManager = ((UIController) context).getTabModel();
boolean isIncognito = arguments.getBoolean(INCOGNITO_MODE, false); mIsIncognito = arguments.getBoolean(INCOGNITO_MODE, false);
boolean darkTheme = mPreferenceManager.getUseTheme() != 0 || isIncognito; boolean darkTheme = mPreferenceManager.getUseTheme() != 0 || mIsIncognito;
mWebpageBitmap = ThemeUtils.getThemedBitmap(context, R.drawable.ic_webpage, darkTheme); mWebpageBitmap = ThemeUtils.getThemedBitmap(context, R.drawable.ic_webpage, darkTheme);
mFolderBitmap = ThemeUtils.getThemedBitmap(context, R.drawable.ic_folder, darkTheme); mFolderBitmap = ThemeUtils.getThemedBitmap(context, R.drawable.ic_folder, darkTheme);
mIconColor = darkTheme ? ThemeUtils.getIconDarkThemeColor(context) : mIconColor = darkTheme ? ThemeUtils.getIconDarkThemeColor(context) :
@ -196,6 +199,18 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
mEventBus.unregister(this); 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 @Subscribe
public void addBookmark(@NonNull final BrowserEvents.BookmarkAdded event) { public void addBookmark(@NonNull final BrowserEvents.BookmarkAdded event) {
updateBookmarkIndicator(event.url); updateBookmarkIndicator(event.url);

17
app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java

@ -1,5 +1,6 @@
package acr.browser.lightning.fragment; package acr.browser.lightning.fragment;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
@ -182,6 +183,22 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
mBus.unregister(this); 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 @Override
public void onClick(@NonNull View v) { public void onClick(@NonNull View v) {
switch (v.getId()) { switch (v.getId()) {

Loading…
Cancel
Save