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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mobile/android/thirdparty/org/adblockplus/browser/SubscriptionContainer.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 15 matching lines...) Expand all
26 import android.content.Context; 26 import android.content.Context;
27 import android.preference.CheckBoxPreference; 27 import android.preference.CheckBoxPreference;
28 import android.preference.Preference; 28 import android.preference.Preference;
29 import android.preference.PreferenceCategory; 29 import android.preference.PreferenceCategory;
30 import android.util.AttributeSet; 30 import android.util.AttributeSet;
31 31
32 public class SubscriptionPreferenceCategory extends PreferenceCategory 32 public class SubscriptionPreferenceCategory extends PreferenceCategory
33 { 33 {
34 volatile static SubscriptionContainer subscriptionContainer = null; 34 volatile static SubscriptionContainer subscriptionContainer = null;
35 private final CheckBoxChangeListener checkBoxChangeListener = new CheckBoxChan geListener(); 35 private final CheckBoxChangeListener checkBoxChangeListener = new CheckBoxChan geListener();
36 private final SubscriptionChangeListener subscriptionChangeListener = new Subs criptionChangeListener();
36 private boolean isEnabledList = false; 37 private boolean isEnabledList = false;
37 private ProgressDialog progressDialog; 38 private ProgressDialog progressDialog;
38 39
39 public SubscriptionPreferenceCategory(Context context) 40 public SubscriptionPreferenceCategory(Context context)
40 { 41 {
41 super(context); 42 super(context);
42 } 43 }
43 44
44 public SubscriptionPreferenceCategory(Context context, AttributeSet attrs) 45 public SubscriptionPreferenceCategory(Context context, AttributeSet attrs)
45 { 46 {
(...skipping 15 matching lines...) Expand all
61 { 62 {
62 subscriptionContainer.refresh(); 63 subscriptionContainer.refresh();
63 } 64 }
64 } 65 }
65 66
66 @Override 67 @Override
67 protected void onAttachedToActivity() 68 protected void onAttachedToActivity()
68 { 69 {
69 this.isEnabledList = this.getKey().endsWith("subscriptionEnabled"); 70 this.isEnabledList = this.getKey().endsWith("subscriptionEnabled");
70 71
71 this.progressDialog = new ProgressDialog(this.getContext());
72
73 this.setEnabled(false); 72 this.setEnabled(false);
74 this.setShouldDisableView(true); 73 this.setShouldDisableView(true);
75 74
76 super.onAttachedToActivity(); 75 super.onAttachedToActivity();
77 76
78 this.progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 77 showProgressDialog();
79 this.progressDialog.setMessage(this.getContext().getString(R.string.abb_adbl ocking_waiting));
80 this.progressDialog.show();
81 78
82 AddOnBridge.postToHandler(new Runnable() 79 AddOnBridge.postToHandler(new Runnable()
83 { 80 {
84 @Override 81 @Override
85 public void run() 82 public void run()
86 { 83 {
87 initSubscriptions(); 84 initSubscriptions();
85 subscriptionContainer.addSubscriptionListener(
86 SubscriptionPreferenceCategory.this.subscriptionChangeListener);
87
88 ThreadUtils.postToUiThread(new Runnable() 88 ThreadUtils.postToUiThread(new Runnable()
89 { 89 {
90 @Override 90 @Override
91 public void run() 91 public void run()
92 { 92 {
93 SubscriptionPreferenceCategory.this.initEntries(); 93 SubscriptionPreferenceCategory.this.refreshEntries();
94 } 94 }
95 }); 95 });
96 } 96 }
97 }); 97 });
98 } 98 }
99 99
100 private CheckBoxPreference createDisabledCheckBox(final int titleId, final int summaryId) 100 private CheckBoxPreference createDisabledCheckBox(final int titleId, final int summaryId)
101 { 101 {
102 final CheckBoxPreference cbp = new CheckBoxPreference(this.getContext()); 102 final CheckBoxPreference cbp = new CheckBoxPreference(this.getContext());
103 cbp.setTitle(titleId); 103 cbp.setTitle(titleId);
(...skipping 11 matching lines...) Expand all
115 cbp.setTitle(subscription.specialization); 115 cbp.setTitle(subscription.specialization);
116 cbp.setSummary(subscription.title); 116 cbp.setSummary(subscription.title);
117 cbp.setChecked(true); 117 cbp.setChecked(true);
118 cbp.setKey(subscription.url); 118 cbp.setKey(subscription.url);
119 cbp.setPersistent(false); 119 cbp.setPersistent(false);
120 cbp.setChecked(subscriptionContainer.isSubscriptionListed(subscription.url)) ; 120 cbp.setChecked(subscriptionContainer.isSubscriptionListed(subscription.url)) ;
121 cbp.setOnPreferenceChangeListener(this.checkBoxChangeListener); 121 cbp.setOnPreferenceChangeListener(this.checkBoxChangeListener);
122 return cbp; 122 return cbp;
123 } 123 }
124 124
125 private void initEntries() 125 private void refreshEntries()
126 { 126 {
127 if (this.isEnabledList) 127 if (this.isEnabledList)
128 { 128 {
129 this.initEntries(R.string.abb_adblocking_none_selected, 129 this.refreshEntries(R.string.abb_adblocking_none_selected,
130 R.string.abb_adblocking_select_below, true); 130 R.string.abb_adblocking_select_below, true);
131 } 131 }
132 else 132 else
133 { 133 {
134 this.initEntries(R.string.abb_adblocking_none_available, 134 this.refreshEntries(R.string.abb_adblocking_none_available,
135 R.string.abb_adblocking_all_selected, false); 135 R.string.abb_adblocking_all_selected, false);
136 } 136 }
137 137
138 this.setEnabled(true); 138 this.setEnabled(true);
139 this.setShouldDisableView(false); 139 this.setShouldDisableView(false);
140 this.progressDialog.dismiss(); 140
141 this.progressDialog = null; 141 dismissProgressDialog();
142 } 142 }
143 143
144 private void initEntries(final int titleId, final int summaryId, boolean enabl ed) 144 private void refreshEntries(final int titleId, final int summaryId, boolean en abled)
145 { 145 {
146 this.removeAll(); 146 this.removeAll();
147 final List<SubscriptionContainer.Subscription> entries = 147 final List<SubscriptionContainer.Subscription> entries =
148 subscriptionContainer.getSubscriptions(enabled); 148 subscriptionContainer.getSubscriptions(enabled);
149 149
150 if (entries.isEmpty()) 150 if (entries.isEmpty())
151 { 151 {
152 this.addPreference(this.createDisabledCheckBox(titleId, summaryId)); 152 this.addPreference(this.createDisabledCheckBox(titleId, summaryId));
153 } 153 }
154 else 154 else
155 { 155 {
156 for (SubscriptionContainer.Subscription e : entries) 156 for (SubscriptionContainer.Subscription e : entries)
157 { 157 {
158 this.addPreference(this.createEnabledCheckBox(e)); 158 this.addPreference(this.createEnabledCheckBox(e));
159 } 159 }
160 } 160 }
161 } 161 }
162 162
163 private static class CheckBoxChangeListener implements OnPreferenceChangeListe ner 163 private void showProgressDialog()
164 {
165 this.progressDialog = new ProgressDialog(this.getContext());
166 this.progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
167 this.progressDialog.setMessage(this.getContext().getString(R.string.abb_adbl ocking_waiting));
168 this.progressDialog.show();
169 }
170
171 private void dismissProgressDialog()
172 {
173 if (this.progressDialog != null)
174 {
175 this.progressDialog.dismiss();
176 this.progressDialog = null;
177 }
178 }
179
180 private class CheckBoxChangeListener implements OnPreferenceChangeListener
164 { 181 {
165 @Override 182 @Override
166 public boolean onPreferenceChange(Preference preference, Object newValue) 183 public boolean onPreferenceChange(Preference preference, Object newValue)
167 { 184 {
168 if (preference instanceof CheckBoxPreference && newValue instanceof Boolea n) 185 if (preference instanceof CheckBoxPreference && newValue instanceof Boolea n)
169 { 186 {
187 showProgressDialog();
188
170 final CheckBoxPreference cbp = (CheckBoxPreference) preference; 189 final CheckBoxPreference cbp = (CheckBoxPreference) preference;
171 final boolean enable = ((Boolean) newValue).booleanValue(); 190 final boolean enable = ((Boolean) newValue).booleanValue();
172 SubscriptionPreferenceCategory.subscriptionContainer.changeSubscriptionS tate( 191 SubscriptionPreferenceCategory.subscriptionContainer.changeSubscriptionS tate(
173 cbp.getKey(), 192 cbp.getKey(),
174 enable); 193 enable);
175 } 194 }
176 return true; 195 return true;
177 } 196 }
178 } 197 }
198
199 private class SubscriptionChangeListener implements SubscriptionContainer.Subs criptionListener
200 {
201 @Override
202 public void onSubscriptionUpdated()
203 {
204 SubscriptionPreferenceCategory.this.refreshEntries();
205 }
206 }
179 } 207 }
180 208
OLDNEW
« 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