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

Side by Side Diff: mobile/android/thirdparty/org/adblockplus/browser/AbpCheckBoxPreference.java

Issue 4920541991403520: Create a minimal settings UI (Closed)
Patch Set: Cleanup of AddOnBridge Created March 22, 2015, 12:13 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
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
18 package org.adblockplus.browser;
19
20 import org.mozilla.gecko.preferences.CustomCheckBoxPreference;
21 import org.mozilla.gecko.util.NativeJSObject;
22 import org.mozilla.gecko.util.ThreadUtils;
23
24 import android.content.Context;
25 import android.util.AttributeSet;
26
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
29 {
30 private String apiKey = "";
31
32 public AbpCheckBoxPreference(Context context)
33 {
34 super(context);
35 }
36
37 public AbpCheckBoxPreference(Context context, AttributeSet attrs)
38 {
39 super(context, attrs);
40 }
41
42 public AbpCheckBoxPreference(Context context, AttributeSet attrs, int defStyle )
43 {
44 super(context, attrs, defStyle);
45 }
46
47 @Override
48 protected void onAttachedToActivity()
49 {
50 super.onAttachedToActivity();
51 this.apiKey = this.getKey().substring(this.getKey().lastIndexOf('.') + 1);
52 this.setEnabled(false);
53 this.recheckValue();
54 }
55
56 private void recheckValue()
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 {
58 AddOnBridge.queryBoolean(this, "query_" + this.apiKey);
59 }
60
61 @Override
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 {
64 super.onClick();
65 AddOnBridge.setBoolean(this, "change_" + this.apiKey, this.isChecked());
66 this.recheckValue();
67 }
68
69 @Override
70 public void onApiRequestSucceeded(NativeJSObject jsObject)
71 {
72 if (jsObject.has("value"))
73 {
74 final boolean enabled = AddOnBridge.getBooleanFromJSObject(jsObject, "valu e", false);
75
76 ThreadUtils.postToUiThread(new Runnable()
77 {
78 @Override
79 public void run()
80 {
81 AbpCheckBoxPreference.this.setChecked(enabled);
82 AbpCheckBoxPreference.this.setEnabled(true);
83 }
84 });
85 }
86 }
87
88 @Override
89 public void onApiRequestFailed(String errorMessage)
90 {
91 // Currently ignored
92 }
93 }
OLDNEW

Powered by Google App Engine
This is Rietveld