From df2b3c4504754b7b64475c442d0b77e25543be4b Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 20 May 2013 19:22:33 -0700 Subject: Added separate setting for preload count for wifi/mobile --- subsonic-android/res/values/strings.xml | 3 ++- subsonic-android/res/xml/settings.xml | 11 +++++++++-- .../github/daneren2005/dsub/activity/SettingsActivity.java | 9 ++++++--- .../src/github/daneren2005/dsub/util/Constants.java | 3 ++- subsonic-android/src/github/daneren2005/dsub/util/Util.java | 9 ++++++++- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/subsonic-android/res/values/strings.xml b/subsonic-android/res/values/strings.xml index 21dd4b88..e494aef0 100644 --- a/subsonic-android/res/values/strings.xml +++ b/subsonic-android/res/values/strings.xml @@ -183,7 +183,8 @@ Username Password Music cache - Songs to preload + Songs to preload (Wifi) + Songs to preload (Mobile) Cache size (MB) Cache location Invalid cache location. Using default. diff --git a/subsonic-android/res/xml/settings.xml b/subsonic-android/res/xml/settings.xml index d21f928f..89ec5699 100644 --- a/subsonic-android/res/xml/settings.xml +++ b/subsonic-android/res/xml/settings.xml @@ -204,8 +204,15 @@ android:key="cacheLocation"/> + + diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java index 18d7e6b4..dc39e2f6 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java @@ -57,7 +57,8 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer private ListPreference networkTimeout; private EditTextPreference cacheSize; private EditTextPreference cacheLocation; - private ListPreference preloadCount; + private ListPreference preloadCountWifi; + private ListPreference preloadCountMobile; private EditTextPreference randomSize; private ListPreference tempLoss; private EditTextPreference bufferLength; @@ -75,7 +76,8 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer networkTimeout = (ListPreference) findPreference(Constants.PREFERENCES_KEY_NETWORK_TIMEOUT); cacheSize = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_CACHE_SIZE); cacheLocation = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_CACHE_LOCATION); - preloadCount = (ListPreference) findPreference(Constants.PREFERENCES_KEY_PRELOAD_COUNT); + preloadCountWifi = (ListPreference) findPreference(Constants.PREFERENCES_KEY_PRELOAD_COUNT_WIFI); + preloadCountMobile = (ListPreference) findPreference(Constants.PREFERENCES_KEY_PRELOAD_COUNT_MOBILE); randomSize = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_RANDOM_SIZE); tempLoss = (ListPreference) findPreference(Constants.PREFERENCES_KEY_TEMP_LOSS); bufferLength = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_BUFFER_LENGTH); @@ -166,7 +168,8 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer networkTimeout.setSummary(networkTimeout.getEntry()); cacheSize.setSummary(cacheSize.getText()); cacheLocation.setSummary(cacheLocation.getText()); - preloadCount.setSummary(preloadCount.getEntry()); + preloadCountWifi.setSummary(preloadCountWifi.getEntry()); + preloadCountMobile.setSummary(preloadCountMobile.getEntry()); randomSize.setSummary(randomSize.getText()); tempLoss.setSummary(tempLoss.getEntry()); bufferLength.setSummary(bufferLength.getText() + " seconds"); diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java index 302ececf..7ab9dd80 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java @@ -72,7 +72,8 @@ public final class Constants { public static final String PREFERENCES_KEY_NETWORK_TIMEOUT = "networkTimeout"; public static final String PREFERENCES_KEY_CACHE_SIZE = "cacheSize"; public static final String PREFERENCES_KEY_CACHE_LOCATION = "cacheLocation"; - public static final String PREFERENCES_KEY_PRELOAD_COUNT = "preloadCount"; + public static final String PREFERENCES_KEY_PRELOAD_COUNT_WIFI = "preloadCountWifi"; + public static final String PREFERENCES_KEY_PRELOAD_COUNT_MOBILE = "preloadCountMobile"; public static final String PREFERENCES_KEY_HIDE_MEDIA = "hideMedia"; public static final String PREFERENCES_KEY_MEDIA_BUTTONS = "mediaButtons"; public static final String PREFERENCES_KEY_SCREEN_LIT_ON_DOWNLOAD = "screenLitOnDownload"; diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Util.java b/subsonic-android/src/github/daneren2005/dsub/util/Util.java index 43aad67b..aafed8da 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/Util.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/Util.java @@ -223,8 +223,15 @@ public final class Util { } public static int getPreloadCount(Context context) { + ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo networkInfo = manager.getActiveNetworkInfo(); + if (networkInfo == null) { + return 3; + } + SharedPreferences prefs = getPreferences(context); - int preloadCount = Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_PRELOAD_COUNT, "-1")); + boolean wifi = networkInfo.getType() == ConnectivityManager.TYPE_WIFI; + int preloadCount = Integer.parseInt(prefs.getString(wifi ? Constants.PREFERENCES_KEY_PRELOAD_COUNT_WIFI : Constants.PREFERENCES_KEY_PRELOAD_COUNT_MOBILE, "-1")); return preloadCount == -1 ? Integer.MAX_VALUE : preloadCount; } -- cgit v1.2.3