diff --git a/ReaderTranslatorMac/Info.plist b/ReaderTranslatorMac/Info.plist
index d81ed1c..6c2d71e 100644
--- a/ReaderTranslatorMac/Info.plist
+++ b/ReaderTranslatorMac/Info.plist
@@ -21,7 +21,7 @@
CFBundleShortVersionString
$(MARKETING_VERSION)
CFBundleVersion
- 1768
+ 1775
LSApplicationCategoryType
public.app-category.education
LSMinimumSystemVersion
diff --git a/ReaderTranslatorPlayer/Info.plist b/ReaderTranslatorPlayer/Info.plist
index 5b6e2a5..7103c29 100644
--- a/ReaderTranslatorPlayer/Info.plist
+++ b/ReaderTranslatorPlayer/Info.plist
@@ -52,7 +52,7 @@
CFBundleShortVersionString
1.0
CFBundleVersion
- 35
+ 64
LSRequiresIPhoneOS
LSSupportsOpeningDocumentsInPlace
diff --git a/ReaderTranslatorPlayer/Store/AudioStore.swift b/ReaderTranslatorPlayer/Store/AudioStore.swift
index e2fdffd..b7ff5bb 100644
--- a/ReaderTranslatorPlayer/Store/AudioStore.swift
+++ b/ReaderTranslatorPlayer/Store/AudioStore.swift
@@ -18,6 +18,8 @@ final class AudioStore: NSObject, ObservableObject {
private(set) var player: AVAudioPlayer?
private var someObservationContext = ""
+ private static var directoryObserver: DirectoryObserver?
+
@Published private(set) var allAudioPlayers = [AVAudioPlayer]()
@Published var timelineStatus = "0.0/0.0"
@@ -52,6 +54,25 @@ final class AudioStore: NSObject, ObservableObject {
private override init() {
super.init()
+ initDirectoryObserver()
+ initAudioSesssion()
+ saveAllAudioPlayer()
+ initMPRemoteCommandCenter()
+
+ if let lastAudio = lastAudio { openAudio(url: lastAudio) }
+ }
+}
+
+extension AudioStore {
+ private func initDirectoryObserver() {
+ if let url = FileStore.shared.folderUrl {
+ Self.directoryObserver = DirectoryObserver(URL: url) {
+ RunLoop.main.perform { self.saveAllAudioPlayer() }
+ }
+ }
+ }
+
+ private func initAudioSesssion() {
do {
let sharedInstance = AVAudioSession.sharedInstance()
@@ -60,25 +81,18 @@ final class AudioStore: NSObject, ObservableObject {
} catch {
Logger.log(type: .error, value: error)
}
-
- saveAllAudioPlayer()
- if let lastAudio = lastAudio { openAudio(url: lastAudio) }
-
- initMPRemoteCommandCenter()
}
-}
-
-extension AudioStore {
+
func updateTimeline(timer _: Timer? = nil) {
guard let player = self.player else { return }
- self.timelineStatus = String(format: "%.1f/%.1f", player.currentTime, player.duration)
+ timelineStatus = String(format: "%.1f/%.1f", player.currentTime, player.duration)
}
}
extension AudioStore {
func openAudio(url: URL?) {
guard let url = url else { return }
-
+
if player != nil { player?.pause() }
player = allAudioPlayers.first { $0.url == url }
guard let player = player else { return }
@@ -123,9 +137,8 @@ extension AudioStore {
}
}
-
extension AudioStore: AVAudioPlayerDelegate {
- func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
+ func audioPlayerDidFinishPlaying(_: AVAudioPlayer, successfully flag: Bool) {
if flag {
nextPlay()
}
diff --git a/ReaderTranslatorPlayer/Store/FileStore.swift b/ReaderTranslatorPlayer/Store/FileStore.swift
index 3a8cd5c..fb9b0fb 100644
--- a/ReaderTranslatorPlayer/Store/FileStore.swift
+++ b/ReaderTranslatorPlayer/Store/FileStore.swift
@@ -12,8 +12,6 @@ final class FileStore: ObservableObject {
private init() {}
static let shared = FileStore()
- static private var directoryObserver: DirectoryObserver?
-
var files: [URL] {
guard let url = folderUrl else { return [] }
@@ -25,7 +23,7 @@ final class FileStore: ObservableObject {
}
}
- private let folderUrl: URL? = {
+ let folderUrl: URL? = {
guard let documentsUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else {
return nil
}
diff --git a/ReaderTranslatorPlayer/Views/PlayerContentView.swift b/ReaderTranslatorPlayer/Views/PlayerContentView.swift
index 255506a..8bf7d9b 100644
--- a/ReaderTranslatorPlayer/Views/PlayerContentView.swift
+++ b/ReaderTranslatorPlayer/Views/PlayerContentView.swift
@@ -18,8 +18,8 @@ struct PlayerContentView: View {
PlayerControlsView()
BookmarksView()
}
- .navigationBarTitle("", displayMode: .inline)
- .navigationBarHidden(store.hideNavBar)
+ .navigationBarTitle("ReaderTranslator", displayMode: .inline)
+// .navigationBarHidden(store.hideNavBar)
.onAppear { self.store.hideNavBar = true }
}
}
diff --git a/ReaderTranslatorPlayer/Views/PlayerContols/PlayerContolsView.swift b/ReaderTranslatorPlayer/Views/PlayerContols/PlayerContolsView.swift
index 9b23cad..4934ff6 100644
--- a/ReaderTranslatorPlayer/Views/PlayerContols/PlayerContolsView.swift
+++ b/ReaderTranslatorPlayer/Views/PlayerContols/PlayerContolsView.swift
@@ -43,10 +43,7 @@ struct PlayerControlsView: View {
private var playPauseButton: some View {
Button(
- action: {
- self.audioStore.saveAllAudioPlayer()
- self.audioStore.isPlaying.toggle()
- },
+ action: { self.audioStore.isPlaying.toggle() },
label: { Text(audioStore.isPlaying ? "Pause" : "Play") }
).buttonStyle(RoundButtonStyle())
}
diff --git a/ReaderTranslatorPlayer/Views/ViewModes/BookmarksView.swift b/ReaderTranslatorPlayer/Views/ViewModes/BookmarksView.swift
index 680b6d6..98bf3c7 100644
--- a/ReaderTranslatorPlayer/Views/ViewModes/BookmarksView.swift
+++ b/ReaderTranslatorPlayer/Views/ViewModes/BookmarksView.swift
@@ -31,7 +31,7 @@ struct BookmarksView: View {
destination: SentencesView(bookmark: bookmark.text),
label: {
Text(bookmark.text)
- .font(.largeTitle)
+ .font(.title)
.lineLimit(1)
}
).layoutPriority(2)
@@ -40,7 +40,7 @@ struct BookmarksView: View {
Spacer()
CircleButton {
- Text("\(bookmark.counter)")
+ Text("\(bookmark.counter)").font(.footnote)
}
.modifier(ButtonModifier())
.onTapGesture {
@@ -67,7 +67,7 @@ struct BookmarksView: View {
struct BookmarksView_Previews: PreviewProvider {
static var previews: some View {
- Store.shared.bookmarks = [.init(text: "test bookmark test test")]
+ Store.shared.bookmarks = [.init(counter: 11, text: "test bookmark test test")]
return BookmarksView()
}
}
diff --git a/ReaderTranslatorPlayer/Views/ViewModes/FileListView.swift b/ReaderTranslatorPlayer/Views/ViewModes/FileListView.swift
index e9b8f47..f7d2b71 100644
--- a/ReaderTranslatorPlayer/Views/ViewModes/FileListView.swift
+++ b/ReaderTranslatorPlayer/Views/ViewModes/FileListView.swift
@@ -11,9 +11,9 @@ import Dispatch
import SwiftUI
struct FileListView: View {
- @ObservedObject var fileStore = FileStore.shared
@ObservedObject var audioStore = AudioStore.shared
- @State var files = FileStore.shared.files
+
+ @State var isEditMode: EditMode = .inactive
var body: some View {
List {
@@ -26,12 +26,13 @@ struct FileListView: View {
do {
try FileManager.default.removeItem(at: url)
- self.audioStore.saveAllAudioPlayer()
} catch {
Logger.log(type: .error, value: error)
}
}
}
+ .navigationBarItems(trailing: EditButton())
+ .environment(\.editMode, $isEditMode)
}
private func buttonView(_ player: AVAudioPlayer) -> some View {