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: Adjusting spacing and curly brackets Created Nov. 2, 2016, 11:53 a.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 11 matching lines...) Expand all
22 import org.mozilla.gecko.R; 22 import org.mozilla.gecko.R;
23 import org.mozilla.gecko.util.ThreadUtils; 23 import org.mozilla.gecko.util.ThreadUtils;
24 24
25 import android.app.ProgressDialog; 25 import android.app.ProgressDialog;
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 implement s
33 Preference.OnPreferenceChangeListener, SubscriptionContainer.Subscriptio nListener
Felix Dahlke 2016/12/13 08:59:20 FYI: We have so far (how I remember it) avoided to
diegocarloslima 2016/12/13 13:31:05 There are a few classes in ABB which implement lis
33 { 34 {
34 volatile static SubscriptionContainer subscriptionContainer = null; 35 volatile static SubscriptionContainer subscriptionContainer = null;
35 private final CheckBoxChangeListener checkBoxChangeListener = new CheckBoxChan geListener();
36 private boolean isEnabledList = false; 36 private boolean isEnabledList = false;
37 private ProgressDialog progressDialog; 37 private ProgressDialog progressDialog;
38 38
39 public SubscriptionPreferenceCategory(Context context) 39 public SubscriptionPreferenceCategory(Context context)
40 { 40 {
41 super(context); 41 super(context);
42 } 42 }
43 43
44 public SubscriptionPreferenceCategory(Context context, AttributeSet attrs) 44 public SubscriptionPreferenceCategory(Context context, AttributeSet attrs)
45 { 45 {
(...skipping 15 matching lines...) Expand all
61 { 61 {
62 subscriptionContainer.refresh(); 62 subscriptionContainer.refresh();
63 } 63 }
64 } 64 }
65 65
66 @Override 66 @Override
67 protected void onAttachedToActivity() 67 protected void onAttachedToActivity()
68 { 68 {
69 this.isEnabledList = this.getKey().endsWith("subscriptionEnabled"); 69 this.isEnabledList = this.getKey().endsWith("subscriptionEnabled");
70 70
71 this.progressDialog = new ProgressDialog(this.getContext());
72
73 this.setEnabled(false); 71 this.setEnabled(false);
74 this.setShouldDisableView(true); 72 this.setShouldDisableView(true);
75 73
76 super.onAttachedToActivity(); 74 super.onAttachedToActivity();
77 75
78 this.progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 76 showProgressDialog();
79 this.progressDialog.setMessage(this.getContext().getString(R.string.abb_adbl ocking_waiting));
80 this.progressDialog.show();
81 77
82 AddOnBridge.postToHandler(new Runnable() 78 AddOnBridge.postToHandler(new Runnable()
83 { 79 {
84 @Override 80 @Override
85 public void run() 81 public void run()
86 { 82 {
87 initSubscriptions(); 83 initSubscriptions();
84 subscriptionContainer.addSubscriptionListener(SubscriptionPreferenceCate gory.this);
88 ThreadUtils.postToUiThread(new Runnable() 85 ThreadUtils.postToUiThread(new Runnable()
89 { 86 {
90 @Override 87 @Override
91 public void run() 88 public void run()
92 { 89 {
93 SubscriptionPreferenceCategory.this.initEntries(); 90 SubscriptionPreferenceCategory.this.refreshEntries();
94 } 91 }
95 }); 92 });
96 } 93 }
97 }); 94 });
98 } 95 }
99 96
97 @Override
98 public boolean onPreferenceChange(Preference preference, Object newValue)
99 {
100 if (preference instanceof CheckBoxPreference && newValue instanceof Boolean)
101 {
102 showProgressDialog();
103
104 final CheckBoxPreference cbp = (CheckBoxPreference) preference;
105 final boolean enable = ((Boolean) newValue).booleanValue();
106 SubscriptionPreferenceCategory.subscriptionContainer.changeSubscriptionSta te(
107 cbp.getKey(),
108 enable);
109 }
110 return true;
111 }
112
113 @Override
114 public void onSubscriptionUpdated()
115 {
116 refreshEntries();
117 }
118
100 private CheckBoxPreference createDisabledCheckBox(final int titleId, final int summaryId) 119 private CheckBoxPreference createDisabledCheckBox(final int titleId, final int summaryId)
101 { 120 {
102 final CheckBoxPreference cbp = new CheckBoxPreference(this.getContext()); 121 final CheckBoxPreference cbp = new CheckBoxPreference(this.getContext());
103 cbp.setTitle(titleId); 122 cbp.setTitle(titleId);
104 cbp.setSummary(summaryId); 123 cbp.setSummary(summaryId);
105 cbp.setEnabled(false); 124 cbp.setEnabled(false);
106 cbp.setShouldDisableView(true); 125 cbp.setShouldDisableView(true);
107 cbp.setSelectable(false); 126 cbp.setSelectable(false);
108 return cbp; 127 return cbp;
109 } 128 }
110 129
111 private CheckBoxPreference createEnabledCheckBox( 130 private CheckBoxPreference createEnabledCheckBox(
112 final SubscriptionContainer.Subscription subscription) 131 final SubscriptionContainer.Subscription subscription)
113 { 132 {
114 final CheckBoxPreference cbp = new CheckBoxPreference(this.getContext()); 133 final CheckBoxPreference cbp = new CheckBoxPreference(this.getContext());
115 cbp.setTitle(subscription.specialization); 134 cbp.setTitle(subscription.specialization);
116 cbp.setSummary(subscription.title); 135 cbp.setSummary(subscription.title);
117 cbp.setChecked(true); 136 cbp.setChecked(true);
118 cbp.setKey(subscription.url); 137 cbp.setKey(subscription.url);
119 cbp.setPersistent(false); 138 cbp.setPersistent(false);
120 cbp.setChecked(subscriptionContainer.isSubscriptionListed(subscription.url)) ; 139 cbp.setChecked(subscriptionContainer.isSubscriptionListed(subscription.url)) ;
121 cbp.setOnPreferenceChangeListener(this.checkBoxChangeListener); 140 cbp.setOnPreferenceChangeListener(SubscriptionPreferenceCategory.this);
122 return cbp; 141 return cbp;
123 } 142 }
124 143
125 private void initEntries() 144 private void refreshEntries()
126 { 145 {
127 if (this.isEnabledList) 146 if (this.isEnabledList)
128 { 147 {
129 this.initEntries(R.string.abb_adblocking_none_selected, 148 this.refreshEntries(R.string.abb_adblocking_none_selected,
130 R.string.abb_adblocking_select_below, true); 149 R.string.abb_adblocking_select_below, true);
131 } 150 }
132 else 151 else
133 { 152 {
134 this.initEntries(R.string.abb_adblocking_none_available, 153 this.refreshEntries(R.string.abb_adblocking_none_available,
135 R.string.abb_adblocking_all_selected, false); 154 R.string.abb_adblocking_all_selected, false);
136 } 155 }
137 156
138 this.setEnabled(true); 157 this.setEnabled(true);
139 this.setShouldDisableView(false); 158 this.setShouldDisableView(false);
140 this.progressDialog.dismiss(); 159
141 this.progressDialog = null; 160 dismissProgressDialog();
142 } 161 }
143 162
144 private void initEntries(final int titleId, final int summaryId, boolean enabl ed) 163 private void refreshEntries(final int titleId, final int summaryId, boolean en abled)
145 { 164 {
146 this.removeAll(); 165 this.removeAll();
147 final List<SubscriptionContainer.Subscription> entries = 166 final List<SubscriptionContainer.Subscription> entries =
148 subscriptionContainer.getSubscriptions(enabled); 167 subscriptionContainer.getSubscriptions(enabled);
149 168
150 if (entries.isEmpty()) 169 if (entries.isEmpty())
151 { 170 {
152 this.addPreference(this.createDisabledCheckBox(titleId, summaryId)); 171 this.addPreference(this.createDisabledCheckBox(titleId, summaryId));
153 } 172 }
154 else 173 else
155 { 174 {
156 for (SubscriptionContainer.Subscription e : entries) 175 for (SubscriptionContainer.Subscription e : entries)
157 { 176 {
158 this.addPreference(this.createEnabledCheckBox(e)); 177 this.addPreference(this.createEnabledCheckBox(e));
159 } 178 }
160 } 179 }
161 } 180 }
162 181
163 private static class CheckBoxChangeListener implements OnPreferenceChangeListe ner 182 private void showProgressDialog()
164 { 183 {
165 @Override 184 this.progressDialog = new ProgressDialog(this.getContext());
166 public boolean onPreferenceChange(Preference preference, Object newValue) 185 this.progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
186 this.progressDialog.setMessage(this.getContext().getString(R.string.abb_adbl ocking_waiting));
187 this.progressDialog.show();
188 }
189
190 private void dismissProgressDialog()
191 {
192 if (this.progressDialog != null)
167 { 193 {
168 if (preference instanceof CheckBoxPreference && newValue instanceof Boolea n) 194 this.progressDialog.dismiss();
169 { 195 this.progressDialog = null;
170 final CheckBoxPreference cbp = (CheckBoxPreference) preference;
171 final boolean enable = ((Boolean) newValue).booleanValue();
172 SubscriptionPreferenceCategory.subscriptionContainer.changeSubscriptionS tate(
173 cbp.getKey(),
174 enable);
175 }
176 return true;
177 } 196 }
178 } 197 }
179 } 198 }
180 199
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