From 3129feac99cc78993e465ba5d30bffcb3390636d Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 12 Jun 2018 19:48:23 +0200 Subject: Add option to disable downloading while roaming --- .../github/daneren2005/dsub/fragments/NowPlayingFragment.java | 2 +- app/src/main/java/github/daneren2005/dsub/util/Constants.java | 1 + app/src/main/java/github/daneren2005/dsub/util/Util.java | 11 ++++++++++- app/src/main/res/values-de/strings.xml | 4 +++- app/src/main/res/values/strings.xml | 4 +++- app/src/main/res/xml/settings_cache.xml | 8 +++++++- 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java index a813fce2..f1b2b9c8 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java @@ -1364,7 +1364,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis switch (playerState) { case DOWNLOADING: if(currentPlaying != null) { - if(Util.isWifiRequiredForDownload(context)) { + if(Util.isWifiRequiredForDownload(context) || Util.isLocalNetworkRequiredForDownload(context)) { statusTextView.setText(context.getResources().getString(R.string.download_playerstate_mobile_disabled)); } else { long bytes = currentPlaying.getPartialFile().length(); diff --git a/app/src/main/java/github/daneren2005/dsub/util/Constants.java b/app/src/main/java/github/daneren2005/dsub/util/Constants.java index 199fc56d..e0a1e164 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/Constants.java +++ b/app/src/main/java/github/daneren2005/dsub/util/Constants.java @@ -103,6 +103,7 @@ public final class Constants { public static final String PREFERENCES_KEY_SCROBBLE = "scrobble"; public static final String PREFERENCES_KEY_REPEAT_MODE = "repeatMode"; public static final String PREFERENCES_KEY_WIFI_REQUIRED_FOR_DOWNLOAD = "wifiRequiredForDownload"; + public static final String PREFERENCES_KEY_LOCAL_NETWORK_REQUIRED_FOR_DOWNLOAD = "localNetworkRequiredForDownload"; public static final String PREFERENCES_KEY_RANDOM_SIZE = "randomSize"; public static final String PREFERENCES_KEY_SLEEP_TIMER_DURATION = "sleepTimerDuration"; public static final String PREFERENCES_KEY_OFFLINE = "offline"; diff --git a/app/src/main/java/github/daneren2005/dsub/util/Util.java b/app/src/main/java/github/daneren2005/dsub/util/Util.java index 7f8a168d..93004a48 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/Util.java +++ b/app/src/main/java/github/daneren2005/dsub/util/Util.java @@ -36,6 +36,7 @@ import android.graphics.drawable.Drawable; import android.media.AudioManager; import android.media.AudioManager.OnAudioFocusChangeListener; import android.net.ConnectivityManager; +import android.net.Network; import android.net.NetworkInfo; import android.net.wifi.WifiManager; import android.os.Build; @@ -1082,7 +1083,10 @@ public final class Util { boolean wifiConnected = connected && networkInfo.getType() == ConnectivityManager.TYPE_WIFI; boolean wifiRequired = isWifiRequiredForDownload(context); - return connected && (!wifiRequired || wifiConnected); + boolean isLocalNetwork = connected && !networkInfo.isRoaming(); + boolean localNetworkRequired = isLocalNetworkRequiredForDownload(context); + + return connected && (!wifiRequired || wifiConnected) && (!localNetworkRequired || isLocalNetwork); } else { return connected; } @@ -1116,6 +1120,11 @@ public final class Util { return prefs.getBoolean(Constants.PREFERENCES_KEY_WIFI_REQUIRED_FOR_DOWNLOAD, false); } + public static boolean isLocalNetworkRequiredForDownload(Context context) { + SharedPreferences prefs = getPreferences(context); + return prefs.getBoolean(Constants.PREFERENCES_KEY_LOCAL_NETWORK_REQUIRED_FOR_DOWNLOAD, false); + } + public static void info(Context context, int titleId, int messageId) { info(context, titleId, messageId, true); } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index c43f3aea..5772e580 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -168,7 +168,7 @@ Wiedergabeliste ist leer Wiedergabeliste wird gemischt... Downloade - %s - Warte auf Wi-Fi für den Download + Warte auf Wi-Fi oder lokales Netzwerk für den Download Buffere Playing shuffle Zeige Album @@ -301,6 +301,8 @@ Unbegrenzt Nur Wi-Fi streaming Medien nur streamen, wenn mit Wi-Fi verbunden + Kein streaming mit Roaming-Netzwerken + Medien nur streamen, wenn mit lokalem Anbieter verbunden Netzwerk Timeout 10 Sekunden 15 Sekunden diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5adf4499..be1a7bff 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -180,7 +180,7 @@ Playlist is empty Shuffle list is loading... Downloading - %s - Waiting for WiFi network to download + Waiting for WiFi or local (non-roaming) network to download Buffering Shuffle mode Artist radio @@ -346,6 +346,8 @@ Unlimited Wi-Fi streaming only Only stream media if connected to Wi-Fi + Don\'t stream when roaming + Don\'t stream media while roaming Network Timeout 10 seconds 15 seconds diff --git a/app/src/main/res/xml/settings_cache.xml b/app/src/main/res/xml/settings_cache.xml index 248572ca..76926379 100644 --- a/app/src/main/res/xml/settings_cache.xml +++ b/app/src/main/res/xml/settings_cache.xml @@ -40,6 +40,12 @@ android:key="wifiRequiredForDownload" android:defaultValue="false"/> + + - \ No newline at end of file + -- cgit v1.2.3