Index: adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/MainPreferences.java |
=================================================================== |
--- a/adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/MainPreferences.java |
+++ b/adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/MainPreferences.java |
@@ -15,93 +15,70 @@ |
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
*/ |
package org.adblockplus.sbrowser.contentblocker; |
import org.adblockplus.sbrowser.contentblocker.engine.Engine; |
import org.adblockplus.sbrowser.contentblocker.engine.EngineService; |
import org.adblockplus.adblockplussbrowser.R; |
+import org.adblockplus.sbrowser.contentblocker.util.SharedPrefsUtils; |
import android.app.AlertDialog; |
import android.app.ProgressDialog; |
import android.content.DialogInterface; |
import android.content.DialogInterface.OnClickListener; |
import android.content.Intent; |
-import android.content.SharedPreferences; |
import android.net.Uri; |
import android.os.Bundle; |
import android.preference.PreferenceActivity; |
import android.preference.PreferenceManager; |
import android.text.Html; |
import android.util.Log; |
import android.view.Gravity; |
import android.widget.Button; |
import android.widget.LinearLayout; |
public class MainPreferences extends PreferenceActivity implements |
- EngineService.OnEngineCreatedCallback, SharedPreferences.OnSharedPreferenceChangeListener |
+ EngineService.OnEngineCreatedCallback, SharedPrefsUtils.OnSharedPreferenceChangeListener |
{ |
private static final String TAG = MainPreferences.class.getSimpleName(); |
private Engine engine = null; |
private AlertDialog dialog; |
private int dialogTitleResId; |
- private SharedPreferences getSharedPreferences() |
- { |
- return PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext()); |
- } |
- |
@Override |
public void onCreate(Bundle savedInstanceState) |
{ |
super.onCreate(savedInstanceState); |
PreferenceManager.setDefaultValues(this, R.xml.preferences_main, false); |
this.getFragmentManager() |
.beginTransaction() |
.replace(android.R.id.content, new Preferences()) |
.commit(); |
- |
- // This try/catch block is a workaround for a preference mismatch |
- // issue. We check for a type mismatch in one particular key and, |
- // if there's a mismatch, clean sweep the preferences. |
- // See: https://issues.adblockplus.org/ticket/3931 |
- try |
- { |
- this.getSharedPreferences().getBoolean( |
- this.getString(R.string.key_application_activated), |
- false); |
- } |
- catch(final Throwable t) |
- { |
- this.getSharedPreferences() |
- .edit() |
- .clear() |
- .commit(); |
- } |
} |
@Override |
protected void onStart() |
{ |
this.dialogTitleResId = R.string.initialization_title; |
this.dialog = ProgressDialog.show(this, |
this.getString(this.dialogTitleResId), |
this.getString(R.string.initialization_message)); |
super.onStart(); |
- this.getSharedPreferences().registerOnSharedPreferenceChangeListener(this); |
+ SharedPrefsUtils.registerOnSharedPreferenceChangeListener(this, this); |
EngineService.startService(this.getApplicationContext(), this); |
} |
@Override |
protected void onStop() |
{ |
super.onStop(); |
- this.getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this); |
+ SharedPrefsUtils.unregisterOnSharedPreferenceChangeListener(this, this); |
this.dismissDialog(); |
} |
private void dismissDialog() |
{ |
if (this.dialog != null) |
{ |
this.dialogTitleResId = 0; |
@@ -141,49 +118,45 @@ public class MainPreferences extends Pre |
else |
{ |
this.checkAAStatusAndProceed(); |
} |
} |
private void checkAAStatusAndProceed() |
{ |
- final SharedPreferences prefs = this.getSharedPreferences(); |
- final String keyAaInfoShown = this.getString(R.string.key_aa_info_shown); |
- final boolean aaInfoShown = prefs.getBoolean(keyAaInfoShown, false); |
+ final boolean aaInfoShown = SharedPrefsUtils.getBoolean(this, R.string.key_aa_info_shown, false); |
if (!aaInfoShown) |
{ |
this.dialogTitleResId = R.string.aa_dialog_title; |
this.dialog = new AlertDialog.Builder(this) |
.setCancelable(false) |
.setTitle(this.dialogTitleResId) |
.setMessage(Html.fromHtml(getString(R.string.aa_dialog_message))) |
.setNeutralButton(R.string.aa_dialog_button, new OnClickListener() |
{ |
@Override |
public void onClick(DialogInterface dialog, int which) |
{ |
- prefs.edit() |
- .putBoolean(keyAaInfoShown, true) |
- .commit(); |
+ SharedPrefsUtils.putBoolean(MainPreferences.this, R.string.key_aa_info_shown, true); |
MainPreferences.this.checkSetupStatus(); |
} |
}).create(); |
this.dialog.show(); |
} |
else |
{ |
this.checkSetupStatus(); |
} |
} |
private void checkSetupStatus() |
{ |
- final boolean applicationActivated = this.getSharedPreferences() |
- .getBoolean(this.getString(R.string.key_application_activated), false); |
+ final boolean applicationActivated = SharedPrefsUtils.getBoolean( |
+ this, R.string.key_application_activated, false); |
if (!applicationActivated) |
{ |
Log.d(TAG, "Showing setup dialog"); |
this.dialogTitleResId = R.string.setup_dialog_title; |
this.dialog = new AlertDialog.Builder(this) |
.setCancelable(false) |
.setTitle(this.dialogTitleResId) |
@@ -217,25 +190,25 @@ public class MainPreferences extends Pre |
{ |
this.dismissDialog(); |
this.checkForCompatibleSBrowserAndProceed(); |
} |
} |
@Override |
- public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) |
+ public void onSharedPreferenceChanged(String key) |
{ |
if (this.getString(R.string.key_automatic_updates).equals(key) && this.engine != null) |
{ |
this.engine.connectivityChanged(); |
} |
else if (this.getString(R.string.key_acceptable_ads).equals(key)) |
{ |
- boolean enabled = sharedPreferences.getBoolean(key, true); |
+ final boolean enabled = SharedPrefsUtils.getBoolean(this, R.string.key_acceptable_ads, true); |
final String id = "url:" + this.engine.getPrefsDefault(Engine.SUBSCRIPTIONS_EXCEPTIONSURL); |
Log.d(TAG, "Acceptable ads " + (enabled ? "enabled" : "disabled")); |
this.engine.changeSubscriptionState(id, enabled); |
} |
else if (this.getString(R.string.key_application_activated).equals(key)) |
{ |
if (this.dialogTitleResId == R.string.setup_dialog_title) |
{ |