OLD | NEW |
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.ENGLISH; |
| 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); |
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 } |
OLD | NEW |