summaryrefslogtreecommitdiffhomepage
path: root/ui/src/main/java/com/wireguard/android/util
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2020-09-22 16:41:08 +0530
committerJason A. Donenfeld <Jason@zx2c4.com>2020-09-22 23:53:27 +0200
commit0ad3781ae5956aa2dbf217edf48c5f8445a92db8 (patch)
tree7bbf4029e44a73b3a6efe209ed9d5f3b4484c159 /ui/src/main/java/com/wireguard/android/util
parentd738161a2ebd6d6494ea5357026fa33884633ae4 (diff)
tv: initial draft of Android TV support
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'ui/src/main/java/com/wireguard/android/util')
-rw-r--r--ui/src/main/java/com/wireguard/android/util/Extensions.kt11
1 files changed, 11 insertions, 0 deletions
diff --git a/ui/src/main/java/com/wireguard/android/util/Extensions.kt b/ui/src/main/java/com/wireguard/android/util/Extensions.kt
index 2d0899c2..b419feef 100644
--- a/ui/src/main/java/com/wireguard/android/util/Extensions.kt
+++ b/ui/src/main/java/com/wireguard/android/util/Extensions.kt
@@ -11,6 +11,7 @@ import androidx.annotation.AttrRes
import androidx.lifecycle.lifecycleScope
import androidx.preference.Preference
import com.wireguard.android.Application
+import com.wireguard.android.R
import com.wireguard.android.activity.SettingsActivity
import kotlinx.coroutines.CoroutineScope
@@ -20,6 +21,16 @@ fun Context.resolveAttribute(@AttrRes attrRes: Int): Int {
return typedValue.data
}
+fun Context.formatBytes(bytes: Long): String {
+ return when {
+ bytes < 1024 -> getString(R.string.transfer_bytes, bytes)
+ bytes < 1024 * 1024 -> getString(R.string.transfer_kibibytes, bytes / 1024.0)
+ bytes < 1024 * 1024 * 1024 -> getString(R.string.transfer_mibibytes, bytes / (1024.0 * 1024.0))
+ bytes < 1024 * 1024 * 1024 * 1024L -> getString(R.string.transfer_gibibytes, bytes / (1024.0 * 1024.0 * 1024.0))
+ else -> getString(R.string.transfer_tibibytes, bytes / (1024.0 * 1024.0 * 1024.0) / 1024.0)
+ }
+}
+
val Any.applicationScope: CoroutineScope
get() = Application.getCoroutineScope()