From b800e14bc505a0bea10b3bbac272e38f68a82ee9 Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Tue, 26 Feb 2013 16:28:35 +0100 Subject: [PATCH] Added option to disable the update checker (in alarm settings screen). --- android/AndroidManifest.xml | 5 +++-- android/res/values/strings.xml | 2 ++ .../transdroid/preferences/Preferences.java | 4 +++- .../preferences/PreferencesAlarm.java | 18 ++++++++++++++++++ .../org/transdroid/service/AlarmSettings.java | 8 +++++++- .../org/transdroid/service/BootReceiver.java | 6 ++++++ .../org/transdroid/service/UpdateService.java | 8 ++++++++ 7 files changed, 47 insertions(+), 4 deletions(-) diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index dcea7127..115bc4f4 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -23,7 +23,8 @@ android:installLocation="auto"> - + @@ -63,7 +64,7 @@ - + diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml index 3ff6a6ee..4674ad62 100644 --- a/android/res/values/strings.xml +++ b/android/res/values/strings.xml @@ -233,6 +233,8 @@ Show torrent counter in ADW Launcher Count only downloads ADW counter only includes downloading torrents +Check for updates +Check transdroid.org for latest app version Waiting to check... Verifying local data... diff --git a/android/src/org/transdroid/preferences/Preferences.java b/android/src/org/transdroid/preferences/Preferences.java index ae69231f..1948670e 100644 --- a/android/src/org/transdroid/preferences/Preferences.java +++ b/android/src/org/transdroid/preferences/Preferences.java @@ -141,6 +141,7 @@ public class Preferences { public static final String KEY_PREF_ALARMCOLOUR = "transdroid_alarm_colour"; public static final String KEY_PREF_ADWNOTIFY = "transdroid_alarm_adwnotify"; public static final String KEY_PREF_ADWONLYDL = "transdroid_alarm_adwonlydl"; + public static final String KEY_PREF_CHECKUPDATES = "transdroid_alarm_checkupdates"; public static final String KEY_WIDGET_DAEMON = "transdroid_widget_daemon"; public static final String KEY_WIDGET_REFRESH = "transdroid_widget_refresh"; @@ -1030,7 +1031,8 @@ public class Preferences { prefs.getBoolean(KEY_PREF_ALARMVIBRATE, false), prefs.getInt(KEY_PREF_ALARMCOLOUR, 0xff7dbb21), prefs.getBoolean(KEY_PREF_ADWNOTIFY, false), - prefs.getBoolean(KEY_PREF_ADWONLYDL, false)); + prefs.getBoolean(KEY_PREF_ADWONLYDL, false), + prefs.getBoolean(KEY_PREF_CHECKUPDATES, true)); } /** diff --git a/android/src/org/transdroid/preferences/PreferencesAlarm.java b/android/src/org/transdroid/preferences/PreferencesAlarm.java index 5429cafe..c5638d13 100644 --- a/android/src/org/transdroid/preferences/PreferencesAlarm.java +++ b/android/src/org/transdroid/preferences/PreferencesAlarm.java @@ -44,6 +44,7 @@ public class PreferencesAlarm extends PreferenceActivity { private ColorPickerPreference alarmColour; private TransdroidCheckBoxPreference adwNotify; private TransdroidCheckBoxPreference adwOnlyDl; + private TransdroidCheckBoxPreference checkForUpdates; @Override protected void onCreate(Bundle savedInstanceState) { @@ -128,6 +129,13 @@ public class PreferencesAlarm extends PreferenceActivity { adwOnlyDl.setKey(Preferences.KEY_PREF_ADWONLYDL); adwOnlyDl.setEnabled(isEnabled && isAdwEnabled); getPreferenceScreen().addItemFromInflater(adwOnlyDl); + // Enable + checkForUpdates = new TransdroidCheckBoxPreference(this); + checkForUpdates.setTitle(R.string.pref_checkforupdates); + checkForUpdates.setSummary(R.string.pref_checkforupdates_info); + checkForUpdates.setKey(Preferences.KEY_PREF_CHECKUPDATES); + checkForUpdates.setDefaultValue(true); + getPreferenceScreen().addItemFromInflater(checkForUpdates); prefs.registerOnSharedPreferenceChangeListener(changesHandler); } @@ -149,6 +157,16 @@ public class PreferencesAlarm extends PreferenceActivity { @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + if (key.equals(Preferences.KEY_PREF_CHECKUPDATES)) { + // Only the update checker setting changed + BootReceiver.cancelUpdateCheck(); + boolean shouldCheckForUpdates = sharedPreferences.getBoolean(Preferences.KEY_PREF_CHECKUPDATES, true); + if (shouldCheckForUpdates) { + BootReceiver.startUpdateCheck(getApplicationContext()); + } + return; + } + // First cancel the alarm BootReceiver.cancelAlarm(); diff --git a/android/src/org/transdroid/service/AlarmSettings.java b/android/src/org/transdroid/service/AlarmSettings.java index a10059a0..7754129a 100644 --- a/android/src/org/transdroid/service/AlarmSettings.java +++ b/android/src/org/transdroid/service/AlarmSettings.java @@ -34,8 +34,9 @@ public class AlarmSettings{ private int alarmColour; private boolean adwNotify; private boolean adwOnlyDl; + private boolean checkForUpdates; - public AlarmSettings(boolean enableAlarm, int alarmInterval, boolean checkRssFeeds, boolean alarmPlaySound, String alarmSoundURI, boolean alarmVibrate, int alarmColour, boolean adwNotify, boolean adwOnlyDl) { + public AlarmSettings(boolean enableAlarm, int alarmInterval, boolean checkRssFeeds, boolean alarmPlaySound, String alarmSoundURI, boolean alarmVibrate, int alarmColour, boolean adwNotify, boolean adwOnlyDl, boolean checkForUpdates) { this.enableAlarm = enableAlarm; this.alarmInterval = alarmInterval; this.checkRssFeeds = checkRssFeeds; @@ -45,6 +46,7 @@ public class AlarmSettings{ this.alarmColour = alarmColour; this.adwNotify = adwNotify; this.adwOnlyDl = adwOnlyDl; + this.checkForUpdates = checkForUpdates; } public boolean isAlarmEnabled() { @@ -86,6 +88,10 @@ public class AlarmSettings{ public boolean showOnlyDownloadsInAdw() { return adwOnlyDl; } + + public boolean shouldCheckForUpdates() { + return checkForUpdates; + } } diff --git a/android/src/org/transdroid/service/BootReceiver.java b/android/src/org/transdroid/service/BootReceiver.java index 8256373b..5cad3929 100644 --- a/android/src/org/transdroid/service/BootReceiver.java +++ b/android/src/org/transdroid/service/BootReceiver.java @@ -71,6 +71,12 @@ public class BootReceiver extends BroadcastReceiver { } } + public static void cancelUpdateCheck() { + if (mgr != null) { + mgr.cancel(pui); + } + } + public static void startUpdateCheck(Context context) { // Set up PendingIntent for the alarm service if (mgr == null) diff --git a/android/src/org/transdroid/service/UpdateService.java b/android/src/org/transdroid/service/UpdateService.java index 89526170..284dc38c 100644 --- a/android/src/org/transdroid/service/UpdateService.java +++ b/android/src/org/transdroid/service/UpdateService.java @@ -77,6 +77,14 @@ public class UpdateService extends IntentService { return; } + // Check if the update service should run + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); + AlarmSettings settings = Preferences.readAlarmSettings(prefs); + if (!settings.shouldCheckForUpdates()) { + TLog.d(LOG_NAME, "The user disabled the update checker service."); + return; + } + DefaultHttpClient httpclient = new DefaultHttpClient(); try {