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

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

@ -18,13 +18,13 @@ public class IncognitoActivity extends BrowserActivity { @@ -18,13 +18,13 @@ public class IncognitoActivity extends BrowserActivity {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
CookieSyncManager.createInstance(this);
}
cookieManager.setAcceptCookie(PreferenceManager.getInstance().getIncognitoCookiesEnabled());
cookieManager.setAcceptCookie(mPreferences.getIncognitoCookiesEnabled());
}
@Override
public synchronized void initializeTabs() {
newTab(null, true);
}
// @Override
// public synchronized void initializeTabs() {
// newTab(null, true);
// }
@Override
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 { @@ -18,14 +18,14 @@ public class MainActivity extends BrowserActivity {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
CookieSyncManager.createInstance(this);
}
cookieManager.setAcceptCookie(PreferenceManager.getInstance().getCookiesEnabled());
cookieManager.setAcceptCookie(mPreferences.getCookiesEnabled());
}
@Override
public synchronized void initializeTabs() {
restoreOrNewTab();
// if incognito mode use newTab(null, true); instead
}
// @Override
// public synchronized void initializeTabs() {
// // restoreOrNewTab();
// // if incognito mode use newTab(null, true); instead
// }
@Override
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; @@ -22,6 +22,7 @@ import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import acr.browser.lightning.R;
import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.reading.HtmlFetcher;
@ -49,7 +50,7 @@ public class ReadingActivity extends AppCompatActivity { @@ -49,7 +50,7 @@ public class ReadingActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
overridePendingTransition(R.anim.slide_in_from_right, R.anim.fade_out_scale);
mPreferences = PreferenceManager.getInstance();
mPreferences = BrowserApp.getAppComponent().getPreferenceManager();
mInvert = mPreferences.getInvertColors();
final int color;
if (mInvert) {

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

@ -12,6 +12,7 @@ import javax.inject.Inject; @@ -12,6 +12,7 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import acr.browser.lightning.controller.BrowserController;
import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.view.LightningView;
/**
@ -25,7 +26,7 @@ public class TabsManager { @@ -25,7 +26,7 @@ public class TabsManager {
private LightningView mCurrentTab;
@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 { @@ -15,8 +15,8 @@ public abstract class ThemableBrowserActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
mTheme = PreferenceManager.getInstance().getUseTheme();
mShowTabsInDrawer = PreferenceManager.getInstance().getShowTabsInDrawer(!isTablet());
mTheme = 0; //PreferenceManager.getInstance().getUseTheme();
mShowTabsInDrawer = false; // PreferenceManager.getInstance().getShowTabsInDrawer(!isTablet());
// set the theme
if (mTheme == 1) {
@ -30,8 +30,8 @@ public abstract class ThemableBrowserActivity extends AppCompatActivity { @@ -30,8 +30,8 @@ public abstract class ThemableBrowserActivity extends AppCompatActivity {
@Override
protected void onResume() {
super.onResume();
int theme = PreferenceManager.getInstance().getUseTheme();
boolean drawerTabs = PreferenceManager.getInstance().getShowTabsInDrawer(!isTablet());
int theme = 0; // PreferenceManager.getInstance().getUseTheme();
boolean drawerTabs = false; // PreferenceManager.getInstance().getShowTabsInDrawer(!isTablet());
if (theme != mTheme || mShowTabsInDrawer != drawerTabs) {
restart();
}

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

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

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

@ -7,8 +7,10 @@ import acr.browser.lightning.constant.BookmarkPage; @@ -7,8 +7,10 @@ import acr.browser.lightning.constant.BookmarkPage;
import acr.browser.lightning.dialog.BookmarksDialogBuilder;
import acr.browser.lightning.fragment.BookmarkSettingsFragment;
import acr.browser.lightning.fragment.BookmarksFragment;
import acr.browser.lightning.fragment.LightningPreferenceFragment;
import acr.browser.lightning.fragment.TabsFragment;
import acr.browser.lightning.object.SearchAdapter;
import acr.browser.lightning.preference.PreferenceManager;
import dagger.Component;
/**
@ -31,4 +33,8 @@ public interface AppComponent { @@ -31,4 +33,8 @@ public interface AppComponent {
void inject(BookmarkPage bookmarkPage);
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 { @@ -57,11 +57,12 @@ public class StartPage {
StringBuilder homepageBuilder = new StringBuilder(StartPage.HEAD);
String icon;
String searchUrl;
switch (PreferenceManager.getInstance().getSearchChoice()) {
final PreferenceManager preferenceManager = BrowserApp.getAppComponent().getPreferenceManager();
switch (preferenceManager.getSearchChoice()) {
case 0:
// CUSTOM SEARCH
icon = "file:///android_asset/lightning.png";
searchUrl = PreferenceManager.getInstance().getSearchUrl();
searchUrl = preferenceManager.getSearchUrl();
break;
case 1:
// GOOGLE_SEARCH;

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

@ -20,6 +20,7 @@ import android.webkit.CookieManager; @@ -20,6 +20,7 @@ import android.webkit.CookieManager;
import android.webkit.URLUtil;
import acr.browser.lightning.R;
import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.utils.Utils;
@ -170,7 +171,7 @@ public class DownloadHandler { @@ -170,7 +171,7 @@ public class DownloadHandler {
// or, should it be set to one of several Environment.DIRECTORY* dirs
// depending on mimetype?
String location = PreferenceManager.getInstance().getDownloadDirectory();
String location = BrowserApp.getAppComponent().getPreferenceManager().getDownloadDirectory();
request.setDestinationInExternalPublicDir(location, filename);
// let this downloaded file be scanned by MediaScanner - so that it can
// 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; @@ -18,7 +18,7 @@ import acr.browser.lightning.R;
import acr.browser.lightning.constant.Constants;
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_ENABLECOOKIES = "allow_cookies";
@ -29,7 +29,6 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref @@ -29,7 +29,6 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref
private static final String SETTINGS_TEXTENCODING = "text_encoding";
private Activity mActivity;
private PreferenceManager mPreferences;
private CheckBoxPreference cbAllowPopups, cbenablecookies, cbcookiesInkognito, cbrestoreTabs;
private Preference renderingmode, urlcontent, textEncoding;
private CharSequence[] mUrlOptions;
@ -46,8 +45,6 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref @@ -46,8 +45,6 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref
}
private void initPrefs() {
// mPreferences storage
mPreferences = PreferenceManager.getInstance();
renderingmode = findPreference(SETTINGS_RENDERINGMODE);
textEncoding = findPreference(SETTINGS_TEXTENCODING);
@ -65,7 +62,7 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref @@ -65,7 +62,7 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref
cbcookiesInkognito.setOnPreferenceChangeListener(this);
cbrestoreTabs.setOnPreferenceChangeListener(this);
switch (mPreferences.getRenderingMode()) {
switch (preferenceManager.getRenderingMode()) {
case 0:
renderingmode.setSummary(getString(R.string.name_normal));
break;
@ -80,16 +77,16 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref @@ -80,16 +77,16 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref
break;
}
textEncoding.setSummary(mPreferences.getTextEncoding());
textEncoding.setSummary(preferenceManager.getTextEncoding());
mUrlOptions = getResources().getStringArray(R.array.url_content_array);
int option = mPreferences.getUrlBoxContentChoice();
int option = preferenceManager.getUrlBoxContentChoice();
urlcontent.setSummary(mUrlOptions[option]);
cbAllowPopups.setChecked(mPreferences.getPopupsEnabled());
cbenablecookies.setChecked(mPreferences.getCookiesEnabled());
cbcookiesInkognito.setChecked(mPreferences.getIncognitoCookiesEnabled());
cbrestoreTabs.setChecked(mPreferences.getRestoreLostTabsEnabled());
cbAllowPopups.setChecked(preferenceManager.getPopupsEnabled());
cbenablecookies.setChecked(preferenceManager.getCookiesEnabled());
cbcookiesInkognito.setChecked(preferenceManager.getIncognitoCookiesEnabled());
cbrestoreTabs.setChecked(preferenceManager.getRestoreLostTabsEnabled());
}
@Override
@ -114,19 +111,19 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref @@ -114,19 +111,19 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref
// switch preferences
switch (preference.getKey()) {
case SETTINGS_NEWWINDOW:
mPreferences.setPopupsEnabled((Boolean) newValue);
preferenceManager.setPopupsEnabled((Boolean) newValue);
cbAllowPopups.setChecked((Boolean) newValue);
return true;
case SETTINGS_ENABLECOOKIES:
mPreferences.setCookiesEnabled((Boolean) newValue);
preferenceManager.setCookiesEnabled((Boolean) newValue);
cbenablecookies.setChecked((Boolean) newValue);
return true;
case SETTINGS_COOKIESINKOGNITO:
mPreferences.setIncognitoCookiesEnabled((Boolean) newValue);
preferenceManager.setIncognitoCookiesEnabled((Boolean) newValue);
cbcookiesInkognito.setChecked((Boolean) newValue);
return true;
case SETTINGS_RESTORETABS:
mPreferences.setRestoreLostTabsEnabled((Boolean) newValue);
preferenceManager.setRestoreLostTabsEnabled((Boolean) newValue);
cbrestoreTabs.setChecked((Boolean) newValue);
return true;
default:
@ -142,12 +139,12 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref @@ -142,12 +139,12 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref
mActivity.getString(R.string.name_grayscale),
mActivity.getString(R.string.name_inverted_grayscale)};
int n = mPreferences.getRenderingMode();
int n = preferenceManager.getRenderingMode();
picker.setSingleChoiceItems(chars, n, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mPreferences.setRenderingMode(which);
preferenceManager.setRenderingMode(which);
switch (which) {
case 0:
renderingmode.setSummary(getString(R.string.name_normal));
@ -178,12 +175,12 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref @@ -178,12 +175,12 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref
AlertDialog.Builder picker = new AlertDialog.Builder(mActivity);
picker.setTitle(getResources().getString(R.string.text_encoding));
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() {
@Override
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]);
}
});
@ -201,12 +198,12 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref @@ -201,12 +198,12 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref
AlertDialog.Builder picker = new AlertDialog.Builder(mActivity);
picker.setTitle(getResources().getString(R.string.url_contents));
int n = mPreferences.getUrlBoxContentChoice();
int n = preferenceManager.getUrlBoxContentChoice();
picker.setSingleChoiceItems(mUrlOptions, n, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mPreferences.setUrlBoxContentChoice(which);
preferenceManager.setUrlBoxContentChoice(which);
if (which < mUrlOptions.length) {
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, @@ -64,6 +64,9 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
@Inject
BookmarksDialogBuilder bookmarksDialogBuilder;
@Inject
PreferenceManager preferenceManager;
// Adapter
private BookmarkViewAdapter mBookmarkAdapter;
@ -151,7 +154,6 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -151,7 +154,6 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
// TODO this code depend way too much on BrowserActivity
super.onActivityCreated(savedInstanceState);
final BrowserActivity activity = (BrowserActivity) getActivity();
final PreferenceManager preferenceManager =PreferenceManager.getInstance();
boolean darkTheme = preferenceManager.getUseTheme() != 0 || activity.isIncognito();
mWebpageBitmap = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_webpage, 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; @@ -21,7 +21,7 @@ import android.widget.TextView;
import acr.browser.lightning.R;
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_FULLSCREEN = "fullscreen";
@ -38,7 +38,6 @@ public class DisplaySettingsFragment extends PreferenceFragment implements Prefe @@ -38,7 +38,6 @@ public class DisplaySettingsFragment extends PreferenceFragment implements Prefe
private static final float XSMALL = 10.0f;
private Activity mActivity;
private PreferenceManager mPreferences;
private CheckBoxPreference cbstatus, cbfullscreen, cbviewport, cboverview, cbreflow;
private Preference theme;
private String[] mThemeOptions;
@ -57,9 +56,8 @@ public class DisplaySettingsFragment extends PreferenceFragment implements Prefe @@ -57,9 +56,8 @@ public class DisplaySettingsFragment extends PreferenceFragment implements Prefe
private void initPrefs() {
// mPreferences storage
mPreferences = PreferenceManager.getInstance();
mThemeOptions = this.getResources().getStringArray(R.array.themes);
mCurrentTheme = mPreferences.getUseTheme();
mCurrentTheme = preferenceManager.getUseTheme();
theme = findPreference(SETTINGS_THEME);
Preference textsize = findPreference(SETTINGS_TEXTSIZE);
@ -77,13 +75,13 @@ public class DisplaySettingsFragment extends PreferenceFragment implements Prefe @@ -77,13 +75,13 @@ public class DisplaySettingsFragment extends PreferenceFragment implements Prefe
cboverview.setOnPreferenceChangeListener(this);
cbreflow.setOnPreferenceChangeListener(this);
cbstatus.setChecked(mPreferences.getHideStatusBarEnabled());
cbfullscreen.setChecked(mPreferences.getFullScreenEnabled());
cbviewport.setChecked(mPreferences.getUseWideViewportEnabled());
cboverview.setChecked(mPreferences.getOverviewModeEnabled());
cbreflow.setChecked(mPreferences.getTextReflowEnabled());
cbstatus.setChecked(preferenceManager.getHideStatusBarEnabled());
cbfullscreen.setChecked(preferenceManager.getFullScreenEnabled());
cbviewport.setChecked(preferenceManager.getUseWideViewportEnabled());
cboverview.setChecked(preferenceManager.getOverviewModeEnabled());
cbreflow.setChecked(preferenceManager.getTextReflowEnabled());
theme.setSummary(mThemeOptions[mPreferences.getUseTheme()]);
theme.setSummary(mThemeOptions[preferenceManager.getUseTheme()]);
}
@Override
@ -105,23 +103,23 @@ public class DisplaySettingsFragment extends PreferenceFragment implements Prefe @@ -105,23 +103,23 @@ public class DisplaySettingsFragment extends PreferenceFragment implements Prefe
// switch preferences
switch (preference.getKey()) {
case SETTINGS_HIDESTATUSBAR:
mPreferences.setHideStatusBarEnabled((Boolean) newValue);
preferenceManager.setHideStatusBarEnabled((Boolean) newValue);
cbstatus.setChecked((Boolean) newValue);
return true;
case SETTINGS_FULLSCREEN:
mPreferences.setFullScreenEnabled((Boolean) newValue);
preferenceManager.setFullScreenEnabled((Boolean) newValue);
cbfullscreen.setChecked((Boolean) newValue);
return true;
case SETTINGS_VIEWPORT:
mPreferences.setUseWideViewportEnabled((Boolean) newValue);
preferenceManager.setUseWideViewportEnabled((Boolean) newValue);
cbviewport.setChecked((Boolean) newValue);
return true;
case SETTINGS_OVERVIEWMODE:
mPreferences.setOverviewModeEnabled((Boolean) newValue);
preferenceManager.setOverviewModeEnabled((Boolean) newValue);
cboverview.setChecked((Boolean) newValue);
return true;
case SETTINGS_REFLOW:
mPreferences.setTextReflowEnabled((Boolean) newValue);
preferenceManager.setTextReflowEnabled((Boolean) newValue);
cbreflow.setChecked((Boolean) newValue);
return true;
default:
@ -157,14 +155,14 @@ public class DisplaySettingsFragment extends PreferenceFragment implements Prefe @@ -157,14 +155,14 @@ public class DisplaySettingsFragment extends PreferenceFragment implements Prefe
});
final int MAX = 5;
bar.setMax(MAX);
bar.setProgress(MAX - mPreferences.getTextSize());
bar.setProgress(MAX - preferenceManager.getTextSize());
builder.setView(view);
builder.setTitle(R.string.title_text_size);
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
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 @@ -194,12 +192,12 @@ public class DisplaySettingsFragment extends PreferenceFragment implements Prefe
AlertDialog.Builder picker = new AlertDialog.Builder(mActivity);
picker.setTitle(getResources().getString(R.string.theme));
int n = mPreferences.getUseTheme();
int n = preferenceManager.getUseTheme();
picker.setSingleChoiceItems(mThemeOptions, n, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mPreferences.setUseTheme(which);
preferenceManager.setUseTheme(which);
if (which < mThemeOptions.length) {
theme.setSummary(mThemeOptions[which]);
}
@ -210,7 +208,7 @@ public class DisplaySettingsFragment extends PreferenceFragment implements Prefe @@ -210,7 +208,7 @@ public class DisplaySettingsFragment extends PreferenceFragment implements Prefe
@Override
public void onClick(DialogInterface dialog, int which) {
if (mCurrentTheme != mPreferences.getUseTheme()) {
if (mCurrentTheme != preferenceManager.getUseTheme()) {
getActivity().onBackPressed();
}
}
@ -218,7 +216,7 @@ public class DisplaySettingsFragment extends PreferenceFragment implements Prefe @@ -218,7 +216,7 @@ public class DisplaySettingsFragment extends PreferenceFragment implements Prefe
picker.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
if (mCurrentTheme != mPreferences.getUseTheme()) {
if (mCurrentTheme != preferenceManager.getUseTheme()) {
getActivity().onBackPressed();
}
}

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

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

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

@ -0,0 +1,27 @@ @@ -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; @@ -20,7 +20,7 @@ import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.utils.Utils;
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_THIRDPCOOKIES = "third_party";
@ -35,7 +35,6 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe @@ -35,7 +35,6 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
private static final String SETTINGS_WEBSTORAGEEXIT = "clear_webstorage_exit";
private Activity mActivity;
private PreferenceManager mPreferences;
private CheckBoxPreference cblocation, cb3cookies, cbsavepasswords, cbcacheexit, cbhistoryexit,
cbcookiesexit, cbwebstorageexit;
private Handler messageHandler;
@ -52,9 +51,6 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe @@ -52,9 +51,6 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
}
private void initPrefs() {
// mPreferences storage
mPreferences = PreferenceManager.getInstance();
Preference clearcache = findPreference(SETTINGS_CLEARCACHE);
Preference clearhistory = findPreference(SETTINGS_CLEARHISTORY);
Preference clearcookies = findPreference(SETTINGS_CLEARCOOKIES);
@ -81,13 +77,13 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe @@ -81,13 +77,13 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
cbcookiesexit.setOnPreferenceChangeListener(this);
cbwebstorageexit.setOnPreferenceChangeListener(this);
cblocation.setChecked(mPreferences.getLocationEnabled());
cbsavepasswords.setChecked(mPreferences.getSavePasswordsEnabled());
cbcacheexit.setChecked(mPreferences.getClearCacheExit());
cbhistoryexit.setChecked(mPreferences.getClearHistoryExitEnabled());
cbcookiesexit.setChecked(mPreferences.getClearCookiesExitEnabled());
cb3cookies.setChecked(mPreferences.getBlockThirdPartyCookiesEnabled());
cbwebstorageexit.setChecked(mPreferences.getClearWebStorageExitEnabled());
cblocation.setChecked(preferenceManager.getLocationEnabled());
cbsavepasswords.setChecked(preferenceManager.getSavePasswordsEnabled());
cbcacheexit.setChecked(preferenceManager.getClearCacheExit());
cbhistoryexit.setChecked(preferenceManager.getClearHistoryExitEnabled());
cbcookiesexit.setChecked(preferenceManager.getClearCookiesExitEnabled());
cb3cookies.setChecked(preferenceManager.getBlockThirdPartyCookiesEnabled());
cbwebstorageexit.setChecked(preferenceManager.getClearWebStorageExitEnabled());
cb3cookies.setEnabled(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
@ -213,31 +209,31 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe @@ -213,31 +209,31 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
// switch preferences
switch (preference.getKey()) {
case SETTINGS_LOCATION:
mPreferences.setLocationEnabled((Boolean) newValue);
preferenceManager.setLocationEnabled((Boolean) newValue);
cblocation.setChecked((Boolean) newValue);
return true;
case SETTINGS_THIRDPCOOKIES:
mPreferences.setBlockThirdPartyCookiesEnabled((Boolean) newValue);
preferenceManager.setBlockThirdPartyCookiesEnabled((Boolean) newValue);
cb3cookies.setChecked((Boolean) newValue);
return true;
case SETTINGS_SAVEPASSWORD:
mPreferences.setSavePasswordsEnabled((Boolean) newValue);
preferenceManager.setSavePasswordsEnabled((Boolean) newValue);
cbsavepasswords.setChecked((Boolean) newValue);
return true;
case SETTINGS_CACHEEXIT:
mPreferences.setClearCacheExit((Boolean) newValue);
preferenceManager.setClearCacheExit((Boolean) newValue);
cbcacheexit.setChecked((Boolean) newValue);
return true;
case SETTINGS_HISTORYEXIT:
mPreferences.setClearHistoryExitEnabled((Boolean) newValue);
preferenceManager.setClearHistoryExitEnabled((Boolean) newValue);
cbhistoryexit.setChecked((Boolean) newValue);
return true;
case SETTINGS_COOKIEEXIT:
mPreferences.setClearCookiesExitEnabled((Boolean) newValue);
preferenceManager.setClearCookiesExitEnabled((Boolean) newValue);
cbcookiesexit.setChecked((Boolean) newValue);
return true;
case SETTINGS_WEBSTORAGEEXIT:
mPreferences.setClearWebStorageExitEnabled((Boolean) newValue);
preferenceManager.setClearWebStorageExitEnabled((Boolean) newValue);
cbwebstorageexit.setChecked((Boolean) newValue);
return true;
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 @@ -129,6 +129,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
@Override
public void onDestroyView() {
super.onDestroyView();
mRecyclerView = 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 { @@ -61,6 +61,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
private final boolean mDarkTheme;
private final boolean mIncognito;
@Inject BookmarkManager mBookmarkManager;
@Inject PreferenceManager mPreferenceManager;
private static final String CACHE_FILE_TYPE = ".sgg";
private static final String ENCODING = "ISO-8859-1";
private static final long INTERVAL_DAY = 86400000;
@ -76,7 +77,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable { @@ -76,7 +77,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
BrowserApp.getAppComponent().inject(this);
mDatabaseHandler = HistoryDatabase.getInstance();
mAllBookmarks.addAll(mBookmarkManager.getAllBookmarks(true));
mUseGoogle = PreferenceManager.getInstance().getGoogleSearchSuggestionsEnabled();
mUseGoogle = mPreferenceManager.getGoogleSearchSuggestionsEnabled();
mContext = context;
mSearchSubtitle = mContext.getString(R.string.suggestion);
mDarkTheme = dark || incognito;
@ -118,7 +119,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable { @@ -118,7 +119,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
}
public void refreshPreferences() {
mUseGoogle = PreferenceManager.getInstance().getGoogleSearchSuggestionsEnabled();
mUseGoogle = mPreferenceManager.getGoogleSearchSuggestionsEnabled();
if (!mUseGoogle) {
synchronized (mSuggestions) {
mSuggestions.clear();

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

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

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

@ -13,6 +13,7 @@ import java.util.HashSet; @@ -13,6 +13,7 @@ import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.preference.PreferenceManager;
@ -44,11 +45,11 @@ public class AdBlock { @@ -44,11 +45,11 @@ public class AdBlock {
if (mBlockedDomainsList.isEmpty() && Constants.FULL_VERSION) {
loadHostsFile(context);
}
mBlockAds = PreferenceManager.getInstance().getAdBlockEnabled();
mBlockAds = BrowserApp.getAppComponent().getPreferenceManager().getAdBlockEnabled();
}
public void updatePreference() {
mBlockAds = PreferenceManager.getInstance().getAdBlockEnabled();
mBlockAds = BrowserApp.getAppComponent().getPreferenceManager().getAdBlockEnabled();
}
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; @@ -55,6 +55,8 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import javax.inject.Inject;
import acr.browser.lightning.R;
import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.constant.Constants;
@ -80,7 +82,8 @@ public class LightningView { @@ -80,7 +82,8 @@ public class LightningView {
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
private final Bitmap mWebpageBitmap;
private static PreferenceManager mPreferences;
@Inject
PreferenceManager mPreferences;
private final AdBlock mAdBlock;
private final IntentUtils mIntentUtils;
private final Paint mPaint = new Paint();
@ -102,7 +105,7 @@ public class LightningView { @@ -102,7 +105,7 @@ public class LightningView {
@SuppressLint("NewApi")
public LightningView(Activity activity, String url, boolean darkTheme, boolean isIncognito, BrowserController controller) {
mPreferences = BrowserApp.getAppComponent().getPreferenceManager();
mActivity = activity;
mWebView = new WebView(activity);
mIsIncognitoTab = isIncognito;
@ -178,7 +181,6 @@ public class LightningView { @@ -178,7 +181,6 @@ public class LightningView {
} else if (settings == null) {
settings = mWebView.getSettings();
}
mPreferences = PreferenceManager.getInstance();
settings.setDefaultTextEncodingName(mPreferences.getTextEncoding());
mHomepage = mPreferences.getHomepage();

Loading…
Cancel
Save