mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Continue naming refactor. Session -> Controller
This commit is contained in:
parent
77e9dc7094
commit
c4bbf4f618
8 changed files with 46 additions and 46 deletions
|
|
@ -12,13 +12,13 @@ public final class Services {
|
||||||
|
|
||||||
public let authenticator: Authenticator
|
public let authenticator: Authenticator
|
||||||
public let dataService: DataService
|
public let dataService: DataService
|
||||||
public let audioSession: AudioController
|
public let audioController: AudioController
|
||||||
|
|
||||||
public init(appEnvironment: AppEnvironment = PublicValet.storedAppEnvironment ?? .initialAppEnvironment) {
|
public init(appEnvironment: AppEnvironment = PublicValet.storedAppEnvironment ?? .initialAppEnvironment) {
|
||||||
let networker = Networker(appEnvironment: appEnvironment)
|
let networker = Networker(appEnvironment: appEnvironment)
|
||||||
self.authenticator = Authenticator(networker: networker)
|
self.authenticator = Authenticator(networker: networker)
|
||||||
self.dataService = DataService(appEnvironment: appEnvironment, networker: networker)
|
self.dataService = DataService(appEnvironment: appEnvironment, networker: networker)
|
||||||
self.audioSession = AudioController(appEnvironment: appEnvironment, networker: networker)
|
self.audioController = AudioController(appEnvironment: appEnvironment, networker: networker)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import SwiftUI
|
||||||
import Views
|
import Views
|
||||||
|
|
||||||
public struct MiniPlayer: View {
|
public struct MiniPlayer: View {
|
||||||
@EnvironmentObject var audioSession: AudioController
|
@EnvironmentObject var audioController: AudioController
|
||||||
@Environment(\.colorScheme) private var colorScheme: ColorScheme
|
@Environment(\.colorScheme) private var colorScheme: ColorScheme
|
||||||
private let presentingView: AnyView
|
private let presentingView: AnyView
|
||||||
|
|
||||||
|
|
@ -30,26 +30,26 @@ public struct MiniPlayer: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
var isPresented: Bool {
|
var isPresented: Bool {
|
||||||
audioSession.item != nil && audioSession.state != .stopped
|
audioController.item != nil && audioController.state != .stopped
|
||||||
}
|
}
|
||||||
|
|
||||||
var playPauseButtonItem: some View {
|
var playPauseButtonItem: some View {
|
||||||
if let item = audioSession.item, audioSession.isLoadingItem(item: item) {
|
if let item = audioController.item, audioController.isLoadingItem(item: item) {
|
||||||
return AnyView(ProgressView())
|
return AnyView(ProgressView())
|
||||||
} else {
|
} else {
|
||||||
return AnyView(Button(
|
return AnyView(Button(
|
||||||
action: {
|
action: {
|
||||||
switch audioSession.state {
|
switch audioController.state {
|
||||||
case .playing:
|
case .playing:
|
||||||
_ = audioSession.pause()
|
_ = audioController.pause()
|
||||||
case .paused:
|
case .paused:
|
||||||
_ = audioSession.unpause()
|
_ = audioController.unpause()
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
label: {
|
label: {
|
||||||
Image(systemName: audioSession.state == .playing ? "pause.circle" : "play.circle")
|
Image(systemName: audioController.state == .playing ? "pause.circle" : "play.circle")
|
||||||
.font(expanded ? .system(size: 64.0, weight: .thin) : .appTitleTwo)
|
.font(expanded ? .system(size: 64.0, weight: .thin) : .appTitleTwo)
|
||||||
}
|
}
|
||||||
))
|
))
|
||||||
|
|
@ -59,7 +59,7 @@ public struct MiniPlayer: View {
|
||||||
var stopButton: some View {
|
var stopButton: some View {
|
||||||
Button(
|
Button(
|
||||||
action: {
|
action: {
|
||||||
audioSession.stop()
|
audioController.stop()
|
||||||
},
|
},
|
||||||
label: {
|
label: {
|
||||||
Image(systemName: "xmark")
|
Image(systemName: "xmark")
|
||||||
|
|
@ -104,7 +104,7 @@ public struct MiniPlayer: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
func viewArticle() {
|
func viewArticle() {
|
||||||
if let item = audioSession.item {
|
if let item = audioController.item {
|
||||||
NSNotification.pushReaderItem(objectID: item.objectID)
|
NSNotification.pushReaderItem(objectID: item.objectID)
|
||||||
withAnimation(.easeIn(duration: 0.1)) {
|
withAnimation(.easeIn(duration: 0.1)) {
|
||||||
expanded = false
|
expanded = false
|
||||||
|
|
@ -210,13 +210,13 @@ public struct MiniPlayer: View {
|
||||||
Spacer()
|
Spacer()
|
||||||
}
|
}
|
||||||
|
|
||||||
Slider(value: $audioSession.timeElapsed,
|
Slider(value: $audioController.timeElapsed,
|
||||||
in: 0 ... self.audioSession.duration,
|
in: 0 ... self.audioController.duration,
|
||||||
onEditingChanged: { scrubStarted in
|
onEditingChanged: { scrubStarted in
|
||||||
if scrubStarted {
|
if scrubStarted {
|
||||||
self.audioSession.scrubState = .scrubStarted
|
self.audioController.scrubState = .scrubStarted
|
||||||
} else {
|
} else {
|
||||||
self.audioSession.scrubState = .scrubEnded(self.audioSession.timeElapsed)
|
self.audioController.scrubState = .scrubEnded(self.audioController.timeElapsed)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.accentColor(.appCtaYellow)
|
.accentColor(.appCtaYellow)
|
||||||
|
|
@ -237,11 +237,11 @@ public struct MiniPlayer: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
HStack {
|
HStack {
|
||||||
Text(audioSession.timeElapsedString ?? "0:00")
|
Text(audioController.timeElapsedString ?? "0:00")
|
||||||
.font(.appCaptionTwo)
|
.font(.appCaptionTwo)
|
||||||
.foregroundColor(.appGrayText)
|
.foregroundColor(.appGrayText)
|
||||||
Spacer()
|
Spacer()
|
||||||
Text(audioSession.durationString ?? "0:00")
|
Text(audioController.durationString ?? "0:00")
|
||||||
.font(.appCaptionTwo)
|
.font(.appCaptionTwo)
|
||||||
.foregroundColor(.appGrayText)
|
.foregroundColor(.appGrayText)
|
||||||
}
|
}
|
||||||
|
|
@ -264,7 +264,7 @@ public struct MiniPlayer: View {
|
||||||
.padding(8)
|
.padding(8)
|
||||||
|
|
||||||
Button(
|
Button(
|
||||||
action: { self.audioSession.skipBackwards(seconds: 30) },
|
action: { self.audioController.skipBackwards(seconds: 30) },
|
||||||
label: {
|
label: {
|
||||||
Image(systemName: "gobackward.30")
|
Image(systemName: "gobackward.30")
|
||||||
.font(.appTitleTwo)
|
.font(.appTitleTwo)
|
||||||
|
|
@ -276,7 +276,7 @@ public struct MiniPlayer: View {
|
||||||
.padding(32)
|
.padding(32)
|
||||||
|
|
||||||
Button(
|
Button(
|
||||||
action: { self.audioSession.skipForward(seconds: 30) },
|
action: { self.audioController.skipForward(seconds: 30) },
|
||||||
label: {
|
label: {
|
||||||
Image(systemName: "goforward.30")
|
Image(systemName: "goforward.30")
|
||||||
.font(.appTitleTwo)
|
.font(.appTitleTwo)
|
||||||
|
|
@ -317,7 +317,7 @@ public struct MiniPlayer: View {
|
||||||
presentingView
|
presentingView
|
||||||
VStack {
|
VStack {
|
||||||
Spacer(minLength: 0)
|
Spacer(minLength: 0)
|
||||||
if let item = self.audioSession.item, isPresented {
|
if let item = self.audioController.item, isPresented {
|
||||||
playerContent(item)
|
playerContent(item)
|
||||||
.offset(y: offset)
|
.offset(y: offset)
|
||||||
.frame(maxHeight: expanded ? .infinity : 88)
|
.frame(maxHeight: expanded ? .infinity : 88)
|
||||||
|
|
@ -333,9 +333,9 @@ public struct MiniPlayer: View {
|
||||||
NavigationView {
|
NavigationView {
|
||||||
VStack {
|
VStack {
|
||||||
List {
|
List {
|
||||||
ForEach(audioSession.voiceList ?? [], id: \.key.self) { voice in
|
ForEach(audioController.voiceList ?? [], id: \.key.self) { voice in
|
||||||
Button(action: {
|
Button(action: {
|
||||||
audioSession.currentVoice = voice.key
|
audioController.currentVoice = voice.key
|
||||||
}) {
|
}) {
|
||||||
HStack {
|
HStack {
|
||||||
Text(voice.name)
|
Text(voice.name)
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import Views
|
||||||
|
|
||||||
struct FeedCardNavigationLink: View {
|
struct FeedCardNavigationLink: View {
|
||||||
@EnvironmentObject var dataService: DataService
|
@EnvironmentObject var dataService: DataService
|
||||||
@EnvironmentObject var audioSession: AudioController
|
@EnvironmentObject var audioController: AudioController
|
||||||
|
|
||||||
let item: LinkedItem
|
let item: LinkedItem
|
||||||
|
|
||||||
|
|
@ -24,7 +24,7 @@ struct FeedCardNavigationLink: View {
|
||||||
.opacity(0)
|
.opacity(0)
|
||||||
.buttonStyle(PlainButtonStyle())
|
.buttonStyle(PlainButtonStyle())
|
||||||
.onAppear {
|
.onAppear {
|
||||||
Task { await viewModel.itemAppeared(item: item, dataService: dataService, audioSession: audioSession) }
|
Task { await viewModel.itemAppeared(item: item, dataService: dataService, audioController: AudioController) }
|
||||||
}
|
}
|
||||||
FeedCard(item: item)
|
FeedCard(item: item)
|
||||||
}
|
}
|
||||||
|
|
@ -34,7 +34,7 @@ struct FeedCardNavigationLink: View {
|
||||||
|
|
||||||
struct GridCardNavigationLink: View {
|
struct GridCardNavigationLink: View {
|
||||||
@EnvironmentObject var dataService: DataService
|
@EnvironmentObject var dataService: DataService
|
||||||
@EnvironmentObject var audioSession: AudioController
|
@EnvironmentObject var audioSession: AudioSession
|
||||||
|
|
||||||
@State private var scale = 1.0
|
@State private var scale = 1.0
|
||||||
|
|
||||||
|
|
@ -63,7 +63,7 @@ struct GridCardNavigationLink: View {
|
||||||
withAnimation { tapAction() }
|
withAnimation { tapAction() }
|
||||||
})
|
})
|
||||||
.onAppear {
|
.onAppear {
|
||||||
Task { await viewModel.itemAppeared(item: item, dataService: dataService, audioSession: audioSession) }
|
Task { await viewModel.itemAppeared(item: item, dataService: dataService, audioController: AudioController) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.aspectRatio(1.8, contentMode: .fill)
|
.aspectRatio(1.8, contentMode: .fill)
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import Views
|
||||||
|
|
||||||
struct HomeFeedContainerView: View {
|
struct HomeFeedContainerView: View {
|
||||||
@EnvironmentObject var dataService: DataService
|
@EnvironmentObject var dataService: DataService
|
||||||
@EnvironmentObject var audioSession: AudioController
|
@EnvironmentObject var audioSession: AudioSession
|
||||||
|
|
||||||
@AppStorage(UserDefaultKey.homeFeedlayoutPreference.rawValue) var prefersListLayout = false
|
@AppStorage(UserDefaultKey.homeFeedlayoutPreference.rawValue) var prefersListLayout = false
|
||||||
@ObservedObject var viewModel: HomeFeedViewModel
|
@ObservedObject var viewModel: HomeFeedViewModel
|
||||||
|
|
@ -259,7 +259,7 @@ import Views
|
||||||
|
|
||||||
struct HomeFeedListView: View {
|
struct HomeFeedListView: View {
|
||||||
@EnvironmentObject var dataService: DataService
|
@EnvironmentObject var dataService: DataService
|
||||||
@EnvironmentObject var audioSession: AudioController
|
@EnvironmentObject var audioSession: AudioSession
|
||||||
|
|
||||||
@Binding var prefersListLayout: Bool
|
@Binding var prefersListLayout: Bool
|
||||||
|
|
||||||
|
|
@ -391,7 +391,7 @@ import Views
|
||||||
|
|
||||||
struct HomeFeedGridView: View {
|
struct HomeFeedGridView: View {
|
||||||
@EnvironmentObject var dataService: DataService
|
@EnvironmentObject var dataService: DataService
|
||||||
@EnvironmentObject var audioSession: AudioController
|
@EnvironmentObject var audioSession: AudioSession
|
||||||
|
|
||||||
@State private var itemToRemove: LinkedItem?
|
@State private var itemToRemove: LinkedItem?
|
||||||
@State private var confirmationShown = false
|
@State private var confirmationShown = false
|
||||||
|
|
|
||||||
|
|
@ -49,14 +49,14 @@ import Views
|
||||||
var searchIdx = 0
|
var searchIdx = 0
|
||||||
var receivedIdx = 0
|
var receivedIdx = 0
|
||||||
|
|
||||||
func itemAppeared(item: LinkedItem, dataService: DataService, audioSession: AudioController) async {
|
func itemAppeared(item: LinkedItem, dataService: DataService, audioController: AudioController) async {
|
||||||
if isLoading { return }
|
if isLoading { return }
|
||||||
let itemIndex = items.firstIndex(where: { $0.id == item.id })
|
let itemIndex = items.firstIndex(where: { $0.id == item.id })
|
||||||
let thresholdIndex = items.index(items.endIndex, offsetBy: -5)
|
let thresholdIndex = items.index(items.endIndex, offsetBy: -5)
|
||||||
|
|
||||||
// Check if user has scrolled to the last five items in the list
|
// Check if user has scrolled to the last five items in the list
|
||||||
if let itemIndex = itemIndex, itemIndex > thresholdIndex, items.count < thresholdIndex + 10 {
|
if let itemIndex = itemIndex, itemIndex > thresholdIndex, items.count < thresholdIndex + 10 {
|
||||||
await loadItems(dataService: dataService, audioSession: audioSession, isRefresh: false)
|
await loadItems(dataService: dataService, audioController: audioController, isRefresh: false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,7 +64,7 @@ import Views
|
||||||
items.insert(item, at: 0)
|
items.insert(item, at: 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadItems(dataService: DataService, audioSession: AudioController, isRefresh: Bool) async {
|
func loadItems(dataService: DataService, audioController: AudioController, isRefresh: Bool) async {
|
||||||
let syncStartTime = Date()
|
let syncStartTime = Date()
|
||||||
let thisSearchIdx = searchIdx
|
let thisSearchIdx = searchIdx
|
||||||
searchIdx += 1
|
searchIdx += 1
|
||||||
|
|
@ -137,7 +137,7 @@ import Views
|
||||||
// This happens because when an article is saved, we check if the user has a recent
|
// This happens because when an article is saved, we check if the user has a recent
|
||||||
// listen. If they do, we will automatically transcribe their message.
|
// listen. If they do, we will automatically transcribe their message.
|
||||||
if let first = newItems.first?.id {
|
if let first = newItems.first?.id {
|
||||||
_ = await audioSession.preload(itemIDs: [first])
|
_ = await audioController.preload(itemIDs: [first])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -153,10 +153,10 @@ import Views
|
||||||
showAudioInfoAlert = false
|
showAudioInfoAlert = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func downloadAudio(audioSession: AudioController, item: LinkedItem) {
|
func downloadAudio(audioController: AudioController, item: LinkedItem) {
|
||||||
Snackbar.show(message: "Downloading Offline Audio")
|
Snackbar.show(message: "Downloading Offline Audio")
|
||||||
Task {
|
Task {
|
||||||
let downloaded = await audioSession.preload(itemIDs: [item.unwrappedID])
|
let downloaded = await audioController.preload(itemIDs: [item.unwrappedID])
|
||||||
Snackbar.show(message: downloaded ? "Audio file downloaded" : "Error downloading audio")
|
Snackbar.show(message: downloaded ? "Audio file downloaded" : "Error downloading audio")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ public struct RootView: View {
|
||||||
InnerRootView(viewModel: viewModel)
|
InnerRootView(viewModel: viewModel)
|
||||||
.environmentObject(viewModel.services.authenticator)
|
.environmentObject(viewModel.services.authenticator)
|
||||||
.environmentObject(viewModel.services.dataService)
|
.environmentObject(viewModel.services.dataService)
|
||||||
.environmentObject(viewModel.services.audioSession)
|
.environmentObject(viewModel.services.audioController)
|
||||||
.environment(\.managedObjectContext, viewModel.services.dataService.viewContext)
|
.environment(\.managedObjectContext, viewModel.services.dataService.viewContext)
|
||||||
.onChange(of: scenePhase) { phase in
|
.onChange(of: scenePhase) { phase in
|
||||||
if phase == .background {
|
if phase == .background {
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ struct WebReaderContainerView: View {
|
||||||
@State var annotation = String()
|
@State var annotation = String()
|
||||||
|
|
||||||
@EnvironmentObject var dataService: DataService
|
@EnvironmentObject var dataService: DataService
|
||||||
@EnvironmentObject var audioSession: AudioController
|
@EnvironmentObject var audioController: AudioController
|
||||||
@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
|
@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
|
||||||
@StateObject var viewModel = WebReaderViewModel()
|
@StateObject var viewModel = WebReaderViewModel()
|
||||||
|
|
||||||
|
|
@ -57,32 +57,32 @@ struct WebReaderContainerView: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
var audioNavbarItem: some View {
|
var audioNavbarItem: some View {
|
||||||
if audioSession.isLoadingItem(item: item) {
|
if audioController.isLoadingItem(item: item) {
|
||||||
return AnyView(ProgressView()
|
return AnyView(ProgressView()
|
||||||
.padding(.horizontal)
|
.padding(.horizontal)
|
||||||
.scaleEffect(navBarVisibilityRatio))
|
.scaleEffect(navBarVisibilityRatio))
|
||||||
} else {
|
} else {
|
||||||
return AnyView(Button(
|
return AnyView(Button(
|
||||||
action: {
|
action: {
|
||||||
switch audioSession.state {
|
switch audioController.state {
|
||||||
case .playing:
|
case .playing:
|
||||||
if audioSession.item == self.item {
|
if audioController.item == self.item {
|
||||||
audioSession.pause()
|
audioController.pause()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fallthrough
|
fallthrough
|
||||||
case .paused:
|
case .paused:
|
||||||
if audioSession.item == self.item {
|
if audioController.item == self.item {
|
||||||
audioSession.unpause()
|
audioController.unpause()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fallthrough
|
fallthrough
|
||||||
default:
|
default:
|
||||||
audioSession.play(item: self.item)
|
audioController.play(item: self.item)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
label: {
|
label: {
|
||||||
Image(systemName: audioSession.isPlayingItem(item: item) ? "pause.circle" : "play.circle")
|
Image(systemName: audioController.isPlayingItem(item: item) ? "pause.circle" : "play.circle")
|
||||||
.font(.appTitleTwo)
|
.font(.appTitleTwo)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
//
|
//
|
||||||
// AudioSession.swift
|
// AudioController.swift
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Created by Jackson Harper on 8/15/22.
|
// Created by Jackson Harper on 8/15/22.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue