1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 05:40:32 +05:30

remove superfluous vars and chaptermodel

This commit is contained in:
Toni Förster 2023-12-03 20:04:57 +01:00
parent 982dca1846
commit aa5d6733b2
No known key found for this signature in database
GPG Key ID: 292F3E5086C83FC7
2 changed files with 4 additions and 11 deletions

View File

@ -131,8 +131,7 @@ final class PlayerModel: ObservableObject {
@Default(.rotateToLandscapeOnEnterFullScreen) private var rotateToLandscapeOnEnterFullScreen @Default(.rotateToLandscapeOnEnterFullScreen) private var rotateToLandscapeOnEnterFullScreen
#endif #endif
@Published var playedChapters: [Int] = [] @Published var currentChapter: Int?
@Published var currentChapterIndex: Int?
var accounts: AccountsModel { .shared } var accounts: AccountsModel { .shared }
var comments: CommentsModel { .shared } var comments: CommentsModel { .shared }

View File

@ -12,11 +12,7 @@ import SwiftUI
@ObservedObject private var player = PlayerModel.shared @ObservedObject private var player = PlayerModel.shared
var isCurrentChapter: Bool { var isCurrentChapter: Bool {
player.currentChapterIndex == chapterIndex player.currentChapter == chapterIndex
}
var hasBeenPlayed: Bool {
player.playedChapters.contains(chapterIndex)
} }
var body: some View { var body: some View {
@ -35,6 +31,7 @@ import SwiftUI
.buttonStyle(.plain) .buttonStyle(.plain)
.onReceive(PlayerTimeModel.shared.$currentTime) { cmTime in .onReceive(PlayerTimeModel.shared.$currentTime) { cmTime in
self.handleTimeUpdate(cmTime) self.handleTimeUpdate(cmTime)
print("currentChapterIndex:", player.currentChapter ?? 0)
} }
} }
@ -80,10 +77,7 @@ import SwiftUI
private func handleTimeUpdate(_ cmTime: CMTime) { private func handleTimeUpdate(_ cmTime: CMTime) {
let time = CMTimeGetSeconds(cmTime) let time = CMTimeGetSeconds(cmTime)
if time >= chapter.start, nextChapterStart == nil || time < nextChapterStart! { if time >= chapter.start, nextChapterStart == nil || time < nextChapterStart! {
player.currentChapterIndex = chapterIndex player.currentChapter = chapterIndex
if !player.playedChapters.contains(chapterIndex) {
player.playedChapters.append(chapterIndex)
}
} }
} }
} }