Index: src/org/adblockplus/android/Preferences.java |
=================================================================== |
--- a/src/org/adblockplus/android/Preferences.java |
+++ b/src/org/adblockplus/android/Preferences.java |
@@ -22,7 +22,6 @@ |
import java.io.OutputStream; |
import java.util.Calendar; |
import java.util.Date; |
-import java.util.List; |
import org.jraf.android.backport.switchwidget.SwitchPreference; |
@@ -100,14 +99,20 @@ |
{ |
copyAssets(); |
} |
+ } |
+ @Override |
+ protected void onStart() |
+ { |
+ super.onStart(); |
AdblockPlus application = AdblockPlus.getApplication(); |
+ application.startEngine(); |
// Initialize subscription list |
subscriptionList = (RefreshableListPreference) findPreference(getString(R.string.pref_subscription)); |
- List<Subscription> subscriptions = application.getSubscriptions(); |
- String[] entries = new String[subscriptions.size()]; |
- String[] entryValues = new String[subscriptions.size()]; |
+ Subscription[] subscriptions = application.getRecommendedSubscriptions(); |
+ String[] entries = new String[subscriptions.length]; |
+ String[] entryValues = new String[subscriptions.length]; |
int i = 0; |
for (Subscription subscription : subscriptions) |
{ |
@@ -116,16 +121,7 @@ |
i++; |
} |
subscriptionList.setEntries(entries); |
- subscriptionList.setEntryValues(entryValues); |
- } |
- |
- @Override |
- protected void onStart() |
- { |
- super.onStart(); |
- AdblockPlus application = AdblockPlus.getApplication(); |
- application.startEngine(); |
- application.startInteractive(); |
+ subscriptionList.setEntryValues(entryValues); |
Felix Dahlke
2013/09/13 14:40:39
Nit: Trailing whitespace.
|
} |
@Override |
@@ -136,22 +132,21 @@ |
final AdblockPlus application = AdblockPlus.getApplication(); |
+ Subscription current = null; |
+ Subscription[] subscriptions = application.getListedSubscriptions(); |
+ if (subscriptions.length > 0) |
+ { |
+ current = subscriptions[0]; |
+ } |
+ |
boolean firstRun = false; |
Wladimir Palant
2013/09/12 11:31:14
I don't think you need the firstRun variable, just
|
- |
- // Get current subscription |
- String current = prefs.getString(getString(R.string.pref_subscription), (String) null); |
- |
- // If there is no current subscription autoselect one |
- if (current == null) |
+ if (application.isFirstRun()) |
{ |
firstRun = true; |
- Subscription offer = application.offerSubscription(); |
- current = offer.url; |
- if (offer != null) |
+ |
+ if (current != null) |
{ |
- subscriptionList.setValue(offer.url); |
- application.setSubscription(offer); |
- new AlertDialog.Builder(this).setTitle(R.string.app_name).setMessage(String.format(getString(R.string.msg_subscription_offer, offer.title))).setIcon(android.R.drawable.ic_dialog_info) |
+ new AlertDialog.Builder(this).setTitle(R.string.app_name).setMessage(String.format(getString(R.string.msg_subscription_offer, current.title))).setIcon(android.R.drawable.ic_dialog_info) |
.setPositiveButton(R.string.ok, null).create().show(); |
} |
} |
@@ -162,7 +157,7 @@ |
@Override |
public void onClick(View v) |
{ |
- application.refreshSubscription(); |
+ application.refreshSubscriptions(); |
} |
}); |
@@ -177,26 +172,19 @@ |
registerReceiver(receiver, new IntentFilter(ProxyService.BROADCAST_STATE_CHANGED)); |
registerReceiver(receiver, new IntentFilter(ProxyService.BROADCAST_PROXY_FAILED)); |
- final String url = current; |
- |
- // Initialize subscription verification |
- (new Thread() |
+ // Update service and UI state according to user settings |
+ if (current != null) |
{ |
- @Override |
- public void run() |
- { |
- if (!application.verifySubscriptions()) |
- { |
- Subscription subscription = application.getSubscription(url); |
- application.setSubscription(subscription); |
- } |
- } |
- }).start(); |
- |
- // Update service and UI state according to user settings |
+ subscriptionList.setValue(current.url); |
+ application.actualizeSubscriptionStatus(current.url); |
+ } |
boolean enabled = prefs.getBoolean(getString(R.string.pref_enabled), false); |
boolean proxyenabled = prefs.getBoolean(getString(R.string.pref_proxyenabled), true); |
boolean autoconfigured = prefs.getBoolean(getString(R.string.pref_proxyautoconfigured), false); |
+ |
+ // This is weird but UI does not update on back button (when returning from advanced preferences) |
+ ((SwitchPreference) findPreference(getString(R.string.pref_enabled))).setChecked(enabled); |
+ |
if (enabled || firstRun) |
setFilteringEnabled(true); |
if (enabled || firstRun || (proxyenabled && !autoconfigured)) |
@@ -229,9 +217,8 @@ |
{ |
super.onStop(); |
AdblockPlus application = AdblockPlus.getApplication(); |
- application.stopInteractive(); |
if (!application.isFilteringEnabled()) |
- application.stopEngine(true); |
+ application.stopEngine(); |
} |
@Override |
@@ -393,9 +380,9 @@ |
} |
else if (getString(R.string.pref_subscription).equals(key)) |
{ |
- String current = sharedPreferences.getString(key, null); |
- Subscription subscription = application.getSubscription(current); |
- application.setSubscription(subscription); |
+ String url = sharedPreferences.getString(key, null); |
+ if (url != null) |
+ application.setSubscription(url); |
} |
else if (getString(R.string.pref_hideicon).equals(key)) |
{ |
@@ -457,7 +444,8 @@ |
} |
if (action.equals(AdblockPlus.BROADCAST_SUBSCRIPTION_STATUS)) |
{ |
- final String text = extra.getString("text"); |
+ //TODO Should check if url matches active subscription |
+ final String text = extra.getString("status"); |
final long time = extra.getLong("time"); |
runOnUiThread(new Runnable() |
{ |