From 725eb7a4cf75a263a2515c5f90c28cf8aa201df2 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Thu, 29 Aug 2013 21:44:46 -0700 Subject: Added sync settings for on, interval, and wifi only --- res/values/arrays.xml | 21 ++++++++++++++++ res/values/strings.xml | 8 +++++- res/xml/settings.xml | 23 +++++++++++++++++ .../daneren2005/dsub/activity/MainActivity.java | 12 ++++++--- .../dsub/activity/SettingsActivity.java | 29 ++++++++++++++++++++++ src/github/daneren2005/dsub/util/Constants.java | 3 +++ 6 files changed, 91 insertions(+), 5 deletions(-) diff --git a/res/values/arrays.xml b/res/values/arrays.xml index d6541f9f..b558d68e 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -150,4 +150,25 @@ @string/settings.video_flash + + 15 + 30 + 60 + 120 + 240 + 360 + 720 + 1440 + + + 15 Minutes + 30 Minutes + 1 Hour + 2 Hours + 3 Hours + 6 Hours + 12 Hours + Daily + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 0b2815ec..87667e51 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -298,7 +298,7 @@ Respond to phone, headset and Bluetooth media buttons Keep screen on Keeping the screen on while downloading improves download speed. - Playlists + Play Random Size Buffer Length (0 = when fully cached) Sleep Timer @@ -324,6 +324,12 @@ HTTP Live Stream (HLS) (Requires Subsonic 4.8+) Direct Transcode (Requires video -> mp4 or similar setup on Server) Flash (Requires Plugin) + Sync + Sync Enabled + Whether or not playlists or podcasts are periodically checked for changes + Sync Interval + Sync on Wifi only + Only sync while on wifi Shuffle By Start Year: diff --git a/res/xml/settings.xml b/res/xml/settings.xml index eb139b83..feb7a81e 100644 --- a/res/xml/settings.xml +++ b/res/xml/settings.xml @@ -150,6 +150,29 @@ android:persistent="false"/> + + + + + + + + + diff --git a/src/github/daneren2005/dsub/activity/MainActivity.java b/src/github/daneren2005/dsub/activity/MainActivity.java index 2bcc9176..da46df71 100644 --- a/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/src/github/daneren2005/dsub/activity/MainActivity.java @@ -316,11 +316,15 @@ public class MainActivity extends SubsonicActivity { Account account = new Account(Constants.SYNC_ACCOUNT_NAME, Constants.SYNC_ACCOUNT_TYPE); accountManager.addAccountExplicitly(account, null, null); + SharedPreferences prefs = Util.getPreferences(this); + boolean syncEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_SYNC_ENABLED, true); + int syncInterval = Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_SYNC_INTERVAL, "60")); + // Make sync run every hour - ContentResolver.setSyncAutomatically(account, Constants.SYNC_ACCOUNT_PLAYLIST_AUTHORITY, true); - ContentResolver.addPeriodicSync(account, Constants.SYNC_ACCOUNT_PLAYLIST_AUTHORITY, new Bundle(), 60L * 60L); - ContentResolver.setSyncAutomatically(account, Constants.SYNC_ACCOUNT_PODCAST_AUTHORITY, true); - ContentResolver.addPeriodicSync(account, Constants.SYNC_ACCOUNT_PODCAST_AUTHORITY, new Bundle(), 60L * 60L); + ContentResolver.setSyncAutomatically(account, Constants.SYNC_ACCOUNT_PLAYLIST_AUTHORITY, syncEnabled); + ContentResolver.addPeriodicSync(account, Constants.SYNC_ACCOUNT_PLAYLIST_AUTHORITY, new Bundle(), 60L * syncInterval); + ContentResolver.setSyncAutomatically(account, Constants.SYNC_ACCOUNT_PODCAST_AUTHORITY, syncEnabled); + ContentResolver.addPeriodicSync(account, Constants.SYNC_ACCOUNT_PODCAST_AUTHORITY, new Bundle(), 60L * syncInterval); } private void showInfoDialog() { diff --git a/src/github/daneren2005/dsub/activity/SettingsActivity.java b/src/github/daneren2005/dsub/activity/SettingsActivity.java index 89d475d3..902c55d8 100644 --- a/src/github/daneren2005/dsub/activity/SettingsActivity.java +++ b/src/github/daneren2005/dsub/activity/SettingsActivity.java @@ -18,6 +18,8 @@ */ package github.daneren2005.dsub.activity; +import android.accounts.Account; +import android.content.ContentResolver; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -73,6 +75,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer private PreferenceCategory serversCategory; private EditTextPreference chatRefreshRate; private ListPreference videoPlayer; + private ListPreference syncInterval; private int serverCount = 3; private SharedPreferences settings; @@ -100,6 +103,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer serversCategory = (PreferenceCategory) findPreference(Constants.PREFERENCES_KEY_SERVER_KEY); chatRefreshRate = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_CHAT_REFRESH); videoPlayer = (ListPreference) findPreference(Constants.PREFERENCES_KEY_VIDEO_PLAYER); + syncInterval = (ListPreference) findPreference(Constants.PREFERENCES_KEY_SYNC_INTERVAL); settings = Util.getPreferences(this); serverCount = settings.getInt(Constants.PREFERENCES_KEY_SERVER_COUNT, 3); @@ -163,6 +167,31 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer } }); + findPreference(Constants.PREFERENCES_KEY_SYNC_ENABLED).setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + Boolean syncEnabled = (Boolean) newValue; + + Account account = new Account(Constants.SYNC_ACCOUNT_NAME, Constants.SYNC_ACCOUNT_TYPE); + ContentResolver.setSyncAutomatically(account, Constants.SYNC_ACCOUNT_PLAYLIST_AUTHORITY, syncEnabled); + ContentResolver.setSyncAutomatically(account, Constants.SYNC_ACCOUNT_PODCAST_AUTHORITY, syncEnabled); + + return true; + } + }); + syncInterval.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + Integer syncInterval = Integer.parseInt(((String) newValue)); + + Account account = new Account(Constants.SYNC_ACCOUNT_NAME, Constants.SYNC_ACCOUNT_TYPE); + ContentResolver.addPeriodicSync(account, Constants.SYNC_ACCOUNT_PLAYLIST_AUTHORITY, new Bundle(), 60L * syncInterval); + ContentResolver.addPeriodicSync(account, Constants.SYNC_ACCOUNT_PODCAST_AUTHORITY, new Bundle(), 60L * syncInterval); + + return true; + } + }); + serversCategory.removePreference(addServerPreference); for (int i = 1; i <= serverCount; i++) { String instance = String.valueOf(i); diff --git a/src/github/daneren2005/dsub/util/Constants.java b/src/github/daneren2005/dsub/util/Constants.java index dcc50181..fccd03cd 100644 --- a/src/github/daneren2005/dsub/util/Constants.java +++ b/src/github/daneren2005/dsub/util/Constants.java @@ -114,6 +114,9 @@ public final class Constants { public static final String PREFERENCES_KEY_CHAT_ENABLED = "chatEnabled"; public static final String PREFERENCES_KEY_VIDEO_PLAYER = "videoPlayer"; public static final String PREFERENCES_KEY_CONTROL_MODE = "remoteControlMode"; + public static final String PREFERENCES_KEY_SYNC_ENABLED = "syncEnabled"; + public static final String PREFERENCES_KEY_SYNC_INTERVAL = "syncInterval"; + public static final String PREFERENCES_KEY_SYNC_WIFI = "syncWifi"; public static final String OFFLINE_SCROBBLE_COUNT = "scrobbleCount"; public static final String OFFLINE_SCROBBLE_ID = "scrobbleID"; -- cgit v1.2.3