1+ // SPDX-FileCopyrightText: 2026 Davide De Rosa
2+ //
3+ // SPDX-License-Identifier: GPL-3.0
4+
15package com.algoritmico.passepartout.extensions
26
3- import com.algoritmico.passepartout.models.AppProfileStatus
4- import com.algoritmico.passepartout.models.ProfileTransfer
57import io.partout.extensions.encodedPassword
68import io.partout.extensions.isInteractive
79import io.partout.models.OpenVPNCredentials
@@ -11,7 +13,6 @@ import io.partout.models.TaggedModuleOpenVPN
1113import io.partout.models.TaggedProfile
1214import kotlinx.serialization.json.JsonObject
1315import kotlinx.serialization.json.jsonPrimitive
14- import java.util.Locale
1516
1617val TaggedProfile .fingerprint: String?
1718 get() = (userInfo as ? JsonObject )
@@ -67,40 +68,3 @@ fun TaggedProfile.withInteractiveOpenVPNCredentials(
6768 }
6869 )
6970}
70-
71- fun AppProfileStatus.statusText (): String {
72- return when (this ) {
73- AppProfileStatus .disconnected -> " Inactive"
74- AppProfileStatus .connecting -> " Activating"
75- AppProfileStatus .connected -> " Active"
76- AppProfileStatus .disconnecting -> " Deactivating"
77- }
78- }
79-
80- fun ProfileTransfer.transferText (): String {
81- return " ↓${received.toLong().formatDataUnit()} ↑${sent.toLong().formatDataUnit()} "
82- }
83-
84- private fun Long.formatDataUnit (): String {
85- val value = coerceAtLeast(0L )
86- if (value == 0L ) {
87- return " 0B"
88- }
89- if (value < KILOBYTE ) {
90- return " ${value} B"
91- }
92- return when {
93- value >= GIGABYTE / 10L -> value.formatDecimalDataUnit(GIGABYTE , " GB" )
94- value >= MEGABYTE / 10L -> value.formatDecimalDataUnit(MEGABYTE , " MB" )
95- else -> " ${value / KILOBYTE } kB"
96- }
97- }
98-
99- private fun Long.formatDecimalDataUnit (unitSize : Long , unit : String ): String {
100- val count = toDouble() / unitSize.toDouble()
101- return String .format(Locale .US , " %.2f%s" , count, unit)
102- }
103-
104- private const val KILOBYTE = 1024L
105- private const val MEGABYTE = KILOBYTE * 1024L
106- private const val GIGABYTE = MEGABYTE * 1024L
0 commit comments