Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: turn methods private and fix text moving depending on number te… #178

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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