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

Allow custom separator #120

Merged
merged 2 commits into from
Jul 30, 2023
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion DatWeatherDoe/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ extension AppDelegate: WeatherViewModelDelegate {
unit: measurementUnit,
isRoundingOff: configManager.isRoundingOffData,
isUnitLetterOff: configManager.isUnitLetterOff,
isUnitSymbolOff: configManager.isUnitSymbolOff
isUnitSymbolOff: configManager.isUnitSymbolOff,
valueSeparator: configManager.valueSeparator
)
)
}
Expand Down
5 changes: 5 additions & 0 deletions DatWeatherDoe/Config/ConfigManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ protocol ConfigManagerType: AnyObject {
var isRoundingOffData: Bool { get set }
var isUnitLetterOff: Bool { get set }
var isUnitSymbolOff: Bool { get set }
var valueSeparator: String { get set }
var isWeatherConditionAsTextEnabled: Bool { get set }
}

Expand All @@ -33,6 +34,7 @@ final class ConfigManager: ConfigManagerType {
case isRoundingOffData
case isUnitLetterOff
case isUnitSymbolOff
case valueSeparator
case isWeatherConditionAsTextEnabled
}

Expand Down Expand Up @@ -72,6 +74,9 @@ final class ConfigManager: ConfigManagerType {
@Storage(key: DefaultsKeys.isUnitSymbolOff.rawValue, defaultValue: false)
public var isUnitSymbolOff: Bool

@Storage(key: DefaultsKeys.valueSeparator.rawValue, defaultValue: "\u{007C}")
public var valueSeparator: String

@Storage(
key: DefaultsKeys.isWeatherConditionAsTextEnabled.rawValue,
defaultValue: false
Expand Down
2 changes: 2 additions & 0 deletions DatWeatherDoe/UI/Configure/ConfigurationCommitter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@
configManager.weatherSourceText = source == .location ? nil : sourceText
}

func setOtherOptionsForConfig(

Check warning on line 22 in DatWeatherDoe/UI/Configure/ConfigurationCommitter.swift

View workflow job for this annotation

GitHub Actions / lint

Function Parameter Count Violation: Function should have 5 parameters or less: it currently has 7 (function_parameter_count)
refreshInterval: RefreshInterval,
isShowingHumidity: Bool,
isRoundingOffData: Bool,
isUnitLetterOff: Bool,
isUnitSymbolOff: Bool,
valueSeparator: String,
isWeatherConditionAsTextEnabled: Bool
) {
configManager.refreshInterval = refreshInterval.rawValue
configManager.isShowingHumidity = isShowingHumidity
configManager.isRoundingOffData = isRoundingOffData
configManager.isUnitLetterOff = isUnitLetterOff
configManager.isUnitSymbolOff = isUnitSymbolOff
configManager.valueSeparator = valueSeparator
configManager.isWeatherConditionAsTextEnabled = isWeatherConditionAsTextEnabled
}
}
9 changes: 9 additions & 0 deletions DatWeatherDoe/UI/Configure/ConfigureView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ struct ConfigureView: View {
Toggle(isOn: $viewModel.isUnitSymbolOff) {}
}

HStack {
Text(LocalizedStringKey("Separate values with"))
Spacer()
TextField(viewModel.valueSeparatorPlaceholder, text: $viewModel.valueSeparator)
.font(.body)
.foregroundColor(.primary)
.frame(width: 114)
}

HStack {
Text(LocalizedStringKey("Weather Condition (as text)"))
Spacer()
Expand Down
9 changes: 9 additions & 0 deletions DatWeatherDoe/UI/Configure/ConfigureViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ final class ConfigureViewModel: ObservableObject {
}
}

@Published private(set) var valueSeparatorHint = ""
@Published private(set) var valueSeparatorPlaceholder = "\u{007C}"
@Published var valueSeparator = "" {
didSet {
configManager.valueSeparator = valueSeparator
}
}

@Published var isWeatherConditionAsTextEnabled: Bool {
didSet {
configManager.isWeatherConditionAsTextEnabled = isWeatherConditionAsTextEnabled
Expand Down Expand Up @@ -132,6 +140,7 @@ final class ConfigureViewModel: ObservableObject {
isRoundingOffData: isRoundingOffData,
isUnitLetterOff: isUnitLetterOff,
isUnitSymbolOff: isUnitSymbolOff,
valueSeparator: valueSeparator,
isWeatherConditionAsTextEnabled: isWeatherConditionAsTextEnabled
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import OSLog
final class HumidityTextBuilder {

private let initial: String
private let valueSeparator: String
private let humidity: Int
private let logger: Logger
private let percentString = "\u{0025}"
Expand All @@ -25,10 +26,12 @@ final class HumidityTextBuilder {

init(
initial: String,
valueSeparator: String,
humidity: Int,
logger: Logger
) {
self.initial = initial
self.valueSeparator = valueSeparator
self.humidity = humidity
self.logger = logger
}
Expand All @@ -40,7 +43,7 @@ final class HumidityTextBuilder {
return initial
}

return "\(initial) | \(humidityString)"
return "\(initial) \(valueSeparator) \(humidityString)"
}

private func buildHumidity() -> String? {
Expand Down
2 changes: 2 additions & 0 deletions DatWeatherDoe/UI/Decorator/Text/WeatherTextBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ final class WeatherTextBuilder {

struct Options {
let isWeatherConditionAsTextEnabled: Bool
let valueSeparator: String
let temperatureOptions: TemperatureTextBuilder.Options
let isShowingHumidity: Bool
}
Expand Down Expand Up @@ -58,6 +59,7 @@ final class WeatherTextBuilder {

return HumidityTextBuilder(
initial: initial,
valueSeparator: options.valueSeparator,
humidity: response.humidity,
logger: logger
).build()
Expand Down
1 change: 1 addition & 0 deletions DatWeatherDoe/UI/Menu Bar/StatusItemManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ final class StatusItemManager {
let isRoundingOff: Bool
let isUnitLetterOff: Bool
let isUnitSymbolOff: Bool
let valueSeparator: String
}

var button: NSStatusBarButton? { statusItem.button }
Expand Down
1 change: 1 addition & 0 deletions DatWeatherDoe/ViewModel/WeatherViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ final class WeatherViewModel: WeatherViewModelType {
private func buildWeatherTextOptions(for unit: MeasurementUnit) -> WeatherTextBuilder.Options {
.init(
isWeatherConditionAsTextEnabled: configManager.isWeatherConditionAsTextEnabled,
valueSeparator: configManager.valueSeparator,
temperatureOptions: .init(
unit: unit.temperatureUnit,
isRoundingOff: configManager.isRoundingOffData,
Expand Down