Browse Source

PreferenceManager injected

master
Stefano Pacifici 9 years ago
parent
commit
5c2cf07e20
  1. 2
      app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java
  2. 15
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  3. 10
      app/src/main/java/acr/browser/lightning/activity/IncognitoActivity.java
  4. 12
      app/src/main/java/acr/browser/lightning/activity/MainActivity.java
  5. 3
      app/src/main/java/acr/browser/lightning/activity/ReadingActivity.java
  6. 3
      app/src/main/java/acr/browser/lightning/activity/TabsManager.java
  7. 8
      app/src/main/java/acr/browser/lightning/activity/ThemableBrowserActivity.java
  8. 5
      app/src/main/java/acr/browser/lightning/activity/ThemableSettingsActivity.java
  9. 6
      app/src/main/java/acr/browser/lightning/app/AppComponent.java
  10. 5
      app/src/main/java/acr/browser/lightning/constant/StartPage.java
  11. 3
      app/src/main/java/acr/browser/lightning/download/DownloadHandler.java
  12. 39
      app/src/main/java/acr/browser/lightning/fragment/AdvancedSettingsFragment.java
  13. 4
      app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java
  14. 40
      app/src/main/java/acr/browser/lightning/fragment/DisplaySettingsFragment.java
  15. 104
      app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java
  16. 27
      app/src/main/java/acr/browser/lightning/fragment/LightningPreferenceFragment.java
  17. 34
      app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java
  18. 1
      app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java
  19. 5
      app/src/main/java/acr/browser/lightning/object/SearchAdapter.java
  20. 18
      app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java
  21. 5
      app/src/main/java/acr/browser/lightning/utils/AdBlock.java
  22. 8
      app/src/main/java/acr/browser/lightning/view/LightningView.java

2
app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java

@ -28,7 +28,7 @@ public class ProxyUtils {
private static ProxyUtils mInstance; private static ProxyUtils mInstance;
private ProxyUtils(Context context) { private ProxyUtils(Context context) {
mPreferences = PreferenceManager.getInstance(); mPreferences = BrowserApp.getAppComponent().getPreferenceManager();
mI2PHelper = new I2PAndroidHelper(context.getApplicationContext()); mI2PHelper = new I2PAndroidHelper(context.getApplicationContext());
} }

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

@ -169,7 +169,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
// Storage // Storage
private HistoryDatabase mHistoryDatabase; private HistoryDatabase mHistoryDatabase;
private PreferenceManager mPreferences;
// The singleton BookmarkManager // The singleton BookmarkManager
@Inject @Inject
@ -188,6 +188,9 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
@Inject @Inject
TabsManager tabsManager; TabsManager tabsManager;
@Inject
PreferenceManager mPreferences;
// Image // Image
private Bitmap mWebpageBitmap; private Bitmap mWebpageBitmap;
private final ColorDrawable mBackground = new ColorDrawable(); private final ColorDrawable mBackground = new ColorDrawable();
@ -207,7 +210,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
public abstract boolean isIncognito(); public abstract boolean isIncognito();
abstract void initializeTabs(); // abstract void initializeTabs();
abstract void closeActivity(); abstract void closeActivity();
@ -229,7 +232,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar(); ActionBar actionBar = getSupportActionBar();
mPreferences = PreferenceManager.getInstance();
//TODO make sure dark theme flag gets set correctly //TODO make sure dark theme flag gets set correctly
mDarkTheme = mPreferences.getUseTheme() != 0 || isIncognito(); mDarkTheme = mPreferences.getUseTheme() != 0 || isIncognito();
mIconColor = mDarkTheme ? ThemeUtils.getIconDarkThemeColor(this) : ThemeUtils.getIconLightThemeColor(this); mIconColor = mDarkTheme ? ThemeUtils.getIconDarkThemeColor(this) : ThemeUtils.getIconLightThemeColor(this);
@ -356,7 +358,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath()); WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath());
} }
initializeTabs(); // initializeTabs();
mProxyUtils.checkForProxy(this); mProxyUtils.checkForProxy(this);
} }
@ -565,6 +567,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
} }
} }
/* TODO !!!! THIS MUST BY RESTORED ASAP !!!!
void restoreOrNewTab() { void restoreOrNewTab() {
mIdGenerator = 0; mIdGenerator = 0;
@ -601,13 +604,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
newTab(url, true); newTab(url, true);
} }
} }
*/
private void initializePreferences() { private void initializePreferences() {
final LightningView currentView = tabsManager.getCurrentTab(); final LightningView currentView = tabsManager.getCurrentTab();
final WebView currentWebView = currentView.getWebView(); final WebView currentWebView = currentView.getWebView();
if (mPreferences == null) {
mPreferences = PreferenceManager.getInstance();
}
mFullScreen = mPreferences.getFullScreenEnabled(); mFullScreen = mPreferences.getFullScreenEnabled();
mColorMode = mPreferences.getColorModeEnabled(); mColorMode = mPreferences.getColorModeEnabled();
mColorMode &= !mDarkTheme; mColorMode &= !mDarkTheme;

10
app/src/main/java/acr/browser/lightning/activity/IncognitoActivity.java

@ -18,13 +18,13 @@ public class IncognitoActivity extends BrowserActivity {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
CookieSyncManager.createInstance(this); CookieSyncManager.createInstance(this);
} }
cookieManager.setAcceptCookie(PreferenceManager.getInstance().getIncognitoCookiesEnabled()); cookieManager.setAcceptCookie(mPreferences.getIncognitoCookiesEnabled());
} }
@Override // @Override
public synchronized void initializeTabs() { // public synchronized void initializeTabs() {
newTab(null, true); // newTab(null, true);
} // }
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {

12
app/src/main/java/acr/browser/lightning/activity/MainActivity.java

@ -18,14 +18,14 @@ public class MainActivity extends BrowserActivity {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
CookieSyncManager.createInstance(this); CookieSyncManager.createInstance(this);
} }
cookieManager.setAcceptCookie(PreferenceManager.getInstance().getCookiesEnabled()); cookieManager.setAcceptCookie(mPreferences.getCookiesEnabled());
} }
@Override // @Override
public synchronized void initializeTabs() { // public synchronized void initializeTabs() {
restoreOrNewTab(); // // restoreOrNewTab();
// if incognito mode use newTab(null, true); instead // // if incognito mode use newTab(null, true); instead
} // }
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {

3
app/src/main/java/acr/browser/lightning/activity/ReadingActivity.java

@ -22,6 +22,7 @@ import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView; import android.widget.TextView;
import acr.browser.lightning.R; import acr.browser.lightning.R;
import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.constant.Constants; import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.reading.HtmlFetcher; import acr.browser.lightning.reading.HtmlFetcher;
@ -49,7 +50,7 @@ public class ReadingActivity extends AppCompatActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
overridePendingTransition(R.anim.slide_in_from_right, R.anim.fade_out_scale); overridePendingTransition(R.anim.slide_in_from_right, R.anim.fade_out_scale);
mPreferences = PreferenceManager.getInstance(); mPreferences = BrowserApp.getAppComponent().getPreferenceManager();
mInvert = mPreferences.getInvertColors(); mInvert = mPreferences.getInvertColors();
final int color; final int color;
if (mInvert) { if (mInvert) {

3
app/src/main/java/acr/browser/lightning/activity/TabsManager.java

@ -12,6 +12,7 @@ import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import acr.browser.lightning.controller.BrowserController; import acr.browser.lightning.controller.BrowserController;
import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.view.LightningView; import acr.browser.lightning.view.LightningView;
/** /**
@ -25,7 +26,7 @@ public class TabsManager {
private LightningView mCurrentTab; private LightningView mCurrentTab;
@Inject @Inject
public TabsManager() { public TabsManager(final Context context, final PreferenceManager preferenceManager) {
} }
/** /**

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

@ -15,8 +15,8 @@ public abstract class ThemableBrowserActivity extends AppCompatActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
mTheme = PreferenceManager.getInstance().getUseTheme(); mTheme = 0; //PreferenceManager.getInstance().getUseTheme();
mShowTabsInDrawer = PreferenceManager.getInstance().getShowTabsInDrawer(!isTablet()); mShowTabsInDrawer = false; // PreferenceManager.getInstance().getShowTabsInDrawer(!isTablet());
// set the theme // set the theme
if (mTheme == 1) { if (mTheme == 1) {
@ -30,8 +30,8 @@ public abstract class ThemableBrowserActivity extends AppCompatActivity {
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
int theme = PreferenceManager.getInstance().getUseTheme(); int theme = 0; // PreferenceManager.getInstance().getUseTheme();
boolean drawerTabs = PreferenceManager.getInstance().getShowTabsInDrawer(!isTablet()); boolean drawerTabs = false; // PreferenceManager.getInstance().getShowTabsInDrawer(!isTablet());
if (theme != mTheme || mShowTabsInDrawer != drawerTabs) { if (theme != mTheme || mShowTabsInDrawer != drawerTabs) {
restart(); restart();
} }

5
app/src/main/java/acr/browser/lightning/activity/ThemableSettingsActivity.java

@ -4,6 +4,7 @@ import android.graphics.drawable.ColorDrawable;
import android.os.Bundle; import android.os.Bundle;
import acr.browser.lightning.R; import acr.browser.lightning.R;
import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.utils.ThemeUtils; import acr.browser.lightning.utils.ThemeUtils;
@ -13,7 +14,7 @@ public abstract class ThemableSettingsActivity extends AppCompatPreferenceActivi
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
mTheme = PreferenceManager.getInstance().getUseTheme(); mTheme = BrowserApp.getAppComponent().getPreferenceManager().getUseTheme();
// set the theme // set the theme
if (mTheme == 0) { if (mTheme == 0) {
@ -32,7 +33,7 @@ public abstract class ThemableSettingsActivity extends AppCompatPreferenceActivi
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
if (PreferenceManager.getInstance().getUseTheme() != mTheme) { if (BrowserApp.getAppComponent().getPreferenceManager().getUseTheme() != mTheme) {
restart(); restart();
} }
} }

6
app/src/main/java/acr/browser/lightning/app/AppComponent.java

@ -7,8 +7,10 @@ import acr.browser.lightning.constant.BookmarkPage;
import acr.browser.lightning.dialog.BookmarksDialogBuilder; import acr.browser.lightning.dialog.BookmarksDialogBuilder;
import acr.browser.lightning.fragment.BookmarkSettingsFragment; import acr.browser.lightning.fragment.BookmarkSettingsFragment;
import acr.browser.lightning.fragment.BookmarksFragment; import acr.browser.lightning.fragment.BookmarksFragment;
import acr.browser.lightning.fragment.LightningPreferenceFragment;
import acr.browser.lightning.fragment.TabsFragment; import acr.browser.lightning.fragment.TabsFragment;
import acr.browser.lightning.object.SearchAdapter; import acr.browser.lightning.object.SearchAdapter;
import acr.browser.lightning.preference.PreferenceManager;
import dagger.Component; import dagger.Component;
/** /**
@ -31,4 +33,8 @@ public interface AppComponent {
void inject(BookmarkPage bookmarkPage); void inject(BookmarkPage bookmarkPage);
void inject(TabsFragment fragment); void inject(TabsFragment fragment);
PreferenceManager getPreferenceManager();
void inject(LightningPreferenceFragment fragment);
} }

5
app/src/main/java/acr/browser/lightning/constant/StartPage.java

@ -57,11 +57,12 @@ public class StartPage {
StringBuilder homepageBuilder = new StringBuilder(StartPage.HEAD); StringBuilder homepageBuilder = new StringBuilder(StartPage.HEAD);
String icon; String icon;
String searchUrl; String searchUrl;
switch (PreferenceManager.getInstance().getSearchChoice()) { final PreferenceManager preferenceManager = BrowserApp.getAppComponent().getPreferenceManager();
switch (preferenceManager.getSearchChoice()) {
case 0: case 0:
// CUSTOM SEARCH // CUSTOM SEARCH
icon = "file:///android_asset/lightning.png"; icon = "file:///android_asset/lightning.png";
searchUrl = PreferenceManager.getInstance().getSearchUrl(); searchUrl = preferenceManager.getSearchUrl();
break; break;
case 1: case 1:
// GOOGLE_SEARCH; // GOOGLE_SEARCH;

3
app/src/main/java/acr/browser/lightning/download/DownloadHandler.java

@ -20,6 +20,7 @@ import android.webkit.CookieManager;
import android.webkit.URLUtil; import android.webkit.URLUtil;
import acr.browser.lightning.R; import acr.browser.lightning.R;
import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.utils.Utils; import acr.browser.lightning.utils.Utils;
@ -170,7 +171,7 @@ public class DownloadHandler {
// or, should it be set to one of several Environment.DIRECTORY* dirs // or, should it be set to one of several Environment.DIRECTORY* dirs
// depending on mimetype? // depending on mimetype?
String location = PreferenceManager.getInstance().getDownloadDirectory(); String location = BrowserApp.getAppComponent().getPreferenceManager().getDownloadDirectory();
request.setDestinationInExternalPublicDir(location, filename); request.setDestinationInExternalPublicDir(location, filename);
// let this downloaded file be scanned by MediaScanner - so that it can // let this downloaded file be scanned by MediaScanner - so that it can
// show up in Gallery app, for example. // show up in Gallery app, for example.

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

@ -18,7 +18,7 @@ import acr.browser.lightning.R;
import acr.browser.lightning.constant.Constants; import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.preference.PreferenceManager;
public class AdvancedSettingsFragment extends PreferenceFragment implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener { public class AdvancedSettingsFragment extends LightningPreferenceFragment implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener {
private static final String SETTINGS_NEWWINDOW = "allow_new_window"; private static final String SETTINGS_NEWWINDOW = "allow_new_window";
private static final String SETTINGS_ENABLECOOKIES = "allow_cookies"; private static final String SETTINGS_ENABLECOOKIES = "allow_cookies";
@ -29,7 +29,6 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref
private static final String SETTINGS_TEXTENCODING = "text_encoding"; private static final String SETTINGS_TEXTENCODING = "text_encoding";
private Activity mActivity; private Activity mActivity;
private PreferenceManager mPreferences;
private CheckBoxPreference cbAllowPopups, cbenablecookies, cbcookiesInkognito, cbrestoreTabs; private CheckBoxPreference cbAllowPopups, cbenablecookies, cbcookiesInkognito, cbrestoreTabs;
private Preference renderingmode, urlcontent, textEncoding; private Preference renderingmode, urlcontent, textEncoding;
private CharSequence[] mUrlOptions; private CharSequence[] mUrlOptions;
@ -46,8 +45,6 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref
} }
private void initPrefs() { private void initPrefs() {
// mPreferences storage
mPreferences = PreferenceManager.getInstance();
renderingmode = findPreference(SETTINGS_RENDERINGMODE); renderingmode = findPreference(SETTINGS_RENDERINGMODE);
textEncoding = findPreference(SETTINGS_TEXTENCODING); textEncoding = findPreference(SETTINGS_TEXTENCODING);
@ -65,7 +62,7 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref
cbcookiesInkognito.setOnPreferenceChangeListener(this); cbcookiesInkognito.setOnPreferenceChangeListener(this);
cbrestoreTabs.setOnPreferenceChangeListener(this); cbrestoreTabs.setOnPreferenceChangeListener(this);
switch (mPreferences.getRenderingMode()) { switch (preferenceManager.getRenderingMode()) {
case 0: case 0:
renderingmode.setSummary(getString(R.string.name_normal)); renderingmode.setSummary(getString(R.string.name_normal));
break; break;
@ -80,16 +77,16 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref
break; break;
} }
textEncoding.setSummary(mPreferences.getTextEncoding()); textEncoding.setSummary(preferenceManager.getTextEncoding());
mUrlOptions = getResources().getStringArray(R.array.url_content_array); mUrlOptions = getResources().getStringArray(R.array.url_content_array);
int option = mPreferences.getUrlBoxContentChoice(); int option = preferenceManager.getUrlBoxContentChoice();
urlcontent.setSummary(mUrlOptions[option]); urlcontent.setSummary(mUrlOptions[option]);
cbAllowPopups.setChecked(mPreferences.getPopupsEnabled()); cbAllowPopups.setChecked(preferenceManager.getPopupsEnabled());
cbenablecookies.setChecked(mPreferences.getCookiesEnabled()); cbenablecookies.setChecked(preferenceManager.getCookiesEnabled());
cbcookiesInkognito.setChecked(mPreferences.getIncognitoCookiesEnabled()); cbcookiesInkognito.setChecked(preferenceManager.getIncognitoCookiesEnabled());
cbrestoreTabs.setChecked(mPreferences.getRestoreLostTabsEnabled()); cbrestoreTabs.setChecked(preferenceManager.getRestoreLostTabsEnabled());
} }
@Override @Override
@ -114,19 +111,19 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref
// switch preferences // switch preferences
switch (preference.getKey()) { switch (preference.getKey()) {
case SETTINGS_NEWWINDOW: case SETTINGS_NEWWINDOW:
mPreferences.setPopupsEnabled((Boolean) newValue); preferenceManager.setPopupsEnabled((Boolean) newValue);
cbAllowPopups.setChecked((Boolean) newValue); cbAllowPopups.setChecked((Boolean) newValue);
return true; return true;
case SETTINGS_ENABLECOOKIES: case SETTINGS_ENABLECOOKIES:
mPreferences.setCookiesEnabled((Boolean) newValue); preferenceManager.setCookiesEnabled((Boolean) newValue);
cbenablecookies.setChecked((Boolean) newValue); cbenablecookies.setChecked((Boolean) newValue);
return true; return true;
case SETTINGS_COOKIESINKOGNITO: case SETTINGS_COOKIESINKOGNITO:
mPreferences.setIncognitoCookiesEnabled((Boolean) newValue); preferenceManager.setIncognitoCookiesEnabled((Boolean) newValue);
cbcookiesInkognito.setChecked((Boolean) newValue); cbcookiesInkognito.setChecked((Boolean) newValue);
return true; return true;
case SETTINGS_RESTORETABS: case SETTINGS_RESTORETABS:
mPreferences.setRestoreLostTabsEnabled((Boolean) newValue); preferenceManager.setRestoreLostTabsEnabled((Boolean) newValue);
cbrestoreTabs.setChecked((Boolean) newValue); cbrestoreTabs.setChecked((Boolean) newValue);
return true; return true;
default: default:
@ -142,12 +139,12 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref
mActivity.getString(R.string.name_grayscale), mActivity.getString(R.string.name_grayscale),
mActivity.getString(R.string.name_inverted_grayscale)}; mActivity.getString(R.string.name_inverted_grayscale)};
int n = mPreferences.getRenderingMode(); int n = preferenceManager.getRenderingMode();
picker.setSingleChoiceItems(chars, n, new DialogInterface.OnClickListener() { picker.setSingleChoiceItems(chars, n, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
mPreferences.setRenderingMode(which); preferenceManager.setRenderingMode(which);
switch (which) { switch (which) {
case 0: case 0:
renderingmode.setSummary(getString(R.string.name_normal)); renderingmode.setSummary(getString(R.string.name_normal));
@ -178,12 +175,12 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref
AlertDialog.Builder picker = new AlertDialog.Builder(mActivity); AlertDialog.Builder picker = new AlertDialog.Builder(mActivity);
picker.setTitle(getResources().getString(R.string.text_encoding)); picker.setTitle(getResources().getString(R.string.text_encoding));
final List<String> textEncodingList = Arrays.asList(Constants.TEXT_ENCODINGS); final List<String> textEncodingList = Arrays.asList(Constants.TEXT_ENCODINGS);
int n = textEncodingList.indexOf(mPreferences.getTextEncoding()); int n = textEncodingList.indexOf(preferenceManager.getTextEncoding());
picker.setSingleChoiceItems(Constants.TEXT_ENCODINGS, n, new DialogInterface.OnClickListener() { picker.setSingleChoiceItems(Constants.TEXT_ENCODINGS, n, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
mPreferences.setTextEncoding(Constants.TEXT_ENCODINGS[which]); preferenceManager.setTextEncoding(Constants.TEXT_ENCODINGS[which]);
textEncoding.setSummary(Constants.TEXT_ENCODINGS[which]); textEncoding.setSummary(Constants.TEXT_ENCODINGS[which]);
} }
}); });
@ -201,12 +198,12 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref
AlertDialog.Builder picker = new AlertDialog.Builder(mActivity); AlertDialog.Builder picker = new AlertDialog.Builder(mActivity);
picker.setTitle(getResources().getString(R.string.url_contents)); picker.setTitle(getResources().getString(R.string.url_contents));
int n = mPreferences.getUrlBoxContentChoice(); int n = preferenceManager.getUrlBoxContentChoice();
picker.setSingleChoiceItems(mUrlOptions, n, new DialogInterface.OnClickListener() { picker.setSingleChoiceItems(mUrlOptions, n, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
mPreferences.setUrlBoxContentChoice(which); preferenceManager.setUrlBoxContentChoice(which);
if (which < mUrlOptions.length) { if (which < mUrlOptions.length) {
urlcontent.setSummary(mUrlOptions[which]); urlcontent.setSummary(mUrlOptions[which]);
} }

4
app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java

@ -64,6 +64,9 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
@Inject @Inject
BookmarksDialogBuilder bookmarksDialogBuilder; BookmarksDialogBuilder bookmarksDialogBuilder;
@Inject
PreferenceManager preferenceManager;
// Adapter // Adapter
private BookmarkViewAdapter mBookmarkAdapter; private BookmarkViewAdapter mBookmarkAdapter;
@ -151,7 +154,6 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
// TODO this code depend way too much on BrowserActivity // TODO this code depend way too much on BrowserActivity
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
final BrowserActivity activity = (BrowserActivity) getActivity(); final BrowserActivity activity = (BrowserActivity) getActivity();
final PreferenceManager preferenceManager =PreferenceManager.getInstance();
boolean darkTheme = preferenceManager.getUseTheme() != 0 || activity.isIncognito(); boolean darkTheme = preferenceManager.getUseTheme() != 0 || activity.isIncognito();
mWebpageBitmap = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_webpage, darkTheme); mWebpageBitmap = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_webpage, darkTheme);
mFolderBitmap = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_folder, darkTheme); mFolderBitmap = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_folder, darkTheme);

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

@ -21,7 +21,7 @@ import android.widget.TextView;
import acr.browser.lightning.R; import acr.browser.lightning.R;
import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.preference.PreferenceManager;
public class DisplaySettingsFragment extends PreferenceFragment implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener { public class DisplaySettingsFragment extends LightningPreferenceFragment implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener {
private static final String SETTINGS_HIDESTATUSBAR = "fullScreenOption"; private static final String SETTINGS_HIDESTATUSBAR = "fullScreenOption";
private static final String SETTINGS_FULLSCREEN = "fullscreen"; private static final String SETTINGS_FULLSCREEN = "fullscreen";
@ -38,7 +38,6 @@ public class DisplaySettingsFragment extends PreferenceFragment implements Prefe
private static final float XSMALL = 10.0f; private static final float XSMALL = 10.0f;
private Activity mActivity; private Activity mActivity;
private PreferenceManager mPreferences;
private CheckBoxPreference cbstatus, cbfullscreen, cbviewport, cboverview, cbreflow; private CheckBoxPreference cbstatus, cbfullscreen, cbviewport, cboverview, cbreflow;
private Preference theme; private Preference theme;
private String[] mThemeOptions; private String[] mThemeOptions;
@ -57,9 +56,8 @@ public class DisplaySettingsFragment extends PreferenceFragment implements Prefe
private void initPrefs() { private void initPrefs() {
// mPreferences storage // mPreferences storage
mPreferences = PreferenceManager.getInstance();
mThemeOptions = this.getResources().getStringArray(R.array.themes); mThemeOptions = this.getResources().getStringArray(R.array.themes);
mCurrentTheme = mPreferences.getUseTheme(); mCurrentTheme = preferenceManager.getUseTheme();
theme = findPreference(SETTINGS_THEME); theme = findPreference(SETTINGS_THEME);
Preference textsize = findPreference(SETTINGS_TEXTSIZE); Preference textsize = findPreference(SETTINGS_TEXTSIZE);
@ -77,13 +75,13 @@ public class DisplaySettingsFragment extends PreferenceFragment implements Prefe
cboverview.setOnPreferenceChangeListener(this); cboverview.setOnPreferenceChangeListener(this);
cbreflow.setOnPreferenceChangeListener(this); cbreflow.setOnPreferenceChangeListener(this);
cbstatus.setChecked(mPreferences.getHideStatusBarEnabled()); cbstatus.setChecked(preferenceManager.getHideStatusBarEnabled());
cbfullscreen.setChecked(mPreferences.getFullScreenEnabled()); cbfullscreen.setChecked(preferenceManager.getFullScreenEnabled());
cbviewport.setChecked(mPreferences.getUseWideViewportEnabled()); cbviewport.setChecked(preferenceManager.getUseWideViewportEnabled());
cboverview.setChecked(mPreferences.getOverviewModeEnabled()); cboverview.setChecked(preferenceManager.getOverviewModeEnabled());
cbreflow.setChecked(mPreferences.getTextReflowEnabled()); cbreflow.setChecked(preferenceManager.getTextReflowEnabled());
theme.setSummary(mThemeOptions[mPreferences.getUseTheme()]); theme.setSummary(mThemeOptions[preferenceManager.getUseTheme()]);
} }
@Override @Override
@ -105,23 +103,23 @@ public class DisplaySettingsFragment extends PreferenceFragment implements Prefe
// switch preferences // switch preferences
switch (preference.getKey()) { switch (preference.getKey()) {
case SETTINGS_HIDESTATUSBAR: case SETTINGS_HIDESTATUSBAR:
mPreferences.setHideStatusBarEnabled((Boolean) newValue); preferenceManager.setHideStatusBarEnabled((Boolean) newValue);
cbstatus.setChecked((Boolean) newValue); cbstatus.setChecked((Boolean) newValue);
return true; return true;
case SETTINGS_FULLSCREEN: case SETTINGS_FULLSCREEN:
mPreferences.setFullScreenEnabled((Boolean) newValue); preferenceManager.setFullScreenEnabled((Boolean) newValue);
cbfullscreen.setChecked((Boolean) newValue); cbfullscreen.setChecked((Boolean) newValue);
return true; return true;
case SETTINGS_VIEWPORT: case SETTINGS_VIEWPORT:
mPreferences.setUseWideViewportEnabled((Boolean) newValue); preferenceManager.setUseWideViewportEnabled((Boolean) newValue);
cbviewport.setChecked((Boolean) newValue); cbviewport.setChecked((Boolean) newValue);
return true; return true;
case SETTINGS_OVERVIEWMODE: case SETTINGS_OVERVIEWMODE:
mPreferences.setOverviewModeEnabled((Boolean) newValue); preferenceManager.setOverviewModeEnabled((Boolean) newValue);
cboverview.setChecked((Boolean) newValue); cboverview.setChecked((Boolean) newValue);
return true; return true;
case SETTINGS_REFLOW: case SETTINGS_REFLOW:
mPreferences.setTextReflowEnabled((Boolean) newValue); preferenceManager.setTextReflowEnabled((Boolean) newValue);
cbreflow.setChecked((Boolean) newValue); cbreflow.setChecked((Boolean) newValue);
return true; return true;
default: default:
@ -157,14 +155,14 @@ public class DisplaySettingsFragment extends PreferenceFragment implements Prefe
}); });
final int MAX = 5; final int MAX = 5;
bar.setMax(MAX); bar.setMax(MAX);
bar.setProgress(MAX - mPreferences.getTextSize()); bar.setProgress(MAX - preferenceManager.getTextSize());
builder.setView(view); builder.setView(view);
builder.setTitle(R.string.title_text_size); builder.setTitle(R.string.title_text_size);
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface arg0, int arg1) { public void onClick(DialogInterface arg0, int arg1) {
mPreferences.setTextSize(MAX - bar.getProgress()); preferenceManager.setTextSize(MAX - bar.getProgress());
} }
}); });
@ -194,12 +192,12 @@ public class DisplaySettingsFragment extends PreferenceFragment implements Prefe
AlertDialog.Builder picker = new AlertDialog.Builder(mActivity); AlertDialog.Builder picker = new AlertDialog.Builder(mActivity);
picker.setTitle(getResources().getString(R.string.theme)); picker.setTitle(getResources().getString(R.string.theme));
int n = mPreferences.getUseTheme(); int n = preferenceManager.getUseTheme();
picker.setSingleChoiceItems(mThemeOptions, n, new DialogInterface.OnClickListener() { picker.setSingleChoiceItems(mThemeOptions, n, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
mPreferences.setUseTheme(which); preferenceManager.setUseTheme(which);
if (which < mThemeOptions.length) { if (which < mThemeOptions.length) {
theme.setSummary(mThemeOptions[which]); theme.setSummary(mThemeOptions[which]);
} }
@ -210,7 +208,7 @@ public class DisplaySettingsFragment extends PreferenceFragment implements Prefe
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if (mCurrentTheme != mPreferences.getUseTheme()) { if (mCurrentTheme != preferenceManager.getUseTheme()) {
getActivity().onBackPressed(); getActivity().onBackPressed();
} }
} }
@ -218,7 +216,7 @@ public class DisplaySettingsFragment extends PreferenceFragment implements Prefe
picker.setOnCancelListener(new DialogInterface.OnCancelListener() { picker.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override @Override
public void onCancel(DialogInterface dialog) { public void onCancel(DialogInterface dialog) {
if (mCurrentTheme != mPreferences.getUseTheme()) { if (mCurrentTheme != preferenceManager.getUseTheme()) {
getActivity().onBackPressed(); getActivity().onBackPressed();
} }
} }

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

@ -28,7 +28,7 @@ import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.utils.ProxyUtils; import acr.browser.lightning.utils.ProxyUtils;
import acr.browser.lightning.utils.Utils; import acr.browser.lightning.utils.Utils;
public class GeneralSettingsFragment extends PreferenceFragment implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener { public class GeneralSettingsFragment extends LightningPreferenceFragment implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener {
private static final String SETTINGS_PROXY = "proxy"; private static final String SETTINGS_PROXY = "proxy";
private static final String SETTINGS_FLASH = "cb_flash"; private static final String SETTINGS_FLASH = "cb_flash";
@ -45,7 +45,6 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
private Activity mActivity; private Activity mActivity;
private static final int API = android.os.Build.VERSION.SDK_INT; private static final int API = android.os.Build.VERSION.SDK_INT;
private PreferenceManager mPreferences;
private CharSequence[] mProxyChoices; private CharSequence[] mProxyChoices;
private Preference proxy, useragent, downloadloc, home, searchengine; private Preference proxy, useragent, downloadloc, home, searchengine;
private String mDownloadLocation; private String mDownloadLocation;
@ -65,9 +64,6 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
} }
private void initPrefs() { private void initPrefs() {
// mPreferences storage
mPreferences = PreferenceManager.getInstance();
proxy = findPreference(SETTINGS_PROXY); proxy = findPreference(SETTINGS_PROXY);
useragent = findPreference(SETTINGS_USERAGENT); useragent = findPreference(SETTINGS_USERAGENT);
downloadloc = findPreference(SETTINGS_DOWNLOAD); downloadloc = findPreference(SETTINGS_DOWNLOAD);
@ -95,23 +91,23 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
cbgooglesuggest.setOnPreferenceChangeListener(this); cbgooglesuggest.setOnPreferenceChangeListener(this);
cbDrawerTabs.setOnPreferenceChangeListener(this); cbDrawerTabs.setOnPreferenceChangeListener(this);
mAgentChoice = mPreferences.getUserAgentChoice(); mAgentChoice = preferenceManager.getUserAgentChoice();
mHomepage = mPreferences.getHomepage(); mHomepage = preferenceManager.getHomepage();
mDownloadLocation = mPreferences.getDownloadDirectory(); mDownloadLocation = preferenceManager.getDownloadDirectory();
mProxyChoices = getResources().getStringArray(R.array.proxy_choices_array); mProxyChoices = getResources().getStringArray(R.array.proxy_choices_array);
int choice = mPreferences.getProxyChoice(); int choice = preferenceManager.getProxyChoice();
if (choice == Constants.PROXY_MANUAL) { if (choice == Constants.PROXY_MANUAL) {
proxy.setSummary(mPreferences.getProxyHost() + ':' + mPreferences.getProxyPort()); proxy.setSummary(preferenceManager.getProxyHost() + ':' + preferenceManager.getProxyPort());
} else { } else {
proxy.setSummary(mProxyChoices[choice]); proxy.setSummary(mProxyChoices[choice]);
} }
if (API >= 19) { if (API >= 19) {
mPreferences.setFlashSupport(0); preferenceManager.setFlashSupport(0);
} }
setSearchEngineSummary(mPreferences.getSearchChoice()); setSearchEngineSummary(preferenceManager.getSearchChoice());
downloadloc.setSummary(Constants.EXTERNAL_STORAGE + '/' + mDownloadLocation); downloadloc.setSummary(Constants.EXTERNAL_STORAGE + '/' + mDownloadLocation);
@ -139,9 +135,9 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
useragent.setSummary(getResources().getString(R.string.agent_custom)); useragent.setSummary(getResources().getString(R.string.agent_custom));
} }
int flashNum = mPreferences.getFlashSupport(); int flashNum = preferenceManager.getFlashSupport();
boolean imagesBool = mPreferences.getBlockImagesEnabled(); boolean imagesBool = preferenceManager.getBlockImagesEnabled();
boolean enableJSBool = mPreferences.getJavaScriptEnabled(); boolean enableJSBool = preferenceManager.getJavaScriptEnabled();
proxy.setEnabled(Constants.FULL_VERSION); proxy.setEnabled(Constants.FULL_VERSION);
cbAds.setEnabled(Constants.FULL_VERSION); cbAds.setEnabled(Constants.FULL_VERSION);
@ -150,17 +146,17 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
cbImages.setChecked(imagesBool); cbImages.setChecked(imagesBool);
cbJsScript.setChecked(enableJSBool); cbJsScript.setChecked(enableJSBool);
cbFlash.setChecked(flashNum > 0); cbFlash.setChecked(flashNum > 0);
cbAds.setChecked(Constants.FULL_VERSION && mPreferences.getAdBlockEnabled()); cbAds.setChecked(Constants.FULL_VERSION && preferenceManager.getAdBlockEnabled());
cbColorMode.setChecked(mPreferences.getColorModeEnabled()); cbColorMode.setChecked(preferenceManager.getColorModeEnabled());
cbgooglesuggest.setChecked(mPreferences.getGoogleSearchSuggestionsEnabled()); cbgooglesuggest.setChecked(preferenceManager.getGoogleSearchSuggestionsEnabled());
cbDrawerTabs.setChecked(mPreferences.getShowTabsInDrawer(true)); cbDrawerTabs.setChecked(preferenceManager.getShowTabsInDrawer(true));
} }
private void searchUrlPicker() { private void searchUrlPicker() {
final AlertDialog.Builder urlPicker = new AlertDialog.Builder(mActivity); final AlertDialog.Builder urlPicker = new AlertDialog.Builder(mActivity);
urlPicker.setTitle(getResources().getString(R.string.custom_url)); urlPicker.setTitle(getResources().getString(R.string.custom_url));
final EditText getSearchUrl = new EditText(mActivity); final EditText getSearchUrl = new EditText(mActivity);
String mSearchUrl = mPreferences.getSearchUrl(); String mSearchUrl = preferenceManager.getSearchUrl();
getSearchUrl.setText(mSearchUrl); getSearchUrl.setText(mSearchUrl);
urlPicker.setView(getSearchUrl); urlPicker.setView(getSearchUrl);
urlPicker.setPositiveButton(getResources().getString(R.string.action_ok), urlPicker.setPositiveButton(getResources().getString(R.string.action_ok),
@ -168,7 +164,7 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
String text = getSearchUrl.getText().toString(); String text = getSearchUrl.getText().toString();
mPreferences.setSearchUrl(text); preferenceManager.setSearchUrl(text);
searchengine.setSummary(getResources().getString(R.string.custom_url) + ": " searchengine.setSummary(getResources().getString(R.string.custom_url) + ": "
+ text); + text);
} }
@ -185,7 +181,7 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
mPreferences.setFlashSupport(1); preferenceManager.setFlashSupport(1);
} }
}) })
.setNegativeButton(getResources().getString(R.string.action_auto), .setNegativeButton(getResources().getString(R.string.action_auto),
@ -193,13 +189,13 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
mPreferences.setFlashSupport(2); preferenceManager.setFlashSupport(2);
} }
}).setOnCancelListener(new DialogInterface.OnCancelListener() { }).setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override @Override
public void onCancel(DialogInterface dialog) { public void onCancel(DialogInterface dialog) {
mPreferences.setFlashSupport(0); preferenceManager.setFlashSupport(0);
} }
}); });
@ -210,7 +206,7 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
private void proxyChoicePicker() { private void proxyChoicePicker() {
AlertDialog.Builder picker = new AlertDialog.Builder(mActivity); AlertDialog.Builder picker = new AlertDialog.Builder(mActivity);
picker.setTitle(getResources().getString(R.string.http_proxy)); picker.setTitle(getResources().getString(R.string.http_proxy));
picker.setSingleChoiceItems(mProxyChoices, mPreferences.getProxyChoice(), picker.setSingleChoiceItems(mProxyChoices, preferenceManager.getProxyChoice(),
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
@ -240,7 +236,7 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
break; break;
} }
mPreferences.setProxyChoice(choice); preferenceManager.setProxyChoice(choice);
if (choice < mProxyChoices.length) if (choice < mProxyChoices.length)
proxy.setSummary(mProxyChoices[choice]); proxy.setSummary(mProxyChoices[choice]);
} }
@ -258,8 +254,8 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
filterArray[0] = new InputFilter.LengthFilter(maxCharacters - 1); filterArray[0] = new InputFilter.LengthFilter(maxCharacters - 1);
eProxyPort.setFilters(filterArray); eProxyPort.setFilters(filterArray);
eProxyHost.setText(mPreferences.getProxyHost()); eProxyHost.setText(preferenceManager.getProxyHost());
eProxyPort.setText(Integer.toString(mPreferences.getProxyPort())); eProxyPort.setText(Integer.toString(preferenceManager.getProxyPort()));
new AlertDialog.Builder(mActivity) new AlertDialog.Builder(mActivity)
.setTitle(R.string.manual_proxy) .setTitle(R.string.manual_proxy)
@ -274,10 +270,10 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
// larger than max integer // larger than max integer
proxyPort = Integer.parseInt(eProxyPort.getText().toString()); proxyPort = Integer.parseInt(eProxyPort.getText().toString());
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
proxyPort = mPreferences.getProxyPort(); proxyPort = preferenceManager.getProxyPort();
} }
mPreferences.setProxyHost(proxyHost); preferenceManager.setProxyHost(proxyHost);
mPreferences.setProxyPort(proxyPort); preferenceManager.setProxyPort(proxyPort);
proxy.setSummary(proxyHost + ':' + proxyPort); proxy.setSummary(proxyHost + ':' + proxyPort);
} }
}).show(); }).show();
@ -291,13 +287,13 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
"DuckDuckGo (Privacy)", "DuckDuckGo Lite (Privacy)", "Baidu (Chinese)", "DuckDuckGo (Privacy)", "DuckDuckGo Lite (Privacy)", "Baidu (Chinese)",
"Yandex (Russian)"}; "Yandex (Russian)"};
int n = mPreferences.getSearchChoice(); int n = preferenceManager.getSearchChoice();
picker.setSingleChoiceItems(chars, n, new DialogInterface.OnClickListener() { picker.setSingleChoiceItems(chars, n, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
mPreferences.setSearchChoice(which); preferenceManager.setSearchChoice(which);
setSearchEngineSummary(which); setSearchEngineSummary(which);
} }
}); });
@ -313,7 +309,7 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
private void homepageDialog() { private void homepageDialog() {
AlertDialog.Builder picker = new AlertDialog.Builder(mActivity); AlertDialog.Builder picker = new AlertDialog.Builder(mActivity);
picker.setTitle(getResources().getString(R.string.home)); picker.setTitle(getResources().getString(R.string.home));
mHomepage = mPreferences.getHomepage(); mHomepage = preferenceManager.getHomepage();
int n; int n;
if (mHomepage.contains("about:home")) { if (mHomepage.contains("about:home")) {
n = 1; n = 1;
@ -331,15 +327,15 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
switch (which + 1) { switch (which + 1) {
case 1: case 1:
mPreferences.setHomepage("about:home"); preferenceManager.setHomepage("about:home");
home.setSummary(getResources().getString(R.string.action_homepage)); home.setSummary(getResources().getString(R.string.action_homepage));
break; break;
case 2: case 2:
mPreferences.setHomepage("about:blank"); preferenceManager.setHomepage("about:blank");
home.setSummary(getResources().getString(R.string.action_blank)); home.setSummary(getResources().getString(R.string.action_blank));
break; break;
case 3: case 3:
mPreferences.setHomepage("about:bookmarks"); preferenceManager.setHomepage("about:bookmarks");
home.setSummary(getResources().getString(R.string.action_bookmarks)); home.setSummary(getResources().getString(R.string.action_bookmarks));
break; break;
case 4: case 4:
@ -361,7 +357,7 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
final AlertDialog.Builder homePicker = new AlertDialog.Builder(mActivity); final AlertDialog.Builder homePicker = new AlertDialog.Builder(mActivity);
homePicker.setTitle(getResources().getString(R.string.title_custom_homepage)); homePicker.setTitle(getResources().getString(R.string.title_custom_homepage));
final EditText getHome = new EditText(mActivity); final EditText getHome = new EditText(mActivity);
mHomepage = mPreferences.getHomepage(); mHomepage = preferenceManager.getHomepage();
if (!mHomepage.startsWith("about:")) { if (!mHomepage.startsWith("about:")) {
getHome.setText(mHomepage); getHome.setText(mHomepage);
} else { } else {
@ -373,7 +369,7 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
String text = getHome.getText().toString(); String text = getHome.getText().toString();
mPreferences.setHomepage(text); preferenceManager.setHomepage(text);
home.setSummary(text); home.setSummary(text);
} }
}); });
@ -383,7 +379,7 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
private void downloadLocDialog() { private void downloadLocDialog() {
AlertDialog.Builder picker = new AlertDialog.Builder(mActivity); AlertDialog.Builder picker = new AlertDialog.Builder(mActivity);
picker.setTitle(getResources().getString(R.string.title_download_location)); picker.setTitle(getResources().getString(R.string.title_download_location));
mDownloadLocation = mPreferences.getDownloadDirectory(); mDownloadLocation = preferenceManager.getDownloadDirectory();
int n; int n;
if (mDownloadLocation.contains(Environment.DIRECTORY_DOWNLOADS)) { if (mDownloadLocation.contains(Environment.DIRECTORY_DOWNLOADS)) {
n = 1; n = 1;
@ -397,7 +393,7 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
switch (which + 1) { switch (which + 1) {
case 1: case 1:
mPreferences.setDownloadDirectory(Environment.DIRECTORY_DOWNLOADS); preferenceManager.setDownloadDirectory(Environment.DIRECTORY_DOWNLOADS);
downloadloc.setSummary(Constants.EXTERNAL_STORAGE + '/' downloadloc.setSummary(Constants.EXTERNAL_STORAGE + '/'
+ Environment.DIRECTORY_DOWNLOADS); + Environment.DIRECTORY_DOWNLOADS);
break; break;
@ -419,12 +415,12 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
private void agentDialog() { private void agentDialog() {
AlertDialog.Builder agentPicker = new AlertDialog.Builder(mActivity); AlertDialog.Builder agentPicker = new AlertDialog.Builder(mActivity);
agentPicker.setTitle(getResources().getString(R.string.title_user_agent)); agentPicker.setTitle(getResources().getString(R.string.title_user_agent));
mAgentChoice = mPreferences.getUserAgentChoice(); mAgentChoice = preferenceManager.getUserAgentChoice();
agentPicker.setSingleChoiceItems(R.array.user_agent, mAgentChoice - 1, agentPicker.setSingleChoiceItems(R.array.user_agent, mAgentChoice - 1,
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
mPreferences.setUserAgentChoice(which + 1); preferenceManager.setUserAgentChoice(which + 1);
switch (which + 1) { switch (which + 1) {
case 1: case 1:
useragent.setSummary(getResources().getString(R.string.agent_default)); useragent.setSummary(getResources().getString(R.string.agent_default));
@ -467,7 +463,7 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
String text = getAgent.getText().toString(); String text = getAgent.getText().toString();
mPreferences.setUserAgentString(text); preferenceManager.setUserAgentString(text);
useragent.setSummary(getResources().getString(R.string.agent_custom)); useragent.setSummary(getResources().getString(R.string.agent_custom));
} }
}); });
@ -479,7 +475,7 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
LinearLayout layout = new LinearLayout(mActivity); LinearLayout layout = new LinearLayout(mActivity);
downLocationPicker.setTitle(getResources().getString(R.string.title_download_location)); downLocationPicker.setTitle(getResources().getString(R.string.title_download_location));
final EditText getDownload = new EditText(mActivity); final EditText getDownload = new EditText(mActivity);
getDownload.setText(mPreferences.getDownloadDirectory()); getDownload.setText(preferenceManager.getDownloadDirectory());
int padding = Utils.dpToPx(10); int padding = Utils.dpToPx(10);
@ -507,7 +503,7 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
String text = getDownload.getText().toString(); String text = getDownload.getText().toString();
mPreferences.setDownloadDirectory(text); preferenceManager.setDownloadDirectory(text);
downloadloc.setSummary(Constants.EXTERNAL_STORAGE + '/' + text); downloadloc.setSummary(Constants.EXTERNAL_STORAGE + '/' + text);
} }
}); });
@ -582,37 +578,37 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
if (cbFlash.isChecked()) { if (cbFlash.isChecked()) {
getFlashChoice(); getFlashChoice();
} else { } else {
mPreferences.setFlashSupport(0); preferenceManager.setFlashSupport(0);
} }
if (!Utils.isFlashInstalled(mActivity) && cbFlash.isChecked()) { if (!Utils.isFlashInstalled(mActivity) && cbFlash.isChecked()) {
Utils.createInformativeDialog(mActivity, R.string.title_warning, R.string.dialog_adobe_not_installed); Utils.createInformativeDialog(mActivity, R.string.title_warning, R.string.dialog_adobe_not_installed);
cbFlash.setEnabled(false); cbFlash.setEnabled(false);
mPreferences.setFlashSupport(0); preferenceManager.setFlashSupport(0);
} }
cbFlash.setChecked((Boolean) newValue); cbFlash.setChecked((Boolean) newValue);
return true; return true;
case SETTINGS_ADS: case SETTINGS_ADS:
mPreferences.setAdBlockEnabled((Boolean) newValue); preferenceManager.setAdBlockEnabled((Boolean) newValue);
cbAds.setChecked((Boolean) newValue); cbAds.setChecked((Boolean) newValue);
return true; return true;
case SETTINGS_IMAGES: case SETTINGS_IMAGES:
mPreferences.setBlockImagesEnabled((Boolean) newValue); preferenceManager.setBlockImagesEnabled((Boolean) newValue);
cbImages.setChecked((Boolean) newValue); cbImages.setChecked((Boolean) newValue);
return true; return true;
case SETTINGS_JAVASCRIPT: case SETTINGS_JAVASCRIPT:
mPreferences.setJavaScriptEnabled((Boolean) newValue); preferenceManager.setJavaScriptEnabled((Boolean) newValue);
cbJsScript.setChecked((Boolean) newValue); cbJsScript.setChecked((Boolean) newValue);
return true; return true;
case SETTINGS_COLORMODE: case SETTINGS_COLORMODE:
mPreferences.setColorModeEnabled((Boolean) newValue); preferenceManager.setColorModeEnabled((Boolean) newValue);
cbColorMode.setChecked((Boolean) newValue); cbColorMode.setChecked((Boolean) newValue);
return true; return true;
case SETTINGS_GOOGLESUGGESTIONS: case SETTINGS_GOOGLESUGGESTIONS:
mPreferences.setGoogleSearchSuggestionsEnabled((Boolean) newValue); preferenceManager.setGoogleSearchSuggestionsEnabled((Boolean) newValue);
cbgooglesuggest.setChecked((Boolean) newValue); cbgooglesuggest.setChecked((Boolean) newValue);
return true; return true;
case SETTINGS_DRAWERTABS: case SETTINGS_DRAWERTABS:
mPreferences.setShowTabsInDrawer((Boolean) newValue); preferenceManager.setShowTabsInDrawer((Boolean) newValue);
cbDrawerTabs.setChecked((Boolean) newValue); cbDrawerTabs.setChecked((Boolean) newValue);
default: default:
return false; return false;

27
app/src/main/java/acr/browser/lightning/fragment/LightningPreferenceFragment.java

@ -0,0 +1,27 @@
package acr.browser.lightning.fragment;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import javax.inject.Inject;
import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.preference.PreferenceManager;
/**
* Simplify {@link PreferenceManager} inject in all the PreferenceFragments
*
* @author Stefano Pacifici
* @date 2015/09/16
*/
public class LightningPreferenceFragment extends PreferenceFragment {
@Inject
PreferenceManager preferenceManager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
BrowserApp.getAppComponent().inject(this);
}
}

34
app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java

@ -20,7 +20,7 @@ import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.utils.Utils; import acr.browser.lightning.utils.Utils;
import acr.browser.lightning.utils.WebUtils; import acr.browser.lightning.utils.WebUtils;
public class PrivacySettingsFragment extends PreferenceFragment implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener { public class PrivacySettingsFragment extends LightningPreferenceFragment implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener {
private static final String SETTINGS_LOCATION = "location"; private static final String SETTINGS_LOCATION = "location";
private static final String SETTINGS_THIRDPCOOKIES = "third_party"; private static final String SETTINGS_THIRDPCOOKIES = "third_party";
@ -35,7 +35,6 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
private static final String SETTINGS_WEBSTORAGEEXIT = "clear_webstorage_exit"; private static final String SETTINGS_WEBSTORAGEEXIT = "clear_webstorage_exit";
private Activity mActivity; private Activity mActivity;
private PreferenceManager mPreferences;
private CheckBoxPreference cblocation, cb3cookies, cbsavepasswords, cbcacheexit, cbhistoryexit, private CheckBoxPreference cblocation, cb3cookies, cbsavepasswords, cbcacheexit, cbhistoryexit,
cbcookiesexit, cbwebstorageexit; cbcookiesexit, cbwebstorageexit;
private Handler messageHandler; private Handler messageHandler;
@ -52,9 +51,6 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
} }
private void initPrefs() { private void initPrefs() {
// mPreferences storage
mPreferences = PreferenceManager.getInstance();
Preference clearcache = findPreference(SETTINGS_CLEARCACHE); Preference clearcache = findPreference(SETTINGS_CLEARCACHE);
Preference clearhistory = findPreference(SETTINGS_CLEARHISTORY); Preference clearhistory = findPreference(SETTINGS_CLEARHISTORY);
Preference clearcookies = findPreference(SETTINGS_CLEARCOOKIES); Preference clearcookies = findPreference(SETTINGS_CLEARCOOKIES);
@ -81,13 +77,13 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
cbcookiesexit.setOnPreferenceChangeListener(this); cbcookiesexit.setOnPreferenceChangeListener(this);
cbwebstorageexit.setOnPreferenceChangeListener(this); cbwebstorageexit.setOnPreferenceChangeListener(this);
cblocation.setChecked(mPreferences.getLocationEnabled()); cblocation.setChecked(preferenceManager.getLocationEnabled());
cbsavepasswords.setChecked(mPreferences.getSavePasswordsEnabled()); cbsavepasswords.setChecked(preferenceManager.getSavePasswordsEnabled());
cbcacheexit.setChecked(mPreferences.getClearCacheExit()); cbcacheexit.setChecked(preferenceManager.getClearCacheExit());
cbhistoryexit.setChecked(mPreferences.getClearHistoryExitEnabled()); cbhistoryexit.setChecked(preferenceManager.getClearHistoryExitEnabled());
cbcookiesexit.setChecked(mPreferences.getClearCookiesExitEnabled()); cbcookiesexit.setChecked(preferenceManager.getClearCookiesExitEnabled());
cb3cookies.setChecked(mPreferences.getBlockThirdPartyCookiesEnabled()); cb3cookies.setChecked(preferenceManager.getBlockThirdPartyCookiesEnabled());
cbwebstorageexit.setChecked(mPreferences.getClearWebStorageExitEnabled()); cbwebstorageexit.setChecked(preferenceManager.getClearWebStorageExitEnabled());
cb3cookies.setEnabled(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP); cb3cookies.setEnabled(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
@ -213,31 +209,31 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
// switch preferences // switch preferences
switch (preference.getKey()) { switch (preference.getKey()) {
case SETTINGS_LOCATION: case SETTINGS_LOCATION:
mPreferences.setLocationEnabled((Boolean) newValue); preferenceManager.setLocationEnabled((Boolean) newValue);
cblocation.setChecked((Boolean) newValue); cblocation.setChecked((Boolean) newValue);
return true; return true;
case SETTINGS_THIRDPCOOKIES: case SETTINGS_THIRDPCOOKIES:
mPreferences.setBlockThirdPartyCookiesEnabled((Boolean) newValue); preferenceManager.setBlockThirdPartyCookiesEnabled((Boolean) newValue);
cb3cookies.setChecked((Boolean) newValue); cb3cookies.setChecked((Boolean) newValue);
return true; return true;
case SETTINGS_SAVEPASSWORD: case SETTINGS_SAVEPASSWORD:
mPreferences.setSavePasswordsEnabled((Boolean) newValue); preferenceManager.setSavePasswordsEnabled((Boolean) newValue);
cbsavepasswords.setChecked((Boolean) newValue); cbsavepasswords.setChecked((Boolean) newValue);
return true; return true;
case SETTINGS_CACHEEXIT: case SETTINGS_CACHEEXIT:
mPreferences.setClearCacheExit((Boolean) newValue); preferenceManager.setClearCacheExit((Boolean) newValue);
cbcacheexit.setChecked((Boolean) newValue); cbcacheexit.setChecked((Boolean) newValue);
return true; return true;
case SETTINGS_HISTORYEXIT: case SETTINGS_HISTORYEXIT:
mPreferences.setClearHistoryExitEnabled((Boolean) newValue); preferenceManager.setClearHistoryExitEnabled((Boolean) newValue);
cbhistoryexit.setChecked((Boolean) newValue); cbhistoryexit.setChecked((Boolean) newValue);
return true; return true;
case SETTINGS_COOKIEEXIT: case SETTINGS_COOKIEEXIT:
mPreferences.setClearCookiesExitEnabled((Boolean) newValue); preferenceManager.setClearCookiesExitEnabled((Boolean) newValue);
cbcookiesexit.setChecked((Boolean) newValue); cbcookiesexit.setChecked((Boolean) newValue);
return true; return true;
case SETTINGS_WEBSTORAGEEXIT: case SETTINGS_WEBSTORAGEEXIT:
mPreferences.setClearWebStorageExitEnabled((Boolean) newValue); preferenceManager.setClearWebStorageExitEnabled((Boolean) newValue);
cbwebstorageexit.setChecked((Boolean) newValue); cbwebstorageexit.setChecked((Boolean) newValue);
return true; return true;
default: default:

1
app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java

@ -129,6 +129,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
@Override @Override
public void onDestroyView() { public void onDestroyView() {
super.onDestroyView();
mRecyclerView = null; mRecyclerView = null;
mTabsAdapter = null; mTabsAdapter = null;
} }

5
app/src/main/java/acr/browser/lightning/object/SearchAdapter.java

@ -61,6 +61,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
private final boolean mDarkTheme; private final boolean mDarkTheme;
private final boolean mIncognito; private final boolean mIncognito;
@Inject BookmarkManager mBookmarkManager; @Inject BookmarkManager mBookmarkManager;
@Inject PreferenceManager mPreferenceManager;
private static final String CACHE_FILE_TYPE = ".sgg"; private static final String CACHE_FILE_TYPE = ".sgg";
private static final String ENCODING = "ISO-8859-1"; private static final String ENCODING = "ISO-8859-1";
private static final long INTERVAL_DAY = 86400000; private static final long INTERVAL_DAY = 86400000;
@ -76,7 +77,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
BrowserApp.getAppComponent().inject(this); BrowserApp.getAppComponent().inject(this);
mDatabaseHandler = HistoryDatabase.getInstance(); mDatabaseHandler = HistoryDatabase.getInstance();
mAllBookmarks.addAll(mBookmarkManager.getAllBookmarks(true)); mAllBookmarks.addAll(mBookmarkManager.getAllBookmarks(true));
mUseGoogle = PreferenceManager.getInstance().getGoogleSearchSuggestionsEnabled(); mUseGoogle = mPreferenceManager.getGoogleSearchSuggestionsEnabled();
mContext = context; mContext = context;
mSearchSubtitle = mContext.getString(R.string.suggestion); mSearchSubtitle = mContext.getString(R.string.suggestion);
mDarkTheme = dark || incognito; mDarkTheme = dark || incognito;
@ -118,7 +119,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
} }
public void refreshPreferences() { public void refreshPreferences() {
mUseGoogle = PreferenceManager.getInstance().getGoogleSearchSuggestionsEnabled(); mUseGoogle = mPreferenceManager.getGoogleSearchSuggestionsEnabled();
if (!mUseGoogle) { if (!mUseGoogle) {
synchronized (mSuggestions) { synchronized (mSuggestions) {
mSuggestions.clear(); mSuggestions.clear();

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

@ -1,11 +1,16 @@
package acr.browser.lightning.preference; package acr.browser.lightning.preference;
import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Environment; import android.os.Environment;
import javax.inject.Inject;
import javax.inject.Singleton;
import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.constant.Constants; import acr.browser.lightning.constant.Constants;
@Singleton
public class PreferenceManager { public class PreferenceManager {
private static class Name { private static class Name {
@ -56,20 +61,13 @@ public class PreferenceManager {
public static final String INITIAL_CHECK_FOR_I2P = "checkForI2P"; public static final String INITIAL_CHECK_FOR_I2P = "checkForI2P";
} }
private static PreferenceManager mInstance;
private final SharedPreferences mPrefs; private final SharedPreferences mPrefs;
private static final String PREFERENCES = "settings"; private static final String PREFERENCES = "settings";
public static PreferenceManager getInstance() { @Inject
if (mInstance == null) { PreferenceManager(final Context context) {
mInstance = new PreferenceManager(); mPrefs = context.getSharedPreferences(PREFERENCES, 0);
}
return mInstance;
}
private PreferenceManager() {
mPrefs = BrowserApp.getAppContext().getSharedPreferences(PREFERENCES, 0);
} }
public boolean getAdBlockEnabled() { public boolean getAdBlockEnabled() {

5
app/src/main/java/acr/browser/lightning/utils/AdBlock.java

@ -13,6 +13,7 @@ import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
import java.util.Set; import java.util.Set;
import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.constant.Constants; import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.preference.PreferenceManager;
@ -44,11 +45,11 @@ public class AdBlock {
if (mBlockedDomainsList.isEmpty() && Constants.FULL_VERSION) { if (mBlockedDomainsList.isEmpty() && Constants.FULL_VERSION) {
loadHostsFile(context); loadHostsFile(context);
} }
mBlockAds = PreferenceManager.getInstance().getAdBlockEnabled(); mBlockAds = BrowserApp.getAppComponent().getPreferenceManager().getAdBlockEnabled();
} }
public void updatePreference() { public void updatePreference() {
mBlockAds = PreferenceManager.getInstance().getAdBlockEnabled(); mBlockAds = BrowserApp.getAppComponent().getPreferenceManager().getAdBlockEnabled();
} }
private void loadBlockedDomainsList(final Context context) { private void loadBlockedDomainsList(final Context context) {

8
app/src/main/java/acr/browser/lightning/view/LightningView.java

@ -55,6 +55,8 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import javax.inject.Inject;
import acr.browser.lightning.R; import acr.browser.lightning.R;
import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.constant.Constants; import acr.browser.lightning.constant.Constants;
@ -80,7 +82,8 @@ public class LightningView {
private static String mDefaultUserAgent; private static String mDefaultUserAgent;
// TODO fix so that mWebpageBitmap can be static - static changes the icon when switching from light to dark and then back to light // TODO fix so that mWebpageBitmap can be static - static changes the icon when switching from light to dark and then back to light
private final Bitmap mWebpageBitmap; private final Bitmap mWebpageBitmap;
private static PreferenceManager mPreferences; @Inject
PreferenceManager mPreferences;
private final AdBlock mAdBlock; private final AdBlock mAdBlock;
private final IntentUtils mIntentUtils; private final IntentUtils mIntentUtils;
private final Paint mPaint = new Paint(); private final Paint mPaint = new Paint();
@ -102,7 +105,7 @@ public class LightningView {
@SuppressLint("NewApi") @SuppressLint("NewApi")
public LightningView(Activity activity, String url, boolean darkTheme, boolean isIncognito, BrowserController controller) { public LightningView(Activity activity, String url, boolean darkTheme, boolean isIncognito, BrowserController controller) {
mPreferences = BrowserApp.getAppComponent().getPreferenceManager();
mActivity = activity; mActivity = activity;
mWebView = new WebView(activity); mWebView = new WebView(activity);
mIsIncognitoTab = isIncognito; mIsIncognitoTab = isIncognito;
@ -178,7 +181,6 @@ public class LightningView {
} else if (settings == null) { } else if (settings == null) {
settings = mWebView.getSettings(); settings = mWebView.getSettings();
} }
mPreferences = PreferenceManager.getInstance();
settings.setDefaultTextEncodingName(mPreferences.getTextEncoding()); settings.setDefaultTextEncodingName(mPreferences.getTextEncoding());
mHomepage = mPreferences.getHomepage(); mHomepage = mPreferences.getHomepage();

Loading…
Cancel
Save