| 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.browser; | 18 package org.adblockplus.browser; |
| 19 | 19 |
| 20 import org.mozilla.gecko.preferences.CustomCheckBoxPreference; | 20 import org.mozilla.gecko.preferences.CustomCheckBoxPreference; |
| 21 import org.mozilla.gecko.util.NativeJSObject; | 21 import org.mozilla.gecko.util.GeckoBundle; |
| 22 import org.mozilla.gecko.util.ThreadUtils; | 22 import org.mozilla.gecko.util.ThreadUtils; |
| 23 | 23 |
| 24 import android.content.Context; | 24 import android.content.Context; |
| 25 import android.util.AttributeSet; | 25 import android.util.AttributeSet; |
| 26 | 26 |
| 27 public class AbpCheckBoxPreference extends CustomCheckBoxPreference implements | 27 public class AbpCheckBoxPreference extends CustomCheckBoxPreference implements |
| 28 AdblockPlusApiCallback | 28 AdblockPlusApiCallback |
| 29 { | 29 { |
| 30 private String apiKey = ""; | 30 private String apiKey = ""; |
| 31 | 31 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 48 protected void onAttachedToActivity() | 48 protected void onAttachedToActivity() |
| 49 { | 49 { |
| 50 super.onAttachedToActivity(); | 50 super.onAttachedToActivity(); |
| 51 this.apiKey = this.getKey().substring(this.getKey().lastIndexOf(".api") + 4)
; | 51 this.apiKey = this.getKey().substring(this.getKey().lastIndexOf(".api") + 4)
; |
| 52 this.setEnabled(false); | 52 this.setEnabled(false); |
| 53 this.refreshValue(); | 53 this.refreshValue(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 private void refreshValue() | 56 private void refreshValue() |
| 57 { | 57 { |
| 58 AddOnBridge.queryValue(this, this.apiKey); | 58 AddOnBridge.queryValue(this.apiKey, this); |
| 59 } | 59 } |
| 60 | 60 |
| 61 @Override | 61 @Override |
| 62 protected void onClick() | 62 protected void onClick() |
| 63 { | 63 { |
| 64 super.onClick(); | 64 super.onClick(); |
| 65 AddOnBridge.setBoolean(this, this.apiKey, this.isChecked()); | 65 AddOnBridge.setBoolean(this.apiKey, this.isChecked(), null); |
| 66 } | 66 } |
| 67 | 67 |
| 68 @Override | 68 @Override |
| 69 public void onApiRequestSucceeded(NativeJSObject jsObject) | 69 public void onApiRequestSucceeded(GeckoBundle bundle) |
| 70 { | 70 { |
| 71 if (jsObject.has("value")) | 71 final boolean enabled = bundle.getBoolean("value"); |
| 72 ThreadUtils.postToUiThread(new Runnable() |
| 72 { | 73 { |
| 73 final boolean enabled = AddOnBridge.getBooleanFromJsObject(jsObject, "valu
e", false); | 74 @Override |
| 74 | 75 public void run() |
| 75 ThreadUtils.postToUiThread(new Runnable() | |
| 76 { | 76 { |
| 77 @Override | 77 AbpCheckBoxPreference.this.setChecked(enabled); |
| 78 public void run() | 78 AbpCheckBoxPreference.this.setEnabled(true); |
| 79 { | 79 } |
| 80 AbpCheckBoxPreference.this.setChecked(enabled); | 80 }); |
| 81 AbpCheckBoxPreference.this.setEnabled(true); | |
| 82 } | |
| 83 }); | |
| 84 } | |
| 85 } | 81 } |
| 86 | 82 |
| 87 @Override | 83 @Override |
| 88 public void onApiRequestFailed(String errorMessage) | 84 public void onApiRequestFailed(String errorMessage) |
| 89 { | 85 { |
| 90 // Currently ignored | 86 // Currently ignored |
| 91 } | 87 } |
| 92 } | 88 } |
| OLD | NEW |