Skip to content

Commit

Permalink
Longman features #61: Fix ReaderTranslatorPlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
filimo committed Feb 5, 2020
1 parent 7e82cac commit edb9e5b
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,22 @@ struct StatusBarView_Voice_Toggle: View {
HStack {
Image.sfSymbol(audio.isSpeakSentences ? "speaker.3.fill" : "speaker")
.onTapGesture { self.audio.isSpeakSentences.toggle() }
Slider(value: $audio.sentencesVolume, in: 0.1 ... 1.0).frame(width: 100)
Slider(
value: $audio.sentencesVolume,
in: 0.1 ... 1.0,
onEditingChanged: { _ in SpeechSynthesizer.speak() }
).frame(width: 100)
}
Divider()
Text("Speak words")
HStack {
Image.sfSymbol(audio.isSpeakWords ? "speaker.3.fill" : "speaker")
.onTapGesture { self.audio.isSpeakWords.toggle() }
Slider(value: $audio.wordsVolume, in: 0.1 ... 1.0).frame(width: 100)
Slider(
value: $audio.wordsVolume,
in: 0.1 ... 1.0,
onEditingChanged: { _ in SpeechSynthesizer.speak() }
).frame(width: 100)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ReaderTranslatorMac/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.9.3</string>
<string>1.9.4</string>
<key>CFBundleVersion</key>
<string>1800</string>
<key>LSApplicationCategoryType</key>
Expand Down
4 changes: 2 additions & 2 deletions ReaderTranslatorPlayer/Store/AudioStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ final class AudioStore: NSObject, ObservableObject {
}

@Published(wrappedValue: nil, key: "lastAudio") var lastAudio: URL?
@Published(key: "isVoiceEnabled") var isEnabled = true
@Published(key: "voiceVolume") var volume: Float = 1
@Published(key: "isSpeakWords") var isSpeakWords = true
@Published(key: "wordsVolume") var wordsVolume: Float = 1
@Published(key: "audioRate") var rate: Float = 1 {
didSet {
setupNowPlaying()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct GTranslatorView: View {
.navigationBarItems(trailing:
Button(action: {
LongmanStore.shared.addAudio(url: self.sentence.url)
LongmanStore.shared.next()
LongmanStore.shared.play()
}, label: { self.soundIco })
)
}
Expand Down
10 changes: 7 additions & 3 deletions ReaderTranslatorPlayer/Views/ViewModes/LongmanView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
// Copyright © 2019 Viktor Kushnerov. All rights reserved.
//

import Combine
import SwiftUI

private var cancellableLongmanSpeak: AnyCancellable?

struct LongmanView: View {
var phrase: String

Expand All @@ -18,9 +21,10 @@ struct LongmanView: View {
LongmanRepresenter(phrase: phrase)
.onAppear {
self.store.hideNavBar = false
if self.longmanStore.word != self.phrase {
RunLoop.main.perform {
self.longmanStore.word = self.phrase
cancellableLongmanSpeak = self.longmanStore.fetchInfo(text: self.phrase)
.sink { isSoundExist in
if isSoundExist {
LongmanStore.shared.play()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
// Copyright © 2019 Viktor Kushnerov. All rights reserved.
//

import Combine
import SwiftUI

private var cancellableLongmanSpeak: AnyCancellable?

struct SentencesView: View {
let bookmark: String

Expand All @@ -27,17 +30,18 @@ struct SentencesView: View {
showGTranlator: self.$showGTranlator,
showLongmanView: self.$showLongmanView)
}
}
}.frame(maxWidth: .infinity, maxHeight: .infinity)
}
navigationLinksView
}
.onAppear {
self.store.hideNavBar = false
if self.longmanStore.word != self.bookmark {
RunLoop.main.perform {
self.longmanStore.word = self.bookmark
cancellableLongmanSpeak = LongmanStore.shared.fetchInfo(text: self.bookmark)
.sink { isSoundExist in
if isSoundExist {
LongmanStore.shared.play()
}
}
}
self.showGTranlator = nil
self.showLongmanView = false
}
Expand All @@ -53,7 +57,7 @@ struct SentencesView: View {
}
if showLongmanView {
NavigationLink(
destination: LongmanView(phrase: longmanStore.word),
destination: LongmanView(phrase: self.bookmark),
isActive: .constant(true),
label: { EmptyView() })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct SentencesView_Row: View {
HStack {
Button(action: {
LongmanStore.shared.addAudio(url: self.sentence.url)
LongmanStore.shared.next()
LongmanStore.shared.play()
}, label: { self.soundIco })
Button(
action: { self.showGTranlator = self.sentence },
Expand Down

0 comments on commit edb9e5b

Please sign in to comment.