Index: adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/MainPreferences.java |
=================================================================== |
--- a/adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/MainPreferences.java |
+++ b/adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/MainPreferences.java |
@@ -15,51 +15,54 @@ |
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
*/ |
package org.adblockplus.sbrowser.contentblocker; |
import org.adblockplus.sbrowser.contentblocker.engine.Engine; |
import org.adblockplus.sbrowser.contentblocker.engine.EngineService; |
import org.adblockplus.adblockplussbrowser.R; |
+import org.adblockplus.sbrowser.contentblocker.util.ConnectivityUtils; |
import org.adblockplus.sbrowser.contentblocker.util.SharedPrefsUtils; |
import android.app.AlertDialog; |
+import android.app.Fragment; |
import android.app.ProgressDialog; |
import android.content.DialogInterface; |
import android.content.DialogInterface.OnClickListener; |
import android.content.Intent; |
import android.net.Uri; |
import android.os.Bundle; |
+import android.preference.Preference; |
import android.preference.PreferenceActivity; |
import android.preference.PreferenceManager; |
import android.text.Html; |
import android.util.Log; |
import android.view.Gravity; |
import android.widget.Button; |
import android.widget.LinearLayout; |
public class MainPreferences extends PreferenceActivity implements |
EngineService.OnEngineCreatedCallback, SharedPrefsUtils.OnSharedPreferenceChangeListener, |
- Engine.SubscriptionUpdateCallback |
+ Engine.SubscriptionUpdateCallback, Preference.OnPreferenceClickListener |
{ |
private static final String TAG = MainPreferences.class.getSimpleName(); |
private Engine engine = null; |
private AlertDialog dialog; |
private int dialogTitleResId; |
@Override |
public void onCreate(Bundle savedInstanceState) |
{ |
super.onCreate(savedInstanceState); |
PreferenceManager.setDefaultValues(this, R.xml.preferences_main, false); |
this.getFragmentManager() |
.beginTransaction() |
- .replace(android.R.id.content, new Preferences()) |
+ .replace(android.R.id.content, new Preferences(), Preferences.class.getSimpleName()) |
.commit(); |
} |
@Override |
protected void onStart() |
{ |
this.dialogTitleResId = R.string.initialization_title; |
this.dialog = ProgressDialog.show(this, |
@@ -194,16 +197,20 @@ public class MainPreferences extends Pre |
} |
if (this.dialogTitleResId == R.string.initialization_title) |
{ |
this.dismissDialog(); |
this.checkForCompatibleSBrowserAndProceed(); |
} |
+ |
+ Fragment preferecesFragment = getFragmentManager().findFragmentByTag(Preferences.class.getSimpleName()); |
+ Preference button = ((Preferences) preferecesFragment).findPreference(getString(R.string.key_force_update_subscriptions)); |
+ button.setOnPreferenceClickListener(this); |
} |
@Override |
public void onSharedPreferenceChanged(String key) |
{ |
if (this.getString(R.string.key_automatic_updates).equals(key) && this.engine != null) |
{ |
this.engine.connectivityChanged(); |
@@ -232,9 +239,56 @@ public class MainPreferences extends Pre |
: getString(R.string.remove_subscription_dialog_message)); |
} |
@Override |
public void subscriptionUpdatedApplied() |
{ |
this.dismissDialog(); |
} |
+ |
+ @Override |
+ public boolean onPreferenceClick(Preference preference) |
+ { |
+ if (getString(R.string.key_force_update_subscriptions).equals(preference.getKey())) |
+ { |
+ if (ConnectivityUtils.hasNonMeteredConnection(this)) |
+ { |
+ engine.forceUpdateSubscriptions(false); |
+ } |
+ else |
+ { |
+ boolean meteredInternetAvailable = ConnectivityUtils.canUseInternet(this, true); |
+ this.dialog = new AlertDialog.Builder(this) |
+ .setTitle(R.string.update_subscriptions) |
+ .setMessage( |
+ meteredInternetAvailable |
+ ? R.string.metered_connection_warning |
+ : R.string.check_your_connection) |
+ .setNegativeButton(android.R.string.cancel, new OnClickListener() |
+ { |
+ @Override |
+ public void onClick(DialogInterface dialog, int which) |
+ { |
+ dialog.cancel(); |
+ } |
+ }) |
+ .create(); |
+ |
+ if (meteredInternetAvailable) |
+ { |
+ this.dialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(android.R.string.yes), |
+ new OnClickListener() |
+ { |
+ @Override |
+ public void onClick(DialogInterface dialogInterface, int i) |
+ { |
+ engine.forceUpdateSubscriptions(true); |
+ } |
+ }); |
+ } |
+ this.dialog.show(); |
+ } |
+ return true; |
+ } |
+ return false; |
+ } |
} |