Skip to content

Commit 41de201

Browse files
committed
Settings view #80: Move voice settings from StatusBar to here.
1 parent 841d262 commit 41de201

File tree

13 files changed

+208
-187
lines changed

13 files changed

+208
-187
lines changed

ReaderTranslator.xcodeproj/project.pbxproj

Lines changed: 45 additions & 39 deletions
Large diffs are not rendered by default.

ReaderTranslator/Components/SettingsView.swift renamed to ReaderTranslator/Components/SettingsView/SettingsView.swift

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,8 @@ struct SettingsView: View {
1515
Group {
1616
if viewStore.showSettings {
1717
VStack {
18-
ForEach(AvailableView.resiableViews, id: \.self) { view in
19-
HStack {
20-
TextField(
21-
"",
22-
value: view.order,
23-
formatter: NumberFormatter.localInt
24-
).frame(width: 20)
25-
Text(view.text).frame(width: 150, alignment: .leading)
26-
TextField(
27-
"",
28-
value: view.width,
29-
formatter: NumberFormatter.localCGFloat
30-
).frame(width: 50)
31-
}
32-
}
18+
SettingsView_Views()
19+
SettingsView_Voice().padding([.top, .bottom], 5)
3320

3421
Button(
3522
action: { self.viewStore.showSettings = false },
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// SettingsView_Views.swift
3+
// ReaderTranslator
4+
//
5+
// Created by Viktor Kushnerov on 11/3/20.
6+
// Copyright © 2020 Viktor Kushnerov. All rights reserved.
7+
//
8+
9+
import SwiftUI
10+
11+
struct SettingsView_Views: View {
12+
var body: some View {
13+
ForEach(AvailableView.resiableViews, id: \.self) { view in
14+
HStack {
15+
TextField(
16+
"",
17+
value: view.order,
18+
formatter: NumberFormatter.localInt
19+
).frame(width: 20)
20+
Text(view.text).frame(width: 150, alignment: .leading)
21+
TextField(
22+
"",
23+
value: view.width,
24+
formatter: NumberFormatter.localCGFloat
25+
).frame(width: 50)
26+
}
27+
}
28+
}
29+
}
30+
31+
struct SettingsView_Views_Previews: PreviewProvider {
32+
static var previews: some View {
33+
SettingsView_Views()
34+
}
35+
}

ReaderTranslator/Views/StatusBarView/StatusBarView_Voice/StatusBarView_Voice.swift renamed to ReaderTranslator/Components/SettingsView/SettingsView_Voice.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88

99
import SwiftUI
1010

11-
struct StatusBarView_Voice: View {
11+
struct SettingsView_Voice: View {
1212
var body: some View {
13-
Group {
14-
Divider().fixedSize()
15-
Text("Voice: ")
16-
StatusBarView_Voice_Select()
17-
StatusBarView_Voice_Favorite()
18-
StatusBarView_Voice_Toggle()
19-
StatusBarView_Voice_Volume()
13+
VStack {
14+
HStack {
15+
SettingsView_Voice_Select()
16+
SettingsView_Voice_Favorite()
17+
}
18+
SettingsView_Voice_Toggle()
19+
SettingsView_Voice_Rate()
2020
}
2121
}
2222
}
2323

2424
struct StatusBarView_Voice_Previews: PreviewProvider {
2525
static var previews: some View {
26-
StatusBarView_Voice()
26+
SettingsView_Voice()
2727
}
2828
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// StatusBarView_Voice_Favorite.swift
3+
// ReaderTranslator
4+
//
5+
// Created by Viktor Kushnerov on 9/28/19.
6+
// Copyright © 2019 Viktor Kushnerov. All rights reserved.
7+
//
8+
9+
import SwiftUI
10+
11+
struct SettingsView_Voice_Favorite: View {
12+
@ObservedObject var store = AudioStore.shared
13+
14+
var body: some View {
15+
Group {
16+
favotiteButton()
17+
MenuButton(label: Image.sfSymbol("list.dash")) {
18+
ForEach(store.favoriteVoiceNames, id: \.id) { item in
19+
Button(
20+
action: {
21+
self.store.language = item.language
22+
self.store.voiceName = item.voice
23+
SpeechSynthesizer.speak(isVoiceEnabled: true)
24+
},
25+
label: {
26+
Text("\(item.language) \(item.voice)")
27+
}
28+
)
29+
}
30+
}
31+
.menuButtonStyle(BorderlessButtonMenuButtonStyle())
32+
.fixedSize()
33+
}
34+
}
35+
36+
private func favotiteButton() -> some View {
37+
let action = FavoriteVoiceName.isFavorite ?
38+
{ FavoriteVoiceName.removeCurrentVoice() } :
39+
{ FavoriteVoiceName.addCurrentVoice() }
40+
let label = FavoriteVoiceName.isFavorite ?
41+
{ Image.sfSymbol("star.fill") } :
42+
{ Image.sfSymbol("star") }
43+
44+
return Button(action: action, label: label)
45+
}
46+
}
47+
48+
struct SettingsView_Voice_Favorite_Previews: PreviewProvider {
49+
static var previews: some View {
50+
SettingsView_Voice_Favorite()
51+
}
52+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
import SwiftUI
1010

11-
struct StatusBarView_Voice_Volume: View {
11+
struct SettingsView_Voice_Rate: View {
1212
@ObservedObject var store = AudioStore.shared
1313

1414
var body: some View {
15-
Group {
15+
HStack {
1616
Text("Rate:")
1717
#if os(macOS)
1818
TextField(
@@ -35,8 +35,8 @@ struct StatusBarView_Voice_Volume: View {
3535
}
3636
}
3737

38-
struct StatusBarView_Voice_Volume_Previews: PreviewProvider {
38+
struct SettingsView_Voice_Volume_Previews: PreviewProvider {
3939
static var previews: some View {
40-
StatusBarView_Voice_Volume()
40+
SettingsView_Voice_Rate()
4141
}
4242
}
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88

99
import SwiftUI
1010

11-
struct StatusBarView_Voice_Select: View {
11+
struct SettingsView_Voice_Select: View {
1212
@ObservedObject var store = AudioStore.shared
1313

1414
var body: some View {
15-
Group {
15+
HStack {
16+
Text("Language: ")
1617
MenuButton(store.language) {
1718
ForEach(SpeechSynthesizer.languages, id: \.self) { language in
1819
Button(
@@ -27,6 +28,7 @@ struct StatusBarView_Voice_Select: View {
2728
.menuButtonStyle(BorderlessButtonMenuButtonStyle())
2829
.fixedSize()
2930

31+
Text("Voice: ")
3032
MenuButton(store.voiceName) {
3133
ForEach(SpeechSynthesizer.getVoices(language: store.language), id: \.id) { voice in
3234
Button(
@@ -46,8 +48,8 @@ struct StatusBarView_Voice_Select: View {
4648
}
4749
}
4850

49-
struct StatusBarView_Voice_Select_Previews: PreviewProvider {
51+
struct SettingsView_Voice_Select_Previews: PreviewProvider {
5052
static var previews: some View {
51-
StatusBarView_Voice_Select()
53+
SettingsView_Voice_Select()
5254
}
5355
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// StatusBarView_Voice_Toggle.swift
3+
// ReaderTranslator
4+
//
5+
// Created by Viktor Kushnerov on 10/3/19.
6+
// Copyright © 2019 Viktor Kushnerov. All rights reserved.
7+
//
8+
9+
import SwiftUI
10+
11+
struct SettingsView_Voice_Toggle: View {
12+
@ObservedObject var audio = AudioStore.shared
13+
14+
var body: some View {
15+
VStack {
16+
HStack {
17+
Text("Speak sentences")
18+
Image.sfSymbol(audio.isSpeakSentences ? "speaker.3.fill" : "speaker")
19+
.onTapGesture { self.audio.isSpeakSentences.toggle() }
20+
Slider(
21+
value: $audio.sentencesVolume,
22+
in: 0.1 ... 1.0,
23+
onEditingChanged: { _ in SpeechSynthesizer.speak() }
24+
).frame(width: 100)
25+
}
26+
HStack {
27+
Text("Speak words")
28+
Image.sfSymbol(audio.isSpeakWords ? "speaker.3.fill" : "speaker")
29+
.onTapGesture { self.audio.isSpeakWords.toggle() }
30+
Slider(
31+
value: $audio.wordsVolume,
32+
in: 0.1 ... 1.0,
33+
onEditingChanged: { _ in SpeechSynthesizer.speak() }
34+
).frame(width: 100)
35+
}
36+
}
37+
}
38+
}

ReaderTranslator/Views/StatusBarView/StatusBarView.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ struct StatusBarView: View {
1818
HStack {
1919
StatusBarView_Zoom()
2020

21-
StatusBarView_Voice().padding([.top, .bottom], 5)
2221
StatusBarView_Safari()
2322
StatusBarView_Bookmarks()
2423
StatusBarView_ViewsEnabler()
@@ -27,7 +26,7 @@ struct StatusBarView: View {
2726
playbackRateView
2827
StatusBarView_SettingsView()
2928
// StatusBarView_Sync()
30-
}.padding(.trailing, 20)
29+
}.padding(5)
3130
}
3231

3332
private var speechHandler: some View {

ReaderTranslator/Views/StatusBarView/StatusBarView_Voice/StatusBarView_Voice_Favorite.swift

Lines changed: 0 additions & 61 deletions
This file was deleted.

ReaderTranslator/Views/StatusBarView/StatusBarView_Voice/StatusBarView_Voice_Toggle.swift

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "list.dash.pdf",
6+
"language-direction" : "left-to-right"
7+
}
8+
],
9+
"info" : {
10+
"version" : 1,
11+
"author" : "xcode"
12+
},
13+
"properties" : {
14+
"preserves-vector-representation" : true
15+
}
16+
}
Binary file not shown.

0 commit comments

Comments
 (0)