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

Delta Between Two Patch Sets: adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/MoreBlockingPreferenceCategory.java

Issue 29453722: Noissue - Lint adjustments and optimizations (Closed)
Left Patch Set: Created June 1, 2017, 9:30 p.m.
Right Patch Set: Adjusting HashSet initialization in Subscription Created July 19, 2017, 4:40 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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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.sbrowser.contentblocker; 18 package org.adblockplus.sbrowser.contentblocker;
19 19
20 import java.util.Collections; 20 import java.util.Collections;
21 import java.util.HashMap; 21 import java.util.HashMap;
22 import java.util.List; 22 import java.util.List;
23 23
24 import org.adblockplus.sbrowser.contentblocker.engine.DefaultSubscriptionInfo; 24 import org.adblockplus.sbrowser.contentblocker.engine.DefaultSubscriptionInfo;
25 import org.adblockplus.sbrowser.contentblocker.engine.Engine; 25 import org.adblockplus.sbrowser.contentblocker.engine.Engine;
26 import org.adblockplus.sbrowser.contentblocker.engine.EngineService; 26 import org.adblockplus.sbrowser.contentblocker.engine.EngineService;
27 import org.adblockplus.sbrowser.contentblocker.engine.SubscriptionInfo; 27 import org.adblockplus.sbrowser.contentblocker.engine.SubscriptionInfo;
28 import org.adblockplus.adblockplussbrowser.R; 28 import org.adblockplus.adblockplussbrowser.R;
29 import org.adblockplus.sbrowser.contentblocker.preferences.MultilineCheckBoxPref erence;
29 30
30 import android.content.Context; 31 import android.content.Context;
31 import android.preference.CheckBoxPreference;
32 import android.preference.Preference; 32 import android.preference.Preference;
33 import android.preference.PreferenceCategory; 33 import android.preference.PreferenceCategory;
34 import android.preference.Preference.OnPreferenceChangeListener; 34 import android.preference.Preference.OnPreferenceChangeListener;
35 import android.text.format.DateUtils; 35 import android.text.format.DateUtils;
36 import android.util.AttributeSet; 36 import android.util.AttributeSet;
37 import android.view.View;
38 import android.view.ViewGroup;
39 37
40 public class MoreBlockingPreferenceCategory extends PreferenceCategory implement s 38 public class MoreBlockingPreferenceCategory extends PreferenceCategory implement s
41 EngineService.OnEngineCreatedCallback, OnPreferenceChangeListener 39 EngineService.OnEngineCreatedCallback, OnPreferenceChangeListener
42 { 40 {
43 private Engine engine = null; 41 private Engine engine = null;
44 private static final int[] WHITELISTED_LIST_TITLES = 42 private static final int[] WHITELISTED_LIST_TITLES =
45 { 43 {
46 R.string.subscription_disable_tracking, 44 R.string.subscription_disable_tracking,
47 R.string.subscription_disable_malware, 45 R.string.subscription_disable_malware,
48 R.string.subscription_disable_anti_adblock, 46 R.string.subscription_disable_anti_adblock,
(...skipping 22 matching lines...) Expand all
71 { 69 {
72 super(context); 70 super(context);
73 } 71 }
74 72
75 public MoreBlockingPreferenceCategory(final Context context, final AttributeSe t attrs) 73 public MoreBlockingPreferenceCategory(final Context context, final AttributeSe t attrs)
76 { 74 {
77 super(context, attrs); 75 super(context, attrs);
78 } 76 }
79 77
80 @Override 78 @Override
81 protected View onCreateView(final ViewGroup parent)
82 {
83 return super.onCreateView(parent);
84 }
85
86 @Override
87 protected void onAttachedToActivity() 79 protected void onAttachedToActivity()
88 { 80 {
89 EngineService.startService(this.getContext().getApplicationContext(), this); 81 EngineService.startService(this.getContext().getApplicationContext(), this);
90 super.onAttachedToActivity(); 82 super.onAttachedToActivity();
91 } 83 }
92 84
93 @Override 85 @Override
94 public void onEngineCreated(final Engine engine, final boolean success) 86 public void onEngineCreated(final Engine engine, final boolean success)
95 { 87 {
96 this.engine = engine; 88 this.engine = engine;
97 final String aaLink = engine.getPrefsDefault(Engine.SUBSCRIPTIONS_EXCEPTIONS URL); 89 final String aaLink = engine.getPrefsDefault(Engine.SUBSCRIPTIONS_EXCEPTIONS URL);
98 90
99 if (success) 91 if (success)
100 { 92 {
101 final List<SubscriptionInfo> subs = engine.getListedSubscriptions(); 93 final List<SubscriptionInfo> subs = engine.getListedSubscriptions();
102 Collections.sort(subs); 94 Collections.sort(subs);
103 this.removeAll(); 95 this.removeAll();
104 96
105 for (final SubscriptionInfo sub : subs) 97 for (final SubscriptionInfo sub : subs)
106 { 98 {
107 final DefaultSubscriptionInfo info = engine.getDefaultSubscriptionInfoFo rUrl(sub.getUrl()); 99 final DefaultSubscriptionInfo info = engine.getDefaultSubscriptionInfoFo rUrl(sub.getUrl());
108 100
109 Integer resInt = URL_TO_RES_ID_MAP.get(sub.getUrl()); 101 Integer resInt = URL_TO_RES_ID_MAP.get(sub.getUrl());
110 if (!(aaLink.equals(sub.getUrl()) || sub.getTitle().startsWith("__")) 102 if (!(aaLink.equals(sub.getUrl()) || sub.getTitle().startsWith("__"))
111 && resInt != null 103 && resInt != null
112 && (info == null || info.getPrefixes().isEmpty() || sub.getType() != SubscriptionInfo.Type.ADS)) 104 && (info == null || info.getPrefixes().isEmpty() || sub.getType() != SubscriptionInfo.Type.ADS))
113 { 105 {
114 106
115 final CheckBoxPreference cbp = new CheckBoxPreference(this.getContext( )); 107 final MultilineCheckBoxPreference cbp = new MultilineCheckBoxPreferenc e(this.getContext());
116 108
117 if (sub.isEnabled()) 109 if (sub.isEnabled())
118 { 110 {
119 final StringBuilder sb = new StringBuilder(); 111 final StringBuilder sb = new StringBuilder();
120 sb.append(this.getContext().getString(R.string.last_update)); 112 sb.append(this.getContext().getString(R.string.last_update));
121 sb.append(' '); 113 sb.append(' ');
122 final long timestamp = sub.getLastUpdateTime(); 114 final long timestamp = sub.getLastUpdateTime();
123 if (timestamp > 0) 115 if (timestamp > 0)
124 { 116 {
125 sb.append(DateUtils.formatDateTime(this.getContext(), timestamp, 117 sb.append(DateUtils.formatDateTime(this.getContext(), timestamp,
(...skipping 14 matching lines...) Expand all
140 this.addPreference(cbp); 132 this.addPreference(cbp);
141 } 133 }
142 } 134 }
143 } 135 }
144 } 136 }
145 137
146 @Override 138 @Override
147 public boolean onPreferenceChange(final Preference preference, final Object ne wValue) 139 public boolean onPreferenceChange(final Preference preference, final Object ne wValue)
148 { 140 {
149 final String id = preference.getKey(); 141 final String id = preference.getKey();
150 final boolean enabled = ((Boolean) newValue); 142 final boolean enabled = (Boolean) newValue;
anton 2017/06/02 07:39:56 minor: double brackets are not required, it could
diegocarloslima 2017/06/02 21:03:41 Acknowledged.
151 143
152 this.engine.changeSubscriptionState(id, enabled); 144 this.engine.changeSubscriptionState(id, enabled);
153 145
154 return true; 146 return true;
155 } 147 }
156 } 148 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld