From f1467a9a9667e051e906a5d490f9b433f65bf6f4 Mon Sep 17 00:00:00 2001 From: Anthony Restaino Date: Fri, 5 Feb 2016 22:17:15 -0500 Subject: [PATCH] Add ability to close all tabs except current tab --- .../browser/lightning/activity/BrowserActivity.java | 12 ++++++++---- .../browser/lightning/browser/BrowserPresenter.java | 12 ++++++++++++ app/src/main/res/values/strings.xml | 1 + 3 files changed, 21 insertions(+), 4 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 0e32eca..3f1d7d3 100644 --- a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java @@ -834,19 +834,23 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements } AlertDialog.Builder builder = new AlertDialog.Builder(this); ArrayAdapter adapter = new ArrayAdapter<>(this, - android.R.layout.simple_dropdown_item_1line); - adapter.add(this.getString(R.string.close_tab)); + android.R.layout.simple_list_item_1); adapter.add(this.getString(R.string.close_all_tabs)); + adapter.add(this.getString(R.string.close_other_tabs)); + adapter.add(this.getString(R.string.close_tab)); builder.setAdapter(adapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case 0: - deleteTab(position); + closeBrowser(); break; case 1: - closeBrowser(); + mPresenter.closeAllOtherTabs(); + break; + case 2: + deleteTab(position); break; default: break; 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 cd24c08..7d7eeec 100644 --- a/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java +++ b/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java @@ -77,6 +77,18 @@ public class BrowserPresenter { mCurrentTab = newTab; } + public void closeAllOtherTabs() { + + while (mTabsModel.last() != mTabsModel.indexOfCurrentTab()) { + deleteTab(mTabsModel.last()); + } + + while (0 != mTabsModel.indexOfCurrentTab()) { + deleteTab(0); + } + + } + public void deleteTab(int position) { final LightningView tabToDelete = mTabsModel.getTabAtPosition(position); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5009095..58e9c79 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -193,6 +193,7 @@ Details about version, author and license. Close tab Close all tabs + Close other tabs Block 3rd Party Cookies Enable Color Mode Reader Mode