Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image viewer #338

Merged
merged 15 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 31 additions & 35 deletions ElementX.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,11 @@ import SwiftUI
import UIKit

struct FilePreviewScreen: View {
@Environment(\.colorScheme) private var colorScheme

var counterColor: Color {
colorScheme == .light ? .element.secondaryContent : .element.tertiaryContent
}

@ObservedObject var context: FilePreviewViewModel.Context

var body: some View {
PreviewController(fileURL: context.viewState.fileURL, title: context.viewState.title)
.ignoresSafeArea()
}
}

Expand Down

This file was deleted.

35 changes: 0 additions & 35 deletions ElementX/Sources/Screens/MediaPlayer/MediaPlayerViewModel.swift

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@
// limitations under the License.
//

import Foundation
import SwiftUI

enum MediaPlayerViewModelAction {
case cancel
}

struct MediaPlayerViewState: BindableState {
let mediaURL: URL
let autoplay: Bool
}

enum MediaPlayerViewAction {
case cancel
struct ActivityCoordinator: CoordinatorProtocol {
let items: [Any]

func toPresentable() -> AnyView {
return AnyView(UIActivityViewControllerWrapper(activityItems: items)
.presentationDetents([.medium])
.ignoresSafeArea())
}
}
22 changes: 17 additions & 5 deletions ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,25 @@ final class RoomScreenCoordinator: CoordinatorProtocol {
// MARK: - Private

private func displayVideo(for videoURL: URL) {
let params = VideoPlayerCoordinatorParameters(videoURL: videoURL)
let params = VideoPlayerCoordinatorParameters(videoURL: videoURL, isModallyPresented: false)
let coordinator = VideoPlayerCoordinator(parameters: params)
coordinator.callback = { [weak self] _ in
self?.navigationController.pop()
}

navigationController.push(coordinator)
if params.isModallyPresented {
coordinator.callback = { [weak self] _ in
self?.navigationController.dismissSheet()
}

let controller = NavigationController()
controller.setRootCoordinator(coordinator)

navigationController.presentSheet(controller)
} else {
coordinator.callback = { [weak self] _ in
self?.navigationController.pop()
}

navigationController.push(coordinator)
}
}

private func displayFile(for fileURL: URL, with title: String?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import SwiftUI

struct VideoPlayerCoordinatorParameters {
let videoURL: URL
let isModallyPresented: Bool
}

enum VideoPlayerCoordinatorAction {
Expand All @@ -34,7 +35,8 @@ final class VideoPlayerCoordinator: CoordinatorProtocol {
init(parameters: VideoPlayerCoordinatorParameters) {
self.parameters = parameters

viewModel = VideoPlayerViewModel(videoURL: parameters.videoURL)
viewModel = VideoPlayerViewModel(videoURL: parameters.videoURL,
isModallyPresented: parameters.isModallyPresented)
}

// MARK: - Public
Expand All @@ -51,6 +53,10 @@ final class VideoPlayerCoordinator: CoordinatorProtocol {
}
}
}

func stop() {
deconfigureAudioSession(.sharedInstance())
}

func toPresentable() -> AnyView {
AnyView(VideoPlayerScreen(context: viewModel.context))
Expand All @@ -62,10 +68,18 @@ final class VideoPlayerCoordinator: CoordinatorProtocol {
do {
try session.setCategory(.playback,
mode: .default,
options: [.defaultToSpeaker, .allowBluetooth, .allowBluetoothA2DP])
options: [.allowBluetooth, .allowBluetoothA2DP])
try session.setActive(true)
} catch {
MXLog.debug("Configure audio session failed: \(error)")
}
}

private func deconfigureAudioSession(_ session: AVAudioSession) {
do {
try session.setActive(false, options: .notifyOthersOnDeactivation)
} catch {
MXLog.debug("Deconfigure audio session failed: \(error)")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ enum VideoPlayerViewModelAction {
}

struct VideoPlayerViewState: BindableState {
var videoURL: URL
var autoplay: Bool
let videoURL: URL
let autoplay: Bool
let isModallyPresented: Bool
}

enum VideoPlayerViewAction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ typealias VideoPlayerViewModelType = StateStoreViewModel<VideoPlayerViewState, V
class VideoPlayerViewModel: VideoPlayerViewModelType, VideoPlayerViewModelProtocol {
var callback: ((VideoPlayerViewModelAction) -> Void)?

init(videoURL: URL, autoplay: Bool = true) {
init(videoURL: URL, autoplay: Bool = true, isModallyPresented: Bool = true) {
super.init(initialViewState: VideoPlayerViewState(videoURL: videoURL,
autoplay: autoplay))
autoplay: autoplay,
isModallyPresented: isModallyPresented))
}

override func process(viewAction: VideoPlayerViewAction) async {
Expand Down
34 changes: 21 additions & 13 deletions ElementX/Sources/Screens/VideoPlayer/View/VideoPlayerScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,33 @@ struct VideoPlayerScreen: View {

var body: some View {
VideoPlayer(player: player())
.ignoresSafeArea()
.background(Color.black.ignoresSafeArea())
.navigationBarTitleDisplayMode(.inline)
.navigationBarBackButtonHidden()
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button {
context.send(viewAction: .cancel)
} label: {
Image(systemName: "chevron.backward")
.foregroundColor(.white)
.fontWeight(.semibold)
}
.toolbar { toolbar }
.onSwipeGesture(minimumDistance: 3.0, down: {
if context.viewState.isModallyPresented {
context.send(viewAction: .cancel)
}
}, right: {
if !context.viewState.isModallyPresented {
context.send(viewAction: .cancel)
}
}
.onSwipeGesture(minimumDistance: 3.0, right: {
context.send(viewAction: .cancel)
})
}

@ToolbarContentBuilder
var toolbar: some ToolbarContent {
ToolbarItem(placement: .cancellationAction) {
Button { context.send(viewAction: .cancel) } label: {
Image(systemName: context.viewState.isModallyPresented ? "xmark" : "chevron.backward")
.foregroundColor(.white)
.fontWeight(.semibold)
}
.accessibilityIdentifier("dismissButton")
}
}

private func player() -> AVPlayer {
let player = AVPlayer(url: context.viewState.videoURL)
if context.viewState.autoplay {
Expand Down
Loading