| 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-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 Loading... | |
| 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 implement s | 32 public class SubscriptionPreferenceCategory extends PreferenceCategory |
| 33 Preference.OnPreferenceChangeListener, SubscriptionContainer.Subscriptio nListener | |
| 34 { | 33 { |
| 35 volatile static SubscriptionContainer subscriptionContainer = null; | 34 volatile static SubscriptionContainer subscriptionContainer = null; |
| 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 28 matching lines...) Expand all Loading... | |
| 74 super.onAttachedToActivity(); | 75 super.onAttachedToActivity(); |
| 75 | 76 |
| 76 showProgressDialog(); | 77 showProgressDialog(); |
| 77 | 78 |
| 78 AddOnBridge.postToHandler(new Runnable() | 79 AddOnBridge.postToHandler(new Runnable() |
| 79 { | 80 { |
| 80 @Override | 81 @Override |
| 81 public void run() | 82 public void run() |
| 82 { | 83 { |
| 83 initSubscriptions(); | 84 initSubscriptions(); |
| 84 subscriptionContainer.addSubscriptionListener(SubscriptionPreferenceCate gory.this); | 85 subscriptionContainer.addSubscriptionListener( |
| 86 SubscriptionPreferenceCategory.this.subscriptionChangeListener); | |
| 87 | |
| 85 ThreadUtils.postToUiThread(new Runnable() | 88 ThreadUtils.postToUiThread(new Runnable() |
| 86 { | 89 { |
| 87 @Override | 90 @Override |
| 88 public void run() | 91 public void run() |
| 89 { | 92 { |
| 90 SubscriptionPreferenceCategory.this.refreshEntries(); | 93 SubscriptionPreferenceCategory.this.refreshEntries(); |
| 91 } | 94 } |
| 92 }); | 95 }); |
| 93 } | 96 } |
| 94 }); | 97 }); |
| 95 } | 98 } |
| 96 | 99 |
| 97 @Override | |
| 98 public boolean onPreferenceChange(Preference preference, Object newValue) | |
| 99 { | |
| 100 if (preference instanceof CheckBoxPreference && newValue instanceof Boolean) | |
|
anton
2016/09/30 07:12:53
i'd prefer here to add spaces for each condition f
diegocarloslima
2016/10/26 13:04:33
Actually, if you look below you will notice that t
| |
| 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 | |
| 119 private CheckBoxPreference createDisabledCheckBox(final int titleId, final int summaryId) | 100 private CheckBoxPreference createDisabledCheckBox(final int titleId, final int summaryId) |
| 120 { | 101 { |
| 121 final CheckBoxPreference cbp = new CheckBoxPreference(this.getContext()); | 102 final CheckBoxPreference cbp = new CheckBoxPreference(this.getContext()); |
| 122 cbp.setTitle(titleId); | 103 cbp.setTitle(titleId); |
| 123 cbp.setSummary(summaryId); | 104 cbp.setSummary(summaryId); |
| 124 cbp.setEnabled(false); | 105 cbp.setEnabled(false); |
| 125 cbp.setShouldDisableView(true); | 106 cbp.setShouldDisableView(true); |
| 126 cbp.setSelectable(false); | 107 cbp.setSelectable(false); |
| 127 return cbp; | 108 return cbp; |
| 128 } | 109 } |
| 129 | 110 |
| 130 private CheckBoxPreference createEnabledCheckBox( | 111 private CheckBoxPreference createEnabledCheckBox( |
| 131 final SubscriptionContainer.Subscription subscription) | 112 final SubscriptionContainer.Subscription subscription) |
| 132 { | 113 { |
| 133 final CheckBoxPreference cbp = new CheckBoxPreference(this.getContext()); | 114 final CheckBoxPreference cbp = new CheckBoxPreference(this.getContext()); |
| 134 cbp.setTitle(subscription.specialization); | 115 cbp.setTitle(subscription.specialization); |
| 135 cbp.setSummary(subscription.title); | 116 cbp.setSummary(subscription.title); |
| 136 cbp.setChecked(true); | 117 cbp.setChecked(true); |
| 137 cbp.setKey(subscription.url); | 118 cbp.setKey(subscription.url); |
| 138 cbp.setPersistent(false); | 119 cbp.setPersistent(false); |
| 139 cbp.setChecked(subscriptionContainer.isSubscriptionListed(subscription.url)) ; | 120 cbp.setChecked(subscriptionContainer.isSubscriptionListed(subscription.url)) ; |
| 140 cbp.setOnPreferenceChangeListener(SubscriptionPreferenceCategory.this); | 121 cbp.setOnPreferenceChangeListener(this.checkBoxChangeListener); |
| 141 return cbp; | 122 return cbp; |
| 142 } | 123 } |
| 143 | 124 |
| 144 private void refreshEntries() | 125 private void refreshEntries() |
| 145 { | 126 { |
| 146 if (this.isEnabledList) | 127 if (this.isEnabledList) |
| 147 { | 128 { |
| 148 this.refreshEntries(R.string.abb_adblocking_none_selected, | 129 this.refreshEntries(R.string.abb_adblocking_none_selected, |
| 149 R.string.abb_adblocking_select_below, true); | 130 R.string.abb_adblocking_select_below, true); |
| 150 } | 131 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 private void showProgressDialog() | 163 private void showProgressDialog() |
| 183 { | 164 { |
| 184 this.progressDialog = new ProgressDialog(this.getContext()); | 165 this.progressDialog = new ProgressDialog(this.getContext()); |
| 185 this.progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); | 166 this.progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
| 186 this.progressDialog.setMessage(this.getContext().getString(R.string.abb_adbl ocking_waiting)); | 167 this.progressDialog.setMessage(this.getContext().getString(R.string.abb_adbl ocking_waiting)); |
| 187 this.progressDialog.show(); | 168 this.progressDialog.show(); |
| 188 } | 169 } |
| 189 | 170 |
| 190 private void dismissProgressDialog() | 171 private void dismissProgressDialog() |
| 191 { | 172 { |
| 192 if(this.progressDialog != null) | 173 if (this.progressDialog != null) |
|
anton
2016/09/30 07:12:53
space here?
diegocarloslima
2016/10/26 13:04:33
Acknowledged.
| |
| 193 { | 174 { |
| 194 this.progressDialog.dismiss(); | 175 this.progressDialog.dismiss(); |
| 195 this.progressDialog = null; | 176 this.progressDialog = null; |
| 196 } | 177 } |
| 197 } | 178 } |
| 179 | |
| 180 private class CheckBoxChangeListener implements OnPreferenceChangeListener | |
| 181 { | |
| 182 @Override | |
| 183 public boolean onPreferenceChange(Preference preference, Object newValue) | |
| 184 { | |
| 185 if (preference instanceof CheckBoxPreference && newValue instanceof Boolea n) | |
| 186 { | |
| 187 showProgressDialog(); | |
| 188 | |
| 189 final CheckBoxPreference cbp = (CheckBoxPreference) preference; | |
| 190 final boolean enable = ((Boolean) newValue).booleanValue(); | |
| 191 SubscriptionPreferenceCategory.subscriptionContainer.changeSubscriptionS tate( | |
| 192 cbp.getKey(), | |
| 193 enable); | |
| 194 } | |
| 195 return true; | |
| 196 } | |
| 197 } | |
| 198 | |
| 199 private class SubscriptionChangeListener implements SubscriptionContainer.Subs criptionListener | |
| 200 { | |
| 201 @Override | |
| 202 public void onSubscriptionUpdated() | |
| 203 { | |
| 204 SubscriptionPreferenceCategory.this.refreshEntries(); | |
| 205 } | |
| 206 } | |
| 198 } | 207 } |
| 199 | 208 |
| LEFT | RIGHT |