Skip to content

Commit

Permalink
Merge branch 'release/1.4.1' into versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeehut committed Dec 15, 2021
2 parents f1078b9 + ca40ad4 commit 6173126
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 152 deletions.
2 changes: 1 addition & 1 deletion App/Sources/Globals/SpeechSynthesizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ final class SpeechSynthesizer: NSObject {
afterCompletionDelay: TimeInterval? = nil
) {
let textToSpeak: String = {
if text.contains("📖") {
if text.contains(String.recitationEmoji) {
return text.replacingOccurrences(of: "📖", with: L10n.SpeechSynthesizer.bookEmojiReplacement)
}
else {
Expand Down
4 changes: 3 additions & 1 deletion App/Sources/Models/Prayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class Prayer {
init(
rakatCount: UInt,
allowLongerRecitations: Bool,
allowSplittingRecitations: Bool
allowSplittingRecitations: Bool,
showStandingRecitationName: Bool
) {
self.rakat = {
var rakat: Rakat = []
Expand Down Expand Up @@ -63,6 +64,7 @@ class Prayer {
let rakah = Rakah(
isBeginningOfPrayer: num == 1,
standingRecitationPart: standingRecitationPart,
showStandingRecitationName: showStandingRecitationName,
includesSittingRecitation: num % 2 == 0 || num == rakatCount,
isEndOfPrayer: num == rakatCount
)
Expand Down
1 change: 0 additions & 1 deletion App/Sources/Models/PrayerState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ class PrayerState {
previousLine: previousLine,
currentArrow: currentArrow,
currentLine: currentLine,
isChapterName: false,
currentIsComponentBeginning: lineIndex == 0,
nextArrow: nextArrow,
nextLine: nextLine,
Expand Down
9 changes: 6 additions & 3 deletions App/Sources/Models/Rakah.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,22 @@ class Rakah {
private let includesSittingRecitation: Bool
private let isEndOfPrayer: Bool
let standingRecitationPart: RecitationPart?
private let showStandingRecitationName: Bool

private var includesStandingRecitation: Bool { standingRecitationPart != nil }

init(
isBeginningOfPrayer: Bool,
standingRecitationPart: RecitationPart?,
showStandingRecitationName: Bool,
includesSittingRecitation: Bool,
isEndOfPrayer: Bool
) {
self.isBeginningOfPrayer = isBeginningOfPrayer
self.includesSittingRecitation = includesSittingRecitation
self.isEndOfPrayer = isEndOfPrayer
self.standingRecitationPart = standingRecitationPart
self.showStandingRecitationName = showStandingRecitationName
}

func components() -> [RakahComponent] {
Expand All @@ -41,10 +44,10 @@ class Rakah {
components.append(RakahComponent(.taawwudh))
}

components.append(RakahComponent(.recitationPart(.init(recitation: .theOpening, partLength: .short))))
components.append(RakahComponent(.recitationPart(.init(recitation: .theOpening, partLength: .short), showName: false)))

if let standingRecitationPart = standingRecitationPart {
let standingRecitationComponent = RakahComponent(.recitationPart(standingRecitationPart))
let standingRecitationComponent = RakahComponent(.recitationPart(standingRecitationPart, showName: showStandingRecitationName))
components.append(standingRecitationComponent)
}

Expand Down Expand Up @@ -86,7 +89,7 @@ extension Rakah {
case takbir(Position)
case openingSupplication
case taawwudh
case recitationPart(RecitationPart)
case recitationPart(RecitationPart, showName: Bool)
case ruku
case straighteningUp // from Ruku
case sajdah
Expand Down
11 changes: 7 additions & 4 deletions App/Sources/Models/RakahComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ class RakahComponent {
isChangingText = false
chapterNumber = nil

case let .recitationPart(recitationPart):
case let .recitationPart(recitationPart, showName):
chapterNumber = recitationPart.recitation.rawValue

var title = recitationPart.recitation.localizedTitle
if recitationPart.totalParts > 1 {
title = l10n.splitRecitationTitle(title, recitationPart.part, recitationPart.totalParts)
}
name = "📖\(chapterNumber!): \(title)"
name = "\(String.recitationEmoji)\(chapterNumber!): \(title)"

spokenTextLines = recitationPart.recitationLines()
spokenTextLines = showName ? [name] + recitationPart.recitationLines() : recitationPart.recitationLines()
needsMovement = false
position = .standing
movementSound = nil
Expand Down Expand Up @@ -171,7 +171,10 @@ class RakahComponent {
}

extension String {
static var recitationEmoji: Character = "📖"

var estimatedReadingTime: Timespan {
RakahComponent.durationPerCharacter * Double(utf8.count) + .milliseconds(500) // add time for context switch
// 500 ms for context switch + 1s remember time for recitation name
RakahComponent.durationPerCharacter * Double(utf8.count) + .milliseconds(500) + .seconds(contains(Self.recitationEmoji) ? 1 : 0)
}
}
57 changes: 10 additions & 47 deletions App/Sources/ScreenFlows/Prayer/PrayerFlowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import UIKit
class PrayerFlowController: FlowController {
private let prayer: Prayer
private let fixedTextSpeedsFactor: Double
private let changingTextSpeedFactor: Double
private let showChangingTextName: Bool
private let recitationSpeedFactor: Double
private var audioMode: AudioMode
private let movementSoundInstrument: String

Expand All @@ -26,16 +25,14 @@ class PrayerFlowController: FlowController {
init(
prayer: Prayer,
fixedTextSpeedsFactor: Double,
changingTextSpeedFactor: Double,
showChangingTextName: Bool,
recitationSpeedFactor: Double,
audioMode: AudioMode,
movementSoundInstrument: String,
speechSynthesizer: SpeechSynthesizer
) {
self.prayer = prayer
self.fixedTextSpeedsFactor = fixedTextSpeedsFactor
self.changingTextSpeedFactor = changingTextSpeedFactor
self.showChangingTextName = showChangingTextName
self.recitationSpeedFactor = recitationSpeedFactor
self.audioMode = audioMode
self.movementSoundInstrument = movementSoundInstrument
self.speechSynthesizer = speechSynthesizer
Expand Down Expand Up @@ -85,7 +82,6 @@ class PrayerFlowController: FlowController {
previousLine: nil,
currentArrow: nil,
currentLine: "\(count)",
isChapterName: false,
currentIsComponentBeginning: false,
nextArrow: nil,
nextLine: nil,
Expand All @@ -96,7 +92,7 @@ class PrayerFlowController: FlowController {
func startPrayer() {
prayerState = PrayerState(
prayer: prayer,
changingTextSpeedFactor: changingTextSpeedFactor,
changingTextSpeedFactor: recitationSpeedFactor,
fixedTextsSpeedFactor: fixedTextSpeedsFactor,
audioMode: audioMode,
movementSoundInstrument: movementSoundInstrument,
Expand All @@ -107,6 +103,9 @@ class PrayerFlowController: FlowController {

// set audio session to this app
try? AVAudioSession.sharedInstance().setActive(true)
if #available(iOS 14.5, *) {
try? AVAudioSession.sharedInstance().setPrefersNoInterruptionsFromSystemAlerts(true)
}

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

private func progressToNextStep() {
if prayerState.moveToNextLine() {
let viewModel = prayerState.prayerViewModel()

// show changing text info if chosen
if self.showChangingTextName && viewModel.currentIsComponentBeginning {
if let chapterNum = prayerState.currentRecitationChapterNum, chapterNum != 1 {
let infoViewModel = PrayerViewModel(
currentComponentName: viewModel.currentComponentName,
previousArrow: viewModel.previousArrow,
previousLine: viewModel.previousLine,
currentArrow: nil,
currentLine: viewModel.currentComponentName,
isChapterName: true,
currentIsComponentBeginning: true,
nextArrow: nil,
nextLine: viewModel.currentLine,
nextIsComponentBeginning: false
)
self.prayerViewCtrl.viewModel = infoViewModel

switch audioMode {
case .movementSound, .none:
let rememberTime = Timespan.milliseconds(1_000)
let waitTime = infoViewModel.currentLine.estimatedReadingTime + rememberTime
delay(by: waitTime) {
self.prayerViewCtrl.viewModel = self.prayerState.prayerViewModel()
self.progressPrayer()
}

case .speechSynthesizer, .movementSoundAndSpeechSynthesizer:
speechSynthesizer.speak(text: infoViewModel.currentLine) {
self.prayerViewCtrl.viewModel = self.prayerState.prayerViewModel()
self.progressPrayer()
}
}

return
}
}

prayerViewCtrl.viewModel = prayerState.prayerViewModel()
progressPrayer()
}
Expand All @@ -207,6 +167,9 @@ extension PrayerFlowController: PrayerFlowDelegate {
countdown?.cancel()
cleanup()
prayerViewCtrl.dismiss(animated: true) {
if #available(iOS 14.5, *) {
try? AVAudioSession.sharedInstance().setPrefersNoInterruptionsFromSystemAlerts(false)
}
try? AVAudioSession.sharedInstance().setActive(false)
UIApplication.shared.isIdleTimerDisabled = false
}
Expand Down
2 changes: 1 addition & 1 deletion App/Sources/ScreenFlows/Prayer/PrayerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PrayerViewController: UIViewController {
updateArrowLabels()
updateSeparators()

if viewModel.isChapterName {
if viewModel.currentLine.contains(String.recitationEmoji) {
currentLineLabel.textColor = Colors.secondary
}
else {
Expand Down
1 change: 0 additions & 1 deletion App/Sources/ScreenFlows/Prayer/PrayerViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ struct PrayerViewModel {

let currentArrow: Position.Arrow?
let currentLine: String
let isChapterName: Bool
let currentIsComponentBeginning: Bool

let nextArrow: Position.Arrow?
Expand Down
10 changes: 5 additions & 5 deletions App/Sources/ScreenFlows/Settings/SettingsFlowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ extension SettingsFlowController: SettingsFlowDelegate {
}

func setChangingPartSpeed(_ changingPartSpeed: Double) {
settingsViewModel.changingTextSpeedFactor = changingPartSpeed
settingsViewModel.recitationSpeedFactor = changingPartSpeed
}

func setShowChangingTextName(_ showChangingTextName: Bool) {
settingsViewModel.showChangingTextName = showChangingTextName
settingsViewModel.showRecitationName = showChangingTextName
}

func setAllowLongerRecitations(_ allowLongerRecitations: Bool) {
Expand Down Expand Up @@ -95,14 +95,14 @@ extension SettingsFlowController: SettingsFlowDelegate {
let prayer = Prayer(
rakatCount: UInt(settingsViewModel.rakatCount),
allowLongerRecitations: settingsViewModel.allowLongerRecitations,
allowSplittingRecitations: settingsViewModel.allowSplittingRecitations
allowSplittingRecitations: settingsViewModel.allowSplittingRecitations,
showStandingRecitationName: settingsViewModel.showRecitationName
)

let prayerFlowCtrl = PrayerFlowController(
prayer: prayer,
fixedTextSpeedsFactor: settingsViewModel.fixedTextsSpeedFactor,
changingTextSpeedFactor: settingsViewModel.changingTextSpeedFactor,
showChangingTextName: settingsViewModel.showChangingTextName,
recitationSpeedFactor: settingsViewModel.recitationSpeedFactor,
audioMode: settingsViewModel.audioMode,
movementSoundInstrument: settingsViewModel.movementSoundInstrument,
speechSynthesizer: settingsViewModel.speechSynthesizer
Expand Down
4 changes: 2 additions & 2 deletions App/Sources/ScreenFlows/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class SettingsViewController: FormViewController {
private func changingTextSpeedRow() -> SliderRow {
SliderRow { row in
row.title = "🔀 " + l10n.AudioSpeedSection.ChangingText.title
row.value = Float(viewModel.changingTextSpeedFactor)
row.value = Float(viewModel.recitationSpeedFactor)
row.displayValueFor = { String(format: "%.2f", $0!) }
row.cell.slider.minimumValue = 0.5
row.cell.slider.maximumValue = 2.0
Expand All @@ -207,7 +207,7 @@ class SettingsViewController: FormViewController {
private func changingTextNameRow() -> SwitchRow {
SwitchRow { row in
row.title = l10n.PrayerSection.ChangingTextName.title
row.value = viewModel.showChangingTextName
row.value = viewModel.showRecitationName
}
.cellSetup { cell, _ in
cell.imageView?.image = UIImage(systemName: "character.book.closed")
Expand Down
16 changes: 8 additions & 8 deletions App/Sources/ScreenFlows/Settings/SettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ class SettingsViewModel {
set { Defaults.fixedTextsSpeedFactor = newValue }
}

var changingTextSpeedFactor: Double {
get { Defaults.changingTextSpeedFactor }
set { Defaults.changingTextSpeedFactor = newValue }
var recitationSpeedFactor: Double {
get { Defaults.recitationSpeedFactor }
set { Defaults.recitationSpeedFactor = newValue }
}

var showChangingTextName: Bool {
get { Defaults.showChangingTextName }
set { Defaults.showChangingTextName = newValue }
var showRecitationName: Bool {
get { Defaults.showRecitationName }
set { Defaults.showRecitationName = newValue }
}

var allowLongerRecitations: Bool {
Expand Down Expand Up @@ -79,8 +79,8 @@ extension DefaultsKeys {

var rakatCount: DefaultsKey<Int> { .init("RakatCount", defaultValue: 4) }
var fixedTextsSpeedFactor: DefaultsKey<Double> { .init("FixedTextsSpeedFactor", defaultValue: 1.0) }
var changingTextSpeedFactor: DefaultsKey<Double> { .init("ChangingTextSpeedFactor", defaultValue: 1.0) }
var showChangingTextName: DefaultsKey<Bool> { .init("ShowChangingTextName", defaultValue: true) }
var recitationSpeedFactor: DefaultsKey<Double> { .init("ChangingTextSpeedFactor", defaultValue: 1.0) }
var showRecitationName: DefaultsKey<Bool> { .init("ShowChangingTextName", defaultValue: true) }
var allowLongerRecitations: DefaultsKey<Bool> { .init("AllowLongerRecitations", defaultValue: false) }
var allowSplittingRecitations: DefaultsKey<Bool> { .init("AllowSplittingRecitations", defaultValue: true) }
var movementSoundInstrument: DefaultsKey<String> { .init("MovementSoundInstrument", defaultValue: defaultInstrument.rawValue) }
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ If needed, pluralize to `Issues`, `PRs` or `Authors` and list multiple separated
### Security
- None.

## [1.4.1] - 2021-12-15
### Fixed
- Fixed an issue where the current line didn't move correctly with screen text & sound if recitation names were turned on.

## [1.4.0] - 2021-12-08
### Added
- Added 35 more Quran recitations (from Surah 55 to 89) in all three supported languages.
Expand Down
Loading

0 comments on commit 6173126

Please sign in to comment.