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

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

Issue 29345373: Issue 2513 - Adblock Browser does not display chosen filter lists as active right away (Closed)
Patch Set: Instead of implementing listener interfaces, declaring private inner classes + class members Created Dec. 13, 2016, 2:01 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
« no previous file with comments | « mobile/android/thirdparty/org/adblockplus/browser/SubscriptionContainer.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mobile/android/thirdparty/org/adblockplus/browser/SubscriptionPreferenceCategory.java
===================================================================
--- a/mobile/android/thirdparty/org/adblockplus/browser/SubscriptionPreferenceCategory.java
+++ b/mobile/android/thirdparty/org/adblockplus/browser/SubscriptionPreferenceCategory.java
@@ -28,16 +28,17 @@ import android.preference.CheckBoxPrefer
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.util.AttributeSet;
public class SubscriptionPreferenceCategory extends PreferenceCategory
{
volatile static SubscriptionContainer subscriptionContainer = null;
private final CheckBoxChangeListener checkBoxChangeListener = new CheckBoxChangeListener();
+ private final SubscriptionChangeListener subscriptionChangeListener = new SubscriptionChangeListener();
private boolean isEnabledList = false;
private ProgressDialog progressDialog;
public SubscriptionPreferenceCategory(Context context)
{
super(context);
}
@@ -63,39 +64,38 @@ public class SubscriptionPreferenceCateg
}
}
@Override
protected void onAttachedToActivity()
{
this.isEnabledList = this.getKey().endsWith("subscriptionEnabled");
- this.progressDialog = new ProgressDialog(this.getContext());
-
this.setEnabled(false);
this.setShouldDisableView(true);
super.onAttachedToActivity();
- this.progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
- this.progressDialog.setMessage(this.getContext().getString(R.string.abb_adblocking_waiting));
- this.progressDialog.show();
+ showProgressDialog();
AddOnBridge.postToHandler(new Runnable()
{
@Override
public void run()
{
initSubscriptions();
+ subscriptionContainer.addSubscriptionListener(
+ SubscriptionPreferenceCategory.this.subscriptionChangeListener);
+
ThreadUtils.postToUiThread(new Runnable()
{
@Override
public void run()
{
- SubscriptionPreferenceCategory.this.initEntries();
+ SubscriptionPreferenceCategory.this.refreshEntries();
}
});
}
});
}
private CheckBoxPreference createDisabledCheckBox(final int titleId, final int summaryId)
{
@@ -117,36 +117,36 @@ public class SubscriptionPreferenceCateg
cbp.setChecked(true);
cbp.setKey(subscription.url);
cbp.setPersistent(false);
cbp.setChecked(subscriptionContainer.isSubscriptionListed(subscription.url));
cbp.setOnPreferenceChangeListener(this.checkBoxChangeListener);
return cbp;
}
- private void initEntries()
+ private void refreshEntries()
{
if (this.isEnabledList)
{
- this.initEntries(R.string.abb_adblocking_none_selected,
+ this.refreshEntries(R.string.abb_adblocking_none_selected,
R.string.abb_adblocking_select_below, true);
}
else
{
- this.initEntries(R.string.abb_adblocking_none_available,
+ this.refreshEntries(R.string.abb_adblocking_none_available,
R.string.abb_adblocking_all_selected, false);
}
this.setEnabled(true);
this.setShouldDisableView(false);
- this.progressDialog.dismiss();
- this.progressDialog = null;
+
+ dismissProgressDialog();
}
- private void initEntries(final int titleId, final int summaryId, boolean enabled)
+ private void refreshEntries(final int titleId, final int summaryId, boolean enabled)
{
this.removeAll();
final List<SubscriptionContainer.Subscription> entries =
subscriptionContainer.getSubscriptions(enabled);
if (entries.isEmpty())
{
this.addPreference(this.createDisabledCheckBox(titleId, summaryId));
@@ -155,26 +155,54 @@ public class SubscriptionPreferenceCateg
{
for (SubscriptionContainer.Subscription e : entries)
{
this.addPreference(this.createEnabledCheckBox(e));
}
}
}
- private static class CheckBoxChangeListener implements OnPreferenceChangeListener
+ private void showProgressDialog()
+ {
+ 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();
+ }
+
+ private void dismissProgressDialog()
+ {
+ if (this.progressDialog != null)
+ {
+ this.progressDialog.dismiss();
+ this.progressDialog = null;
+ }
+ }
+
+ private class CheckBoxChangeListener implements OnPreferenceChangeListener
{
@Override
public boolean onPreferenceChange(Preference preference, Object newValue)
{
if (preference instanceof CheckBoxPreference && newValue instanceof Boolean)
{
+ showProgressDialog();
+
final CheckBoxPreference cbp = (CheckBoxPreference) preference;
final boolean enable = ((Boolean) newValue).booleanValue();
SubscriptionPreferenceCategory.subscriptionContainer.changeSubscriptionState(
cbp.getKey(),
enable);
}
return true;
}
}
+
+ private class SubscriptionChangeListener implements SubscriptionContainer.SubscriptionListener
+ {
+ @Override
+ public void onSubscriptionUpdated()
+ {
+ SubscriptionPreferenceCategory.this.refreshEntries();
+ }
+ }
}
« no previous file with comments | « mobile/android/thirdparty/org/adblockplus/browser/SubscriptionContainer.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld