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 698c453..39e409b 100644 --- a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java @@ -908,6 +908,12 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements mTabsView.tabChanged(position); } + @Override + public void notifyTabViewInitialized() { + Log.d(TAG, "Notify Tabs Initialized"); + mTabsView.tabsInitialized(); + } + @Override public void tabChanged(LightningView tab) { mPresenter.tabChangeOccurred(tab); 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 494c897..99abbbd 100644 --- a/app/src/main/java/acr/browser/lightning/activity/TabsManager.java +++ b/app/src/main/java/acr/browser/lightning/activity/TabsManager.java @@ -484,7 +484,7 @@ public class TabsManager { * @return Return the index of the current tab, or -1 if the * current tab is null. */ - public int indexOfCurrentTab() { + public synchronized int indexOfCurrentTab() { return mTabList.indexOf(mCurrentTab); } @@ -493,7 +493,7 @@ public class TabsManager { * * @return Return the index of the tab, or -1 if the tab isn't in the list. */ - public int indexOfTab(LightningView tab) { + public synchronized int indexOfTab(LightningView tab) { return mTabList.indexOf(tab); } 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 e03d68c..179f2bb 100644 --- a/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java +++ b/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java @@ -7,6 +7,7 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.Log; +import com.anthonycr.bonsai.Schedulers; import com.squareup.otto.Bus; import javax.inject.Inject; @@ -63,13 +64,14 @@ public class BrowserPresenter { */ public void setupTabs(@Nullable Intent intent) { mTabsModel.initializeTabs((Activity) mView, intent, mIsIncognito) + .subscribeOn(Schedulers.main()) .subscribe(new OnSubscribe() { @Override public void onComplete() { // At this point we always have at least a tab in the tab manager - tabChanged(mTabsModel.last()); - mView.notifyTabViewAdded(); + mView.notifyTabViewInitialized(); mView.updateTabNumber(mTabsModel.size()); + tabChanged(mTabsModel.last()); } }); } diff --git a/app/src/main/java/acr/browser/lightning/browser/BrowserView.java b/app/src/main/java/acr/browser/lightning/browser/BrowserView.java index 4ef45f5..b701bbb 100644 --- a/app/src/main/java/acr/browser/lightning/browser/BrowserView.java +++ b/app/src/main/java/acr/browser/lightning/browser/BrowserView.java @@ -35,4 +35,6 @@ public interface BrowserView { void notifyTabViewChanged(int position); + void notifyTabViewInitialized(); + } diff --git a/app/src/main/java/acr/browser/lightning/browser/TabsView.java b/app/src/main/java/acr/browser/lightning/browser/TabsView.java index 8c4e64e..e0ecbe9 100644 --- a/app/src/main/java/acr/browser/lightning/browser/TabsView.java +++ b/app/src/main/java/acr/browser/lightning/browser/TabsView.java @@ -8,4 +8,5 @@ public interface TabsView { void tabChanged(int position); + void tabsInitialized(); } 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 fbf3f7d..6426945 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java +++ b/app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java @@ -98,8 +98,8 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View mColorMode = mPreferences.getColorModeEnabled(); mColorMode &= !mDarkTheme; mIconColor = mDarkTheme ? - ThemeUtils.getIconDarkThemeColor(context) : - ThemeUtils.getIconLightThemeColor(context); + ThemeUtils.getIconDarkThemeColor(context) : + ThemeUtils.getIconLightThemeColor(context); } @Nullable @@ -184,6 +184,13 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View mBus.unregister(this); } + @Override + public void tabsInitialized() { + if (mTabsAdapter != null) { + mTabsAdapter.notifyDataSetChanged(); + } + } + public void reinitializePreferences() { Activity activity = getActivity(); if (activity == null) { @@ -193,8 +200,8 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View mColorMode = mPreferences.getColorModeEnabled(); mColorMode &= !mDarkTheme; mIconColor = mDarkTheme ? - ThemeUtils.getIconDarkThemeColor(activity) : - ThemeUtils.getIconLightThemeColor(activity); + ThemeUtils.getIconDarkThemeColor(activity) : + ThemeUtils.getIconLightThemeColor(activity); if (mTabsAdapter != null) { mTabsAdapter.notifyDataSetChanged(); } @@ -356,7 +363,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View public Bitmap getDesaturatedBitmap(@NonNull Bitmap favicon) { Bitmap grayscaleBitmap = Bitmap.createBitmap(favicon.getWidth(), - favicon.getHeight(), Bitmap.Config.ARGB_8888); + favicon.getHeight(), Bitmap.Config.ARGB_8888); Canvas c = new Canvas(grayscaleBitmap); if (mColorMatrix == null || mFilter == null || mPaint == null) {