diff options
Diffstat (limited to 'src/github/daneren2005/dsub/activity/SettingsActivity.java')
-rw-r--r-- | src/github/daneren2005/dsub/activity/SettingsActivity.java | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/github/daneren2005/dsub/activity/SettingsActivity.java b/src/github/daneren2005/dsub/activity/SettingsActivity.java index c723cca5..f8fed602 100644 --- a/src/github/daneren2005/dsub/activity/SettingsActivity.java +++ b/src/github/daneren2005/dsub/activity/SettingsActivity.java @@ -19,6 +19,8 @@ package github.daneren2005.dsub.activity; import android.annotation.TargetApi; +import android.accounts.Account; +import android.content.ContentResolver; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -78,6 +80,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; @@ -107,6 +110,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer addServerPreference = (Preference) findPreference(Constants.PREFERENCES_KEY_SERVER_ADD); 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); @@ -154,6 +158,31 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer editor.commit(); serverSettings.put(instance, new ServerSettings(instance)); + + return true; + } + }); + + 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; } @@ -254,6 +283,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer bufferLength.setSummary(bufferLength.getText() + " seconds"); chatRefreshRate.setSummary(chatRefreshRate.getText()); videoPlayer.setSummary(videoPlayer.getEntry()); + syncInterval.setSummary(syncInterval.getEntry()); for (ServerSettings ss : serverSettings.values()) { ss.update(); } |