Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/MainPreferences.java

Issue 29674689: Issue 6289 - Fix OnSharedPreferenceChangeListener (Closed)
Patch Set: Created Jan. 19, 2018, 2:36 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/MainPreferences.java
===================================================================
--- a/adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/MainPreferences.java
+++ b/adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/MainPreferences.java
@@ -33,18 +33,17 @@ import android.preference.PreferenceActi
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, SharedPrefsUtils.OnSharedPreferenceChangeListener,
- Engine.SubscriptionUpdateCallback
+ EngineService.OnEngineCreatedCallback, Engine.SubscriptionUpdateCallback
{
private static final String TAG = MainPreferences.class.getSimpleName();
private Engine engine = null;
private AlertDialog dialog;
private int dialogTitleResId;
@Override
public void onCreate(Bundle savedInstanceState)
@@ -61,25 +60,25 @@ public class MainPreferences extends Pre
@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();
- SharedPrefsUtils.registerOnSharedPreferenceChangeListener(this, this);
+ SharedPrefsUtils.registerOnSharedPreferenceChangeListener(this, listener);
EngineService.startService(this.getApplicationContext(), this);
}
@Override
protected void onStop()
{
super.onStop();
- SharedPrefsUtils.unregisterOnSharedPreferenceChangeListener(this, this);
+ SharedPrefsUtils.unregisterOnSharedPreferenceChangeListener(this, listener);
this.dismissDialog();
}
private void dismissDialog()
{
if (this.dialog != null)
{
this.dialogTitleResId = 0;
@@ -197,44 +196,49 @@ public class MainPreferences extends Pre
{
this.dismissDialog();
this.checkForCompatibleSBrowserAndProceed();
}
}
@Override
- 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))
- {
- 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)
- {
- this.dismissDialog();
- }
- }
- }
-
- @Override
public void subscriptionUpdateRequested(final boolean enabled)
{
this.dialog = ProgressDialog.show(this, null, enabled
? getString(R.string.add_subscription_dialog_message)
: getString(R.string.remove_subscription_dialog_message));
}
@Override
public void subscriptionUpdatedApplied()
{
this.dismissDialog();
}
+
+ private final SharedPrefsUtils.OnSharedPreferenceChangeListener listener =
+ new SharedPrefsUtils.OnSharedPreferenceChangeListener()
+ {
+ @Override
+ protected void onSharedPreferenceChanged(String key)
+ {
+ if (getString(R.string.key_automatic_updates).equals(key) && engine != null)
+ {
+ engine.connectivityChanged();
+ }
+ else if (getString(R.string.key_acceptable_ads).equals(key))
+ {
+ final boolean enabled = SharedPrefsUtils.getBoolean
+ (MainPreferences.this, R.string.key_acceptable_ads, true);
+ final String id = "url:" + engine.getPrefsDefault(Engine.SUBSCRIPTIONS_EXCEPTIONSURL);
+ Log.d(TAG, "Acceptable ads " + (enabled ? "enabled" : "disabled"));
+ engine.changeSubscriptionState(id, enabled);
+ }
+ else if (getString(R.string.key_application_activated).equals(key))
+ {
+ if (dialogTitleResId == R.string.setup_dialog_title)
+ {
+ dismissDialog();
+ }
+ }
+ }
+ };
}

Powered by Google App Engine
This is Rietveld