Skip to content

Commit de8696f

Browse files
authored
Merge pull request #1 from loopandlearn/honor-global-snooze
Honor global snooze
2 parents 2437e57 + 91a1c7f commit de8696f

File tree

4 files changed

+67
-71
lines changed

4 files changed

+67
-71
lines changed

Config.xcconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
unique_id = ${DEVELOPMENT_TEAM}
77

88
//Version (DEFAULT)
9-
LOOP_FOLLOW_MARKETING_VERSION = 2.8.3
9+
LOOP_FOLLOW_MARKETING_VERSION = 2.8.5

LoopFollow/Alarm/AlarmEditing/Components/AlarmAudioSection.swift

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -96,33 +96,39 @@ private struct TonePickerSheet: View {
9696

9797
var body: some View {
9898
NavigationView {
99-
List {
100-
ForEach(SoundFile.allCases) { tone in
101-
Button {
102-
selected = tone
103-
AlarmSound.setSoundFile(str: tone.rawValue)
104-
AlarmSound.stop()
105-
AlarmSound.playTest()
106-
} label: {
107-
HStack {
108-
Text(tone.displayName)
109-
if tone == selected {
110-
Spacer()
111-
Image(systemName: "checkmark")
112-
.foregroundColor(.accentColor)
99+
ScrollViewReader { proxy in
100+
List {
101+
ForEach(SoundFile.allCases) { tone in
102+
Button {
103+
selected = tone
104+
AlarmSound.setSoundFile(str: tone.rawValue)
105+
AlarmSound.stop()
106+
AlarmSound.playTest()
107+
} label: {
108+
HStack {
109+
Text(tone.displayName)
110+
if tone == selected {
111+
Spacer()
112+
Image(systemName: "checkmark")
113+
.foregroundColor(.accentColor)
114+
}
113115
}
114116
}
117+
.id(tone)
115118
}
116119
}
117-
}
118-
.navigationTitle("Choose Tone")
119-
.toolbar {
120-
ToolbarItem(placement: .confirmationAction) {
121-
Button("Done") {
122-
AlarmSound.stop()
123-
dismiss()
120+
.navigationTitle("Choose Tone")
121+
.toolbar {
122+
ToolbarItem(placement: .confirmationAction) {
123+
Button("Done") {
124+
AlarmSound.stop()
125+
dismiss()
126+
}
124127
}
125128
}
129+
.onAppear {
130+
proxy.scrollTo(selected, anchor: .center)
131+
}
126132
}
127133
}
128134
}

LoopFollow/Alarm/AlarmManager.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ class AlarmManager {
4343
func checkAlarms(data: AlarmData) {
4444
let now = Date()
4545
var alarmTriggered = false
46+
47+
let config = Storage.shared.alarmConfiguration.value
48+
49+
// Honor the "Snooze All" setting. If active, stop any current alarm and exit.
50+
if let snoozeUntil = config.snoozeUntil, snoozeUntil > now {
51+
if Observable.shared.currentAlarm.value != nil {
52+
stopAlarm()
53+
}
54+
return
55+
}
56+
4657
let alarms = Storage.shared.alarms.value
4758

4859
let sorted = alarms.sorted(by: Alarm.byPriorityThenSpec)

LoopFollow/Controllers/Graphs.swift

Lines changed: 28 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,71 +1772,50 @@ extension MainViewController {
17721772
}
17731773

17741774
func wrapText(_ text: String, maxLineLength: Int) -> String {
1775-
return text
1776-
var lines: [String] = []
1777-
var currentLine = ""
1778-
1779-
let words = text.components(separatedBy: .whitespacesAndNewlines)
1780-
for word in words {
1781-
if word.count > maxLineLength {
1782-
var wordToProcess = word
1783-
while !wordToProcess.isEmpty {
1784-
let spaceCount = currentLine.isEmpty ? 0 : 1
1785-
let availableSpace = maxLineLength - (currentLine.count + spaceCount)
1786-
1787-
if availableSpace <= 0 {
1788-
if !currentLine.isEmpty {
1789-
lines.append(currentLine)
1790-
currentLine = ""
1791-
}
1792-
continue
1793-
}
1775+
guard maxLineLength > 0 else {
1776+
return text
1777+
}
17941778

1795-
let takeCount = min(wordToProcess.count, availableSpace)
1796-
if takeCount <= 0 {
1797-
if !currentLine.isEmpty {
1798-
lines.append(currentLine)
1799-
currentLine = ""
1800-
}
1801-
continue
1802-
}
1779+
var result: [String] = []
1780+
let lines = text.components(separatedBy: .newlines)
18031781

1804-
let index = wordToProcess.index(wordToProcess.startIndex, offsetBy: takeCount)
1805-
let substring = wordToProcess[..<index]
1782+
for line in lines {
1783+
var currentLine = ""
1784+
let words = line.components(separatedBy: .whitespaces)
18061785

1807-
if currentLine.isEmpty {
1808-
currentLine = String(substring)
1809-
} else {
1810-
currentLine += " " + substring
1786+
for word in words {
1787+
// Handles words that are longer than a single line.
1788+
if word.count > maxLineLength {
1789+
if !currentLine.isEmpty {
1790+
result.append(currentLine)
1791+
currentLine = ""
18111792
}
18121793

1813-
wordToProcess = String(wordToProcess[index...])
1814-
1815-
if currentLine.count >= maxLineLength {
1816-
lines.append(currentLine)
1817-
currentLine = ""
1794+
var wordToSplit = word
1795+
while !wordToSplit.isEmpty {
1796+
let splitIndex = wordToSplit.index(wordToSplit.startIndex, offsetBy: min(maxLineLength, wordToSplit.count))
1797+
result.append(String(wordToSplit[..<splitIndex]))
1798+
wordToSplit = String(wordToSplit[splitIndex...])
18181799
}
1819-
}
1820-
} else {
1821-
let spaceNeeded = currentLine.isEmpty ? 0 : 1
1822-
if currentLine.count + spaceNeeded + word.count > maxLineLength {
1823-
lines.append(currentLine)
1824-
currentLine = word
18251800
} else {
1801+
// The word fits on the line.
18261802
if currentLine.isEmpty {
18271803
currentLine = word
1828-
} else {
1804+
} else if currentLine.count + word.count + 1 <= maxLineLength {
18291805
currentLine += " " + word
1806+
} else {
1807+
result.append(currentLine)
1808+
currentLine = word
18301809
}
18311810
}
18321811
}
1833-
}
18341812

1835-
if !currentLine.isEmpty {
1836-
lines.append(currentLine)
1813+
if !currentLine.isEmpty {
1814+
result.append(currentLine)
1815+
}
18371816
}
18381817

1839-
return lines.joined(separator: "\r\n")
1818+
return result.joined(separator: "\r\n")
18401819
}
18411820

18421821
func formatPillText(line1: String, time: TimeInterval, line2: String? = nil) -> String {

0 commit comments

Comments
 (0)