From aac73cd6d774c64f003851af3e3e2da66f7876aa Mon Sep 17 00:00:00 2001 From: tzugen Date: Wed, 3 Nov 2021 12:55:20 +0100 Subject: [PATCH] Further cleanup maxBitrate function --- .../org/moire/ultrasonic/util/Settings.kt | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/Settings.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/Settings.kt index fd541dd6..d7c8545f 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/Settings.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/Settings.kt @@ -69,14 +69,21 @@ object Settings { @JvmStatic val maxBitRate: Int get() { - val preferences = preferences - return preferences.getString( - if (Util.networkInfo().unmetered) Constants.PREFERENCES_KEY_MAX_BITRATE_WIFI - else Constants.PREFERENCES_KEY_MAX_BITRATE_MOBILE, - "0" - )!!.toInt() + val network = Util.networkInfo() + + if (!network.connected) return 0 + + if (network.unmetered) { + return maxWifiBitRate + } else { + return maxMobileBitRate + } } + private var maxWifiBitRate by StringIntSetting(Constants.PREFERENCES_KEY_MAX_BITRATE_WIFI) + + private var maxMobileBitRate by StringIntSetting(Constants.PREFERENCES_KEY_MAX_BITRATE_MOBILE) + @JvmStatic val preloadCount: Int get() {