Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
3 * Copyright (C) 2006-2016 Eyeo GmbH | |
anton
2017/08/08 05:43:41
it should be -2017
jens
2017/08/08 13:53:05
Acknowledged.
anton
2017/08/11 11:25:07
also please check `e` or `E` should used
jens
2017/08/11 13:27:23
Acknowledged.
| |
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.sbrowser.contentblocker.util; | |
19 | |
20 import java.util.List; | |
21 import java.util.Locale; | |
22 | |
23 import org.adblockplus.sbrowser.contentblocker.engine.DefaultSubscriptionInfo; | |
24 import org.adblockplus.sbrowser.contentblocker.engine.Engine; | |
25 | |
26 import android.content.res.Resources; | |
27 | |
28 public class SubscriptionUtils | |
29 { | |
30 | |
31 private static final String INDONESIAN_OLD = "in"; | |
32 private static final String INDONESIAN_NEW = "id"; | |
33 private static final String HEBREW_OLD = "iw"; | |
34 private static final String HEBREW_NEW = "he"; | |
35 private static final String YIDDISH_OLD = "ji"; | |
36 private static final String YIDDISH_NEW = "yi"; | |
37 | |
38 /** | |
39 * @param defaultSubscriptions | |
40 * @return The URL of the filter list which fits best for the device language. | |
41 * If no match was found, return EASYLIST as default. | |
42 */ | |
43 public static String chooseDefaultSubscriptionUrl(List<DefaultSubscriptionInfo > defaultSubscriptions) | |
44 { | |
45 for (final DefaultSubscriptionInfo info : defaultSubscriptions) | |
46 { | |
47 if (info != null && info.getPrefixes().contains(getDeviceLanguageCode()) & & info.isComplete()) | |
48 { | |
49 return info.getUrl(); | |
50 } | |
51 } | |
52 return Engine.EASYLIST_URL; | |
53 } | |
54 | |
55 @SuppressWarnings("deprecation") | |
56 private static String getDeviceLanguageCode() | |
57 { | |
58 Locale locale; | |
59 if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) | |
60 { | |
61 locale = Resources.getSystem().getConfiguration().getLocales().get(0); | |
62 } | |
63 else | |
64 { | |
65 locale = Resources.getSystem().getConfiguration().locale; | |
66 } | |
67 | |
68 return convertOldISOCodes(locale.getLanguage()); | |
69 } | |
70 | |
71 /* | |
72 * ISO 639 is not a stable standard; some of the language codes it defines | |
73 * (specifically "iw", "ji", and "in") have changed. Android returns the old c odes | |
74 * ("iw", "ji", and "in") but in subscriptions.xnl we use the new codes ("he", "yi", and "id"). | |
75 * To match the device language to a subscription, we need to convert the old codes. | |
76 */ | |
77 private static String convertOldISOCodes(String language) | |
78 { | |
79 switch (language) | |
80 { | |
81 case HEBREW_OLD: | |
82 return HEBREW_NEW; | |
83 case YIDDISH_OLD: | |
84 return YIDDISH_NEW; | |
85 case INDONESIAN_OLD: | |
86 return INDONESIAN_NEW; | |
87 default: | |
88 return language; | |
89 } | |
90 } | |
91 } | |
OLD | NEW |