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

Unified Diff: mobile/android/thirdparty/org/adblockplus/browser/MoreSubscriptionsPreferenceGroup.java

Issue 29543774: Issue 2801 - Create 'Whitelisted websites' screen and add link to 'Ad blocking' screen (Closed)
Patch Set: Adjustments accordingly to Thomas's comments. Also, adjusting strings for multilocale build Created Sept. 19, 2017, 3:18 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mobile/android/thirdparty/org/adblockplus/browser/MoreSubscriptionsPreferenceGroup.java
===================================================================
--- a/mobile/android/thirdparty/org/adblockplus/browser/MoreSubscriptionsPreferenceGroup.java
+++ b/mobile/android/thirdparty/org/adblockplus/browser/MoreSubscriptionsPreferenceGroup.java
@@ -34,25 +34,25 @@ import android.preference.CheckBoxPrefer
import android.preference.Preference;
import android.preference.PreferenceGroup;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
public class MoreSubscriptionsPreferenceGroup extends PreferenceGroup implements
- UrlInputDialog.UrlReadyCallback
+ InputValidatorDialogPreference.OnInputReadyListener
{
private static final String TAG = "AdblockBrowser.OtherPreferenceGroup";
private static final HashMap<String, Integer> BUILTIN_URL_TO_INDEX = new HashMap<String, Integer>();
private static final HashSet<String> IGNORED_URLS = new HashSet<String>();
private static SubscriptionContainer recommendedSubscriptions = null;
private final CheckBoxChangeListener checkBoxChangeListener = new CheckBoxChangeListener();
- private final ActiveSubscriptionContainer activeSubscriptions;
+ private final ActiveSubscriptionContainer activeSubscriptions = new ActiveSubscriptionContainer();
private ProgressDialog progressDialog;
private static final int[] BUILTIN_TITLES =
{
R.string.abb_subscription_disable_tracking,
R.string.abb_subscription_disable_malware,
R.string.abb_subscription_disable_anti_adblock,
R.string.abb_subscription_disable_social_media
@@ -65,16 +65,18 @@ public class MoreSubscriptionsPreference
"Malware Domains",
"https://easylist-downloads.adblockplus.org/malwaredomains_full.txt",
"Adblock Warning Removal List",
"https://easylist-downloads.adblockplus.org/antiadblockfilters.txt",
"Fanboy's Social Blocking List",
"https://easylist-downloads.adblockplus.org/fanboy-social.txt"
};
+ private static final String USER_SUBSCRIPTION_PREFIX = "~user~";
+
static
{
for (int i = 0; i < BUILTIN_TITLES.length; i++)
{
BUILTIN_URL_TO_INDEX.put(BUILTIN_LISTS[i * 2 + 1], Integer.valueOf(i));
}
IGNORED_URLS.add("https://easylist-downloads.adblockplus.org/exceptionrules.txt");
@@ -97,17 +99,16 @@ public class MoreSubscriptionsPreference
{
this(context, attrs, 0);
}
public MoreSubscriptionsPreferenceGroup(final Context context, final AttributeSet attrs,
final int defStyleAttr)
{
super(context, attrs, defStyleAttr);
- this.activeSubscriptions = new ActiveSubscriptionContainer(context);
}
@Override
protected View onCreateView(final ViewGroup parent)
{
this.setLayoutResource(R.layout.abb_minimal_widget);
return super.onCreateView(parent);
}
@@ -139,18 +140,16 @@ public class MoreSubscriptionsPreference
super.onAttachedToActivity();
this.progressDialog = new ProgressDialog(this.getContext());
this.progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
this.progressDialog.setMessage(this.getContext().getString(R.string.abb_adblocking_waiting));
this.progressDialog.show();
- UrlInputOpenerPreference.setRedirectUrlReadyCallback(this);
-
AddOnBridge.postToHandler(new Runnable()
{
@Override
public void run()
{
initRecommendedSubscriptions();
MoreSubscriptionsPreferenceGroup.this.activeSubscriptions.refresh();
@@ -164,45 +163,50 @@ public class MoreSubscriptionsPreference
});
}
});
}
private void initEntries()
{
this.removeAll();
- int i = 0;
- for (; i < BUILTIN_TITLES.length; i++)
+ for (int i = 0; i < BUILTIN_TITLES.length; i++)
{
final CheckBoxPreference cbp = new CustomCheckBoxPreference(this.getContext());
final String url = BUILTIN_LISTS[i * 2 + 1];
- cbp.setOrder(i);
cbp.setTitle(BUILTIN_TITLES[i]);
cbp.setKey(url);
cbp.setChecked(this.activeSubscriptions.enabledSubscriptions.containsKey(url));
cbp.setOnPreferenceChangeListener(this.checkBoxChangeListener);
cbp.setPersistent(false);
this.addPreference(cbp);
}
for (Entry<String, String> e : this.activeSubscriptions.enabledSubscriptions.entrySet())
{
if (!BUILTIN_URL_TO_INDEX.containsKey(e.getKey()))
{
final CheckBoxPreference cbp = new CustomCheckBoxPreference(this.getContext());
- cbp.setOrder(i++);
cbp.setTitle(e.getValue());
cbp.setKey(e.getKey());
cbp.setChecked(true);
cbp.setOnPreferenceChangeListener(this.checkBoxChangeListener);
cbp.setPersistent(false);
this.addPreference(cbp);
}
}
+ final InputValidatorDialogPreference inputPreference = new InputValidatorDialogPreference(
+ this.getContext());
+ inputPreference.setTitle(R.string.abb_pref_category_add_other_list);
+ inputPreference.setDialogTitle(R.string.abb_pref_category_add_other_list);
+ inputPreference.getEditText().setHint(R.string.abb_add_subscription_url);
+ inputPreference.setOnInputReadyListener(this);
+ this.addPreference(inputPreference);
+
this.setEnabled(true);
this.setShouldDisableView(false);
if (this.progressDialog != null)
{
this.progressDialog.dismiss();
this.progressDialog = null;
}
}
@@ -260,37 +264,26 @@ public class MoreSubscriptionsPreference
MoreSubscriptionsPreferenceGroup.this.progressDialog = null;
}
}
}
});
}
@Override
- public void callback(final String url)
+ public void onInputReady(String input)
{
- if (url == null)
- {
- return;
- }
-
- Log.d(TAG, "Adding: " + url);
- this.addNewSubscription(url);
+ Log.d(TAG, "Adding: " + input);
+ this.addNewSubscription(input);
}
private static class ActiveSubscriptionContainer implements AdblockPlusApiCallback
{
public final HashMap<String, String> enabledSubscriptions = new HashMap<String, String>();
private final Semaphore entriesReady = new Semaphore(0);
- private final Context context;
-
- ActiveSubscriptionContainer(Context context)
- {
- this.context = context;
- }
public void refresh()
{
AddOnBridge.queryActiveSubscriptions(this);
this.entriesReady.acquireUninterruptibly();
}
@Override
@@ -300,24 +293,19 @@ public class MoreSubscriptionsPreference
{
this.enabledSubscriptions.clear();
if (jsObject.getBoolean("success"))
{
NativeJSObject[] subs = jsObject.getObjectArray("value");
for (int i = 0; i < subs.length; i++)
{
final String url = subs[i].getString("url");
+ final String title = subs[i].has("title") ? subs[i].getString("title") : url;
- String title = subs[i].has("title") ? subs[i].getString("title") : url;
- if (title.startsWith("~user~"))
- {
- title = this.context.getString(R.string.abb_pref_category_whitelisted_sites);
- }
-
- if (!IGNORED_URLS.contains(url))
+ if (!IGNORED_URLS.contains(url) && !url.startsWith(USER_SUBSCRIPTION_PREFIX))
{
Log.d(TAG, "Adding: " + url + ", " + title);
this.enabledSubscriptions.put(url, title);
}
}
}
}
finally

Powered by Google App Engine
This is Rietveld