Skip to content

Commit

Permalink
feat: turn methods private and fix text moving depending on number te…
Browse files Browse the repository at this point in the history
…xt from slider

feat: change indentation to spacebar
  • Loading branch information
Harry-KNIGHT committed Nov 29, 2023
1 parent d035ecc commit 9a37f74
Showing 1 changed file with 39 additions and 13 deletions.
52 changes: 39 additions & 13 deletions ControlRoom/Simulator UI/ControlScreens/StatusBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,16 @@ struct StatusBarView: View {
.pickerStyle(.radioGroup)

VStack(spacing: 0) {
Text("Current battery percentage: \(Int(round(batteryLevel)))%")
Slider(value: $batteryLevel, in: 0...100, onEditingChanged: levelChanged, minimumValueLabel: Text("0%"), maximumValueLabel: Text("100%")) {
Text("Current battery percentage: \(Int(round(batteryLevel)))%")
.font(.callout.monospacedDigit())

Slider(
value: $batteryLevel,
in: 0...100,
onEditingChanged: levelChanged,
minimumValueLabel: Text("0%"),
maximumValueLabel: Text("100%")
) {
Text("Level:")
}
}
Expand All @@ -125,12 +133,14 @@ struct StatusBarView: View {
}
}

// MARK: Private methods

/// Changes the system clock to a new value.
func setTime() {
private func setTime() {
SimCtl.overrideStatusBarTime(simulator.udid, time: time)
}

func setAppleTime() {
private func setAppleTime() {
let calendar = Calendar.current
var components = calendar.dateComponents([.year, .month, .day], from: Date.now)
components.hour = 9
Expand All @@ -145,36 +155,52 @@ struct StatusBarView: View {

/// Sends status bar updates all at once; simctl gets unhappy if we send them individually, but
/// also for whatever reason prefers cellular data sent separately from WiFi.
func updateWiFiData() {
SimCtl.overrideStatusBarWiFi(simulator.udid, network: dataNetwork,
wifiMode: wiFiMode, wifiBars: wiFiBar)
private func updateWiFiData() {
SimCtl.overrideStatusBarWiFi(
simulator.udid,
network: dataNetwork,
wifiMode: wiFiMode,
wifiBars: wiFiBar
)
}

func updateCellularData() {
SimCtl.overrideStatusBarCellular(simulator.udid, cellMode: cellularMode,
cellBars: cellularBar, carrier: carrierName)
private func updateCellularData() {
SimCtl.overrideStatusBarCellular(
simulator.udid,
cellMode: cellularMode,
cellBars: cellularBar,
carrier: carrierName
)
}

/// Sends battery updates all at once; simctl gets unhappy if we send them individually.
func updateBattery() {
SimCtl.overrideStatusBarBattery(simulator.udid, level: Int(batteryLevel), state: batteryState)
private func updateBattery() {
SimCtl.overrideStatusBarBattery(
simulator.udid,
level: Int(batteryLevel),
state: batteryState
)
}

/// Triggered when the user adjusts the battery level.
func levelChanged(_ isEditing: Bool) {
private func levelChanged(_ isEditing: Bool) {
if isEditing == false {
updateBattery()
}
}
}

// MARK: Preview

struct StatusBarViewView_Previews: PreviewProvider {
static var previews: some View {
StatusBarView(simulator: .example)
.environmentObject(Preferences())
}
}

// MARK: Extensions

extension SimCtl.StatusBar.DataNetwork {
var displayName: String {
switch self {
Expand Down

0 comments on commit 9a37f74

Please sign in to comment.