Browse Source

Support swapping tabs and bookmarks drawers

master
Anthony Restaino 8 years ago
parent
commit
08161059c9
  1. 27
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 2
      app/src/main/java/acr/browser/lightning/activity/ThemableBrowserActivity.java
  3. 39
      app/src/main/java/acr/browser/lightning/fragment/DisplaySettingsFragment.java
  4. 10
      app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java
  5. 9
      app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java
  6. 5
      app/src/main/res/values/strings.xml
  7. 26
      app/src/main/res/xml/preference_display.xml
  8. 4
      app/src/main/res/xml/preference_general.xml

27
app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java

@ -173,6 +173,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -173,6 +173,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
private boolean mIsFullScreen = false;
private boolean mIsImmersive = false;
private boolean mShowTabsInDrawer;
private boolean mSwapBookmarksAndTabs;
private int mOriginalOrientation;
private int mBackgroundColor;
private int mIconColor;
@ -247,6 +248,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -247,6 +248,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
mDisabledIconColor = mDarkTheme ? ContextCompat.getColor(this, R.color.icon_dark_theme_disabled) :
ContextCompat.getColor(this, R.color.icon_light_theme_disabled);
mShowTabsInDrawer = mPreferences.getShowTabsInDrawer(!isTablet());
mSwapBookmarksAndTabs = mPreferences.getBookmarksAndTabsSwapped();
// initialize background ColorDrawable
int primaryColor = ThemeUtils.getPrimaryColor(this);
@ -289,7 +291,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -289,7 +291,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
final TabsFragment tabsFragment = new TabsFragment();
mTabsView = tabsFragment;
final int containerId = mShowTabsInDrawer ? R.id.left_drawer : R.id.tabs_toolbar_container;
final Bundle tabsFragmentArguments = new Bundle();
tabsFragmentArguments.putBoolean(TabsFragment.IS_INCOGNITO, isIncognito());
tabsFragmentArguments.putBoolean(TabsFragment.VERTICAL_MODE, mShowTabsInDrawer);
@ -303,8 +304,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -303,8 +304,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
final FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager
.beginTransaction()
.replace(containerId, tabsFragment, TAG_TABS_FRAGMENT)
.replace(R.id.right_drawer, bookmarksFragment, TAG_BOOKMARK_FRAGMENT)
.replace(getTabsFragmentViewId(), tabsFragment, TAG_TABS_FRAGMENT)
.replace(getBookmarksFragmentViewId(), bookmarksFragment, TAG_BOOKMARK_FRAGMENT)
.commit();
if (mShowTabsInDrawer) {
mToolbarLayout.removeView(findViewById(R.id.tabs_toolbar_container));
@ -333,7 +334,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -333,7 +334,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
}
updateTabNumber(0);
} else {
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, mDrawerLeft);
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, mSwapBookmarksAndTabs ? mDrawerRight : mDrawerLeft);
mArrowImage.setImageResource(R.drawable.ic_action_home);
mArrowImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
}
@ -378,6 +379,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -378,6 +379,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath());
}
@SuppressWarnings("VariableNotUsedInsideIf")
Intent intent = savedInstanceState == null ? getIntent() : null;
boolean launchedFromHistory = intent != null && (intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0;
@ -395,6 +397,19 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -395,6 +397,19 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
}
}
@IdRes
private int getBookmarksFragmentViewId() {
return mSwapBookmarksAndTabs ? R.id.left_drawer : R.id.right_drawer;
}
private int getTabsFragmentViewId() {
if (mShowTabsInDrawer) {
return mSwapBookmarksAndTabs ? R.id.right_drawer : R.id.left_drawer;
} else {
return R.id.tabs_toolbar_container;
}
}
static boolean isPanicTrigger(@Nullable Intent intent) {
return intent != null && INTENT_PANIC_TRIGGER.equals(intent.getAction());
}
@ -1239,6 +1254,10 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1239,6 +1254,10 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
protected void onResume() {
super.onResume();
Log.d(TAG, "onResume");
if (mSwapBookmarksAndTabs != mPreferences.getBookmarksAndTabsSwapped()) {
restart();
}
if (mSuggestionsAdapter != null) {
mSuggestionsAdapter.refreshPreferences();
mSuggestionsAdapter.refreshBookmarks();

2
app/src/main/java/acr/browser/lightning/activity/ThemableBrowserActivity.java

@ -68,7 +68,7 @@ public abstract class ThemableBrowserActivity extends AppCompatActivity { @@ -68,7 +68,7 @@ public abstract class ThemableBrowserActivity extends AppCompatActivity {
return (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE;
}
private void restart() {
protected void restart() {
finish();
startActivity(new Intent(this, getClass()));
}

39
app/src/main/java/acr/browser/lightning/fragment/DisplaySettingsFragment.java

@ -31,6 +31,9 @@ public class DisplaySettingsFragment extends LightningPreferenceFragment impleme @@ -31,6 +31,9 @@ public class DisplaySettingsFragment extends LightningPreferenceFragment impleme
private static final String SETTINGS_REFLOW = "text_reflow";
private static final String SETTINGS_THEME = "app_theme";
private static final String SETTINGS_TEXTSIZE = "text_size";
private static final String SETTINGS_DRAWERTABS = "cb_drawertabs";
private static final String SETTINGS_SWAPTABS = "cb_swapdrawers";
private static final float XXLARGE = 30.0f;
private static final float XLARGE = 26.0f;
private static final float LARGE = 22.0f;
@ -67,6 +70,8 @@ public class DisplaySettingsFragment extends LightningPreferenceFragment impleme @@ -67,6 +70,8 @@ public class DisplaySettingsFragment extends LightningPreferenceFragment impleme
cbviewport = (CheckBoxPreference) findPreference(SETTINGS_VIEWPORT);
cboverview = (CheckBoxPreference) findPreference(SETTINGS_OVERVIEWMODE);
cbreflow = (CheckBoxPreference) findPreference(SETTINGS_REFLOW);
CheckBoxPreference cbDrawerTabs = (CheckBoxPreference) findPreference(SETTINGS_DRAWERTABS);
CheckBoxPreference cbSwapTabs = (CheckBoxPreference) findPreference(SETTINGS_SWAPTABS);
theme.setOnPreferenceClickListener(this);
textsize.setOnPreferenceClickListener(this);
@ -75,12 +80,16 @@ public class DisplaySettingsFragment extends LightningPreferenceFragment impleme @@ -75,12 +80,16 @@ public class DisplaySettingsFragment extends LightningPreferenceFragment impleme
cbviewport.setOnPreferenceChangeListener(this);
cboverview.setOnPreferenceChangeListener(this);
cbreflow.setOnPreferenceChangeListener(this);
cbDrawerTabs.setOnPreferenceChangeListener(this);
cbSwapTabs.setOnPreferenceChangeListener(this);
cbstatus.setChecked(mPreferenceManager.getHideStatusBarEnabled());
cbfullscreen.setChecked(mPreferenceManager.getFullScreenEnabled());
cbviewport.setChecked(mPreferenceManager.getUseWideViewportEnabled());
cboverview.setChecked(mPreferenceManager.getOverviewModeEnabled());
cbreflow.setChecked(mPreferenceManager.getTextReflowEnabled());
cbDrawerTabs.setChecked(mPreferenceManager.getShowTabsInDrawer(true));
cbSwapTabs.setChecked(mPreferenceManager.getBookmarksAndTabsSwapped());
theme.setSummary(mThemeOptions[mPreferenceManager.getUseTheme()]);
}
@ -101,27 +110,37 @@ public class DisplaySettingsFragment extends LightningPreferenceFragment impleme @@ -101,27 +110,37 @@ public class DisplaySettingsFragment extends LightningPreferenceFragment impleme
@Override
public boolean onPreferenceChange(@NonNull Preference preference, Object newValue) {
boolean checked = false;
if (newValue instanceof Boolean) {
checked = Boolean.TRUE.equals(newValue);
}
// switch preferences
switch (preference.getKey()) {
case SETTINGS_HIDESTATUSBAR:
mPreferenceManager.setHideStatusBarEnabled((Boolean) newValue);
cbstatus.setChecked((Boolean) newValue);
mPreferenceManager.setHideStatusBarEnabled(checked);
cbstatus.setChecked(checked);
return true;
case SETTINGS_FULLSCREEN:
mPreferenceManager.setFullScreenEnabled((Boolean) newValue);
cbfullscreen.setChecked((Boolean) newValue);
mPreferenceManager.setFullScreenEnabled(checked);
cbfullscreen.setChecked(checked);
return true;
case SETTINGS_VIEWPORT:
mPreferenceManager.setUseWideViewportEnabled((Boolean) newValue);
cbviewport.setChecked((Boolean) newValue);
mPreferenceManager.setUseWideViewportEnabled(checked);
cbviewport.setChecked(checked);
return true;
case SETTINGS_OVERVIEWMODE:
mPreferenceManager.setOverviewModeEnabled((Boolean) newValue);
cboverview.setChecked((Boolean) newValue);
mPreferenceManager.setOverviewModeEnabled(checked);
cboverview.setChecked(checked);
return true;
case SETTINGS_REFLOW:
mPreferenceManager.setTextReflowEnabled((Boolean) newValue);
cbreflow.setChecked((Boolean) newValue);
mPreferenceManager.setTextReflowEnabled(checked);
cbreflow.setChecked(checked);
return true;
case SETTINGS_DRAWERTABS:
mPreferenceManager.setShowTabsInDrawer(checked);
return true;
case SETTINGS_SWAPTABS:
mPreferenceManager.setBookmarkAndTabsSwapped(checked);
return true;
default:
return false;

10
app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java

@ -43,8 +43,6 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme @@ -43,8 +43,6 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
private static final String SETTINGS_HOME = "home";
private static final String SETTINGS_SEARCHENGINE = "search";
private static final String SETTINGS_GOOGLESUGGESTIONS = "google_suggestions";
private static final String SETTINGS_DRAWERTABS = "cb_drawertabs";
private Activity mActivity;
private static final int API = android.os.Build.VERSION.SDK_INT;
private CharSequence[] mProxyChoices;
@ -77,7 +75,6 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme @@ -77,7 +75,6 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
CheckBoxPreference cbJsScript = (CheckBoxPreference) findPreference(SETTINGS_JAVASCRIPT);
CheckBoxPreference cbColorMode = (CheckBoxPreference) findPreference(SETTINGS_COLORMODE);
CheckBoxPreference cbgooglesuggest = (CheckBoxPreference) findPreference(SETTINGS_GOOGLESUGGESTIONS);
CheckBoxPreference cbDrawerTabs = (CheckBoxPreference) findPreference(SETTINGS_DRAWERTABS);
proxy.setOnPreferenceClickListener(this);
useragent.setOnPreferenceClickListener(this);
@ -90,7 +87,6 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme @@ -90,7 +87,6 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
cbJsScript.setOnPreferenceChangeListener(this);
cbColorMode.setOnPreferenceChangeListener(this);
cbgooglesuggest.setOnPreferenceChangeListener(this);
cbDrawerTabs.setOnPreferenceChangeListener(this);
mAgentChoice = mPreferenceManager.getUserAgentChoice();
mHomepage = mPreferenceManager.getHomepage();
@ -149,7 +145,6 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme @@ -149,7 +145,6 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
cbAds.setChecked(Constants.FULL_VERSION && mPreferenceManager.getAdBlockEnabled());
cbColorMode.setChecked(mPreferenceManager.getColorModeEnabled());
cbgooglesuggest.setChecked(mPreferenceManager.getGoogleSearchSuggestionsEnabled());
cbDrawerTabs.setChecked(mPreferenceManager.getShowTabsInDrawer(true));
}
private void searchUrlPicker() {
@ -543,7 +538,7 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme @@ -543,7 +538,7 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
public boolean onPreferenceChange(@NonNull Preference preference, Object newValue) {
boolean checked = false;
if (newValue instanceof Boolean) {
checked = (Boolean) newValue;
checked = Boolean.TRUE.equals(newValue);
}
switch (preference.getKey()) {
case SETTINGS_FLASH:
@ -574,9 +569,6 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme @@ -574,9 +569,6 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
case SETTINGS_GOOGLESUGGESTIONS:
mPreferenceManager.setGoogleSearchSuggestionsEnabled(checked);
return true;
case SETTINGS_DRAWERTABS:
mPreferenceManager.setShowTabsInDrawer(checked);
return true;
default:
return false;
}

9
app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java

@ -54,6 +54,7 @@ public class PreferenceManager { @@ -54,6 +54,7 @@ public class PreferenceManager {
public static final String SHOW_TABS_IN_DRAWER = "showTabsInDrawer";
public static final String DO_NOT_TRACK = "doNotTrack";
public static final String IDENTIFYING_HEADERS = "removeIdentifyingHeaders";
public static final String SWAP_BOOKMARKS_AND_TABS = "swapBookmarksAndTabs";
public static final String USE_PROXY = "useProxy";
public static final String PROXY_CHOICE = "proxyChoice";
@ -74,6 +75,14 @@ public class PreferenceManager { @@ -74,6 +75,14 @@ public class PreferenceManager {
mPrefs = context.getSharedPreferences(PREFERENCES, 0);
}
public boolean getBookmarksAndTabsSwapped() {
return mPrefs.getBoolean(Name.SWAP_BOOKMARKS_AND_TABS, false);
}
public void setBookmarkAndTabsSwapped(boolean swap) {
putBoolean(Name.SWAP_BOOKMARKS_AND_TABS, swap);
}
public boolean getAdBlockEnabled() {
return mPrefs.getBoolean(Name.BLOCK_ADS, false);
}

5
app/src/main/res/values/strings.xml

@ -225,10 +225,11 @@ @@ -225,10 +225,11 @@
<string name="dialog_folder">What would you like to do with this folder?</string>
<string name="clear_web_storage">Clear Web Storage</string>
<string name="clear_web_storage_exit">Clear web storage on exit</string>
<string name="message_web_storage_cleared">Web Storage Cleared</string>
<string name="message_web_storage_cleared">Web storage cleared</string>
<string name="hosts_source">Hosts File Ad Blocking Source</string>
<string name="settings_adblock">Ad Block Settings</string>
<string name="tabs_in_drawer">Show tabs in Navigation Drawer</string>
<string name="tabs_in_drawer">Show tabs in navigation drawer</string>
<string name="swap_bookmarks_and_tabs">Swap bookmark and tab drawers</string>
<string name="do_not_track">Request \'Do Not Track\'</string>
<string name="remove_identifying_headers">Remove Identifying Headers</string>
<string name="action_add_to_homescreen">Add to Homescreen</string>

26
app/src/main/res/xml/preference_display.xml

@ -2,33 +2,41 @@ @@ -2,33 +2,41 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/settings_display">
<CheckBoxPreference
android:defaultValue="true"
android:key="cb_drawertabs"
android:title="@string/tabs_in_drawer"/>
<CheckBoxPreference
android:defaultValue="true"
android:key="cb_swapdrawers"
android:title="@string/swap_bookmarks_and_tabs"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="fullScreenOption"
android:title="@string/fullScreenOption" />
android:title="@string/fullScreenOption"/>
<CheckBoxPreference
android:defaultValue="true"
android:key="fullscreen"
android:title="@string/fullscreen" />
android:title="@string/fullscreen"/>
<CheckBoxPreference
android:defaultValue="true"
android:key="wideViewPort"
android:title="@string/wideViewPort"
android:summary="@string/recommended" />
android:summary="@string/recommended"
android:title="@string/wideViewPort"/>
<CheckBoxPreference
android:defaultValue="true"
android:key="overViewMode"
android:title="@string/overViewMode"
android:summary="@string/recommended" />
android:summary="@string/recommended"
android:title="@string/overViewMode"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="text_reflow"
android:title="@string/reflow" />
android:title="@string/reflow"/>
<Preference
android:key="app_theme"
android:title="@string/theme" />
android:title="@string/theme"/>
<Preference
android:key="text_size"
android:title="@string/title_text_size" />
android:title="@string/title_text_size"/>
</PreferenceCategory>
</PreferenceScreen>

4
app/src/main/res/xml/preference_general.xml

@ -2,10 +2,6 @@ @@ -2,10 +2,6 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/settings_general">
<CheckBoxPreference
android:defaultValue="true"
android:key="cb_drawertabs"
android:title="@string/tabs_in_drawer" />
<CheckBoxPreference
android:defaultValue="false"
android:key="cb_flash"

Loading…
Cancel
Save