Merge pull request #1303 from omnivore-app/chore/mac-app-resurrection

Mac App Updates
This commit is contained in:
Jackson Harper 2022-10-13 11:24:55 +08:00 committed by GitHub
commit d345aee14b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 1860 additions and 1903 deletions

View file

@ -153,15 +153,6 @@
"version" : "2.1.0"
}
},
{
"identity" : "pspdfkit-sp",
"kind" : "remoteSourceControl",
"location" : "https://github.com/PSPDFKit/PSPDFKit-SP",
"state" : {
"branch" : "master",
"revision" : "e9757beadad1b30de84073d3c33c1cd0f7a94b80"
}
},
{
"identity" : "sovran-swift",
"kind" : "remoteSourceControl",

View file

@ -56,7 +56,7 @@ let package = Package(
var appPackageDependencies: [Target.Dependency] {
var deps: [Target.Dependency] = ["Views", "Services", "Models", "Utils"]
// #if canImport(UIKit)
deps.append(.product(name: "PSPDFKit", package: "PSPDFKit-SP"))
// deps.append(.product(name: "PSPDFKit", package: "PSPDFKit-SP"))
// #endif
return deps
}
@ -70,7 +70,7 @@ var dependencies: [Package.Dependency] {
.package(url: "https://github.com/google/GoogleSignIn-iOS", from: "6.2.2")
]
// #if canImport(UIKit)
deps.append(.package(url: "https://github.com/PSPDFKit/PSPDFKit-SP", branch: "master"))
// deps.append(.package(url: "https://github.com/PSPDFKit/PSPDFKit-SP", branch: "master"))
// #endif
return deps
}

View file

@ -18,7 +18,11 @@ public final class Services {
let networker = Networker(appEnvironment: appEnvironment)
self.authenticator = Authenticator(networker: networker)
self.dataService = DataService(appEnvironment: appEnvironment, networker: networker)
self.audioController = AudioController(dataService: dataService)
#if os(iOS)
self.audioController = AudioController(dataService: dataService)
#else
self.audioController = AudioController()
#endif
}
}

View file

@ -1,498 +1,494 @@
//
// MiniPlayer.swift
//
//
// Created by Jackson Harper on 8/15/22.
//
#if os(iOS)
import Foundation
import Models
import Services
import SwiftUI
import Views
import Foundation
import Models
import Services
import SwiftUI
import Views
public struct MiniPlayer: View {
@EnvironmentObject var audioController: AudioController
@Environment(\.colorScheme) private var colorScheme: ColorScheme
private let presentingView: AnyView
public struct MiniPlayer: View {
@EnvironmentObject var audioController: AudioController
@Environment(\.colorScheme) private var colorScheme: ColorScheme
private let presentingView: AnyView
@State var expanded = false
@State var offset: CGFloat = 0
@State var showVoiceSheet = false
@State var showLanguageSheet = false
@State var expanded = false
@State var offset: CGFloat = 0
@State var showVoiceSheet = false
@State var showLanguageSheet = false
@State var tabIndex: Int = 0
@Namespace private var animation
@State var tabIndex: Int = 0
@Namespace private var animation
let minExpandedHeight = UIScreen.main.bounds.height / 3
let minExpandedHeight = UIScreen.main.bounds.height / 3
init<PresentingView>(
presentingView: PresentingView
) where PresentingView: View {
self.presentingView = AnyView(presentingView)
}
var isPresented: Bool {
audioController.itemAudioProperties != nil && audioController.state != .stopped
}
var playPauseButtonImage: String {
switch audioController.state {
case .playing:
return "pause.circle"
case .paused:
return "play.circle"
case .reachedEnd:
return "gobackward"
default:
return ""
init<PresentingView>(
presentingView: PresentingView
) where PresentingView: View {
self.presentingView = AnyView(presentingView)
}
}
var playPauseButtonItem: some View {
if let itemID = audioController.itemAudioProperties?.itemID, audioController.isLoadingItem(itemID: itemID) {
return AnyView(ProgressView())
} else {
return AnyView(Button(
var isPresented: Bool {
audioController.itemAudioProperties != nil && audioController.state != .stopped
}
var playPauseButtonImage: String {
switch audioController.state {
case .playing:
return "pause.circle"
case .paused:
return "play.circle"
case .reachedEnd:
return "gobackward"
default:
return ""
}
}
var playPauseButtonItem: some View {
if let itemID = audioController.itemAudioProperties?.itemID, audioController.isLoadingItem(itemID: itemID) {
return AnyView(ProgressView())
} else {
return AnyView(Button(
action: {
switch audioController.state {
case .playing:
audioController.pause()
case .paused:
audioController.unpause()
case .reachedEnd:
audioController.seek(to: 0.0)
audioController.unpause()
default:
break
}
},
label: {
Image(systemName: playPauseButtonImage)
.font(expanded ? .system(size: 56.0, weight: .thin) : .appTitleTwo)
}
))
}
}
var stopButton: some View {
Button(
action: {
switch audioController.state {
case .playing:
audioController.pause()
case .paused:
audioController.unpause()
case .reachedEnd:
audioController.seek(to: 0.0)
audioController.unpause()
default:
break
audioController.stop()
},
label: {
Image(systemName: "xmark")
.font(.appTitleTwo)
}
)
}
var closeButton: some View {
Button(
action: {
withAnimation(.interactiveSpring()) {
self.expanded = false
}
},
label: {
Image(systemName: playPauseButtonImage)
.font(expanded ? .system(size: 56.0, weight: .thin) : .appTitleTwo)
Image(systemName: "chevron.down")
.font(.appNavbarIcon)
.tint(.appGrayTextContrast)
}
))
)
// .contentShape(Rectangle())
}
}
var stopButton: some View {
Button(
action: {
audioController.stop()
},
label: {
Image(systemName: "xmark")
.font(.appTitleTwo)
}
)
}
var closeButton: some View {
Button(
action: {
withAnimation(.interactiveSpring()) {
self.expanded = false
func viewArticle() {
if let objectID = audioController.itemAudioProperties?.objectID {
NSNotification.pushReaderItem(objectID: objectID)
withAnimation(.easeIn(duration: 0.1)) {
expanded = false
}
},
label: {
Image(systemName: "chevron.down")
.font(.appNavbarIcon)
.tint(.appGrayTextContrast)
}
)
// .contentShape(Rectangle())
}
func viewArticle() {
if let objectID = audioController.itemAudioProperties?.objectID {
NSNotification.pushReaderItem(objectID: objectID)
withAnimation(.easeIn(duration: 0.1)) {
expanded = false
}
}
}
func defaultArtwork(forDimensions dim: Double) -> some View {
ZStack(alignment: .center) {
Color.appButtonBackground
.frame(width: dim, height: dim)
.cornerRadius(6)
func defaultArtwork(forDimensions dim: Double) -> some View {
ZStack(alignment: .center) {
Color.appButtonBackground
.frame(width: dim, height: dim)
.cornerRadius(6)
Image(systemName: "headphones")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: dim / 2, height: dim / 2)
Image(systemName: "headphones")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: dim / 2, height: dim / 2)
}
}
}
struct SpeechCard: View {
let id: Int
@EnvironmentObject var audioController: AudioController
struct SpeechCard: View {
let id: Int
@EnvironmentObject var audioController: AudioController
var body: some View {
Group {
if id != self.audioController.currentAudioIndex || self.audioController.isLoading {
Text(self.audioController.textItems?[id] ?? "\(id)")
.font(.textToSpeechRead.leading(.loose))
.foregroundColor(Color.appGrayTextContrast)
} else {
Group {
Text(audioController.readText)
var body: some View {
Group {
if id != self.audioController.currentAudioIndex || self.audioController.isLoading {
Text(self.audioController.textItems?[id] ?? "\(id)")
.font(.textToSpeechRead.leading(.loose))
.foregroundColor(Color.appGrayTextContrast)
+
Text(audioController.unreadText)
.font(.textToSpeechRead.leading(.loose))
.foregroundColor(Color.appGrayText)
}
}
}
.padding(16)
}
init(id: Int) {
self.id = id
}
}
var audioCards: some View {
ZStack {
let textItems = self.audioController.textItems ?? []
TabView(selection: $tabIndex) {
ForEach(0 ..< textItems.count, id: \.self) { id in
SpeechCard(id: id)
.tag(id)
}
}
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
.onChange(of: tabIndex, perform: { index in
if index != audioController.currentAudioIndex, index < (audioController.textItems?.count ?? 0) {
audioController.seek(toUtterance: index)
}
})
.onChange(of: audioController.currentAudioIndex, perform: { index in
if index >= textItems.count {
return
}
if self.audioController.state != .reachedEnd {
tabIndex = index
}
})
if audioController.state == .reachedEnd {
// If we have reached the end display a replay button with an overlay behind
Color.systemBackground.opacity(0.85)
.frame(
minWidth: 0,
maxWidth: .infinity,
minHeight: 0,
maxHeight: .infinity,
alignment: .topLeading
)
Button(
action: {
tabIndex = 0
audioController.unpause()
audioController.seek(to: 0.0)
},
label: {
HStack {
Image(systemName: "gobackward")
.font(.appCallout)
.tint(.appGrayTextContrast)
Text("Replay")
}
}
).buttonStyle(RoundedRectButtonStyle())
}
}
}
// swiftlint:disable:next function_body_length
func playerContent(_ itemAudioProperties: LinkedItemAudioProperties) -> some View {
VStack(spacing: 0) {
if expanded {
ZStack {
closeButton
.padding(.top, 24)
.padding(.leading, 16)
.frame(maxWidth: .infinity, alignment: .leading)
Capsule()
.fill(.gray)
.frame(width: 60, height: 4)
.padding(.top, 8)
.transition(.opacity)
}
} else {
HStack(alignment: .center, spacing: 8) {
let dim = 64.0
if let imageURL = itemAudioProperties.imageURL {
AsyncImage(url: imageURL) { phase in
if let image = phase.image {
image
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: dim, height: dim)
.cornerRadius(6)
} else if phase.error != nil {
defaultArtwork(forDimensions: dim)
} else {
Color.appButtonBackground
.frame(width: dim, height: dim)
.cornerRadius(6)
}
}
} else {
defaultArtwork(forDimensions: dim)
}
VStack {
Text(itemAudioProperties.title)
.font(.appCallout)
.foregroundColor(.appGrayTextContrast)
.fixedSize(horizontal: false, vertical: false)
.frame(maxWidth: .infinity, alignment: .leading)
if let byline = itemAudioProperties.byline {
Text(byline)
.font(.appCaption)
.lineSpacing(1.25)
.foregroundColor(.appGrayText)
.fixedSize(horizontal: false, vertical: false)
.frame(maxWidth: .infinity, alignment: .leading)
Group {
Text(audioController.readText)
.font(.textToSpeechRead.leading(.loose))
.foregroundColor(Color.appGrayTextContrast)
+
Text(audioController.unreadText)
.font(.textToSpeechRead.leading(.loose))
.foregroundColor(Color.appGrayText)
}
}
playPauseButtonItem
.frame(width: 28, height: 28)
stopButton
.frame(width: 28, height: 28)
}
.padding(16)
.frame(maxHeight: .infinity)
}
if expanded {
audioCards
init(id: Int) {
self.id = id
}
}
Spacer()
Group {
ScrubberView(value: $audioController.timeElapsed,
minValue: 0, maxValue: self.audioController.duration,
onEditingChanged: { scrubStarted in
if scrubStarted {
self.audioController.scrubState = .scrubStarted
} else {
self.audioController.scrubState = .scrubEnded(self.audioController.timeElapsed)
}
})
HStack {
Text(audioController.timeElapsedString ?? "0:00")
.font(.appCaptionTwo)
.foregroundColor(.appGrayText)
Spacer()
Text(audioController.durationString ?? "0:00")
.font(.appCaptionTwo)
.foregroundColor(.appGrayText)
var audioCards: some View {
ZStack {
let textItems = self.audioController.textItems ?? []
TabView(selection: $tabIndex) {
ForEach(0 ..< textItems.count, id: \.self) { id in
SpeechCard(id: id)
.tag(id)
}
}
.padding(.leading, 16)
.padding(.trailing, 16)
HStack(alignment: .center, spacing: 36) {
Menu {
playbackRateButton(rate: 1.0, title: "1.0×", selected: audioController.playbackRate == 1.0)
playbackRateButton(rate: 1.1, title: "1.1×", selected: audioController.playbackRate == 1.1)
playbackRateButton(rate: 1.2, title: "1.2×", selected: audioController.playbackRate == 1.2)
playbackRateButton(rate: 1.5, title: "1.5×", selected: audioController.playbackRate == 1.5)
playbackRateButton(rate: 1.7, title: "1.7×", selected: audioController.playbackRate == 1.7)
playbackRateButton(rate: 2.0, title: "2.0×", selected: audioController.playbackRate == 2.0)
} label: {
VStack {
Text(String(format: "%.1f×", audioController.playbackRate))
.font(.appCallout)
.lineLimit(0)
}
.contentShape(Rectangle())
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
.onChange(of: tabIndex, perform: { index in
if index != audioController.currentAudioIndex, index < (audioController.textItems?.count ?? 0) {
audioController.seek(toUtterance: index)
}
.padding(8)
})
.onChange(of: audioController.currentAudioIndex, perform: { index in
if index >= textItems.count {
return
}
if self.audioController.state != .reachedEnd {
tabIndex = index
}
})
if audioController.state == .reachedEnd {
// If we have reached the end display a replay button with an overlay behind
Color.systemBackground.opacity(0.85)
.frame(
minWidth: 0,
maxWidth: .infinity,
minHeight: 0,
maxHeight: .infinity,
alignment: .topLeading
)
Button(
action: { self.audioController.skipBackwards(seconds: 30) },
action: {
tabIndex = 0
audioController.unpause()
audioController.seek(to: 0.0)
},
label: {
Image(systemName: "gobackward.30")
.font(.appTitleTwo)
}
)
playPauseButtonItem
.frame(width: 56, height: 56)
Button(
action: { self.audioController.skipForward(seconds: 30) },
label: {
Image(systemName: "goforward.30")
.font(.appTitleTwo)
}
)
Menu {
Button("View Article", action: { viewArticle() })
Button("Change Voice", action: { showVoiceSheet = true })
} label: {
VStack {
Image(systemName: "ellipsis")
.font(.appCallout)
.frame(width: 20, height: 20)
}
.contentShape(Rectangle())
}
.padding(8)
}.padding(.bottom, 16)
}
}
.padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
.background(
Color.systemBackground
.shadow(color: expanded ? .clear : .gray.opacity(0.33), radius: 8, x: 0, y: 4)
.mask(Rectangle().padding(.top, -20))
)
.onTapGesture {
withAnimation(.easeIn(duration: 0.08)) { expanded = true }
}.sheet(isPresented: $showVoiceSheet) {
NavigationView {
TextToSpeechVoiceSelectionView(forLanguage: audioController.currentVoiceLanguage, showLanguageChanger: true)
.navigationBarTitle("Voice")
.navigationBarTitleDisplayMode(.inline)
.navigationBarItems(leading: Button(action: { self.showVoiceSheet = false }, label: {
Image(systemName: "chevron.backward")
.font(.appNavbarIcon)
.tint(.appGrayTextContrast)
}))
}
}.sheet(isPresented: $showLanguageSheet) {
NavigationView {
TextToSpeechLanguageView()
.navigationBarTitle("Language")
.navigationBarTitleDisplayMode(.inline)
.navigationBarItems(leading: Button(action: { self.showLanguageSheet = false }) {
Image(systemName: "chevron.backward")
.font(.appNavbarIcon)
.tint(.appGrayTextContrast)
})
}
}
}
func playbackRateButton(rate: Double, title: String, selected: Bool) -> some View {
Button(action: {
audioController.playbackRate = rate
}) {
HStack {
Text(title)
Spacer()
if selected {
Image(systemName: "checkmark")
}
}
.contentShape(Rectangle())
}
.buttonStyle(PlainButtonStyle())
}
public var body: some View {
ZStack(alignment: .center) {
presentingView
if let itemAudioProperties = self.audioController.itemAudioProperties, isPresented {
ZStack(alignment: .bottom) {
Color.systemBackground.edgesIgnoringSafeArea(.bottom)
.frame(height: 88, alignment: .bottom)
VStack {
Spacer(minLength: 0)
playerContent(itemAudioProperties)
.offset(y: offset)
.frame(maxHeight: expanded ? .infinity : 88)
.tint(.appGrayTextContrast)
.gesture(DragGesture().onEnded(onDragEnded(value:)).onChanged(onDragChanged(value:)))
.background(expanded ? .clear : .systemBackground)
}
}
}
}
}
var changeVoiceView: some View {
NavigationView {
VStack {
List {
ForEach(audioController.voiceList ?? [], id: \.key.self) { voice in
Button(action: {
audioController.currentVoice = voice.key
self.showVoiceSheet = false
}) {
HStack {
Text(voice.name)
Image(systemName: "gobackward")
.font(.appCallout)
.tint(.appGrayTextContrast)
Text("Replay")
}
}
).buttonStyle(RoundedRectButtonStyle())
}
}
}
Spacer()
// swiftlint:disable:next function_body_length
func playerContent(_ itemAudioProperties: LinkedItemAudioProperties) -> some View {
VStack(spacing: 0) {
if expanded {
ZStack {
closeButton
.padding(.top, 24)
.padding(.leading, 16)
.frame(maxWidth: .infinity, alignment: .leading)
if voice.selected {
Image(systemName: "checkmark")
Capsule()
.fill(.gray)
.frame(width: 60, height: 4)
.padding(.top, 8)
.transition(.opacity)
}
} else {
HStack(alignment: .center, spacing: 8) {
let dim = 64.0
if let imageURL = itemAudioProperties.imageURL {
AsyncImage(url: imageURL) { phase in
if let image = phase.image {
image
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: dim, height: dim)
.cornerRadius(6)
} else if phase.error != nil {
defaultArtwork(forDimensions: dim)
} else {
Color.appButtonBackground
.frame(width: dim, height: dim)
.cornerRadius(6)
}
}
} else {
defaultArtwork(forDimensions: dim)
}
VStack {
Text(itemAudioProperties.title)
.font(.appCallout)
.foregroundColor(.appGrayTextContrast)
.fixedSize(horizontal: false, vertical: false)
.frame(maxWidth: .infinity, alignment: .leading)
if let byline = itemAudioProperties.byline {
Text(byline)
.font(.appCaption)
.lineSpacing(1.25)
.foregroundColor(.appGrayText)
.fixedSize(horizontal: false, vertical: false)
.frame(maxWidth: .infinity, alignment: .leading)
}
}
playPauseButtonItem
.frame(width: 28, height: 28)
stopButton
.frame(width: 28, height: 28)
}
.padding(16)
.frame(maxHeight: .infinity)
}
if expanded {
audioCards
Spacer()
Group {
ScrubberView(value: $audioController.timeElapsed,
minValue: 0, maxValue: self.audioController.duration,
onEditingChanged: { scrubStarted in
if scrubStarted {
self.audioController.scrubState = .scrubStarted
} else {
self.audioController.scrubState = .scrubEnded(self.audioController.timeElapsed)
}
})
HStack {
Text(audioController.timeElapsedString ?? "0:00")
.font(.appCaptionTwo)
.foregroundColor(.appGrayText)
Spacer()
Text(audioController.durationString ?? "0:00")
.font(.appCaptionTwo)
.foregroundColor(.appGrayText)
}
}
.padding(.leading, 16)
.padding(.trailing, 16)
HStack(alignment: .center, spacing: 36) {
Menu {
playbackRateButton(rate: 1.0, title: "1.0×", selected: audioController.playbackRate == 1.0)
playbackRateButton(rate: 1.1, title: "1.1×", selected: audioController.playbackRate == 1.1)
playbackRateButton(rate: 1.2, title: "1.2×", selected: audioController.playbackRate == 1.2)
playbackRateButton(rate: 1.5, title: "1.5×", selected: audioController.playbackRate == 1.5)
playbackRateButton(rate: 1.7, title: "1.7×", selected: audioController.playbackRate == 1.7)
playbackRateButton(rate: 2.0, title: "2.0×", selected: audioController.playbackRate == 2.0)
} label: {
VStack {
Text(String(format: "%.1f×", audioController.playbackRate))
.font(.appCallout)
.lineLimit(0)
}
.contentShape(Rectangle())
}
.buttonStyle(PlainButtonStyle())
.padding(8)
Button(
action: { self.audioController.skipBackwards(seconds: 30) },
label: {
Image(systemName: "gobackward.30")
.font(.appTitleTwo)
}
)
playPauseButtonItem
.frame(width: 56, height: 56)
Button(
action: { self.audioController.skipForward(seconds: 30) },
label: {
Image(systemName: "goforward.30")
.font(.appTitleTwo)
}
)
Menu {
Button("View Article", action: { viewArticle() })
Button("Change Voice", action: { showVoiceSheet = true })
} label: {
VStack {
Image(systemName: "ellipsis")
.font(.appCallout)
.frame(width: 20, height: 20)
}
.contentShape(Rectangle())
}
.padding(8)
}.padding(.bottom, 16)
}
}
.padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
.background(
Color.systemBackground
.shadow(color: expanded ? .clear : .gray.opacity(0.33), radius: 8, x: 0, y: 4)
.mask(Rectangle().padding(.top, -20))
)
.onTapGesture {
withAnimation(.easeIn(duration: 0.08)) { expanded = true }
}.sheet(isPresented: $showVoiceSheet) {
NavigationView {
TextToSpeechVoiceSelectionView(forLanguage: audioController.currentVoiceLanguage, showLanguageChanger: true)
.navigationBarTitle("Voice")
.navigationBarTitleDisplayMode(.inline)
.navigationBarItems(leading: Button(action: { self.showVoiceSheet = false }, label: {
Image(systemName: "chevron.backward")
.font(.appNavbarIcon)
.tint(.appGrayTextContrast)
}))
}
}.sheet(isPresented: $showLanguageSheet) {
NavigationView {
TextToSpeechLanguageView()
.navigationBarTitle("Language")
.navigationBarTitleDisplayMode(.inline)
.navigationBarItems(leading: Button(action: { self.showLanguageSheet = false }) {
Image(systemName: "chevron.backward")
.font(.appNavbarIcon)
.tint(.appGrayTextContrast)
})
}
}
}
func playbackRateButton(rate: Double, title: String, selected: Bool) -> some View {
Button(action: {
audioController.playbackRate = rate
}) {
HStack {
Text(title)
Spacer()
if selected {
Image(systemName: "checkmark")
}
}
.padding(.top, 32)
.listStyle(.plain)
Spacer()
.contentShape(Rectangle())
}
.navigationBarTitle("Voice")
.navigationBarTitleDisplayMode(.inline)
.navigationBarItems(leading: Button(action: { self.showVoiceSheet = false }) {
Image(systemName: "chevron.backward")
.font(.appNavbarIcon)
.tint(.appGrayTextContrast)
})
.buttonStyle(PlainButtonStyle())
}
}
var scrubbing: Bool {
switch audioController.scrubState {
case .scrubStarted:
return true
default:
return false
}
}
public var body: some View {
ZStack(alignment: .center) {
presentingView
if let itemAudioProperties = self.audioController.itemAudioProperties, isPresented {
ZStack(alignment: .bottom) {
Color.systemBackground.edgesIgnoringSafeArea(.bottom)
.frame(height: 88, alignment: .bottom)
func onDragChanged(value: DragGesture.Value) {
if value.translation.height > 0, expanded, !scrubbing {
offset = value.translation.height
}
}
func onDragEnded(value: DragGesture.Value) {
withAnimation(.interactiveSpring()) {
if value.translation.height > minExpandedHeight, !scrubbing {
expanded = false
VStack {
Spacer(minLength: 0)
playerContent(itemAudioProperties)
.offset(y: offset)
.frame(maxHeight: expanded ? .infinity : 88)
.tint(.appGrayTextContrast)
.gesture(DragGesture().onEnded(onDragEnded(value:)).onChanged(onDragChanged(value:)))
.background(expanded ? .clear : .systemBackground)
}
}
}
}
}
var changeVoiceView: some View {
NavigationView {
VStack {
List {
ForEach(audioController.voiceList ?? [], id: \.key.self) { voice in
Button(action: {
audioController.currentVoice = voice.key
self.showVoiceSheet = false
}) {
HStack {
Text(voice.name)
Spacer()
if voice.selected {
Image(systemName: "checkmark")
}
}
.contentShape(Rectangle())
}
.buttonStyle(PlainButtonStyle())
}
}
.padding(.top, 32)
.listStyle(.plain)
Spacer()
}
.navigationBarTitle("Voice")
.navigationBarTitleDisplayMode(.inline)
.navigationBarItems(leading: Button(action: { self.showVoiceSheet = false }) {
Image(systemName: "chevron.backward")
.font(.appNavbarIcon)
.tint(.appGrayTextContrast)
})
}
}
var scrubbing: Bool {
switch audioController.scrubState {
case .scrubStarted:
return true
default:
return false
}
}
func onDragChanged(value: DragGesture.Value) {
if value.translation.height > 0, expanded, !scrubbing {
offset = value.translation.height
}
}
func onDragEnded(value: DragGesture.Value) {
withAnimation(.interactiveSpring()) {
if value.translation.height > minExpandedHeight, !scrubbing {
expanded = false
}
offset = 0
}
offset = 0
}
}
}
public extension View {
func miniPlayer() -> some View {
MiniPlayer(presentingView: self)
public extension View {
func miniPlayer() -> some View {
MiniPlayer(presentingView: self)
}
}
}
#endif

View file

@ -1,73 +1,70 @@
//
// ScrubberView.swift
//
//
// Created by Jackson Harper on 9/27/22.
//
#if os(iOS)
import Foundation
import SwiftUI
import Foundation
import SwiftUI
struct ScrubberView: UIViewRepresentable {
typealias UIViewType = UISlider
struct ScrubberView: UIViewRepresentable {
typealias UIViewType = UISlider
@Binding var value: Double
var minValue: Double
var maxValue: Double
var onEditingChanged: (Bool) -> Void
init(value: Binding<Double>, minValue: Double, maxValue: Double, onEditingChanged: @escaping (Bool) -> Void) {
self._value = value
self.minValue = minValue
self.maxValue = maxValue
self.onEditingChanged = onEditingChanged
}
func makeUIView(context: Context) -> UISlider {
let slider = UISlider(frame: .zero)
slider.maximumValue = Float(minValue)
slider.maximumValue = Float(maxValue)
let tintColor = UIColor(Color.appCtaYellow)
let image = UIImage(systemName: "circle.fill",
withConfiguration: UIImage.SymbolConfiguration(scale: .small))?
.withTintColor(tintColor)
.withRenderingMode(.alwaysOriginal)
slider.setThumbImage(image, for: .selected)
slider.setThumbImage(image, for: .normal)
slider.minimumTrackTintColor = tintColor
slider.addTarget(context.coordinator,
action: #selector(Coordinator.valueChanged(_:)),
for: .valueChanged)
return slider
}
func updateUIView(_ uiView: UISlider, context _: Context) {
uiView.value = Float(value)
}
func makeCoordinator() -> Coordinator {
let coordinator = Coordinator(value: $value, onEditingChanged: onEditingChanged)
return coordinator
}
class Coordinator: NSObject {
var value: Binding<Double>
@Binding var value: Double
var minValue: Double
var maxValue: Double
var onEditingChanged: (Bool) -> Void
init(value: Binding<Double>, onEditingChanged: @escaping (Bool) -> Void) {
self.value = value
init(value: Binding<Double>, minValue: Double, maxValue: Double, onEditingChanged: @escaping (Bool) -> Void) {
self._value = value
self.minValue = minValue
self.maxValue = maxValue
self.onEditingChanged = onEditingChanged
super.init()
}
@objc func valueChanged(_ sender: UISlider) {
value.wrappedValue = Double(sender.value)
onEditingChanged(sender.isTracking)
func makeUIView(context: Context) -> UISlider {
let slider = UISlider(frame: .zero)
slider.maximumValue = Float(minValue)
slider.maximumValue = Float(maxValue)
let tintColor = UIColor(Color.appCtaYellow)
let image = UIImage(systemName: "circle.fill",
withConfiguration: UIImage.SymbolConfiguration(scale: .small))?
.withTintColor(tintColor)
.withRenderingMode(.alwaysOriginal)
slider.setThumbImage(image, for: .selected)
slider.setThumbImage(image, for: .normal)
slider.minimumTrackTintColor = tintColor
slider.addTarget(context.coordinator,
action: #selector(Coordinator.valueChanged(_:)),
for: .valueChanged)
return slider
}
func updateUIView(_ uiView: UISlider, context _: Context) {
uiView.value = Float(value)
}
func makeCoordinator() -> Coordinator {
let coordinator = Coordinator(value: $value, onEditingChanged: onEditingChanged)
return coordinator
}
class Coordinator: NSObject {
var value: Binding<Double>
var onEditingChanged: (Bool) -> Void
init(value: Binding<Double>, onEditingChanged: @escaping (Bool) -> Void) {
self.value = value
self.onEditingChanged = onEditingChanged
super.init()
}
@objc func valueChanged(_ sender: UISlider) {
value.wrappedValue = Double(sender.value)
onEditingChanged(sender.isTracking)
}
}
}
}
#endif

View file

@ -3,6 +3,38 @@ import Services
import SwiftUI
import Views
struct MacFeedCardNavigationLink: View {
@EnvironmentObject var dataService: DataService
@EnvironmentObject var audioController: AudioController
let item: LinkedItem
@ObservedObject var viewModel: HomeFeedViewModel
var body: some View {
ZStack {
NavigationLink(
destination: LinkItemDetailView(
linkedItemObjectID: item.objectID,
isPDF: item.isPDF
),
tag: item.objectID,
selection: $viewModel.selectedLinkItem
) {
EmptyView()
}
.opacity(0)
.buttonStyle(PlainButtonStyle())
.onAppear {
Task { await viewModel.itemAppeared(item: item, dataService: dataService, audioController: audioController) }
}
FeedCard(item: item) {
viewModel.selectedLinkItem = item.objectID
}
}
}
}
struct FeedCardNavigationLink: View {
@EnvironmentObject var dataService: DataService
@EnvironmentObject var audioController: AudioController

View file

@ -8,13 +8,20 @@ import Views
#if os(macOS)
struct HomeFeedView: View {
@EnvironmentObject var dataService: DataService
@EnvironmentObject var audioController: AudioController
@State private var itemToRemove: LinkedItem?
@State private var confirmationShown = false
@ObservedObject var viewModel: HomeFeedViewModel
func loadItems(isRefresh: Bool) {
Task { await viewModel.loadItems(dataService: dataService, isRefresh: isRefresh) }
Task {
await viewModel.loadItems(
dataService: dataService,
audioController: audioController,
isRefresh: isRefresh
)
}
}
var body: some View {
@ -31,7 +38,7 @@ import Views
List {
Section {
ForEach(viewModel.items) { item in
FeedCardNavigationLink(
MacFeedCardNavigationLink(
item: item,
viewModel: viewModel
)

View file

@ -28,6 +28,7 @@ import Views
@Published var showLoadingBar = false
@Published var appliedSort = LinkedItemSort.newest.rawValue
@Published var selectedLinkItem: NSManagedObjectID? // used by mac app only
@Published var selectedItem: LinkedItem?
@Published var linkIsActive = false
@ -43,20 +44,26 @@ import Views
// Pop the current selected item if needed
if selectedItem != nil, selectedItem?.objectID != objectID {
// Temporarily disable animation to avoid excessive animations
UIView.setAnimationsEnabled(false)
#if os(iOS)
UIView.setAnimationsEnabled(false)
#endif
linkIsActive = false
selectedItem = nil
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(100)) {
self.selectedLinkItem = objectID
self.selectedItem = dataService.viewContext.object(with: objectID) as? LinkedItem
self.linkIsActive = true
}
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(200)) {
UIView.setAnimationsEnabled(true)
#if os(iOS)
UIView.setAnimationsEnabled(true)
#endif
}
} else {
selectedLinkItem = objectID
selectedItem = dataService.viewContext.object(with: objectID) as? LinkedItem
linkIsActive = true
}

View file

@ -3,13 +3,15 @@ import SwiftUI
struct HomeView: View {
@StateObject private var viewModel = HomeFeedViewModel()
var navView: some View {
NavigationView {
HomeFeedContainerView(viewModel: viewModel)
#if os(iOS)
var navView: some View {
NavigationView {
HomeFeedContainerView(viewModel: viewModel)
}
.navigationViewStyle(.stack)
.accentColor(.appGrayTextContrast)
}
.navigationViewStyle(.stack)
.accentColor(.appGrayTextContrast)
}
#endif
var body: some View {
#if os(iOS)

View file

@ -1,153 +1,155 @@
import Introspect
import Models
import Services
import SwiftUI
import UIKit
import Views
#if os(iOS)
import Introspect
import Models
import Services
import SwiftUI
import UIKit
import Views
struct LibrarySearchView: View {
@State private var searchBar: UISearchBar?
@State private var recents: [String] = []
@StateObject var viewModel = LibrarySearchViewModel()
struct LibrarySearchView: View {
@State private var searchBar: UISearchBar?
@State private var recents: [String] = []
@StateObject var viewModel = LibrarySearchViewModel()
@EnvironmentObject var dataService: DataService
@Environment(\.isSearching) var isSearching
@Environment(\.dismiss) private var dismiss
@EnvironmentObject var dataService: DataService
@Environment(\.isSearching) var isSearching
@Environment(\.dismiss) private var dismiss
let homeFeedViewModel: HomeFeedViewModel
let homeFeedViewModel: HomeFeedViewModel
init(homeFeedViewModel: HomeFeedViewModel) {
self.homeFeedViewModel = homeFeedViewModel
}
func performTypeahead(_ searchTerm: String) {
Task {
await viewModel.search(dataService: self.dataService, searchTerm: searchTerm)
init(homeFeedViewModel: HomeFeedViewModel) {
self.homeFeedViewModel = homeFeedViewModel
}
}
func setSearchTerm(_ searchTerm: String) {
viewModel.searchTerm = searchTerm
searchBar?.becomeFirstResponder()
performTypeahead(searchTerm)
}
func performTypeahead(_ searchTerm: String) {
Task {
await viewModel.search(dataService: self.dataService, searchTerm: searchTerm)
}
}
func performSearch(_ searchTerm: String) {
let term = searchTerm.trimmingCharacters(in: Foundation.CharacterSet.whitespacesAndNewlines)
viewModel.saveRecentSearch(dataService: dataService, searchTerm: term)
recents = viewModel.recentSearches(dataService: dataService)
homeFeedViewModel.searchTerm = term
func setSearchTerm(_ searchTerm: String) {
viewModel.searchTerm = searchTerm
searchBar?.becomeFirstResponder()
performTypeahead(searchTerm)
}
dismiss()
}
func performSearch(_ searchTerm: String) {
let term = searchTerm.trimmingCharacters(in: Foundation.CharacterSet.whitespacesAndNewlines)
viewModel.saveRecentSearch(dataService: dataService, searchTerm: term)
recents = viewModel.recentSearches(dataService: dataService)
homeFeedViewModel.searchTerm = term
func recentSearchRow(_ term: String) -> some View {
HStack {
dismiss()
}
func recentSearchRow(_ term: String) -> some View {
HStack {
Image(systemName: "clock.arrow.circlepath")
Text(term).foregroundColor(.appGrayText)
}.onTapGesture {
performSearch(term)
HStack {
Image(systemName: "clock.arrow.circlepath")
Text(term).foregroundColor(.appGrayText)
}.onTapGesture {
performSearch(term)
}
Spacer()
Image(systemName: "arrow.up.backward")
.onTapGesture {
setSearchTerm(viewModel.searchTerm + (viewModel.searchTerm.count > 0 ? " " : "") + term)
}
.searchCompletion(term)
}.swipeActions(edge: .trailing, allowsFullSwipe: true) {
Button {
withAnimation(.linear(duration: 0.4)) {
viewModel.removeRecentSearch(dataService: dataService, searchTerm: term)
self.recents = viewModel.recentSearches(dataService: dataService)
}
} label: {
Label("Remove", systemImage: "trash")
}.tint(.red)
}
Spacer()
Image(systemName: "arrow.up.backward")
.onTapGesture {
setSearchTerm(viewModel.searchTerm + (viewModel.searchTerm.count > 0 ? " " : "") + term)
}
.searchCompletion(term)
}.swipeActions(edge: .trailing, allowsFullSwipe: true) {
Button {
withAnimation(.linear(duration: 0.4)) {
viewModel.removeRecentSearch(dataService: dataService, searchTerm: term)
self.recents = viewModel.recentSearches(dataService: dataService)
}
} label: {
Label("Remove", systemImage: "trash")
}.tint(.red)
}
}
var body: some View {
NavigationView {
innerBody
}.introspectViewController { controller in
searchBar = Introspect.findChild(ofType: UISearchBar.self, in: controller.view)
}
}
var innerBody: some View {
ZStack {
if let linkRequest = viewModel.linkRequest {
NavigationLink(
destination: WebReaderLoadingContainer(requestID: linkRequest.serverID),
tag: linkRequest,
selection: $viewModel.linkRequest
) {
EmptyView()
}
var body: some View {
NavigationView {
innerBody
}.introspectViewController { controller in
searchBar = Introspect.findChild(ofType: UISearchBar.self, in: controller.view)
}
listBody
.navigationTitle("Search")
.navigationBarItems(trailing: Button(action: { dismiss() }, label: { Text("Close") }))
.navigationBarTitleDisplayMode(NavigationBarItem.TitleDisplayMode.inline)
.searchable(text: $viewModel.searchTerm, placement: .navigationBarDrawer(displayMode: .always)) {
ForEach(viewModel.items) { item in
HStack {
Text(item.title)
Spacer()
Image(systemName: "chevron.right")
}.onTapGesture {
viewModel.linkRequest = LinkRequest(id: UUID(), serverID: item.id)
}
}
var innerBody: some View {
ZStack {
if let linkRequest = viewModel.linkRequest {
NavigationLink(
destination: WebReaderLoadingContainer(requestID: linkRequest.serverID),
tag: linkRequest,
selection: $viewModel.linkRequest
) {
EmptyView()
}
}
.onAppear {
self.recents = viewModel.recentSearches(dataService: dataService)
}
.onSubmit(of: .search) {
performSearch(viewModel.searchTerm)
}
.onChange(of: viewModel.searchTerm) { term in
performTypeahead(term)
}
}
}
var listBody: some View {
VStack {
List {
if viewModel.searchTerm.count == 0 {
if recents.count > 0 {
Section("Recent Searches") {
ForEach(recents, id: \.self) { term in
recentSearchRow(term)
listBody
.navigationTitle("Search")
.navigationBarItems(trailing: Button(action: { dismiss() }, label: { Text("Close") }))
.navigationBarTitleDisplayMode(NavigationBarItem.TitleDisplayMode.inline)
.searchable(text: $viewModel.searchTerm, placement: .navigationBarDrawer(displayMode: .always)) {
ForEach(viewModel.items) { item in
HStack {
Text(item.title)
Spacer()
Image(systemName: "chevron.right")
}.onTapGesture {
viewModel.linkRequest = LinkRequest(id: UUID(), serverID: item.id)
}
}
}
Section("Narrow with advanced search") {
(Text("**in:** ") + Text("filter to inbox, archive, or all"))
.foregroundColor(.appGrayText)
.onTapGesture { setSearchTerm("is:") }
(Text("**title:** ") + Text("search for a specific title"))
.foregroundColor(.appGrayText)
.onTapGesture { setSearchTerm("site:") }
(Text("**has:highlights** ") + Text("any saved read with highlights"))
.foregroundColor(.appGrayText)
.onTapGesture { setSearchTerm("has:highlights") }
Button(action: {}, label: {
Text("[More on Advanced Search](https://omnivore.app/help/search)")
.underline()
.padding(.top, 25)
})
.onAppear {
self.recents = viewModel.recentSearches(dataService: dataService)
}
}
}.listStyle(PlainListStyle())
.onSubmit(of: .search) {
performSearch(viewModel.searchTerm)
}
.onChange(of: viewModel.searchTerm) { term in
performTypeahead(term)
}
}
}
var listBody: some View {
VStack {
List {
if viewModel.searchTerm.count == 0 {
if recents.count > 0 {
Section("Recent Searches") {
ForEach(recents, id: \.self) { term in
recentSearchRow(term)
}
}
}
Section("Narrow with advanced search") {
(Text("**in:** ") + Text("filter to inbox, archive, or all"))
.foregroundColor(.appGrayText)
.onTapGesture { setSearchTerm("is:") }
(Text("**title:** ") + Text("search for a specific title"))
.foregroundColor(.appGrayText)
.onTapGesture { setSearchTerm("site:") }
(Text("**has:highlights** ") + Text("any saved read with highlights"))
.foregroundColor(.appGrayText)
.onTapGesture { setSearchTerm("has:highlights") }
Button(action: {}, label: {
Text("[More on Advanced Search](https://omnivore.app/help/search)")
.underline()
.padding(.top, 25)
})
}
}
}.listStyle(PlainListStyle())
}
}
}
}
#endif

View file

@ -1,204 +1,96 @@
import SwiftUI
#if os(iOS)
import SwiftUI
// Mostly from: https://kavsoft.dev/swiftui_3.0_marquee_text_animation with some customizations
// Mostly from: https://kavsoft.dev/swiftui_3.0_marquee_text_animation with some customizations
struct Marquee: View {
var text: String
var font: UIFont
struct Marquee: View {
var text: String
var font: UIFont
// Storing Text Size
@State var storedSize: CGSize = .zero
@State var offset: CGFloat = 0
@State var animatedText: String = ""
// Storing Text Size
@State var storedSize: CGSize = .zero
@State var offset: CGFloat = 0
@State var animatedText: String = ""
var animationSpeed: Double = 0.03
var delayTime: Double = 3.0
var animationSpeed: Double = 0.03
var delayTime: Double = 3.0
var body: some View {
// Since it scrolls horizontal using ScrollView
GeometryReader { proxy in
var body: some View {
// Since it scrolls horizontal using ScrollView
GeometryReader { proxy in
let size = proxy.size
let size = proxy.size
let condition = textSize(text: text).width < (size.width - 50)
let condition = textSize(text: text).width < (size.width - 50)
ScrollView(condition ? .init() : .horizontal, showsIndicators: false) {
HStack(alignment: .center) {
Spacer(minLength: 0)
Text(condition ? text : animatedText)
.font(Font(font))
.offset(x: condition ? 0 : offset)
.padding(.horizontal, 15)
Spacer(minLength: 0)
ScrollView(condition ? .init() : .horizontal, showsIndicators: false) {
HStack(alignment: .center) {
Spacer(minLength: 0)
Text(condition ? text : animatedText)
.font(Font(font))
.offset(x: condition ? 0 : offset)
.padding(.horizontal, 15)
Spacer(minLength: 0)
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
}
.frame(height: storedSize.height)
.overlay(content: {
HStack {
let color: Color = .systemBackground
LinearGradient(colors: [color, color.opacity(0.7), color.opacity(0.5), color.opacity(0.3)], startPoint: .leading, endPoint: .trailing)
.frame(width: 8)
Spacer()
LinearGradient(colors: [color, color.opacity(0.7), color.opacity(0.5), color.opacity(0.3)].reversed(), startPoint: .leading, endPoint: .trailing)
.frame(width: 8)
}
})
.disabled(true)
.onAppear {
startAnimation(text: text)
}
.onReceive(Timer.publish(every: (animationSpeed * storedSize.width) + delayTime,
on: .main,
in: .default).autoconnect()
) { _ in
offset = 0
withAnimation(.linear(duration: animationSpeed * storedSize.width).delay(delayTime)) {
offset = -storedSize.width
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
}
.frame(height: storedSize.height)
.overlay(content: {
HStack {
let color: Color = .systemBackground
LinearGradient(colors: [color, color.opacity(0.7), color.opacity(0.5), color.opacity(0.3)], startPoint: .leading, endPoint: .trailing)
.frame(width: 8)
Spacer()
LinearGradient(colors: [color, color.opacity(0.7), color.opacity(0.5), color.opacity(0.3)].reversed(), startPoint: .leading, endPoint: .trailing)
.frame(width: 8)
.onChange(of: text) { newValue in
animatedText = ""
offset = 0
startAnimation(text: newValue)
}
})
.disabled(true)
.onAppear {
startAnimation(text: text)
}
.onReceive(Timer.publish(every: (animationSpeed * storedSize.width) + delayTime,
on: .main,
in: .default).autoconnect()
) { _ in
offset = 0
withAnimation(.linear(duration: animationSpeed * storedSize.width).delay(delayTime)) {
func startAnimation(text: String) {
// Double the text with some spacing so that we can create a continuous loop
animatedText.append(text)
(1 ... 15).forEach { _ in
animatedText.append(" ")
}
storedSize = textSize(text: animatedText)
animatedText.append(text)
let timing: Double = (animationSpeed * storedSize.width)
withAnimation(.linear(duration: timing).delay(delayTime)) {
offset = -storedSize.width
}
}
.onChange(of: text) { newValue in
animatedText = ""
offset = 0
startAnimation(text: newValue)
func textSize(text: String) -> CGSize {
let attributes = [NSAttributedString.Key.font: font]
let size = (text as NSString).size(withAttributes: attributes)
return size
}
}
func startAnimation(text: String) {
// Double the text with some spacing so that we can create a continuous loop
animatedText.append(text)
(1 ... 15).forEach { _ in
animatedText.append(" ")
}
storedSize = textSize(text: animatedText)
animatedText.append(text)
let timing: Double = (animationSpeed * storedSize.width)
withAnimation(.linear(duration: timing).delay(delayTime)) {
offset = -storedSize.width
}
}
func textSize(text: String) -> CGSize {
let attributes = [NSAttributedString.Key.font: font]
let size = (text as NSString).size(withAttributes: attributes)
return size
}
}
// Old version:
//
// struct MarqueTextView: View {
// let font: Font
//
// @State var text: String
// @State private var intrinsicSize: CGSize = .zero
// @State private var truncatedSize: CGSize = .zero
//
// @State private var shouldAnimate: Bool = false
// @State private var animationOffset: Double = 0.0
//
// var body: some View {
// GeometryReader { geo in
// ScrollView(.horizontal, showsIndicators: false) {
// HStack(alignment: .center) {
// Spacer(minLength: 0)
// Text(text)
// .font(font)
// .lineLimit(1)
// .lineSpacing(1.25)
// .offset(x: animationOffset)
// .readSize { size in
// truncatedSize = size
// intrinsicSize = geo.size
//
// shouldAnimate = textSize().width > intrinsicSize.width
// }
// Spacer(minLength: 0)
// }
// .frame(width: max(geo.size.width, textSize().width + 10))
// }
// .frame(maxWidth: .infinity, alignment: .center)
// .disabled(true)
// .onChange(of: shouldAnimate) { _ in
//
// let baseText = text
// text.append(" ")
// let initialSize = textSize()
//
// print("starting animation, truncatedSize: ", truncatedSize, "geo width: ", geo.size)
// if shouldAnimate {
// DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(500)) {
// withAnimation(.linear(duration: 0.05 * truncatedSize.width)) {
// animationOffset = -truncatedSize.width
// }
// }
// }
// }
// .onReceive(Timer.publish(every: 0.05 * truncatedSize.width + 0.5, on: .main, in: .default).autoconnect()) { _ in
// if shouldAnimate {
// animationOffset = 0
// withAnimation(.linear(duration: 0.05 * truncatedSize.width)) {
// animationOffset = -truncatedSize.width
// }
// }
// }
// }
// }
//
// func textSize() -> CGSize {
// let attributes = [NSAttributedString.Key.font: UIFont(name: "Inter-Regular", size: 16)!]
// return (text as NSString).size(withAttributes: attributes)
// }
// }
//
//// text()
//// .lineLimit(lineLimit)
//// .offset(x: animationOffset)
//// .readSize { size in
//// truncatedSize = size
//// shouldAnimate = truncatedSize != intrinsicSize
//// print("trunvatedSize: ", truncatedSize, "intrinsicSize: ", intrinsicSize)
//// }
//// .background(
//// text()
//// .fixedSize(horizontal: false, vertical: true)
//// .hidden()
//// .readSize { size in
//// intrinsicSize = size
//// shouldAnimate = truncatedSize != intrinsicSize
//// }
//// )
//// .onChange(of: shouldAnimate, perform: { _ in
//// print("starting animation")
//// DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(500)) {
//// withAnimation(.linear(duration: 0.2 * intrinsicSize.width)) {
//// animationOffset = intrinsicSize.width
//// }
//// }
//// })
//// }
//// }
//
// extension View {
// func readSize(onChange: @escaping (CGSize) -> Void) -> some View {
// background(
// GeometryReader { geometryProxy in
// Color.clear
// .preference(key: SizePreferenceKey.self, value: geometryProxy.size)
// }
// )
// .onPreferenceChange(SizePreferenceKey.self, perform: onChange)
// }
// }
//
// struct SizePreferenceKey: PreferenceKey {
// static var defaultValue: CGSize = .zero
// static func reduce(value _: inout CGSize, nextValue _: () -> CGSize) {}
// }
#endif

View file

@ -99,11 +99,13 @@ struct ProfileView: View {
}
}
Section {
NavigationLink(destination: TextToSpeechView()) {
Text("Text to Speech")
#if os(iOS)
Section {
NavigationLink(destination: TextToSpeechView()) {
Text("Text to Speech")
}
}
}
#endif
Section {
NavigationLink(

View file

@ -1,47 +1,49 @@
import Models
import Services
import SwiftUI
import Views
#if os(iOS)
import Models
import Services
import SwiftUI
import Views
struct TextToSpeechLanguageView: View {
@EnvironmentObject var audioController: AudioController
struct TextToSpeechLanguageView: View {
@EnvironmentObject var audioController: AudioController
var body: some View {
Group {
#if os(iOS)
Form {
innerBody
}
#elseif os(macOS)
List {
innerBody
}
.listStyle(InsetListStyle())
#endif
var body: some View {
Group {
#if os(iOS)
Form {
innerBody
}
#elseif os(macOS)
List {
innerBody
}
.listStyle(InsetListStyle())
#endif
}
}
}
private var innerBody: some View {
ForEach(Voices.Languages, id: \.key.self) { language in
Button(action: {
audioController.defaultLanguage = language.key
}) {
HStack {
Text(language.name)
private var innerBody: some View {
ForEach(Voices.Languages, id: \.key.self) { language in
Button(action: {
audioController.defaultLanguage = language.key
}) {
HStack {
Text(language.name)
Spacer()
Spacer()
if audioController.defaultLanguage == language.key {
if audioController.isPlaying, audioController.isLoading {
ProgressView()
} else {
Image(systemName: "checkmark")
if audioController.defaultLanguage == language.key {
if audioController.isPlaying, audioController.isLoading {
ProgressView()
} else {
Image(systemName: "checkmark")
}
}
}
.contentShape(Rectangle())
}
.contentShape(Rectangle())
.buttonStyle(PlainButtonStyle())
}
.buttonStyle(PlainButtonStyle())
}
}
}
#endif

View file

@ -1,14 +1,14 @@
import Models
import Services
import SwiftUI
import Views
#if os(iOS)
import Models
import Services
import SwiftUI
import Views
struct TextToSpeechView: View {
@EnvironmentObject var audioController: AudioController
struct TextToSpeechView: View {
@EnvironmentObject var audioController: AudioController
var body: some View {
Group {
#if os(iOS)
var body: some View {
Group {
Form {
Section("Audio Settings") {
Toggle("Enable audio prefetch", isOn: $audioController.preloadEnabled)
@ -18,22 +18,17 @@ struct TextToSpeechView: View {
}
innerBody
}
#elseif os(macOS)
List {
innerBody
}
.listStyle(InsetListStyle())
#endif
}
}
}
private var innerBody: some View {
Section("Voices") {
ForEach(Voices.Languages, id: \.key) { language in
NavigationLink(destination: TextToSpeechVoiceSelectionView(forLanguage: language, showLanguageChanger: false)) {
Text(language.name)
private var innerBody: some View {
Section("Voices") {
ForEach(Voices.Languages, id: \.key) { language in
NavigationLink(destination: TextToSpeechVoiceSelectionView(forLanguage: language, showLanguageChanger: false)) {
Text(language.name)
}
}
}
}
}
}
#endif

View file

@ -1,21 +1,21 @@
import Models
import Services
import SwiftUI
import Views
#if os(iOS)
import Models
import Services
import SwiftUI
import Views
struct TextToSpeechVoiceSelectionView: View {
@EnvironmentObject var audioController: AudioController
let language: VoiceLanguage
let showLanguageChanger: Bool
struct TextToSpeechVoiceSelectionView: View {
@EnvironmentObject var audioController: AudioController
let language: VoiceLanguage
let showLanguageChanger: Bool
init(forLanguage: VoiceLanguage, showLanguageChanger: Bool) {
self.language = forLanguage
self.showLanguageChanger = showLanguageChanger
}
init(forLanguage: VoiceLanguage, showLanguageChanger: Bool) {
self.language = forLanguage
self.showLanguageChanger = showLanguageChanger
}
var body: some View {
Group {
#if os(iOS)
var body: some View {
Group {
Form {
if showLanguageChanger {
Section("Language") {
@ -26,22 +26,16 @@ struct TextToSpeechVoiceSelectionView: View {
}
innerBody
}
#elseif os(macOS)
List {
innerBody
}
.listStyle(InsetListStyle())
#endif
}
.navigationTitle("Choose a Voice")
}
.navigationTitle("Choose a Voice")
}
private var innerBody: some View {
ForEach(language.categories, id: \.self) { category in
Section(category.rawValue) {
ForEach(audioController.voiceList?.filter { $0.category == category } ?? [], id: \.key.self) { voice in
HStack {
// Voice samples are not working yet
private var innerBody: some View {
ForEach(language.categories, id: \.self) { category in
Section(category.rawValue) {
ForEach(audioController.voiceList?.filter { $0.category == category } ?? [], id: \.key.self) { voice in
HStack {
// Voice samples are not working yet
// Button(action: {
// audioController.playVoiceSample(voice: voice.key)
// }) {
@ -49,28 +43,29 @@ struct TextToSpeechVoiceSelectionView: View {
// }
// .buttonStyle(PlainButtonStyle())
Button(action: {
audioController.setPreferredVoice(voice.key, forLanguage: language.key)
audioController.currentVoice = voice.key
}) {
HStack {
Text(voice.name)
Spacer()
Button(action: {
audioController.setPreferredVoice(voice.key, forLanguage: language.key)
audioController.currentVoice = voice.key
}) {
HStack {
Text(voice.name)
Spacer()
if voice.selected {
if audioController.isPlaying, audioController.isLoading {
ProgressView()
} else {
Image(systemName: "checkmark")
if voice.selected {
if audioController.isPlaying, audioController.isLoading {
ProgressView()
} else {
Image(systemName: "checkmark")
}
}
}
.contentShape(Rectangle())
}
.contentShape(Rectangle())
.buttonStyle(PlainButtonStyle())
}
.buttonStyle(PlainButtonStyle())
}
}
}
}
}
}
#endif

View file

@ -48,15 +48,17 @@ struct EmailAuthView: View {
Color.appBackground.edgesIgnoringSafeArea(.all)
primaryContent
.frame(maxWidth: 300)
#if os(iOS)
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .barTrailing) {
Button(
action: { presentationMode.wrappedValue.dismiss() },
label: { Image(systemName: "xmark").foregroundColor(.appGrayTextContrast) }
)
}
#endif
.toolbar {
ToolbarItem(placement: .barTrailing) {
Button(
action: { presentationMode.wrappedValue.dismiss() },
label: { Image(systemName: "xmark").foregroundColor(.appGrayTextContrast) }
)
}
}
}
}
}

View file

@ -52,10 +52,12 @@ struct EmailLoginFormView: View {
.font(.appFootnote)
.foregroundColor(.appGrayText)
TextField("", text: $email)
#if os(iOS)
.keyboardType(.emailAddress)
.textContentType(.emailAddress)
.textInputAutocapitalization(.never)
.disableAutocorrection(true)
#endif
.disableAutocorrection(true)
.focused($focusedField, equals: .email)
.submitLabel(.next)
}
@ -67,8 +69,10 @@ struct EmailLoginFormView: View {
.foregroundColor(.appGrayText)
SecureField("", text: $password)
.textContentType(.password)
#if os(iOS)
.textInputAutocapitalization(.never)
.disableAutocorrection(true)
#endif
.disableAutocorrection(true)
.focused($focusedField, equals: .password)
.submitLabel(.done)
}

View file

@ -96,10 +96,12 @@ struct EmailSignupFormView: View {
.foregroundColor(.appGrayText)
TextField("", text: $email)
.focused($focusedField, equals: .email)
#if os(iOS)
.textContentType(.emailAddress)
.keyboardType(.emailAddress)
.textInputAutocapitalization(.never)
.disableAutocorrection(true)
#endif
.disableAutocorrection(true)
.submitLabel(.next)
}
.padding(.bottom, 8)
@ -111,9 +113,11 @@ struct EmailSignupFormView: View {
.foregroundColor(.appGrayText)
SecureField("", text: $password)
.focused($focusedField, equals: .password)
#if os(iOS)
.textContentType(.newPassword)
.textInputAutocapitalization(.never)
.disableAutocorrection(true)
#endif
.disableAutocorrection(true)
.submitLabel(.next)
}
.padding(.bottom, 8)
@ -125,9 +129,11 @@ struct EmailSignupFormView: View {
.foregroundColor(.appGrayText)
TextField("", text: $name)
.focused($focusedField, equals: .fullName)
#if os(iOS)
.textContentType(.name)
.keyboardType(.alphabet)
.disableAutocorrection(true)
#endif
.disableAutocorrection(true)
.submitLabel(.next)
}
.padding(.bottom, 8)
@ -141,10 +147,12 @@ struct EmailSignupFormView: View {
.foregroundColor(.appGrayText)
TextField("", text: $viewModel.potentialUsername)
.focused($focusedField, equals: .username)
#if os(iOS)
.textInputAutocapitalization(.never)
.textContentType(.username)
.disableAutocorrection(true)
.keyboardType(.alphabet)
#endif
.disableAutocorrection(true)
.submitLabel(.done)
}

View file

@ -51,8 +51,10 @@ struct InnerRootView: View {
.onAppear {
viewModel.triggerPushNotificationRequestIfNeeded()
}
#if os(iOS)
.miniPlayer()
.snackBar(isShowing: $viewModel.showSnackbar, message: viewModel.snackbarMessage)
#endif
.snackBar(isShowing: $viewModel.showSnackbar, message: viewModel.snackbarMessage)
// Schedule the dismissal every time we present the snackbar.
.onChange(of: viewModel.showSnackbar) { newValue in
if newValue {

View file

@ -75,47 +75,49 @@ struct WebReaderContainerView: View {
}
}
var audioNavbarItem: some View {
if audioController.isLoadingItem(itemID: item.unwrappedID) {
return AnyView(ProgressView()
#if os(iOS)
var audioNavbarItem: some View {
if audioController.isLoadingItem(itemID: item.unwrappedID) {
return AnyView(ProgressView()
.padding(.horizontal)
.scaleEffect(navBarVisibilityRatio))
} else {
return AnyView(Button(
action: {
switch audioController.state {
case .playing:
if audioController.itemAudioProperties?.itemID == self.item.unwrappedID {
audioController.pause()
return
}
fallthrough
case .paused:
if audioController.itemAudioProperties?.itemID == self.item.unwrappedID {
audioController.unpause()
return
}
fallthrough
default:
audioController.play(itemAudioProperties: item.audioProperties)
}
},
label: {
textToSpeechButtonImage
}
)
.padding(.horizontal)
.scaleEffect(navBarVisibilityRatio))
} else {
return AnyView(Button(
action: {
switch audioController.state {
case .playing:
if audioController.itemAudioProperties?.itemID == self.item.unwrappedID {
audioController.pause()
return
}
fallthrough
case .paused:
if audioController.itemAudioProperties?.itemID == self.item.unwrappedID {
audioController.unpause()
return
}
fallthrough
default:
audioController.play(itemAudioProperties: item.audioProperties)
}
},
label: {
textToSpeechButtonImage
}
)
.padding(.horizontal)
.scaleEffect(navBarVisibilityRatio))
}
}
}
var textToSpeechButtonImage: some View {
if audioController.state == .stopped || audioController.itemAudioProperties?.itemID != self.item.id {
return Image(systemName: "headphones").font(.appTitleThree)
var textToSpeechButtonImage: some View {
if audioController.state == .stopped || audioController.itemAudioProperties?.itemID != self.item.id {
return Image(systemName: "headphones").font(.appTitleThree)
}
let name = audioController.isPlayingItem(itemID: item.unwrappedID) ? "pause.circle" : "play.circle"
return Image(systemName: name).font(.appNavbarIcon)
}
let name = audioController.isPlayingItem(itemID: item.unwrappedID) ? "pause.circle" : "play.circle"
return Image(systemName: name).font(.appNavbarIcon)
}
#endif
var navBar: some View {
HStack(alignment: .center) {
@ -131,8 +133,8 @@ struct WebReaderContainerView: View {
)
.scaleEffect(navBarVisibilityRatio)
Spacer()
audioNavbarItem
#endif
audioNavbarItem
Button(
action: { showPreferencesPopover.toggle() },
label: {

View file

@ -0,0 +1,11 @@
#if os(macOS)
import Foundation
public final class AudioController: ObservableObject {
public init() {}
public func preload(itemIDs _: [String]) {}
public func downloadForOffline(itemID _: String) -> Bool { true }
}
#endif

View file

@ -26,11 +26,11 @@ public final class OmnivoreWebView: WKWebView {
#if os(iOS)
initNativeIOSMenus()
#endif
if #available(iOS 16.0, *) {
self.isFindInteractionEnabled = true
}
if #available(iOS 16.0, *) {
self.isFindInteractionEnabled = true
}
#endif
NotificationCenter.default.addObserver(forName: NSNotification.Name("SpeakingReaderItem"), object: nil, queue: OperationQueue.main, using: { notification in
if let pageID = notification.userInfo?["pageID"] as? String, let anchorIdx = notification.userInfo?["anchorIdx"] as? String {

View file

@ -3,10 +3,12 @@ import SwiftUI
import Utils
public struct FeedCard: View {
let tapHandler: () -> Void
@ObservedObject var item: LinkedItem
public init(item: LinkedItem) {
public init(item: LinkedItem, tapHandler: @escaping () -> Void = {}) {
self.item = item
self.tapHandler = tapHandler
}
public var body: some View {
@ -76,6 +78,11 @@ public struct FeedCard: View {
}
}
.padding(.top, 0)
#if os(macOS)
.onTapGesture {
tapHandler()
}
#endif
}
}
.padding(.top, 0)