feat: set GIF pause and auto resume when toggle content warning overlay

This commit is contained in:
CMK 2021-04-20 13:40:14 +08:00
parent 04d427ea93
commit f6e785a894
4 changed files with 49 additions and 12 deletions

View File

@ -469,6 +469,7 @@ extension StatusSection {
statusView.revealContentWarningButton.isHidden = false statusView.revealContentWarningButton.isHidden = false
statusView.contentWarningOverlayView.isHidden = true statusView.contentWarningOverlayView.isHidden = true
statusView.statusMosaicImageViewContainer.contentWarningOverlayView.isHidden = false statusView.statusMosaicImageViewContainer.contentWarningOverlayView.isHidden = false
statusView.playerContainerView.contentWarningOverlayView.isHidden = false
statusView.updateContentWarningDisplay(isHidden: true, animated: false) statusView.updateContentWarningDisplay(isHidden: true, animated: false)
func updateContentOverlay() { func updateContentOverlay() {

View File

@ -417,26 +417,52 @@ extension StatusProviderFacade {
extension StatusProviderFacade { extension StatusProviderFacade {
static func responseToStatusContentWarningRevealAction(dependency: NotificationViewController, cell: UITableViewCell) {
let status = Future<Status?, Never> { promise in
guard let diffableDataSource = dependency.viewModel.diffableDataSource,
let indexPath = dependency.tableView.indexPath(for: cell),
let item = diffableDataSource.itemIdentifier(for: indexPath) else {
promise(.success(nil))
return
}
switch item {
case .notification(let objectID, _):
dependency.viewModel.fetchedResultsController.managedObjectContext.perform {
let notification = dependency.viewModel.fetchedResultsController.managedObjectContext.object(with: objectID) as! MastodonNotification
promise(.success(notification.status))
}
default:
promise(.success(nil))
}
}
_responseToStatusContentWarningRevealAction(
dependency: dependency,
status: status
)
}
static func responseToStatusContentWarningRevealAction(provider: StatusProvider, cell: UITableViewCell) { static func responseToStatusContentWarningRevealAction(provider: StatusProvider, cell: UITableViewCell) {
_responseToStatusContentWarningRevealAction( _responseToStatusContentWarningRevealAction(
provider: provider, dependency: provider,
status: provider.status(for: cell, indexPath: nil) status: provider.status(for: cell, indexPath: nil)
) )
} }
private static func _responseToStatusContentWarningRevealAction(provider: StatusProvider, status: Future<Status?, Never>) { private static func _responseToStatusContentWarningRevealAction(dependency: NeedsDependency, status: Future<Status?, Never>) {
status status
.compactMap { [weak provider] status -> AnyPublisher<Status?, Never>? in .compactMap { [weak dependency] status -> AnyPublisher<Status?, Never>? in
guard let provider = provider else { return nil } guard let dependency = dependency else { return nil }
guard let _status = status else { return nil } guard let _status = status else { return nil }
return provider.context.managedObjectContext.performChanges { return dependency.context.managedObjectContext.performChanges {
guard let status = provider.context.managedObjectContext.object(with: _status.objectID) as? Status else { return } guard let status = dependency.context.managedObjectContext.object(with: _status.objectID) as? Status else { return }
let appStartUpTimestamp = provider.context.documentStore.appStartUpTimestamp let appStartUpTimestamp = dependency.context.documentStore.appStartUpTimestamp
let isRevealing: Bool = { let isRevealing: Bool = {
if provider.context.documentStore.defaultRevealStatusDict[status.id] == true { if dependency.context.documentStore.defaultRevealStatusDict[status.id] == true {
return true return true
} }
if status.reblog.flatMap({ provider.context.documentStore.defaultRevealStatusDict[$0.id] }) == true { if status.reblog.flatMap({ dependency.context.documentStore.defaultRevealStatusDict[$0.id] }) == true {
return true return true
} }
if let revealedAt = status.revealedAt, revealedAt > appStartUpTimestamp { if let revealedAt = status.revealedAt, revealedAt > appStartUpTimestamp {
@ -446,15 +472,20 @@ extension StatusProviderFacade {
return false return false
}() }()
// toggle reveal // toggle reveal
provider.context.documentStore.defaultRevealStatusDict[status.id] = false dependency.context.documentStore.defaultRevealStatusDict[status.id] = false
status.update(isReveal: !isRevealing) status.update(isReveal: !isRevealing)
status.reblog?.update(isReveal: !isRevealing) status.reblog?.update(isReveal: !isRevealing)
// pause video playback if isRevealing before toggle // pause video playback if isRevealing before toggle
if isRevealing, let attachment = (status.reblog ?? status).mediaAttachments?.first, if isRevealing, let attachment = (status.reblog ?? status).mediaAttachments?.first,
let playerViewModel = provider.context.videoPlaybackService.dequeueVideoPlayerViewModel(for: attachment), playerViewModel.videoKind == .video { let playerViewModel = dependency.context.videoPlaybackService.dequeueVideoPlayerViewModel(for: attachment) {
playerViewModel.pause() playerViewModel.pause()
} }
// resume GIF playback if NOT isRevealing before toggle
if !isRevealing, let attachment = (status.reblog ?? status).mediaAttachments?.first,
let playerViewModel = dependency.context.videoPlaybackService.dequeueVideoPlayerViewModel(for: attachment), playerViewModel.videoKind == .gif {
playerViewModel.play()
}
} }
.map { result in .map { result in
return status return status
@ -464,7 +495,7 @@ extension StatusProviderFacade {
.sink { _ in .sink { _ in
// do nothing // do nothing
} }
.store(in: &provider.context.disposeBag) .store(in: &dependency.context.disposeBag)
} }
} }

View File

@ -22,6 +22,7 @@ final class PlayerContainerView: UIView {
let contentWarningOverlayView: ContentWarningOverlayView = { let contentWarningOverlayView: ContentWarningOverlayView = {
let contentWarningOverlayView = ContentWarningOverlayView() let contentWarningOverlayView = ContentWarningOverlayView()
contentWarningOverlayView.update(cornerRadius: PlayerContainerView.cornerRadius)
return contentWarningOverlayView return contentWarningOverlayView
}() }()

View File

@ -181,6 +181,10 @@ extension ContentWarningOverlayView {
} }
} }
func update(cornerRadius: CGFloat) {
blurVisualEffectView.layer.cornerRadius = cornerRadius
}
} }
extension ContentWarningOverlayView { extension ContentWarningOverlayView {