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

Side by Side Diff: src/org/adblockplus/android/BridgeCommand.java

Issue 4705284891082752: Proxy configurators (Closed)
Patch Set: Created Aug. 11, 2014, 12: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 <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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.android; 18 package org.adblockplus.android;
19 19
20 import org.adblockplus.libadblockplus.FilterChangeCallback; 20 import java.util.HashMap;
21 import org.adblockplus.libadblockplus.JsValue; 21 import java.util.Locale;
22 import org.adblockplus.libadblockplus.Subscription;
23 22
24 import android.content.Context; 23 public enum BridgeCommand
24 {
25 /** Used for e.g. no-traffic check, rebuilds/redisplays notification. */
26 STATE_CHANGED,
27 UNKNOWN;
25 28
26 public class AndroidFilterChangeCallback extends FilterChangeCallback 29 private static final HashMap<String, BridgeCommand> MAP = new HashMap<String, BridgeCommand>();
27 {
28 private final Context context;
29 30
30 public AndroidFilterChangeCallback(final Context context) 31 static
31 { 32 {
32 this.context = context; 33 final Locale locale = Locale.getDefault();
Felix Dahlke 2014/08/19 09:06:00 Shouldn't we hard code EN-US here instead? Otherwi
René Jeschke 2014/08/19 10:41:33 Done.
34 for (final BridgeCommand e : BridgeCommand.values())
35 {
36 if (e != UNKNOWN)
37 {
38 final String name = e.toString();
39 MAP.put(name, e);
40 MAP.put(name.toLowerCase(locale), e);
41 MAP.put(name.toUpperCase(locale), e);
42 }
43 }
33 } 44 }
34 45
35 @Override 46 public static BridgeCommand fromString(final String str)
36 public void filterChangeCallback(final String action, final JsValue jsValue)
37 { 47 {
38 if (action.equals("subscription.lastDownload") || action.equals("subscriptio n.downloadStatus")) 48 final BridgeCommand e = MAP.get(str);
Felix Dahlke 2014/08/19 09:06:00 I guess I'm missing something here, but wouldn't B
René Jeschke 2014/08/19 10:41:33 'valueOf' requires that 'str' exactly matches the
Felix Dahlke 2014/08/19 12:37:26 This seems overengineered. If we really do need a
René Jeschke 2014/08/19 12:57:36 I just don't know why you insist on replacing a fu
Felix Dahlke 2014/08/19 13:14:57 I just get the very strong expression that this is
René Jeschke 2014/08/19 13:23:53 Well, k. But I won't leave exception handling for
39 { 49 return e != null ? e : UNKNOWN;
40 final Subscription sub = new Subscription(jsValue);
41
42 Utils.updateSubscriptionStatus(this.context, sub);
43 }
44 } 50 }
45 } 51 }
OLDNEW

Powered by Google App Engine
This is Rietveld