Smoothly close browser by closing the activity after the drawers are closed, removed bus event

This commit is contained in:
Anthony Restaino 2016-03-01 22:07:55 -05:00
parent e0ace14029
commit 6308677438
5 changed files with 51 additions and 22 deletions

View File

@ -1064,9 +1064,12 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
mBrowserFrame.setBackgroundColor(mBackgroundColor); mBrowserFrame.setBackgroundColor(mBackgroundColor);
performExitCleanUp(); performExitCleanUp();
mBrowserFrame.removeAllViews(); mBrowserFrame.removeAllViews();
int size = mTabsManager.size();
mTabsManager.shutdown(); mTabsManager.shutdown();
mCurrentView = null; mCurrentView = null;
mEventBus.post(new BrowserEvents.TabsChanged()); for (int n = 0; n < size; n++) {
mTabsView.tabRemoved(n);
}
finish(); finish();
} }
@ -1393,8 +1396,39 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
mDrawerLayout.openDrawer(mDrawerRight); 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.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 @Override
@ -1913,7 +1947,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
case R.id.action_toggle_desktop: case R.id.action_toggle_desktop:
currentTab.toggleDesktopUA(this); currentTab.toggleDesktopUA(this);
currentTab.reload(); currentTab.reload();
closeDrawers(); closeDrawers(null);
break; break;
} }
} }
@ -2174,7 +2208,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
final LightningView currentTab = mTabsManager.getCurrentTab(); final LightningView currentTab = mTabsManager.getCurrentTab();
if (currentTab != null) { if (currentTab != null) {
currentTab.loadHomepage(); currentTab.loadHomepage();
closeDrawers(); closeDrawers(null);
} }
} }

View File

@ -61,7 +61,11 @@ public class IncognitoActivity extends BrowserActivity {
@Override @Override
public void closeActivity() { public void closeActivity() {
closeDrawers(); closeDrawers(new Runnable() {
@Override
public void run() {
closeBrowser(); closeBrowser();
} }
});
}
} }

View File

@ -65,10 +65,14 @@ public class MainActivity extends BrowserActivity {
@Override @Override
public void closeActivity() { public void closeActivity() {
closeDrawers(); closeDrawers(new Runnable() {
@Override
public void run() {
performExitCleanUp(); performExitCleanUp();
moveTaskToBack(true); moveTaskToBack(true);
} }
});
}
} }

View File

@ -40,12 +40,6 @@ public final class BrowserEvents {
public static class UserPressedBack { public static class UserPressedBack {
} }
/**
* Notify that the user closed or opened a tab
*/
public static class TabsChanged {
}
/** /**
* *
*/ */

View File

@ -183,13 +183,6 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
mBus.unregister(this); mBus.unregister(this);
} }
@Subscribe
public void tabsChanged(final BrowserEvents.TabsChanged event) {
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()) {