Skip to content

Commit 6173126

Browse files
committed
Merge branch 'release/1.4.1' into versions
2 parents f1078b9 + ca40ad4 commit 6173126

18 files changed

+109
-152
lines changed

App/Sources/Globals/SpeechSynthesizer.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ final class SpeechSynthesizer: NSObject {
7171
afterCompletionDelay: TimeInterval? = nil
7272
) {
7373
let textToSpeak: String = {
74-
if text.contains("📖") {
74+
if text.contains(String.recitationEmoji) {
7575
return text.replacingOccurrences(of: "📖", with: L10n.SpeechSynthesizer.bookEmojiReplacement)
7676
}
7777
else {

App/Sources/Models/Prayer.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class Prayer {
2222
init(
2323
rakatCount: UInt,
2424
allowLongerRecitations: Bool,
25-
allowSplittingRecitations: Bool
25+
allowSplittingRecitations: Bool,
26+
showStandingRecitationName: Bool
2627
) {
2728
self.rakat = {
2829
var rakat: Rakat = []
@@ -63,6 +64,7 @@ class Prayer {
6364
let rakah = Rakah(
6465
isBeginningOfPrayer: num == 1,
6566
standingRecitationPart: standingRecitationPart,
67+
showStandingRecitationName: showStandingRecitationName,
6668
includesSittingRecitation: num % 2 == 0 || num == rakatCount,
6769
isEndOfPrayer: num == rakatCount
6870
)

App/Sources/Models/PrayerState.swift

-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ class PrayerState {
125125
previousLine: previousLine,
126126
currentArrow: currentArrow,
127127
currentLine: currentLine,
128-
isChapterName: false,
129128
currentIsComponentBeginning: lineIndex == 0,
130129
nextArrow: nextArrow,
131130
nextLine: nextLine,

App/Sources/Models/Rakah.swift

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,22 @@ class Rakah {
1717
private let includesSittingRecitation: Bool
1818
private let isEndOfPrayer: Bool
1919
let standingRecitationPart: RecitationPart?
20+
private let showStandingRecitationName: Bool
2021

2122
private var includesStandingRecitation: Bool { standingRecitationPart != nil }
2223

2324
init(
2425
isBeginningOfPrayer: Bool,
2526
standingRecitationPart: RecitationPart?,
27+
showStandingRecitationName: Bool,
2628
includesSittingRecitation: Bool,
2729
isEndOfPrayer: Bool
2830
) {
2931
self.isBeginningOfPrayer = isBeginningOfPrayer
3032
self.includesSittingRecitation = includesSittingRecitation
3133
self.isEndOfPrayer = isEndOfPrayer
3234
self.standingRecitationPart = standingRecitationPart
35+
self.showStandingRecitationName = showStandingRecitationName
3336
}
3437

3538
func components() -> [RakahComponent] {
@@ -41,10 +44,10 @@ class Rakah {
4144
components.append(RakahComponent(.taawwudh))
4245
}
4346

44-
components.append(RakahComponent(.recitationPart(.init(recitation: .theOpening, partLength: .short))))
47+
components.append(RakahComponent(.recitationPart(.init(recitation: .theOpening, partLength: .short), showName: false)))
4548

4649
if let standingRecitationPart = standingRecitationPart {
47-
let standingRecitationComponent = RakahComponent(.recitationPart(standingRecitationPart))
50+
let standingRecitationComponent = RakahComponent(.recitationPart(standingRecitationPart, showName: showStandingRecitationName))
4851
components.append(standingRecitationComponent)
4952
}
5053

@@ -86,7 +89,7 @@ extension Rakah {
8689
case takbir(Position)
8790
case openingSupplication
8891
case taawwudh
89-
case recitationPart(RecitationPart)
92+
case recitationPart(RecitationPart, showName: Bool)
9093
case ruku
9194
case straighteningUp // from Ruku
9295
case sajdah

App/Sources/Models/RakahComponent.swift

+7-4
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,16 @@ class RakahComponent {
8383
isChangingText = false
8484
chapterNumber = nil
8585

86-
case let .recitationPart(recitationPart):
86+
case let .recitationPart(recitationPart, showName):
8787
chapterNumber = recitationPart.recitation.rawValue
8888

8989
var title = recitationPart.recitation.localizedTitle
9090
if recitationPart.totalParts > 1 {
9191
title = l10n.splitRecitationTitle(title, recitationPart.part, recitationPart.totalParts)
9292
}
93-
name = "📖\(chapterNumber!): \(title)"
93+
name = "\(String.recitationEmoji)\(chapterNumber!): \(title)"
9494

95-
spokenTextLines = recitationPart.recitationLines()
95+
spokenTextLines = showName ? [name] + recitationPart.recitationLines() : recitationPart.recitationLines()
9696
needsMovement = false
9797
position = .standing
9898
movementSound = nil
@@ -171,7 +171,10 @@ class RakahComponent {
171171
}
172172

173173
extension String {
174+
static var recitationEmoji: Character = "📖"
175+
174176
var estimatedReadingTime: Timespan {
175-
RakahComponent.durationPerCharacter * Double(utf8.count) + .milliseconds(500) // add time for context switch
177+
// 500 ms for context switch + 1s remember time for recitation name
178+
RakahComponent.durationPerCharacter * Double(utf8.count) + .milliseconds(500) + .seconds(contains(Self.recitationEmoji) ? 1 : 0)
176179
}
177180
}

App/Sources/ScreenFlows/Prayer/PrayerFlowController.swift

+10-47
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import UIKit
1111
class PrayerFlowController: FlowController {
1212
private let prayer: Prayer
1313
private let fixedTextSpeedsFactor: Double
14-
private let changingTextSpeedFactor: Double
15-
private let showChangingTextName: Bool
14+
private let recitationSpeedFactor: Double
1615
private var audioMode: AudioMode
1716
private let movementSoundInstrument: String
1817

@@ -26,16 +25,14 @@ class PrayerFlowController: FlowController {
2625
init(
2726
prayer: Prayer,
2827
fixedTextSpeedsFactor: Double,
29-
changingTextSpeedFactor: Double,
30-
showChangingTextName: Bool,
28+
recitationSpeedFactor: Double,
3129
audioMode: AudioMode,
3230
movementSoundInstrument: String,
3331
speechSynthesizer: SpeechSynthesizer
3432
) {
3533
self.prayer = prayer
3634
self.fixedTextSpeedsFactor = fixedTextSpeedsFactor
37-
self.changingTextSpeedFactor = changingTextSpeedFactor
38-
self.showChangingTextName = showChangingTextName
35+
self.recitationSpeedFactor = recitationSpeedFactor
3936
self.audioMode = audioMode
4037
self.movementSoundInstrument = movementSoundInstrument
4138
self.speechSynthesizer = speechSynthesizer
@@ -85,7 +82,6 @@ class PrayerFlowController: FlowController {
8582
previousLine: nil,
8683
currentArrow: nil,
8784
currentLine: "\(count)",
88-
isChapterName: false,
8985
currentIsComponentBeginning: false,
9086
nextArrow: nil,
9187
nextLine: nil,
@@ -96,7 +92,7 @@ class PrayerFlowController: FlowController {
9692
func startPrayer() {
9793
prayerState = PrayerState(
9894
prayer: prayer,
99-
changingTextSpeedFactor: changingTextSpeedFactor,
95+
changingTextSpeedFactor: recitationSpeedFactor,
10096
fixedTextsSpeedFactor: fixedTextSpeedsFactor,
10197
audioMode: audioMode,
10298
movementSoundInstrument: movementSoundInstrument,
@@ -107,6 +103,9 @@ class PrayerFlowController: FlowController {
107103

108104
// set audio session to this app
109105
try? AVAudioSession.sharedInstance().setActive(true)
106+
if #available(iOS 14.5, *) {
107+
try? AVAudioSession.sharedInstance().setPrefersNoInterruptionsFromSystemAlerts(true)
108+
}
110109

111110
// prevent screen from locking
112111
UIApplication.shared.isIdleTimerDisabled = true
@@ -146,45 +145,6 @@ class PrayerFlowController: FlowController {
146145

147146
private func progressToNextStep() {
148147
if prayerState.moveToNextLine() {
149-
let viewModel = prayerState.prayerViewModel()
150-
151-
// show changing text info if chosen
152-
if self.showChangingTextName && viewModel.currentIsComponentBeginning {
153-
if let chapterNum = prayerState.currentRecitationChapterNum, chapterNum != 1 {
154-
let infoViewModel = PrayerViewModel(
155-
currentComponentName: viewModel.currentComponentName,
156-
previousArrow: viewModel.previousArrow,
157-
previousLine: viewModel.previousLine,
158-
currentArrow: nil,
159-
currentLine: viewModel.currentComponentName,
160-
isChapterName: true,
161-
currentIsComponentBeginning: true,
162-
nextArrow: nil,
163-
nextLine: viewModel.currentLine,
164-
nextIsComponentBeginning: false
165-
)
166-
self.prayerViewCtrl.viewModel = infoViewModel
167-
168-
switch audioMode {
169-
case .movementSound, .none:
170-
let rememberTime = Timespan.milliseconds(1_000)
171-
let waitTime = infoViewModel.currentLine.estimatedReadingTime + rememberTime
172-
delay(by: waitTime) {
173-
self.prayerViewCtrl.viewModel = self.prayerState.prayerViewModel()
174-
self.progressPrayer()
175-
}
176-
177-
case .speechSynthesizer, .movementSoundAndSpeechSynthesizer:
178-
speechSynthesizer.speak(text: infoViewModel.currentLine) {
179-
self.prayerViewCtrl.viewModel = self.prayerState.prayerViewModel()
180-
self.progressPrayer()
181-
}
182-
}
183-
184-
return
185-
}
186-
}
187-
188148
prayerViewCtrl.viewModel = prayerState.prayerViewModel()
189149
progressPrayer()
190150
}
@@ -207,6 +167,9 @@ extension PrayerFlowController: PrayerFlowDelegate {
207167
countdown?.cancel()
208168
cleanup()
209169
prayerViewCtrl.dismiss(animated: true) {
170+
if #available(iOS 14.5, *) {
171+
try? AVAudioSession.sharedInstance().setPrefersNoInterruptionsFromSystemAlerts(false)
172+
}
210173
try? AVAudioSession.sharedInstance().setActive(false)
211174
UIApplication.shared.isIdleTimerDisabled = false
212175
}

App/Sources/ScreenFlows/Prayer/PrayerViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class PrayerViewController: UIViewController {
2121
updateArrowLabels()
2222
updateSeparators()
2323

24-
if viewModel.isChapterName {
24+
if viewModel.currentLine.contains(String.recitationEmoji) {
2525
currentLineLabel.textColor = Colors.secondary
2626
}
2727
else {

App/Sources/ScreenFlows/Prayer/PrayerViewModel.swift

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ struct PrayerViewModel {
1414

1515
let currentArrow: Position.Arrow?
1616
let currentLine: String
17-
let isChapterName: Bool
1817
let currentIsComponentBeginning: Bool
1918

2019
let nextArrow: Position.Arrow?

App/Sources/ScreenFlows/Settings/SettingsFlowController.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ extension SettingsFlowController: SettingsFlowDelegate {
3939
}
4040

4141
func setChangingPartSpeed(_ changingPartSpeed: Double) {
42-
settingsViewModel.changingTextSpeedFactor = changingPartSpeed
42+
settingsViewModel.recitationSpeedFactor = changingPartSpeed
4343
}
4444

4545
func setShowChangingTextName(_ showChangingTextName: Bool) {
46-
settingsViewModel.showChangingTextName = showChangingTextName
46+
settingsViewModel.showRecitationName = showChangingTextName
4747
}
4848

4949
func setAllowLongerRecitations(_ allowLongerRecitations: Bool) {
@@ -95,14 +95,14 @@ extension SettingsFlowController: SettingsFlowDelegate {
9595
let prayer = Prayer(
9696
rakatCount: UInt(settingsViewModel.rakatCount),
9797
allowLongerRecitations: settingsViewModel.allowLongerRecitations,
98-
allowSplittingRecitations: settingsViewModel.allowSplittingRecitations
98+
allowSplittingRecitations: settingsViewModel.allowSplittingRecitations,
99+
showStandingRecitationName: settingsViewModel.showRecitationName
99100
)
100101

101102
let prayerFlowCtrl = PrayerFlowController(
102103
prayer: prayer,
103104
fixedTextSpeedsFactor: settingsViewModel.fixedTextsSpeedFactor,
104-
changingTextSpeedFactor: settingsViewModel.changingTextSpeedFactor,
105-
showChangingTextName: settingsViewModel.showChangingTextName,
105+
recitationSpeedFactor: settingsViewModel.recitationSpeedFactor,
106106
audioMode: settingsViewModel.audioMode,
107107
movementSoundInstrument: settingsViewModel.movementSoundInstrument,
108108
speechSynthesizer: settingsViewModel.speechSynthesizer

App/Sources/ScreenFlows/Settings/SettingsViewController.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class SettingsViewController: FormViewController {
189189
private func changingTextSpeedRow() -> SliderRow {
190190
SliderRow { row in
191191
row.title = "🔀 " + l10n.AudioSpeedSection.ChangingText.title
192-
row.value = Float(viewModel.changingTextSpeedFactor)
192+
row.value = Float(viewModel.recitationSpeedFactor)
193193
row.displayValueFor = { String(format: "%.2f", $0!) }
194194
row.cell.slider.minimumValue = 0.5
195195
row.cell.slider.maximumValue = 2.0
@@ -207,7 +207,7 @@ class SettingsViewController: FormViewController {
207207
private func changingTextNameRow() -> SwitchRow {
208208
SwitchRow { row in
209209
row.title = l10n.PrayerSection.ChangingTextName.title
210-
row.value = viewModel.showChangingTextName
210+
row.value = viewModel.showRecitationName
211211
}
212212
.cellSetup { cell, _ in
213213
cell.imageView?.image = UIImage(systemName: "character.book.closed")

App/Sources/ScreenFlows/Settings/SettingsViewModel.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ class SettingsViewModel {
1818
set { Defaults.fixedTextsSpeedFactor = newValue }
1919
}
2020

21-
var changingTextSpeedFactor: Double {
22-
get { Defaults.changingTextSpeedFactor }
23-
set { Defaults.changingTextSpeedFactor = newValue }
21+
var recitationSpeedFactor: Double {
22+
get { Defaults.recitationSpeedFactor }
23+
set { Defaults.recitationSpeedFactor = newValue }
2424
}
2525

26-
var showChangingTextName: Bool {
27-
get { Defaults.showChangingTextName }
28-
set { Defaults.showChangingTextName = newValue }
26+
var showRecitationName: Bool {
27+
get { Defaults.showRecitationName }
28+
set { Defaults.showRecitationName = newValue }
2929
}
3030

3131
var allowLongerRecitations: Bool {
@@ -79,8 +79,8 @@ extension DefaultsKeys {
7979

8080
var rakatCount: DefaultsKey<Int> { .init("RakatCount", defaultValue: 4) }
8181
var fixedTextsSpeedFactor: DefaultsKey<Double> { .init("FixedTextsSpeedFactor", defaultValue: 1.0) }
82-
var changingTextSpeedFactor: DefaultsKey<Double> { .init("ChangingTextSpeedFactor", defaultValue: 1.0) }
83-
var showChangingTextName: DefaultsKey<Bool> { .init("ShowChangingTextName", defaultValue: true) }
82+
var recitationSpeedFactor: DefaultsKey<Double> { .init("ChangingTextSpeedFactor", defaultValue: 1.0) }
83+
var showRecitationName: DefaultsKey<Bool> { .init("ShowChangingTextName", defaultValue: true) }
8484
var allowLongerRecitations: DefaultsKey<Bool> { .init("AllowLongerRecitations", defaultValue: false) }
8585
var allowSplittingRecitations: DefaultsKey<Bool> { .init("AllowSplittingRecitations", defaultValue: true) }
8686
var movementSoundInstrument: DefaultsKey<String> { .init("MovementSoundInstrument", defaultValue: defaultInstrument.rawValue) }

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ If needed, pluralize to `Issues`, `PRs` or `Authors` and list multiple separated
3131
### Security
3232
- None.
3333

34+
## [1.4.1] - 2021-12-15
35+
### Fixed
36+
- Fixed an issue where the current line didn't move correctly with screen text & sound if recitation names were turned on.
37+
3438
## [1.4.0] - 2021-12-08
3539
### Added
3640
- Added 35 more Quran recitations (from Surah 55 to 89) in all three supported languages.

0 commit comments

Comments
 (0)