| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 package org.adblockplus.sbrowser.contentblocker; | 18 package org.adblockplus.sbrowser.contentblocker; |
| 19 | 19 |
| 20 import org.adblockplus.sbrowser.contentblocker.engine.Engine; | 20 import org.adblockplus.sbrowser.contentblocker.engine.Engine; |
| 21 import org.adblockplus.sbrowser.contentblocker.engine.EngineService; | 21 import org.adblockplus.sbrowser.contentblocker.engine.EngineService; |
| 22 import org.adblockplus.adblockplussbrowser.R; | 22 import org.adblockplus.adblockplussbrowser.R; |
| 23 import org.adblockplus.sbrowser.contentblocker.util.ConnectivityUtils; | |
| 23 import org.adblockplus.sbrowser.contentblocker.util.SharedPrefsUtils; | 24 import org.adblockplus.sbrowser.contentblocker.util.SharedPrefsUtils; |
| 24 | 25 |
| 25 import android.app.AlertDialog; | 26 import android.app.AlertDialog; |
| 27 import android.app.Fragment; | |
| 26 import android.app.ProgressDialog; | 28 import android.app.ProgressDialog; |
| 27 import android.content.DialogInterface; | 29 import android.content.DialogInterface; |
| 28 import android.content.DialogInterface.OnClickListener; | 30 import android.content.DialogInterface.OnClickListener; |
| 29 import android.content.Intent; | 31 import android.content.Intent; |
| 30 import android.net.Uri; | 32 import android.net.Uri; |
| 31 import android.os.Bundle; | 33 import android.os.Bundle; |
| 34 import android.preference.Preference; | |
| 32 import android.preference.PreferenceActivity; | 35 import android.preference.PreferenceActivity; |
| 33 import android.preference.PreferenceManager; | 36 import android.preference.PreferenceManager; |
| 34 import android.text.Html; | 37 import android.text.Html; |
| 35 import android.util.Log; | 38 import android.util.Log; |
| 36 import android.view.Gravity; | 39 import android.view.Gravity; |
| 37 import android.widget.Button; | 40 import android.widget.Button; |
| 38 import android.widget.LinearLayout; | 41 import android.widget.LinearLayout; |
| 39 | 42 |
| 40 public class MainPreferences extends PreferenceActivity implements | 43 public class MainPreferences extends PreferenceActivity implements |
| 41 EngineService.OnEngineCreatedCallback, SharedPrefsUtils.OnSharedPreferenceCh angeListener, | 44 EngineService.OnEngineCreatedCallback, SharedPrefsUtils.OnSharedPreferenceCh angeListener, |
| 42 Engine.SubscriptionUpdateCallback | 45 Engine.SubscriptionUpdateCallback, Preference.OnPreferenceClickListener |
| 43 { | 46 { |
| 44 private static final String TAG = MainPreferences.class.getSimpleName(); | 47 private static final String TAG = MainPreferences.class.getSimpleName(); |
| 45 private Engine engine = null; | 48 private Engine engine = null; |
| 46 private AlertDialog dialog; | 49 private AlertDialog dialog; |
| 47 private int dialogTitleResId; | 50 private int dialogTitleResId; |
| 48 | 51 |
| 49 @Override | 52 @Override |
| 50 public void onCreate(Bundle savedInstanceState) | 53 public void onCreate(Bundle savedInstanceState) |
| 51 { | 54 { |
| 52 super.onCreate(savedInstanceState); | 55 super.onCreate(savedInstanceState); |
| 53 PreferenceManager.setDefaultValues(this, R.xml.preferences_main, false); | 56 PreferenceManager.setDefaultValues(this, R.xml.preferences_main, false); |
| 54 | 57 |
| 55 this.getFragmentManager() | 58 this.getFragmentManager() |
| 56 .beginTransaction() | 59 .beginTransaction() |
| 57 .replace(android.R.id.content, new Preferences()) | 60 .replace(android.R.id.content, new Preferences(), Preferences.class.getS impleName()) |
| 58 .commit(); | 61 .commit(); |
| 59 } | 62 } |
| 60 | 63 |
| 61 @Override | 64 @Override |
| 62 protected void onStart() | 65 protected void onStart() |
| 63 { | 66 { |
| 64 this.dialogTitleResId = R.string.initialization_title; | 67 this.dialogTitleResId = R.string.initialization_title; |
| 65 this.dialog = ProgressDialog.show(this, | 68 this.dialog = ProgressDialog.show(this, |
| 66 this.getString(this.dialogTitleResId), | 69 this.getString(this.dialogTitleResId), |
| 67 this.getString(R.string.initialization_message)); | 70 this.getString(R.string.initialization_message)); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 { | 195 { |
| 193 this.engine.setSubscriptionUpdateCallback(this); | 196 this.engine.setSubscriptionUpdateCallback(this); |
| 194 } | 197 } |
| 195 | 198 |
| 196 if (this.dialogTitleResId == R.string.initialization_title) | 199 if (this.dialogTitleResId == R.string.initialization_title) |
| 197 { | 200 { |
| 198 this.dismissDialog(); | 201 this.dismissDialog(); |
| 199 | 202 |
| 200 this.checkForCompatibleSBrowserAndProceed(); | 203 this.checkForCompatibleSBrowserAndProceed(); |
| 201 } | 204 } |
| 205 | |
| 206 Fragment preferecesFragment = getFragmentManager().findFragmentByTag(Prefere nces.class.getSimpleName()); | |
| 207 Preference button = ((Preferences) preferecesFragment).findPreference(getStr ing(R.string.key_update_subscriptions)); | |
| 208 button.setOnPreferenceClickListener(this); | |
| 202 } | 209 } |
| 203 | 210 |
| 204 @Override | 211 @Override |
| 205 public void onSharedPreferenceChanged(String key) | 212 public void onSharedPreferenceChanged(String key) |
| 206 { | 213 { |
| 207 if (this.getString(R.string.key_automatic_updates).equals(key) && this.engin e != null) | 214 if (this.getString(R.string.key_automatic_updates).equals(key) && this.engin e != null) |
| 208 { | 215 { |
| 209 this.engine.connectivityChanged(); | 216 this.engine.connectivityChanged(); |
| 210 } | 217 } |
| 211 else if (this.getString(R.string.key_acceptable_ads).equals(key)) | 218 else if (this.getString(R.string.key_acceptable_ads).equals(key)) |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 230 this.dialog = ProgressDialog.show(this, null, enabled | 237 this.dialog = ProgressDialog.show(this, null, enabled |
| 231 ? getString(R.string.add_subscription_dialog_message) | 238 ? getString(R.string.add_subscription_dialog_message) |
| 232 : getString(R.string.remove_subscription_dialog_message)); | 239 : getString(R.string.remove_subscription_dialog_message)); |
| 233 } | 240 } |
| 234 | 241 |
| 235 @Override | 242 @Override |
| 236 public void subscriptionUpdatedApplied() | 243 public void subscriptionUpdatedApplied() |
| 237 { | 244 { |
| 238 this.dismissDialog(); | 245 this.dismissDialog(); |
| 239 } | 246 } |
| 247 | |
| 248 @Override | |
| 249 public boolean onPreferenceClick(Preference preference) | |
|
diegocarloslima
2018/01/19 13:59:00
So far, instead of adding specific preference logi
jens
2018/01/19 14:32:55
Right, but we only did that for those preferences,
| |
| 250 { | |
| 251 if (getString(R.string.key_update_subscriptions).equals(preference.getKey()) ) | |
| 252 { | |
| 253 boolean hasInternet = ConnectivityUtils.hasInternetConnection(this); | |
| 254 if (hasInternet && ConnectivityUtils.hasWifiConnection(this)) | |
| 255 { | |
| 256 engine.forceUpdateSubscriptions(false); | |
| 257 } | |
| 258 else | |
| 259 { | |
| 260 this.dialog = new AlertDialog.Builder(this) | |
| 261 .setTitle(R.string.update_subscriptions) | |
| 262 .setMessage( | |
| 263 hasInternet | |
| 264 ? R.string.metered_connection_warning | |
| 265 : R.string.check_your_connection) | |
| 266 .setNegativeButton(android.R.string.cancel, new OnClickListener() | |
| 267 { | |
| 268 @Override | |
| 269 public void onClick(DialogInterface dialog, int which) | |
| 270 { | |
| 271 dialog.cancel(); | |
| 272 } | |
| 273 }) | |
| 274 .create(); | |
| 275 | |
| 276 if (hasInternet) | |
| 277 { | |
| 278 this.dialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(andro id.R.string.yes), | |
| 279 new OnClickListener() | |
| 280 { | |
| 281 @Override | |
| 282 public void onClick(DialogInterface dialogInterface, int i) | |
| 283 { | |
| 284 engine.forceUpdateSubscriptions(true); | |
| 285 } | |
| 286 }); | |
| 287 } | |
| 288 this.dialog.show(); | |
| 289 } | |
| 290 return true; | |
| 291 } | |
| 292 return false; | |
| 293 } | |
| 240 } | 294 } |
| OLD | NEW |