Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 |
(...skipping 20 matching lines...) Expand all Loading... | |
31 import org.adblockplus.adblockplussbrowser.R; | 31 import org.adblockplus.adblockplussbrowser.R; |
32 import org.adblockplus.sbrowser.contentblocker.engine.Engine; | 32 import org.adblockplus.sbrowser.contentblocker.engine.Engine; |
33 import org.adblockplus.sbrowser.contentblocker.engine.EngineService; | 33 import org.adblockplus.sbrowser.contentblocker.engine.EngineService; |
34 | 34 |
35 import java.util.Collections; | 35 import java.util.Collections; |
36 import java.util.Set; | 36 import java.util.Set; |
37 import java.util.TreeSet; | 37 import java.util.TreeSet; |
38 | 38 |
39 public class WhitelistedWebsitesPreferenceCategory extends PreferenceCategory | 39 public class WhitelistedWebsitesPreferenceCategory extends PreferenceCategory |
40 { | 40 { |
41 | 41 private final Set<String> whitelistedWebsites = new TreeSet<String>(); |
anton
2017/03/06 09:36:32
is empty line required?
diegocarloslima
2017/03/09 20:15:04
Not actually. Will fix that
| |
42 private final Set<String> whitelistedWebsites = new TreeSet<>(); | |
43 private Engine engine; | 42 private Engine engine; |
44 | 43 |
45 public WhitelistedWebsitesPreferenceCategory(Context context, AttributeSet att rs) | 44 public WhitelistedWebsitesPreferenceCategory(Context context, AttributeSet att rs) |
anton
2017/03/06 09:36:32
please make sure it suits into line length (see ou
Felix Dahlke
2017/03/07 15:43:38
For Java code it's 100, see: https://developer.moz
anton
2017/03/09 09:57:40
no problem
| |
46 { | 45 { |
47 super(context, attrs); | 46 super(context, attrs); |
48 // This is required to remove the title TextView of the PreferenceCategory | 47 // This is required to remove the title TextView of the PreferenceCategory |
49 this.setLayoutResource(R.layout.empty_view); | 48 this.setLayoutResource(R.layout.empty_view); |
50 } | 49 } |
51 | 50 |
52 @Override | 51 @Override |
53 protected void onAttachedToActivity() | 52 protected void onAttachedToActivity() |
54 { | 53 { |
55 super.onAttachedToActivity(); | 54 super.onAttachedToActivity(); |
56 EngineService.startService(this.getContext().getApplicationContext(), | 55 EngineService.startService(this.getContext().getApplicationContext(), |
57 new EngineService.OnEngineCreatedCallback() | 56 new EngineService.OnEngineCreatedCallback() |
58 { | 57 { |
59 @Override | 58 @Override |
60 public void onEngineCreated(Engine engine, boolean success) | 59 public void onEngineCreated(Engine engine, boolean success) |
61 { | 60 { |
62 if (!success) | 61 if (!success) |
63 { | 62 { |
64 return; | 63 return; |
65 } | 64 } |
66 WhitelistedWebsitesPreferenceCategory.this.engine = engine; | 65 WhitelistedWebsitesPreferenceCategory.this.engine = engine; |
67 WhitelistedWebsitesPreferenceCategory.this.initEntries(); | 66 WhitelistedWebsitesPreferenceCategory.this.initEntries(); |
68 } | 67 } |
69 }); | 68 }); |
70 } | 69 } |
71 | 70 |
72 private void initEntries() | 71 private void initEntries() |
73 { | 72 { |
74 final SharedPreferences prefs = | 73 final SharedPreferences prefs = |
75 PreferenceManager.getDefaultSharedPreferences(this.getContext().getAppli cationContext()); | 74 PreferenceManager.getDefaultSharedPreferences(this.getContext().getAppli cationContext()); |
anton
2017/03/06 09:36:32
please make sure it suits into line length (see ou
| |
76 final String key = this.getContext().getString(R.string.key_whitelisted_webs ites); | 75 final String key = this.getContext().getString(R.string.key_whitelisted_webs ites); |
anton
2017/03/06 09:36:31
please make sure it suits into line length (see ou
| |
77 this.whitelistedWebsites.clear(); | 76 this.whitelistedWebsites.clear(); |
78 this.whitelistedWebsites.addAll(prefs.getStringSet(key, Collections.<String> emptySet())); | 77 this.whitelistedWebsites.addAll(prefs.getStringSet(key, Collections.<String> emptySet())); |
anton
2017/03/06 09:36:31
please make sure it suits into line length (see ou
| |
79 this.refreshEntries(); | 78 this.refreshEntries(); |
80 } | 79 } |
81 | 80 |
82 private void refreshEntries() | 81 private void refreshEntries() |
83 { | 82 { |
84 this.removeAll(); | 83 this.removeAll(); |
85 for (final String url : this.whitelistedWebsites) | 84 for (final String url : this.whitelistedWebsites) |
86 { | 85 { |
87 final WhitelistedWebsitePreference whitelistedWebsitePreference = | 86 final WhitelistedWebsitePreference whitelistedWebsitePreference = |
88 new WhitelistedWebsitePreference(this.getContext(), url, new DialogInt erface.OnClickListener() | 87 new WhitelistedWebsitePreference(this.getContext(), url, new DialogInt erface.OnClickListener() |
anton
2017/03/06 09:36:31
please make sure it suits into line length (see ou
| |
89 { | 88 { |
90 @Override | 89 @Override |
91 public void onClick(DialogInterface dialog, int which) | 90 public void onClick(DialogInterface dialog, int which) |
92 { | 91 { |
93 removeWhitelistedWebsite(url); | 92 removeWhitelistedWebsite(url); |
94 } | 93 } |
95 }); | 94 }); |
96 this.addPreference(whitelistedWebsitePreference); | 95 this.addPreference(whitelistedWebsitePreference); |
97 } | 96 } |
98 | 97 |
99 final UrlInputOpenerPreference urlPreference = new UrlInputOpenerPreference( this.getContext()); | 98 final UrlInputOpenerPreference urlPreference = new UrlInputOpenerPreference( this.getContext()); |
anton
2017/03/06 09:36:32
please make sure it suits into line length (see ou
| |
100 urlPreference.setTitle(R.string.whitelisted_websites_add_button); | 99 urlPreference.setTitle(R.string.whitelisted_websites_add_button); |
101 urlPreference.setDialogTitle(R.string.whitelist_website_dialog_title); | 100 urlPreference.setDialogTitle(R.string.whitelist_website_dialog_title); |
102 urlPreference.setDialogMessage(R.string.whitelist_website_dialog_message); | 101 urlPreference.setDialogMessage(R.string.whitelist_website_dialog_message); |
103 urlPreference.getEditText().setHint(R.string.whitelist_website_dialog_hint); | 102 urlPreference.getEditText().setHint(R.string.whitelist_website_dialog_hint); |
104 urlPreference.setOnUrlReadyListener(new UrlInputOpenerPreference.OnUrlReadyL istener() | 103 urlPreference.setOnUrlReadyListener(new UrlInputOpenerPreference.OnUrlReadyL istener() |
anton
2017/03/06 09:36:32
please make sure it suits into line length (see ou
| |
105 { | 104 { |
106 @Override | 105 @Override |
107 public void onUrlReady(String url) | 106 public void onUrlReady(String url) |
108 { | 107 { |
109 WhitelistedWebsitesPreferenceCategory.this.whitelistWebsite(url); | 108 WhitelistedWebsitesPreferenceCategory.this.whitelistWebsite(url); |
110 } | 109 } |
111 }); | 110 }); |
112 this.addPreference(urlPreference); | 111 this.addPreference(urlPreference); |
113 } | 112 } |
114 | 113 |
115 private void whitelistWebsite(String url) | 114 private void whitelistWebsite(String url) |
116 { | 115 { |
117 this.whitelistedWebsites.add(url); | 116 this.whitelistedWebsites.add(url); |
118 final SharedPreferences prefs = | 117 final SharedPreferences prefs = |
119 PreferenceManager.getDefaultSharedPreferences(this.getContext().getAppli cationContext()); | 118 PreferenceManager.getDefaultSharedPreferences(this.getContext().getAppli cationContext()); |
anton
2017/03/06 09:36:32
please make sure it suits into line length (see ou
| |
120 final String key = this.getContext().getString(R.string.key_whitelisted_webs ites); | 119 final String key = this.getContext().getString(R.string.key_whitelisted_webs ites); |
anton
2017/03/06 09:36:31
please make sure it suits into line length (see ou
| |
121 prefs.edit().putStringSet(key, this.whitelistedWebsites).apply(); | 120 prefs.edit().putStringSet(key, this.whitelistedWebsites).apply(); |
122 this.refreshEntries(); | 121 this.refreshEntries(); |
123 this.engine.requestUpdateBroadcast(); | 122 this.engine.requestUpdateBroadcast(); |
124 } | 123 } |
125 | 124 |
126 private void removeWhitelistedWebsite(String url) | 125 private void removeWhitelistedWebsite(String url) |
127 { | 126 { |
128 this.whitelistedWebsites.remove(url); | 127 this.whitelistedWebsites.remove(url); |
129 final SharedPreferences prefs = | 128 final SharedPreferences prefs = |
130 PreferenceManager.getDefaultSharedPreferences(this.getContext().getAppli cationContext()); | 129 PreferenceManager.getDefaultSharedPreferences(this.getContext().getAppli cationContext()); |
anton
2017/03/06 09:36:31
please make sure it suits into line length (see ou
| |
131 final String key = this.getContext().getString(R.string.key_whitelisted_webs ites); | 130 final String key = this.getContext().getString(R.string.key_whitelisted_webs ites); |
anton
2017/03/06 09:36:31
please make sure it suits into line length (see ou
| |
132 prefs.edit().putStringSet(key, this.whitelistedWebsites).apply(); | 131 prefs.edit().putStringSet(key, this.whitelistedWebsites).apply(); |
133 this.refreshEntries(); | 132 this.refreshEntries(); |
134 this.engine.requestUpdateBroadcast(); | 133 this.engine.requestUpdateBroadcast(); |
135 } | 134 } |
136 | 135 |
137 private static class WhitelistedWebsitePreference extends DialogPreference | 136 private static class WhitelistedWebsitePreference extends DialogPreference |
138 { | 137 { |
139 private final DialogInterface.OnClickListener onDeleteClickListener; | 138 private final DialogInterface.OnClickListener onDeleteClickListener; |
140 | 139 |
141 WhitelistedWebsitePreference(Context context, String url, DialogInterface.On ClickListener onDeleteClickListener) | 140 WhitelistedWebsitePreference(Context context, String url, |
anton
2017/03/09 09:57:40
exceeds 100 characters line limit (not too signifi
| |
141 DialogInterface.OnClickListener onDeleteClickListener) | |
142 { | 142 { |
143 super(context); | 143 super(context); |
144 this.onDeleteClickListener = onDeleteClickListener; | 144 this.onDeleteClickListener = onDeleteClickListener; |
145 final String message = context.getString(R.string.whitelist_remove_dialog_ message, url); | 145 final String message = context.getString(R.string.whitelist_remove_dialog_ message, url); |
anton
2017/03/06 09:36:32
please make sure it suits into line length (see ou
| |
146 setWidgetLayoutResource(R.layout.whitelisted_website_delete_widget); | 146 setWidgetLayoutResource(R.layout.whitelisted_website_delete_widget); |
147 setTitle(url); | 147 setTitle(url); |
148 setDialogTitle(R.string.whitelist_remove_dialog_title); | 148 setDialogTitle(R.string.whitelist_remove_dialog_title); |
149 setDialogMessage(Html.fromHtml(message)); | 149 setDialogMessage(Html.fromHtml(message)); |
150 setNegativeButtonText(android.R.string.cancel); | 150 setNegativeButtonText(android.R.string.cancel); |
151 } | 151 } |
152 | 152 |
153 @Override | 153 @Override |
154 protected void onBindView(View view) | 154 protected void onBindView(View view) |
155 { | 155 { |
156 super.onBindView(view); | 156 super.onBindView(view); |
157 final View deleteButton = view.findViewById(R.id.whitelisted_website_delet e_button); | 157 final View deleteButton = view.findViewById(R.id.whitelisted_website_delet e_button); |
anton
2017/03/06 09:36:32
please make sure it suits into line length (see ou
| |
158 deleteButton.setOnClickListener(new View.OnClickListener() | 158 deleteButton.setOnClickListener(new View.OnClickListener() |
159 { | 159 { |
160 @Override | 160 @Override |
161 public void onClick(View v) | 161 public void onClick(View v) |
162 { | 162 { |
163 if (getDialog() == null || !getDialog().isShowing()) | 163 if (getDialog() == null || !getDialog().isShowing()) |
164 { | 164 { |
165 showDialog(null); | 165 showDialog(null); |
166 } | 166 } |
167 } | 167 } |
168 }); | 168 }); |
169 } | 169 } |
170 | 170 |
171 @Override | 171 @Override |
172 protected void onClick() | 172 protected void onClick() |
173 { | 173 { |
174 // Overriding the default behaviour of showing a dialog here | 174 // Overriding the default behaviour of showing a dialog here |
175 // We just want to show a dialog when the delete button is clicked | 175 // We just want to show a dialog when the delete button is clicked |
176 } | 176 } |
177 | 177 |
178 @Override | 178 @Override |
179 protected void onPrepareDialogBuilder(AlertDialog.Builder builder) | 179 protected void onPrepareDialogBuilder(AlertDialog.Builder builder) |
180 { | 180 { |
181 builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClic kListener() | 181 builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClic kListener() |
anton
2017/03/06 09:36:31
please make sure it suits into line length (see ou
| |
182 { | 182 { |
183 @Override | 183 @Override |
184 public void onClick(DialogInterface dialog, int which) | 184 public void onClick(DialogInterface dialog, int which) |
185 { | 185 { |
186 if (WhitelistedWebsitePreference.this.onDeleteClickListener != null) | 186 if (WhitelistedWebsitePreference.this.onDeleteClickListener != null) |
187 { | 187 { |
188 WhitelistedWebsitePreference.this.onDeleteClickListener.onClick(dial og, which); | 188 WhitelistedWebsitePreference.this.onDeleteClickListener.onClick(dial og, which); |
anton
2017/03/06 09:36:32
please make sure it suits into line length (see ou
| |
189 } | 189 } |
190 } | 190 } |
191 }); | 191 }); |
192 } | 192 } |
193 } | 193 } |
194 } | 194 } |
LEFT | RIGHT |