variableValueAsPercentage

This commit is contained in:
spaced4ndy
2024-06-26 15:07:37 +04:00
parent 55a05ebe5c
commit 14f79df72f
2 changed files with 21 additions and 12 deletions
@@ -278,7 +278,7 @@ struct SubsStatusIndicator: View {
Button {
showServersSummary = true
} label: {
SubscriptionStatusView(activeSubs: subs.ssActive, pendingSubs: subs.ssPending)
SubscriptionStatusView(activeSubs: subs.ssActive, pendingSubs: subs.ssPending, variableValueAsPercentage: true)
}
.onAppear {
startInitialTimer()
@@ -291,6 +291,7 @@ struct SubscriptionStatusView: View {
@EnvironmentObject var m: ChatModel
var activeSubs: Int
var pendingSubs: Int
var variableValueAsPercentage: Bool = false
var body: some View {
let netInfo = m.networkInfo
@@ -320,13 +321,18 @@ struct SubscriptionStatusView: View {
}
}
// We manipulate variableValue so all "wifi" sections are filled only with 100% active subs,
// unless variableValueAsPercentage is true; same for cellularbarsColor
var wifiColor: (Color, Double, Double) {
if activeSubs > 0 {
let wifiVariableValue = ( // wifi has 3 sections
activeSubsPercentage >= 1 ? 1
: (activeSubsPercentage >= 0.5 && activeSubsPercentage < 1) ? 0.6
: (activeSubsPercentage > 0 && activeSubsPercentage < 0.5) ? 0.3
: 0
let wifiVariableValue = (
variableValueAsPercentage ? activeSubsPercentage
: ( // "wifi" has 3 sections
activeSubsPercentage >= 1 ? 1
: (activeSubsPercentage >= 0.5 && activeSubsPercentage < 1) ? 0.6
: (activeSubsPercentage > 0 && activeSubsPercentage < 0.5) ? 0.3
: 0
)
)
return (.accentColor, wifiVariableValue, activeSubsPercentage)
} else {
@@ -336,12 +342,15 @@ struct SubscriptionStatusView: View {
var cellularbarsColor: (Color, Double, Double) {
if activeSubs > 0 {
let wifiVariableValue = ( // cellularbars has 4 sections
activeSubsPercentage >= 1 ? 1
: (activeSubsPercentage >= 0.67 && activeSubsPercentage < 1) ? 0.7
: (activeSubsPercentage >= 0.33 && activeSubsPercentage < 0.67) ? 0.45
: (activeSubsPercentage > 0 && activeSubsPercentage < 0.33) ? 0.2
: 0
let wifiVariableValue = (
variableValueAsPercentage ? activeSubsPercentage
: ( // "cellularbars" has 4 sections
activeSubsPercentage >= 1 ? 1
: (activeSubsPercentage >= 0.67 && activeSubsPercentage < 1) ? 0.7
: (activeSubsPercentage >= 0.33 && activeSubsPercentage < 0.67) ? 0.45
: (activeSubsPercentage > 0 && activeSubsPercentage < 0.33) ? 0.2
: 0
)
)
return (.accentColor, wifiVariableValue, activeSubsPercentage)
} else {