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 ++++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) (limited to 'app/src/main/java') 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); } -- cgit v1.2.3