From bd8c4391611cc85413e6b9a42cb58f5103de80a5 Mon Sep 17 00:00:00 2001 From: Anthony Restaino Date: Sun, 20 Mar 2016 13:07:50 -0400 Subject: [PATCH] Fixed bug where multiple processes caused incognito to nor respond to preference changes. Possibly in the future I should explore gong back to multiprocess for incognito mode but right now it causes bugs. Also tweaked UI color in color mode --- app/src/main/AndroidManifest.xml | 1 - .../browser/lightning/activity/BrowserActivity.java | 13 ++++++++----- .../acr/browser/lightning/activity/TabsManager.java | 7 ++++--- .../acr/browser/lightning/app/AppComponent.java | 3 +++ .../browser/lightning/browser/BrowserPresenter.java | 4 +++- .../browser/lightning/controller/UIController.java | 3 +++ .../lightning/fragment/BookmarksFragment.java | 4 +++- .../browser/lightning/fragment/TabsFragment.java | 13 ++++++------- 8 files changed, 30 insertions(+), 18 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 16875ed..a1e9dfd 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -129,7 +129,6 @@ android:configChanges="orientation|screenSize|keyboardHidden|keyboard" android:label="@string/app_name" android:launchMode="singleTask" - android:process=":incognito" android:theme="@style/Theme.DarkTheme" android:windowSoftInputMode="stateHidden"> diff --git a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java index e13af26..2e8f4eb 100644 --- a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java @@ -4,9 +4,6 @@ package acr.browser.lightning.activity; -import android.animation.ArgbEvaluator; -import android.animation.ValueAnimator; -import android.animation.ValueAnimator.AnimatorUpdateListener; import android.annotation.TargetApi; import android.app.Activity; import android.content.ClipData; @@ -191,7 +188,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @Inject LightningDialogBuilder mBookmarksDialogBuilder; - @Inject TabsManager mTabsManager; + private TabsManager mTabsManager; @Inject HistoryDatabase mHistoryDatabase; @@ -244,6 +241,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements setContentView(R.layout.activity_main); ButterKnife.bind(this); + mTabsManager = new TabsManager(); mPresenter = new BrowserPresenter(this, isIncognito()); initialize(); @@ -815,6 +813,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements quit.setOnClickListener(this); } + @Override + public TabsManager getTabModel() { + return mTabsManager; + } + @Override public void showCloseDialog(final int position) { if (position < 0) { @@ -1284,7 +1287,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements if (requestedColor == defaultColor) { return mDarkTheme ? DrawableUtils.mixColor(0.25f, defaultColor, Color.WHITE): Color.WHITE; } else { - return DrawableUtils.mixColor(0.5f, requestedColor, Color.WHITE); + return DrawableUtils.mixColor(0.25f, requestedColor, Color.WHITE); } } diff --git a/app/src/main/java/acr/browser/lightning/activity/TabsManager.java b/app/src/main/java/acr/browser/lightning/activity/TabsManager.java index 25a0d71..91a1cd1 100644 --- a/app/src/main/java/acr/browser/lightning/activity/TabsManager.java +++ b/app/src/main/java/acr/browser/lightning/activity/TabsManager.java @@ -21,6 +21,7 @@ import javax.inject.Inject; import javax.inject.Singleton; import acr.browser.lightning.R; +import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.constant.Constants; import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.react.Action; @@ -36,7 +37,6 @@ import acr.browser.lightning.view.LightningView; * and tracks the current tab. It handles creation, deletion, * restoration, state saving, and switching of tabs. */ -@Singleton public class TabsManager { private static final String TAG = TabsManager.class.getSimpleName(); @@ -54,8 +54,9 @@ public class TabsManager { @Inject Bus mEventBus; @Inject Application mApp; - @Inject - public TabsManager() {} + public TabsManager() { + BrowserApp.getAppComponent().inject(this); + } // TODO remove and make presenter call new tab methods so it always knows @Deprecated diff --git a/app/src/main/java/acr/browser/lightning/app/AppComponent.java b/app/src/main/java/acr/browser/lightning/app/AppComponent.java index 232a45c..4753254 100644 --- a/app/src/main/java/acr/browser/lightning/app/AppComponent.java +++ b/app/src/main/java/acr/browser/lightning/app/AppComponent.java @@ -4,6 +4,7 @@ import javax.inject.Singleton; import acr.browser.lightning.activity.BrowserActivity; import acr.browser.lightning.activity.ReadingActivity; +import acr.browser.lightning.activity.TabsManager; import acr.browser.lightning.activity.ThemableBrowserActivity; import acr.browser.lightning.activity.ThemableSettingsActivity; import acr.browser.lightning.browser.BrowserPresenter; @@ -64,4 +65,6 @@ public interface AppComponent { void inject(BrowserPresenter presenter); + void inject(TabsManager manager); + } diff --git a/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java b/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java index b510019..6920748 100644 --- a/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java +++ b/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java @@ -16,6 +16,7 @@ import acr.browser.lightning.activity.TabsManager; import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.bus.BrowserEvents; import acr.browser.lightning.constant.Constants; +import acr.browser.lightning.controller.UIController; import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.react.OnSubscribe; import acr.browser.lightning.utils.UrlUtils; @@ -30,7 +31,7 @@ public class BrowserPresenter { private static final String TAG = BrowserPresenter.class.getSimpleName(); - @Inject TabsManager mTabsModel; + private TabsManager mTabsModel; @Inject PreferenceManager mPreferences; @Inject Bus mEventBus; @@ -42,6 +43,7 @@ public class BrowserPresenter { public BrowserPresenter(@NonNull BrowserView view, boolean isIncognito) { BrowserApp.getAppComponent().inject(this); + mTabsModel = ((UIController) view).getTabModel(); mView = view; mIsIncognito = isIncognito; mTabsModel.setTabNumberChangedListener(new TabsManager.TabNumberChangedListener() { diff --git a/app/src/main/java/acr/browser/lightning/controller/UIController.java b/app/src/main/java/acr/browser/lightning/controller/UIController.java index b06e85a..e28ca13 100644 --- a/app/src/main/java/acr/browser/lightning/controller/UIController.java +++ b/app/src/main/java/acr/browser/lightning/controller/UIController.java @@ -14,6 +14,7 @@ import android.view.View; import android.webkit.ValueCallback; import android.webkit.WebChromeClient.CustomViewCallback; +import acr.browser.lightning.activity.TabsManager; import acr.browser.lightning.view.LightningView; public interface UIController { @@ -61,4 +62,6 @@ public interface UIController { void tabChanged(LightningView tab); + TabsManager getTabModel(); + } diff --git a/app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java b/app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java index c82e703..ea01e8b 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java +++ b/app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java @@ -42,6 +42,7 @@ import acr.browser.lightning.async.AsyncExecutor; import acr.browser.lightning.bus.BookmarkEvents; import acr.browser.lightning.bus.BrowserEvents; import acr.browser.lightning.constant.Constants; +import acr.browser.lightning.controller.UIController; import acr.browser.lightning.database.BookmarkManager; import acr.browser.lightning.database.HistoryItem; import acr.browser.lightning.dialog.LightningDialogBuilder; @@ -72,7 +73,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @Inject PreferenceManager mPreferenceManager; - @Inject TabsManager mTabsManager; + private TabsManager mTabsManager; // Adapter private BookmarkViewAdapter mBookmarkAdapter; @@ -107,6 +108,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, BrowserApp.getAppComponent().inject(this); 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; mWebpageBitmap = ThemeUtils.getThemedBitmap(context, R.drawable.ic_webpage, darkTheme); diff --git a/app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java b/app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java index ac51ab9..8071e59 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java +++ b/app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java @@ -31,7 +31,6 @@ import android.widget.LinearLayout; import android.widget.TextView; import com.squareup.otto.Bus; -import com.squareup.otto.Subscribe; import javax.inject.Inject; @@ -39,7 +38,6 @@ import acr.browser.lightning.R; import acr.browser.lightning.activity.TabsManager; import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.browser.TabsView; -import acr.browser.lightning.bus.BrowserEvents; import acr.browser.lightning.bus.NavigationEvents; import acr.browser.lightning.bus.TabEvents; import acr.browser.lightning.controller.UIController; @@ -77,7 +75,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View private UIController mUiController; private RecyclerView mRecyclerView; - @Inject TabsManager tabsManager; + private TabsManager mTabsManager; @Inject Bus mBus; @Inject PreferenceManager mPreferences; @@ -91,6 +89,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View final Bundle arguments = getArguments(); final Context context = getContext(); mUiController = (UIController) getActivity(); + mTabsManager = mUiController.getTabModel(); mIsIncognito = arguments.getBoolean(IS_INCOGNITO, false); mShowInNavigationDrawer = arguments.getBoolean(VERTICAL_MODE, true); mDarkTheme = mPreferences.getUseTheme() != 0 || mIsIncognito; @@ -187,7 +186,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View public void onClick(@NonNull View v) { switch (v.getId()) { case R.id.tab_header_button: - mUiController.showCloseDialog(tabsManager.indexOfCurrentTab()); + mUiController.showCloseDialog(mTabsManager.indexOfCurrentTab()); break; case R.id.new_tab_button: mBus.post(new TabEvents.NewTab()); @@ -220,7 +219,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View @Override public void tabAdded() { if (mTabsAdapter != null) { - mTabsAdapter.notifyItemInserted(tabsManager.last()); + mTabsAdapter.notifyItemInserted(mTabsManager.last()); mRecyclerView.postDelayed(new Runnable() { @Override public void run() { @@ -292,7 +291,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View ViewCompat.jumpDrawablesToCurrentState(holder.exitButton); - LightningView web = tabsManager.getTabAtPosition(position); + LightningView web = mTabsManager.getTabAtPosition(position); if (web == null) { return; } @@ -340,7 +339,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View @Override public int getItemCount() { - return tabsManager.size(); + return mTabsManager.size(); } public Bitmap getDesaturatedBitmap(@NonNull Bitmap favicon) {