diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 69f65a75e..6c16bc6ae 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -22,6 +22,7 @@
android:required="false" />
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 587bb6aa3..2e78cdcc7 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -9,19 +9,21 @@
Version
%d versions available
%d version available
- Notify
Cache downloaded apps
Keep downloaded apk files on SD card
Updates
Other
- Notify when new updates are available
- Update app list from repositories automatically
-
- Update history
- Days to show new/updated apps
Last repo scan: %s
never
+
Automatic repo scan
+ Update app list from repositories automatically
+ Only on wifi
+ Update app lists automatically only on wifi
+ Notify
+ Notify when new updates are available
+ Update history
+ Days to show new/updated apps
Search Results
App Details
diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml
index f755058ef..fb2820414 100644
--- a/res/xml/preferences.xml
+++ b/res/xml/preferences.xml
@@ -5,6 +5,9 @@
android:summary="@string/update_apps_list" android:key="updateInterval"
android:defaultValue="24" android:entries="@array/updateIntervalNames"
android:entryValues="@array/updateIntervalValues" />
+
diff --git a/src/org/fdroid/fdroid/PreferencesActivity.java b/src/org/fdroid/fdroid/PreferencesActivity.java
index c60de6c88..7fc1e6092 100644
--- a/src/org/fdroid/fdroid/PreferencesActivity.java
+++ b/src/org/fdroid/fdroid/PreferencesActivity.java
@@ -22,7 +22,9 @@ import android.content.Intent;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
-import android.preference.Preference.OnPreferenceClickListener;
+import android.preference.Preference.OnPreferenceChangeListener;
+import android.preference.ListPreference;
+import android.preference.CheckBoxPreference;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
@@ -30,7 +32,7 @@ import android.support.v4.app.NavUtils;
import org.fdroid.fdroid.compat.ActionBarCompat;
public class PreferencesActivity extends PreferenceActivity implements
- OnPreferenceClickListener {
+ OnPreferenceChangeListener {
Intent ret;
@@ -39,10 +41,14 @@ public class PreferencesActivity extends PreferenceActivity implements
super.onCreate(savedInstanceState);
ActionBarCompat.create(this).setDisplayHomeAsUpEnabled(true);
addPreferencesFromResource(R.xml.preferences);
- //for (String prefkey : new String[] { }) {
- //Preference pref = findPreference(prefkey);
- //pref.setOnPreferenceClickListener(this);
- //}
+ for (String prefkey : new String[] { "updateInterval" }) {
+ Preference pref = findPreference(prefkey);
+ pref.setOnPreferenceChangeListener(this);
+ CheckBoxPreference onlyOnWifi = (CheckBoxPreference)
+ findPreference("updateOnWifiOnly");
+ onlyOnWifi.setEnabled(Integer.parseInt(
+ ((ListPreference)pref).getValue()) > 0);
+ }
}
@Override
@@ -56,13 +62,16 @@ public class PreferencesActivity extends PreferenceActivity implements
}
@Override
- public boolean onPreferenceClick(Preference preference) {
- // Currently no actions are returned
- //String key = preference.getKey();
- //if (key.equals("...")) {
- Intent ret = new Intent();
- setResult(RESULT_OK, ret);
- return true;
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ String key = preference.getKey();
+ if (key.equals("updateInterval")) {
+ int interval = Integer.parseInt(newValue.toString());
+ CheckBoxPreference onlyOnWifi = (CheckBoxPreference)
+ findPreference("updateOnWifiOnly");
+ onlyOnWifi.setEnabled(interval > 0);
+ return true;
+ }
+ return false;
}
}
diff --git a/src/org/fdroid/fdroid/UpdateService.java b/src/org/fdroid/fdroid/UpdateService.java
index 02b778913..0ceda5841 100644
--- a/src/org/fdroid/fdroid/UpdateService.java
+++ b/src/org/fdroid/fdroid/UpdateService.java
@@ -30,6 +30,8 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.BitmapFactory;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.ResultReceiver;
import android.os.SystemClock;
@@ -137,6 +139,18 @@ public class UpdateService extends IntentService implements ProgressListener {
+ "ms ago, interval is " + interval + " hours");
return;
}
+
+ // If we are to update the repos only on wifi, make sure that
+ // connection is active
+ if (prefs.getBoolean("updateOnWifiOnly", false)) {
+ ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
+ NetworkInfo.State wifi = conMan.getNetworkInfo(1).getState();
+ if (wifi != NetworkInfo.State.CONNECTED &&
+ wifi != NetworkInfo.State.CONNECTING) {
+ Log.d("FDroid", "Skipping update - wifi not available");
+ return;
+ }
+ }
} else {
Log.d("FDroid", "Unscheduled (manually requested) update");
}