diff options
author | Florian Bruhin <git@the-compiler.org> | 2018-06-12 19:48:23 +0200 |
---|---|---|
committer | Florian Bruhin <git@the-compiler.org> | 2018-06-13 08:11:17 +0200 |
commit | 3129feac99cc78993e465ba5d30bffcb3390636d (patch) | |
tree | 8169d754da55be14909486835c909207ba5de730 /app/src/main/java/github | |
parent | 3cb68cf66cde60ac780f7c87510d447dd2873cbb (diff) | |
download | dsub-3129feac99cc78993e465ba5d30bffcb3390636d.tar.gz dsub-3129feac99cc78993e465ba5d30bffcb3390636d.tar.bz2 dsub-3129feac99cc78993e465ba5d30bffcb3390636d.zip |
Add option to disable downloading while roaming
Diffstat (limited to 'app/src/main/java/github')
3 files changed, 12 insertions, 2 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); } |