From 630867743805411eae4b7745a1d01fa954fa9649 Mon Sep 17 00:00:00 2001 From: Anthony Restaino Date: Tue, 1 Mar 2016 22:07:55 -0500 Subject: [PATCH] Smoothly close browser by closing the activity after the drawers are closed, removed bus event --- .../lightning/activity/BrowserActivity.java | 42 +++++++++++++++++-- .../lightning/activity/IncognitoActivity.java | 8 +++- .../lightning/activity/MainActivity.java | 10 +++-- .../browser/lightning/bus/BrowserEvents.java | 6 --- .../lightning/fragment/TabsFragment.java | 7 ---- 5 files changed, 51 insertions(+), 22 deletions(-) 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 ac3cd0f..d8d45db 100644 --- a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java @@ -1064,9 +1064,12 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements mBrowserFrame.setBackgroundColor(mBackgroundColor); performExitCleanUp(); mBrowserFrame.removeAllViews(); + int size = mTabsManager.size(); mTabsManager.shutdown(); mCurrentView = null; - mEventBus.post(new BrowserEvents.TabsChanged()); + for (int n = 0; n < size; n++) { + mTabsView.tabRemoved(n); + } finish(); } @@ -1393,8 +1396,39 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements mDrawerLayout.openDrawer(mDrawerRight); } - void closeDrawers() { + /** + * This method closes any open drawer and executes + * the runnable after the drawers are completely closed. + * + * @param runnable an optional runnable to run after + * the drawers are closed. + */ + void closeDrawers(@Nullable final Runnable runnable) { + if (!mDrawerLayout.isDrawerOpen(mDrawerLeft) && !mDrawerLayout.isDrawerOpen(mDrawerRight)) { + if (runnable != null) { + runnable.run(); + return; + } + } mDrawerLayout.closeDrawers(); + mDrawerLayout.addDrawerListener(new DrawerListener() { + @Override + public void onDrawerSlide(View drawerView, float slideOffset) {} + + @Override + public void onDrawerOpened(View drawerView) {} + + @Override + public void onDrawerClosed(View drawerView) { + if (runnable != null) { + runnable.run(); + } + mDrawerLayout.removeDrawerListener(this); + } + + @Override + public void onDrawerStateChanged(int newState) {} + }); } @Override @@ -1913,7 +1947,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements case R.id.action_toggle_desktop: currentTab.toggleDesktopUA(this); currentTab.reload(); - closeDrawers(); + closeDrawers(null); break; } } @@ -2174,7 +2208,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements final LightningView currentTab = mTabsManager.getCurrentTab(); if (currentTab != null) { currentTab.loadHomepage(); - closeDrawers(); + closeDrawers(null); } } diff --git a/app/src/main/java/acr/browser/lightning/activity/IncognitoActivity.java b/app/src/main/java/acr/browser/lightning/activity/IncognitoActivity.java index e05512d..fa2460b 100644 --- a/app/src/main/java/acr/browser/lightning/activity/IncognitoActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/IncognitoActivity.java @@ -61,7 +61,11 @@ public class IncognitoActivity extends BrowserActivity { @Override public void closeActivity() { - closeDrawers(); - closeBrowser(); + closeDrawers(new Runnable() { + @Override + public void run() { + closeBrowser(); + } + }); } } diff --git a/app/src/main/java/acr/browser/lightning/activity/MainActivity.java b/app/src/main/java/acr/browser/lightning/activity/MainActivity.java index ff00bde..32ca6eb 100644 --- a/app/src/main/java/acr/browser/lightning/activity/MainActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/MainActivity.java @@ -65,9 +65,13 @@ public class MainActivity extends BrowserActivity { @Override public void closeActivity() { - closeDrawers(); - performExitCleanUp(); - moveTaskToBack(true); + closeDrawers(new Runnable() { + @Override + public void run() { + performExitCleanUp(); + moveTaskToBack(true); + } + }); } diff --git a/app/src/main/java/acr/browser/lightning/bus/BrowserEvents.java b/app/src/main/java/acr/browser/lightning/bus/BrowserEvents.java index 231076c..17dbe66 100644 --- a/app/src/main/java/acr/browser/lightning/bus/BrowserEvents.java +++ b/app/src/main/java/acr/browser/lightning/bus/BrowserEvents.java @@ -40,12 +40,6 @@ public final class BrowserEvents { public static class UserPressedBack { } - /** - * Notify that the user closed or opened a tab - */ - public static class TabsChanged { - } - /** * */ 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 263ea95..ac51ab9 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java +++ b/app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java @@ -183,13 +183,6 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View mBus.unregister(this); } - @Subscribe - public void tabsChanged(final BrowserEvents.TabsChanged event) { - if (mTabsAdapter != null) { - mTabsAdapter.notifyDataSetChanged(); - } - } - @Override public void onClick(@NonNull View v) { switch (v.getId()) {