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

Delta Between Two Patch Sets: mobile/android/thirdparty/org/adblockplus/browser/AbpCheckBoxPreference.java

Issue 4920541991403520: Create a minimal settings UI (Closed)
Left Patch Set: Cleanup of AddOnBridge Created March 22, 2015, 12:13 p.m.
Right Patch Set: Removed default case Created March 22, 2015, 9:23 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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.NativeJSObject;
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
Felix Dahlke 2015/03/22 15:51:45 What's that, 80 columns? :P We do have 100 for Jav
René Jeschke 2015/03/22 16:44:55 Yes, and it would end on column 102 :p
Felix Dahlke 2015/03/22 17:44:34 Touché :P
28 AdblockPlusApiCallback 28 AdblockPlusApiCallback
29 { 29 {
30 private String apiKey = ""; 30 private String apiKey = "";
31 31
32 public AbpCheckBoxPreference(Context context) 32 public AbpCheckBoxPreference(Context context)
33 { 33 {
34 super(context); 34 super(context);
35 } 35 }
36 36
37 public AbpCheckBoxPreference(Context context, AttributeSet attrs) 37 public AbpCheckBoxPreference(Context context, AttributeSet attrs)
38 { 38 {
39 super(context, attrs); 39 super(context, attrs);
40 } 40 }
41 41
42 public AbpCheckBoxPreference(Context context, AttributeSet attrs, int defStyle ) 42 public AbpCheckBoxPreference(Context context, AttributeSet attrs, int defStyle )
43 { 43 {
44 super(context, attrs, defStyle); 44 super(context, attrs, defStyle);
45 } 45 }
46 46
47 @Override 47 @Override
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('.') + 1); 51 this.apiKey = this.getKey().substring(this.getKey().lastIndexOf(".api") + 4) ;
52 this.setEnabled(false); 52 this.setEnabled(false);
53 this.recheckValue(); 53 this.refreshValue();
54 } 54 }
55 55
56 private void recheckValue() 56 private void refreshValue()
Felix Dahlke 2015/03/22 15:51:45 Naming nit: Isn't this rather logically "refreshVa
René Jeschke 2015/03/22 16:44:55 Yup
57 { 57 {
58 AddOnBridge.queryBoolean(this, "query_" + this.apiKey); 58 AddOnBridge.queryBoolean(this, this.apiKey);
59 } 59 }
60 60
61 @Override 61 @Override
62 protected void onClick() 62 protected void onClick()
Felix Dahlke 2015/03/22 15:51:45 IIRC, setChecked is invoked whenever the value cha
René Jeschke 2015/03/22 16:44:55 Because I call 'setChecked()' to set the checkbox
Felix Dahlke 2015/03/22 17:44:34 Well, you could use super.setChecked. Potentially
René Jeschke 2015/03/22 18:32:41 What I mean is: If we do put this logic into 'set
Felix Dahlke 2015/03/22 20:10:24 You mean, CheckBoxPreference itself will call setC
René Jeschke 2015/03/22 21:04:45 Ok, as discussed on IRC, we will leave this as is.
63 { 63 {
64 super.onClick(); 64 super.onClick();
65 AddOnBridge.setBoolean(this, "change_" + this.apiKey, this.isChecked()); 65 AddOnBridge.setBoolean(this, this.apiKey, this.isChecked());
66 this.recheckValue(); 66 this.refreshValue();
67 } 67 }
68 68
69 @Override 69 @Override
70 public void onApiRequestSucceeded(NativeJSObject jsObject) 70 public void onApiRequestSucceeded(NativeJSObject jsObject)
71 { 71 {
72 if (jsObject.has("value")) 72 if (jsObject.has("value"))
73 { 73 {
74 final boolean enabled = AddOnBridge.getBooleanFromJSObject(jsObject, "valu e", false); 74 final boolean enabled = AddOnBridge.getBooleanFromJsObject(jsObject, "valu e", false);
75 75
76 ThreadUtils.postToUiThread(new Runnable() 76 ThreadUtils.postToUiThread(new Runnable()
77 { 77 {
78 @Override 78 @Override
79 public void run() 79 public void run()
80 { 80 {
81 AbpCheckBoxPreference.this.setChecked(enabled); 81 AbpCheckBoxPreference.this.setChecked(enabled);
82 AbpCheckBoxPreference.this.setEnabled(true); 82 AbpCheckBoxPreference.this.setEnabled(true);
83 } 83 }
84 }); 84 });
85 } 85 }
86 } 86 }
87 87
88 @Override 88 @Override
89 public void onApiRequestFailed(String errorMessage) 89 public void onApiRequestFailed(String errorMessage)
90 { 90 {
91 // Currently ignored 91 // Currently ignored
92 } 92 }
93 } 93 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld