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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 20 matching lines...) Expand all
31 import android.os.Bundle; 31 import android.os.Bundle;
32 import android.preference.PreferenceActivity; 32 import android.preference.PreferenceActivity;
33 import android.preference.PreferenceManager; 33 import android.preference.PreferenceManager;
34 import android.text.Html; 34 import android.text.Html;
35 import android.util.Log; 35 import android.util.Log;
36 import android.view.Gravity; 36 import android.view.Gravity;
37 import android.widget.Button; 37 import android.widget.Button;
38 import android.widget.LinearLayout; 38 import android.widget.LinearLayout;
39 39
40 public class MainPreferences extends PreferenceActivity implements 40 public class MainPreferences extends PreferenceActivity implements
41 EngineService.OnEngineCreatedCallback, SharedPrefsUtils.OnSharedPreferenceCh angeListener, 41 EngineService.OnEngineCreatedCallback, Engine.SubscriptionUpdateCallback
42 Engine.SubscriptionUpdateCallback
43 { 42 {
44 private static final String TAG = MainPreferences.class.getSimpleName(); 43 private static final String TAG = MainPreferences.class.getSimpleName();
45 private Engine engine = null; 44 private Engine engine = null;
46 private AlertDialog dialog; 45 private AlertDialog dialog;
47 private int dialogTitleResId; 46 private int dialogTitleResId;
48 47
49 @Override 48 @Override
50 public void onCreate(Bundle savedInstanceState) 49 public void onCreate(Bundle savedInstanceState)
51 { 50 {
52 super.onCreate(savedInstanceState); 51 super.onCreate(savedInstanceState);
53 PreferenceManager.setDefaultValues(this, R.xml.preferences_main, false); 52 PreferenceManager.setDefaultValues(this, R.xml.preferences_main, false);
54 53
55 this.getFragmentManager() 54 this.getFragmentManager()
56 .beginTransaction() 55 .beginTransaction()
57 .replace(android.R.id.content, new Preferences()) 56 .replace(android.R.id.content, new Preferences())
58 .commit(); 57 .commit();
59 } 58 }
60 59
61 @Override 60 @Override
62 protected void onStart() 61 protected void onStart()
63 { 62 {
64 this.dialogTitleResId = R.string.initialization_title; 63 this.dialogTitleResId = R.string.initialization_title;
65 this.dialog = ProgressDialog.show(this, 64 this.dialog = ProgressDialog.show(this,
66 this.getString(this.dialogTitleResId), 65 this.getString(this.dialogTitleResId),
67 this.getString(R.string.initialization_message)); 66 this.getString(R.string.initialization_message));
68 super.onStart(); 67 super.onStart();
69 SharedPrefsUtils.registerOnSharedPreferenceChangeListener(this, this); 68 SharedPrefsUtils.registerOnSharedPreferenceChangeListener(this, listener);
70 EngineService.startService(this.getApplicationContext(), this); 69 EngineService.startService(this.getApplicationContext(), this);
71 } 70 }
72 71
73 @Override 72 @Override
74 protected void onStop() 73 protected void onStop()
75 { 74 {
76 super.onStop(); 75 super.onStop();
77 SharedPrefsUtils.unregisterOnSharedPreferenceChangeListener(this, this); 76 SharedPrefsUtils.unregisterOnSharedPreferenceChangeListener(this, listener);
78 this.dismissDialog(); 77 this.dismissDialog();
79 } 78 }
80 79
81 private void dismissDialog() 80 private void dismissDialog()
82 { 81 {
83 if (this.dialog != null) 82 if (this.dialog != null)
84 { 83 {
85 this.dialogTitleResId = 0; 84 this.dialogTitleResId = 0;
86 this.dialog.dismiss(); 85 this.dialog.dismiss();
87 this.dialog = null; 86 this.dialog = null;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 194
196 if (this.dialogTitleResId == R.string.initialization_title) 195 if (this.dialogTitleResId == R.string.initialization_title)
197 { 196 {
198 this.dismissDialog(); 197 this.dismissDialog();
199 198
200 this.checkForCompatibleSBrowserAndProceed(); 199 this.checkForCompatibleSBrowserAndProceed();
201 } 200 }
202 } 201 }
203 202
204 @Override 203 @Override
205 public void onSharedPreferenceChanged(String key)
206 {
207 if (this.getString(R.string.key_automatic_updates).equals(key) && this.engin e != null)
208 {
209 this.engine.connectivityChanged();
210 }
211 else if (this.getString(R.string.key_acceptable_ads).equals(key))
212 {
213 final boolean enabled = SharedPrefsUtils.getBoolean(this, R.string.key_acc eptable_ads, true);
214 final String id = "url:" + this.engine.getPrefsDefault(Engine.SUBSCRIPTION S_EXCEPTIONSURL);
215 Log.d(TAG, "Acceptable ads " + (enabled ? "enabled" : "disabled"));
216 this.engine.changeSubscriptionState(id, enabled);
217 }
218 else if (this.getString(R.string.key_application_activated).equals(key))
219 {
220 if (this.dialogTitleResId == R.string.setup_dialog_title)
221 {
222 this.dismissDialog();
223 }
224 }
225 }
226
227 @Override
228 public void subscriptionUpdateRequested(final boolean enabled) 204 public void subscriptionUpdateRequested(final boolean enabled)
229 { 205 {
230 this.dialog = ProgressDialog.show(this, null, enabled 206 this.dialog = ProgressDialog.show(this, null, enabled
231 ? getString(R.string.add_subscription_dialog_message) 207 ? getString(R.string.add_subscription_dialog_message)
232 : getString(R.string.remove_subscription_dialog_message)); 208 : getString(R.string.remove_subscription_dialog_message));
233 } 209 }
234 210
235 @Override 211 @Override
236 public void subscriptionUpdatedApplied() 212 public void subscriptionUpdatedApplied()
237 { 213 {
238 this.dismissDialog(); 214 this.dismissDialog();
239 } 215 }
216
217 private final SharedPrefsUtils.OnSharedPreferenceChangeListener listener =
218 new SharedPrefsUtils.OnSharedPreferenceChangeListener()
219 {
220 @Override
221 protected void onSharedPreferenceChanged(String key)
222 {
223 if (getString(R.string.key_automatic_updates).equals(key) && engine != nul l)
224 {
225 engine.connectivityChanged();
226 }
227 else if (getString(R.string.key_acceptable_ads).equals(key))
228 {
229 final boolean enabled = SharedPrefsUtils.getBoolean
230 (MainPreferences.this, R.string.key_acceptable_ads, true);
231 final String id = "url:" + engine.getPrefsDefault(Engine.SUBSCRIPTIONS_E XCEPTIONSURL);
232 Log.d(TAG, "Acceptable ads " + (enabled ? "enabled" : "disabled"));
233 engine.changeSubscriptionState(id, enabled);
234 }
235 else if (getString(R.string.key_application_activated).equals(key))
236 {
237 if (dialogTitleResId == R.string.setup_dialog_title)
238 {
239 dismissDialog();
240 }
241 }
242 }
243 };
240 } 244 }
OLDNEW

Powered by Google App Engine
This is Rietveld