Continue naming refactor. Session -> Controller
This commit is contained in:
@ -12,13 +12,13 @@ public final class Services {
|
||||
|
||||
public let authenticator: Authenticator
|
||||
public let dataService: DataService
|
||||
public let audioSession: AudioController
|
||||
public let audioController: AudioController
|
||||
|
||||
public init(appEnvironment: AppEnvironment = PublicValet.storedAppEnvironment ?? .initialAppEnvironment) {
|
||||
let networker = Networker(appEnvironment: appEnvironment)
|
||||
self.authenticator = Authenticator(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
|
||||
|
||||
public struct MiniPlayer: View {
|
||||
@EnvironmentObject var audioSession: AudioController
|
||||
@EnvironmentObject var audioController: AudioController
|
||||
@Environment(\.colorScheme) private var colorScheme: ColorScheme
|
||||
private let presentingView: AnyView
|
||||
|
||||
@ -30,26 +30,26 @@ public struct MiniPlayer: View {
|
||||
}
|
||||
|
||||
var isPresented: Bool {
|
||||
audioSession.item != nil && audioSession.state != .stopped
|
||||
audioController.item != nil && audioController.state != .stopped
|
||||
}
|
||||
|
||||
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())
|
||||
} else {
|
||||
return AnyView(Button(
|
||||
action: {
|
||||
switch audioSession.state {
|
||||
switch audioController.state {
|
||||
case .playing:
|
||||
_ = audioSession.pause()
|
||||
_ = audioController.pause()
|
||||
case .paused:
|
||||
_ = audioSession.unpause()
|
||||
_ = audioController.unpause()
|
||||
default:
|
||||
break
|
||||
}
|
||||
},
|
||||
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)
|
||||
}
|
||||
))
|
||||
@ -59,7 +59,7 @@ public struct MiniPlayer: View {
|
||||
var stopButton: some View {
|
||||
Button(
|
||||
action: {
|
||||
audioSession.stop()
|
||||
audioController.stop()
|
||||
},
|
||||
label: {
|
||||
Image(systemName: "xmark")
|
||||
@ -104,7 +104,7 @@ public struct MiniPlayer: View {
|
||||
}
|
||||
|
||||
func viewArticle() {
|
||||
if let item = audioSession.item {
|
||||
if let item = audioController.item {
|
||||
NSNotification.pushReaderItem(objectID: item.objectID)
|
||||
withAnimation(.easeIn(duration: 0.1)) {
|
||||
expanded = false
|
||||
@ -210,13 +210,13 @@ public struct MiniPlayer: View {
|
||||
Spacer()
|
||||
}
|
||||
|
||||
Slider(value: $audioSession.timeElapsed,
|
||||
in: 0 ... self.audioSession.duration,
|
||||
Slider(value: $audioController.timeElapsed,
|
||||
in: 0 ... self.audioController.duration,
|
||||
onEditingChanged: { scrubStarted in
|
||||
if scrubStarted {
|
||||
self.audioSession.scrubState = .scrubStarted
|
||||
self.audioController.scrubState = .scrubStarted
|
||||
} else {
|
||||
self.audioSession.scrubState = .scrubEnded(self.audioSession.timeElapsed)
|
||||
self.audioController.scrubState = .scrubEnded(self.audioController.timeElapsed)
|
||||
}
|
||||
})
|
||||
.accentColor(.appCtaYellow)
|
||||
@ -237,11 +237,11 @@ public struct MiniPlayer: View {
|
||||
}
|
||||
|
||||
HStack {
|
||||
Text(audioSession.timeElapsedString ?? "0:00")
|
||||
Text(audioController.timeElapsedString ?? "0:00")
|
||||
.font(.appCaptionTwo)
|
||||
.foregroundColor(.appGrayText)
|
||||
Spacer()
|
||||
Text(audioSession.durationString ?? "0:00")
|
||||
Text(audioController.durationString ?? "0:00")
|
||||
.font(.appCaptionTwo)
|
||||
.foregroundColor(.appGrayText)
|
||||
}
|
||||
@ -264,7 +264,7 @@ public struct MiniPlayer: View {
|
||||
.padding(8)
|
||||
|
||||
Button(
|
||||
action: { self.audioSession.skipBackwards(seconds: 30) },
|
||||
action: { self.audioController.skipBackwards(seconds: 30) },
|
||||
label: {
|
||||
Image(systemName: "gobackward.30")
|
||||
.font(.appTitleTwo)
|
||||
@ -276,7 +276,7 @@ public struct MiniPlayer: View {
|
||||
.padding(32)
|
||||
|
||||
Button(
|
||||
action: { self.audioSession.skipForward(seconds: 30) },
|
||||
action: { self.audioController.skipForward(seconds: 30) },
|
||||
label: {
|
||||
Image(systemName: "goforward.30")
|
||||
.font(.appTitleTwo)
|
||||
@ -317,7 +317,7 @@ public struct MiniPlayer: View {
|
||||
presentingView
|
||||
VStack {
|
||||
Spacer(minLength: 0)
|
||||
if let item = self.audioSession.item, isPresented {
|
||||
if let item = self.audioController.item, isPresented {
|
||||
playerContent(item)
|
||||
.offset(y: offset)
|
||||
.frame(maxHeight: expanded ? .infinity : 88)
|
||||
@ -333,9 +333,9 @@ public struct MiniPlayer: View {
|
||||
NavigationView {
|
||||
VStack {
|
||||
List {
|
||||
ForEach(audioSession.voiceList ?? [], id: \.key.self) { voice in
|
||||
ForEach(audioController.voiceList ?? [], id: \.key.self) { voice in
|
||||
Button(action: {
|
||||
audioSession.currentVoice = voice.key
|
||||
audioController.currentVoice = voice.key
|
||||
}) {
|
||||
HStack {
|
||||
Text(voice.name)
|
||||
|
||||
@ -5,7 +5,7 @@ import Views
|
||||
|
||||
struct FeedCardNavigationLink: View {
|
||||
@EnvironmentObject var dataService: DataService
|
||||
@EnvironmentObject var audioSession: AudioController
|
||||
@EnvironmentObject var audioController: AudioController
|
||||
|
||||
let item: LinkedItem
|
||||
|
||||
@ -24,7 +24,7 @@ struct FeedCardNavigationLink: View {
|
||||
.opacity(0)
|
||||
.buttonStyle(PlainButtonStyle())
|
||||
.onAppear {
|
||||
Task { await viewModel.itemAppeared(item: item, dataService: dataService, audioSession: audioSession) }
|
||||
Task { await viewModel.itemAppeared(item: item, dataService: dataService, audioController: AudioController) }
|
||||
}
|
||||
FeedCard(item: item)
|
||||
}
|
||||
@ -34,7 +34,7 @@ struct FeedCardNavigationLink: View {
|
||||
|
||||
struct GridCardNavigationLink: View {
|
||||
@EnvironmentObject var dataService: DataService
|
||||
@EnvironmentObject var audioSession: AudioController
|
||||
@EnvironmentObject var audioSession: AudioSession
|
||||
|
||||
@State private var scale = 1.0
|
||||
|
||||
@ -63,7 +63,7 @@ struct GridCardNavigationLink: View {
|
||||
withAnimation { tapAction() }
|
||||
})
|
||||
.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)
|
||||
|
||||
@ -12,7 +12,7 @@ import Views
|
||||
|
||||
struct HomeFeedContainerView: View {
|
||||
@EnvironmentObject var dataService: DataService
|
||||
@EnvironmentObject var audioSession: AudioController
|
||||
@EnvironmentObject var audioSession: AudioSession
|
||||
|
||||
@AppStorage(UserDefaultKey.homeFeedlayoutPreference.rawValue) var prefersListLayout = false
|
||||
@ObservedObject var viewModel: HomeFeedViewModel
|
||||
@ -259,7 +259,7 @@ import Views
|
||||
|
||||
struct HomeFeedListView: View {
|
||||
@EnvironmentObject var dataService: DataService
|
||||
@EnvironmentObject var audioSession: AudioController
|
||||
@EnvironmentObject var audioSession: AudioSession
|
||||
|
||||
@Binding var prefersListLayout: Bool
|
||||
|
||||
@ -391,7 +391,7 @@ import Views
|
||||
|
||||
struct HomeFeedGridView: View {
|
||||
@EnvironmentObject var dataService: DataService
|
||||
@EnvironmentObject var audioSession: AudioController
|
||||
@EnvironmentObject var audioSession: AudioSession
|
||||
|
||||
@State private var itemToRemove: LinkedItem?
|
||||
@State private var confirmationShown = false
|
||||
|
||||
@ -49,14 +49,14 @@ import Views
|
||||
var searchIdx = 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 }
|
||||
let itemIndex = items.firstIndex(where: { $0.id == item.id })
|
||||
let thresholdIndex = items.index(items.endIndex, offsetBy: -5)
|
||||
|
||||
// Check if user has scrolled to the last five items in the list
|
||||
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)
|
||||
}
|
||||
|
||||
func loadItems(dataService: DataService, audioSession: AudioController, isRefresh: Bool) async {
|
||||
func loadItems(dataService: DataService, audioController: AudioController, isRefresh: Bool) async {
|
||||
let syncStartTime = Date()
|
||||
let thisSearchIdx = searchIdx
|
||||
searchIdx += 1
|
||||
@ -137,7 +137,7 @@ import Views
|
||||
// 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.
|
||||
if let first = newItems.first?.id {
|
||||
_ = await audioSession.preload(itemIDs: [first])
|
||||
_ = await audioController.preload(itemIDs: [first])
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -153,10 +153,10 @@ import Views
|
||||
showAudioInfoAlert = false
|
||||
}
|
||||
|
||||
func downloadAudio(audioSession: AudioController, item: LinkedItem) {
|
||||
func downloadAudio(audioController: AudioController, item: LinkedItem) {
|
||||
Snackbar.show(message: "Downloading Offline Audio")
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ public struct RootView: View {
|
||||
InnerRootView(viewModel: viewModel)
|
||||
.environmentObject(viewModel.services.authenticator)
|
||||
.environmentObject(viewModel.services.dataService)
|
||||
.environmentObject(viewModel.services.audioSession)
|
||||
.environmentObject(viewModel.services.audioController)
|
||||
.environment(\.managedObjectContext, viewModel.services.dataService.viewContext)
|
||||
.onChange(of: scenePhase) { phase in
|
||||
if phase == .background {
|
||||
|
||||
@ -24,7 +24,7 @@ struct WebReaderContainerView: View {
|
||||
@State var annotation = String()
|
||||
|
||||
@EnvironmentObject var dataService: DataService
|
||||
@EnvironmentObject var audioSession: AudioController
|
||||
@EnvironmentObject var audioController: AudioController
|
||||
@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
|
||||
@StateObject var viewModel = WebReaderViewModel()
|
||||
|
||||
@ -57,32 +57,32 @@ struct WebReaderContainerView: View {
|
||||
}
|
||||
|
||||
var audioNavbarItem: some View {
|
||||
if audioSession.isLoadingItem(item: item) {
|
||||
if audioController.isLoadingItem(item: item) {
|
||||
return AnyView(ProgressView()
|
||||
.padding(.horizontal)
|
||||
.scaleEffect(navBarVisibilityRatio))
|
||||
} else {
|
||||
return AnyView(Button(
|
||||
action: {
|
||||
switch audioSession.state {
|
||||
switch audioController.state {
|
||||
case .playing:
|
||||
if audioSession.item == self.item {
|
||||
audioSession.pause()
|
||||
if audioController.item == self.item {
|
||||
audioController.pause()
|
||||
return
|
||||
}
|
||||
fallthrough
|
||||
case .paused:
|
||||
if audioSession.item == self.item {
|
||||
audioSession.unpause()
|
||||
if audioController.item == self.item {
|
||||
audioController.unpause()
|
||||
return
|
||||
}
|
||||
fallthrough
|
||||
default:
|
||||
audioSession.play(item: self.item)
|
||||
audioController.play(item: self.item)
|
||||
}
|
||||
},
|
||||
label: {
|
||||
Image(systemName: audioSession.isPlayingItem(item: item) ? "pause.circle" : "play.circle")
|
||||
Image(systemName: audioController.isPlayingItem(item: item) ? "pause.circle" : "play.circle")
|
||||
.font(.appTitleTwo)
|
||||
}
|
||||
)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
//
|
||||
// AudioSession.swift
|
||||
// AudioController.swift
|
||||
//
|
||||
//
|
||||
// Created by Jackson Harper on 8/15/22.
|
||||
|
||||
Reference in New Issue
Block a user