mirror of
https://github.com/cranci1/Sora.git
synced 2026-04-21 00:22:12 +00:00
Added invisible control overlays + fixed overlapping images in portrait mode in library view (#53)
Some checks are pending
Build and Release IPA / Build IPA (push) Waiting to run
Some checks are pending
Build and Release IPA / Build IPA (push) Waiting to run
This commit is contained in:
commit
82f7870b07
2 changed files with 68 additions and 4 deletions
|
|
@ -136,6 +136,7 @@ class CustomMediaPlayerViewController: UIViewController {
|
||||||
loadSubtitleSettings()
|
loadSubtitleSettings()
|
||||||
setupPlayerViewController()
|
setupPlayerViewController()
|
||||||
setupControls()
|
setupControls()
|
||||||
|
addInvisibleControlOverlays()
|
||||||
setupSubtitleLabel()
|
setupSubtitleLabel()
|
||||||
setupDismissButton()
|
setupDismissButton()
|
||||||
setupMenuButton()
|
setupMenuButton()
|
||||||
|
|
@ -346,6 +347,45 @@ class CustomMediaPlayerViewController: UIViewController {
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addInvisibleControlOverlays() {
|
||||||
|
let playPauseOverlay = UIButton(type: .custom)
|
||||||
|
playPauseOverlay.backgroundColor = .clear
|
||||||
|
playPauseOverlay.addTarget(self, action: #selector(togglePlayPause), for: .touchUpInside)
|
||||||
|
view.addSubview(playPauseOverlay)
|
||||||
|
playPauseOverlay.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
NSLayoutConstraint.activate([
|
||||||
|
playPauseOverlay.centerXAnchor.constraint(equalTo: playPauseButton.centerXAnchor),
|
||||||
|
playPauseOverlay.centerYAnchor.constraint(equalTo: playPauseButton.centerYAnchor),
|
||||||
|
playPauseOverlay.widthAnchor.constraint(equalTo: playPauseButton.widthAnchor, constant: 20),
|
||||||
|
playPauseOverlay.heightAnchor.constraint(equalTo: playPauseButton.heightAnchor, constant: 20)
|
||||||
|
])
|
||||||
|
|
||||||
|
let backwardOverlay = UIButton(type: .custom)
|
||||||
|
backwardOverlay.backgroundColor = .clear
|
||||||
|
backwardOverlay.addTarget(self, action: #selector(seekBackward), for: .touchUpInside)
|
||||||
|
view.addSubview(backwardOverlay)
|
||||||
|
backwardOverlay.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
NSLayoutConstraint.activate([
|
||||||
|
backwardOverlay.centerXAnchor.constraint(equalTo: backwardButton.centerXAnchor),
|
||||||
|
backwardOverlay.centerYAnchor.constraint(equalTo: backwardButton.centerYAnchor),
|
||||||
|
backwardOverlay.widthAnchor.constraint(equalTo: backwardButton.widthAnchor, constant: 20),
|
||||||
|
backwardOverlay.heightAnchor.constraint(equalTo: backwardButton.heightAnchor, constant: 20)
|
||||||
|
])
|
||||||
|
|
||||||
|
let forwardOverlay = UIButton(type: .custom)
|
||||||
|
forwardOverlay.backgroundColor = .clear
|
||||||
|
forwardOverlay.addTarget(self, action: #selector(seekForward), for: .touchUpInside)
|
||||||
|
view.addSubview(forwardOverlay)
|
||||||
|
forwardOverlay.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
NSLayoutConstraint.activate([
|
||||||
|
forwardOverlay.centerXAnchor.constraint(equalTo: forwardButton.centerXAnchor),
|
||||||
|
forwardOverlay.centerYAnchor.constraint(equalTo: forwardButton.centerYAnchor),
|
||||||
|
forwardOverlay.widthAnchor.constraint(equalTo: forwardButton.widthAnchor, constant: 20),
|
||||||
|
forwardOverlay.heightAnchor.constraint(equalTo: forwardButton.heightAnchor, constant: 20)
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func setupSubtitleLabel() {
|
func setupSubtitleLabel() {
|
||||||
subtitleLabel = UILabel()
|
subtitleLabel = UILabel()
|
||||||
subtitleLabel.textAlignment = .center
|
subtitleLabel.textAlignment = .center
|
||||||
|
|
@ -735,6 +775,14 @@ class CustomMediaPlayerViewController: UIViewController {
|
||||||
|
|
||||||
@objc func togglePlayPause() {
|
@objc func togglePlayPause() {
|
||||||
if isPlaying {
|
if isPlaying {
|
||||||
|
if !isControlsVisible {
|
||||||
|
isControlsVisible = true
|
||||||
|
UIView.animate(withDuration: 0.5) {
|
||||||
|
self.controlsContainerView.alpha = 1.0
|
||||||
|
self.skip85Button.alpha = 0.8
|
||||||
|
self.view.layoutIfNeeded()
|
||||||
|
}
|
||||||
|
}
|
||||||
player.pause()
|
player.pause()
|
||||||
playPauseButton.image = UIImage(systemName: "play.fill")
|
playPauseButton.image = UIImage(systemName: "play.fill")
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,26 @@ struct LibraryView: View {
|
||||||
GridItem(.adaptive(minimum: 150), spacing: 12)
|
GridItem(.adaptive(minimum: 150), spacing: 12)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
private var columnsCount: Int {
|
||||||
|
if UIDevice.current.userInterfaceIdiom == .pad {
|
||||||
|
let isLandscape = UIScreen.main.bounds.width > UIScreen.main.bounds.height
|
||||||
|
return isLandscape ? mediaColumnsLandscape : mediaColumnsPortrait
|
||||||
|
} else {
|
||||||
|
return verticalSizeClass == .compact ? mediaColumnsLandscape : mediaColumnsPortrait
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var cellWidth: CGFloat {
|
||||||
|
let keyWindow = UIApplication.shared.connectedScenes
|
||||||
|
.compactMap { ($0 as? UIWindowScene)?.windows.first(where: { $0.isKeyWindow }) }
|
||||||
|
.first
|
||||||
|
let safeAreaInsets = keyWindow?.safeAreaInsets ?? .zero
|
||||||
|
let safeWidth = UIScreen.main.bounds.width - safeAreaInsets.left - safeAreaInsets.right
|
||||||
|
let totalSpacing: CGFloat = 16 * CGFloat(columnsCount + 1)
|
||||||
|
let availableWidth = safeWidth - totalSpacing
|
||||||
|
return availableWidth / CGFloat(columnsCount)
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationView {
|
NavigationView {
|
||||||
ScrollView {
|
ScrollView {
|
||||||
|
|
@ -76,10 +96,6 @@ struct LibraryView: View {
|
||||||
.frame(maxWidth: .infinity)
|
.frame(maxWidth: .infinity)
|
||||||
} else {
|
} else {
|
||||||
LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 12), count: columnsCount), spacing: 12) {
|
LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 12), count: columnsCount), spacing: 12) {
|
||||||
let totalSpacing: CGFloat = 16 * CGFloat(columnsCount + 1)
|
|
||||||
let availableWidth = UIScreen.main.bounds.width - totalSpacing
|
|
||||||
let cellWidth = availableWidth / CGFloat(columnsCount)
|
|
||||||
|
|
||||||
ForEach(libraryManager.bookmarks) { item in
|
ForEach(libraryManager.bookmarks) { item in
|
||||||
if let module = moduleManager.modules.first(where: { $0.id.uuidString == item.moduleId }) {
|
if let module = moduleManager.modules.first(where: { $0.id.uuidString == item.moduleId }) {
|
||||||
NavigationLink(destination: MediaInfoView(title: item.title, imageUrl: item.imageUrl, href: item.href, module: module)) {
|
NavigationLink(destination: MediaInfoView(title: item.title, imageUrl: item.imageUrl, href: item.href, module: module)) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue