From 494af4b396c99503716543962ef489a42ecc362d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Corre=CC=82a?= Date: Wed, 14 Aug 2019 13:37:46 -0300 Subject: [PATCH 01/11] feat: add mediacontrol elements inner class --- Clappr.xcodeproj/project.pbxproj | 14 +++++ .../Core/MediaControl/MediaControl.swift | 11 ++++ .../Element/MediaControlElementTests.swift | 61 +++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/Element/MediaControlElementTests.swift diff --git a/Clappr.xcodeproj/project.pbxproj b/Clappr.xcodeproj/project.pbxproj index c8dac8524..cd18b1f94 100644 --- a/Clappr.xcodeproj/project.pbxproj +++ b/Clappr.xcodeproj/project.pbxproj @@ -94,6 +94,8 @@ 32E4021F1FF43534001C2096 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 32E4021D1FF43534001C2096 /* Nimble.framework */; }; 32FC971B20B7257800ABA0C2 /* AVURLAssetWithCookiesBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57937C561FB0DD0D000A239E /* AVURLAssetWithCookiesBuilder.swift */; }; 32FC971C20B72C4200ABA0C2 /* AVURLAssetWithCookiesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57937C581FB0DD27000A239E /* AVURLAssetWithCookiesTests.swift */; }; + 4807611A23046FF400B1BB0C /* MediaControlElementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4807611723046F9B00B1BB0C /* MediaControlElementTests.swift */; }; + 4807611B23046FF600B1BB0C /* MediaControlElementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4807611723046F9B00B1BB0C /* MediaControlElementTests.swift */; }; 4822B6AD220B6F7200D1C134 /* Core+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48563228220B47B10096CDAE /* Core+Ext.swift */; }; 4822B6AF220C72AE00D1C134 /* SeekBubble.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4822B6AE220C72AE00D1C134 /* SeekBubble.swift */; }; 4822B6B1220C72D100D1C134 /* SeekBubbleSide.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4822B6B0220C72D100D1C134 /* SeekBubbleSide.swift */; }; @@ -417,6 +419,7 @@ 32E4020E1FF43262001C2096 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 32E4021C1FF43533001C2096 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/tvOS/Quick.framework; sourceTree = ""; }; 32E4021D1FF43534001C2096 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/tvOS/Nimble.framework; sourceTree = ""; }; + 4807611723046F9B00B1BB0C /* MediaControlElementTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaControlElementTests.swift; sourceTree = ""; }; 4822B6AE220C72AE00D1C134 /* SeekBubble.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeekBubble.swift; sourceTree = ""; }; 4822B6B0220C72D100D1C134 /* SeekBubbleSide.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeekBubbleSide.swift; sourceTree = ""; }; 4822B6B32214961900D1C134 /* ClapprAnimationDuration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClapprAnimationDuration.swift; sourceTree = ""; }; @@ -729,6 +732,14 @@ path = Helper; sourceTree = ""; }; + 4807611623046F5B00B1BB0C /* Element */ = { + isa = PBXGroup; + children = ( + 4807611723046F9B00B1BB0C /* MediaControlElementTests.swift */, + ); + path = Element; + sourceTree = ""; + }; 4822B6B2220C72E300D1C134 /* SeekBubble */ = { isa = PBXGroup; children = ( @@ -1240,6 +1251,7 @@ C9EDF8462162C93900789E2F /* MediaControl */ = { isa = PBXGroup; children = ( + 4807611623046F5B00B1BB0C /* Element */, E7D0BD15218A382E00F5FDF2 /* Seekbar */, C9EDF85C2163E17F00789E2F /* Layout */, C9EDF8492162CCB700789E2F /* MediaControlTests.swift */, @@ -1909,6 +1921,7 @@ 571B7B2B2175015F005C0942 /* AVURLAssetStub.swift in Sources */, 571B7B292175013F005C0942 /* AVFoundationPlaybackTests.swift in Sources */, 32755E2421503A830088724E /* PlaybackTests.swift in Sources */, + 4807611B23046FF600B1BB0C /* MediaControlElementTests.swift in Sources */, 48A29BFA221C8F290004AD3B /* CoreStub.swift in Sources */, 48A29BF9221C8F1A0004AD3B /* AVFoundationPlaybackMock.swift in Sources */, 576786C12188A4C60046508C /* Array+appendOrReplaceTests.swift in Sources */, @@ -1965,6 +1978,7 @@ 322EA4CA20F941300018973A /* AVURLAssetStub.swift in Sources */, 23EDF916224D819600FB0D96 /* SwiftVersionTests.swift in Sources */, C93212472212013700F0C47B /* UIImageViewTests.swift in Sources */, + 4807611A23046FF400B1BB0C /* MediaControlElementTests.swift in Sources */, 9EED97062088E48700D1C84A /* AVPlayerStub.swift in Sources */, 96B4656B1BF6028A0025975A /* UIPluginTests.swift in Sources */, C9EDF8562162D10B00789E2F /* ContainerStub.swift in Sources */, diff --git a/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControl.swift b/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControl.swift index 1b5940630..1e45088f0 100644 --- a/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControl.swift +++ b/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControl.swift @@ -1,6 +1,17 @@ import Foundation open class MediaControl: UICorePlugin, UIGestureRecognizerDelegate { + + open class Element: UICorePlugin, MediaControlPluginType { + open var panel: MediaControlPanel { + return .center + } + + open var position: MediaControlPosition { + return .left + } + } + public var tapGesture: UITapGestureRecognizer? var mediaControlView: MediaControlView = .fromNib() diff --git a/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/Element/MediaControlElementTests.swift b/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/Element/MediaControlElementTests.swift new file mode 100644 index 000000000..d73468035 --- /dev/null +++ b/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/Element/MediaControlElementTests.swift @@ -0,0 +1,61 @@ +import Quick +import Nimble + +@testable import Clappr + +class MediaControlElementTests: QuickSpec { + override func spec() { + var mediaControlElement: MediaControl.Element! + var core: Core! + + beforeEach { + core = CoreStub() + mediaControlElement = StubMediaControlElement(context: core) + } + + describe("MediaControlElement") { + it("is a UICorePlugin") { + expect(mediaControlElement).to(beAKindOf(UICorePlugin.self)) + } + + it("has a view") { + expect(mediaControlElement.view).to(beAKindOf(UIView.self)) + expect(mediaControlElement.view).toNot(beNil()) + } + } + + describe("panel") { + it("is a MediaControlPanel type") { + expect(mediaControlElement.panel).to(beAKindOf(MediaControlPanel.self)) + } + + it("has top, center, bottom and modal properties") { + expect(MediaControlPanel.top).to(beAKindOf(MediaControlPanel.self)) + expect(MediaControlPanel.center).to(beAKindOf(MediaControlPanel.self)) + expect(MediaControlPanel.bottom).to(beAKindOf(MediaControlPanel.self)) + expect(MediaControlPanel.modal).to(beAKindOf(MediaControlPanel.self)) + } + } + + describe("position") { + it("is a MediaControlPosition type") { + expect(mediaControlElement.position).to(beAKindOf(MediaControlPosition.self)) + } + + it("has left, center, right and none properties") { + expect(MediaControlPosition.left).to(beAKindOf(MediaControlPosition.self)) + expect(MediaControlPosition.center).to(beAKindOf(MediaControlPosition.self)) + expect(MediaControlPosition.right).to(beAKindOf(MediaControlPosition.self)) + expect(MediaControlPosition.none).to(beAKindOf(MediaControlPosition.self)) + } + } + } +} + +class StubMediaControlElement: MediaControl.Element { + override class var name: String { + return "StubMediaControlElement" + } + + override func bindEvents() { } +} From bb51830bc72422e465cf39a55a268b2023d67e08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Corre=CC=82a?= Date: Wed, 14 Aug 2019 13:53:42 -0300 Subject: [PATCH 02/11] feat: adhere to mediacontrol element inner class --- Clappr.xcodeproj/project.pbxproj | 16 ++--- Sources/Clappr/Classes/Base/Core.swift | 4 +- .../Core/MediaControl/FullscreenButton.swift | 2 +- .../Core/MediaControl/MediaControl.swift | 16 +---- .../MediaControl/MediaControlElement.swift | 30 +++++++++ .../MediaControl/MediaControlPlugin.swift | 28 --------- .../Plugin/Core/MediaControl/PlayButton.swift | 2 +- .../QuickSeekMediaControlPlugin.swift | 2 +- .../MediaControl/{ => Seekbar}/Seekbar.swift | 2 +- .../Core/MediaControl/TimeIndicator.swift | 2 +- .../MediaControl/FullscreenButtonTests.swift | 2 +- .../MediaControlPluginTests.swift | 61 ------------------- .../Core/MediaControl/MediaControlTests.swift | 8 +-- .../MediaControl/Seekbar/SeekbarTests.swift | 2 +- .../MediaControl/TimeIndicatorTests.swift | 2 +- Tests/Clappr_Tests/CoreTests.swift | 2 +- Tests/Clappr_Tests/PlayButtonTests.swift | 2 +- 17 files changed, 54 insertions(+), 129 deletions(-) create mode 100644 Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControlElement.swift delete mode 100644 Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControlPlugin.swift rename Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/{ => Seekbar}/Seekbar.swift (98%) delete mode 100644 Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/MediaControlPluginTests.swift diff --git a/Clappr.xcodeproj/project.pbxproj b/Clappr.xcodeproj/project.pbxproj index cd18b1f94..6abd5133d 100644 --- a/Clappr.xcodeproj/project.pbxproj +++ b/Clappr.xcodeproj/project.pbxproj @@ -95,7 +95,6 @@ 32FC971B20B7257800ABA0C2 /* AVURLAssetWithCookiesBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57937C561FB0DD0D000A239E /* AVURLAssetWithCookiesBuilder.swift */; }; 32FC971C20B72C4200ABA0C2 /* AVURLAssetWithCookiesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57937C581FB0DD27000A239E /* AVURLAssetWithCookiesTests.swift */; }; 4807611A23046FF400B1BB0C /* MediaControlElementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4807611723046F9B00B1BB0C /* MediaControlElementTests.swift */; }; - 4807611B23046FF600B1BB0C /* MediaControlElementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4807611723046F9B00B1BB0C /* MediaControlElementTests.swift */; }; 4822B6AD220B6F7200D1C134 /* Core+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48563228220B47B10096CDAE /* Core+Ext.swift */; }; 4822B6AF220C72AE00D1C134 /* SeekBubble.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4822B6AE220C72AE00D1C134 /* SeekBubble.swift */; }; 4822B6B1220C72D100D1C134 /* SeekBubbleSide.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4822B6B0220C72D100D1C134 /* SeekBubbleSide.swift */; }; @@ -234,7 +233,7 @@ 9EED97062088E48700D1C84A /* AVPlayerStub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EED97052088E48700D1C84A /* AVPlayerStub.swift */; }; 9EED97082088E5B800D1C84A /* AVPlayerItemStub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EED97072088E5B800D1C84A /* AVPlayerItemStub.swift */; }; AB0A58DF21FA2F520075729E /* QuickSeekAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB0A58DE21FA2F520075729E /* QuickSeekAnimation.swift */; }; - AB163506215AB97800635233 /* MediaControlPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB163505215AB97800635233 /* MediaControlPlugin.swift */; }; + AB163506215AB97800635233 /* MediaControlElement.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB163505215AB97800635233 /* MediaControlElement.swift */; }; AB16350D215AC9FC00635233 /* MediaControlView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB16350A215AC9FC00635233 /* MediaControlView.swift */; }; AB16350F215AC9FC00635233 /* MediaControlView.xib in Resources */ = {isa = PBXBuildFile; fileRef = AB16350B215AC9FC00635233 /* MediaControlView.xib */; }; AB163517215ACA0C00635233 /* MediaControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB163514215ACA0C00635233 /* MediaControl.swift */; }; @@ -262,7 +261,6 @@ C990DAA62194B17D00EB6FFA /* AVFoundationPlaybackStateMachineEventsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C990DAA42194B17D00EB6FFA /* AVFoundationPlaybackStateMachineEventsTests.swift */; }; C9B6D6E7216FDD5400588896 /* FullscreenButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9B6D6E6216FDD5400588896 /* FullscreenButton.swift */; }; C9B8414922E0F454009DE097 /* OrientationObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9B8414822E0F454009DE097 /* OrientationObserver.swift */; }; - C9EDF8482162C98D00789E2F /* MediaControlPluginTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9EDF8472162C98D00789E2F /* MediaControlPluginTests.swift */; }; C9EDF84A2162CCB700789E2F /* MediaControlTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9EDF8492162CCB700789E2F /* MediaControlTests.swift */; }; C9EDF84D2162CEF500789E2F /* UIViewControllerMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9EDF84C2162CEF500789E2F /* UIViewControllerMock.swift */; }; C9EDF84F2162CF1600789E2F /* UINavigationControllerMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9EDF84E2162CF1600789E2F /* UINavigationControllerMock.swift */; }; @@ -531,7 +529,7 @@ 9EED97052088E48700D1C84A /* AVPlayerStub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AVPlayerStub.swift; sourceTree = ""; }; 9EED97072088E5B800D1C84A /* AVPlayerItemStub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AVPlayerItemStub.swift; sourceTree = ""; }; AB0A58DE21FA2F520075729E /* QuickSeekAnimation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuickSeekAnimation.swift; sourceTree = ""; }; - AB163505215AB97800635233 /* MediaControlPlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaControlPlugin.swift; sourceTree = ""; }; + AB163505215AB97800635233 /* MediaControlElement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaControlElement.swift; sourceTree = ""; }; AB16350A215AC9FC00635233 /* MediaControlView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MediaControlView.swift; sourceTree = ""; }; AB16350B215AC9FC00635233 /* MediaControlView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MediaControlView.xib; sourceTree = ""; }; AB163514215ACA0C00635233 /* MediaControl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MediaControl.swift; sourceTree = ""; }; @@ -551,7 +549,6 @@ C990DAA42194B17D00EB6FFA /* AVFoundationPlaybackStateMachineEventsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AVFoundationPlaybackStateMachineEventsTests.swift; sourceTree = ""; }; C9B6D6E6216FDD5400588896 /* FullscreenButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FullscreenButton.swift; sourceTree = ""; }; C9B8414822E0F454009DE097 /* OrientationObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrientationObserver.swift; sourceTree = ""; }; - C9EDF8472162C98D00789E2F /* MediaControlPluginTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaControlPluginTests.swift; sourceTree = ""; }; C9EDF8492162CCB700789E2F /* MediaControlTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaControlTests.swift; sourceTree = ""; }; C9EDF84C2162CEF500789E2F /* UIViewControllerMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewControllerMock.swift; sourceTree = ""; }; C9EDF84E2162CF1600789E2F /* UINavigationControllerMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UINavigationControllerMock.swift; sourceTree = ""; }; @@ -1168,12 +1165,11 @@ isa = PBXGroup; children = ( C9F6D7B2218264E90055A599 /* Seekbar */, - C9F6D7B8218265140055A599 /* Seekbar.swift */, AB163509215AC9E600635233 /* Layout */, + AB163505215AB97800635233 /* MediaControlElement.swift */, E7BEEB58217506C100B8F7FA /* TimeIndicator.swift */, C9B6D6E6216FDD5400588896 /* FullscreenButton.swift */, AB163514215ACA0C00635233 /* MediaControl.swift */, - AB163505215AB97800635233 /* MediaControlPlugin.swift */, 320A7A14216FBF89006D2B24 /* PlayButton.swift */, 4856322A220B4C9C0096CDAE /* QuickSeekMediaControlPlugin.swift */, ); @@ -1255,7 +1251,6 @@ E7D0BD15218A382E00F5FDF2 /* Seekbar */, C9EDF85C2163E17F00789E2F /* Layout */, C9EDF8492162CCB700789E2F /* MediaControlTests.swift */, - C9EDF8472162C98D00789E2F /* MediaControlPluginTests.swift */, C98C014B2166B50E009DFE0A /* FullscreenButtonTests.swift */, E7BEEB5A21751D9600B8F7FA /* TimeIndicatorTests.swift */, 487747D3220B5BCD000167CE /* QuickSeekMediaControlPluginTests.swift */, @@ -1296,6 +1291,7 @@ C9F6D7B2218264E90055A599 /* Seekbar */ = { isa = PBXGroup; children = ( + C9F6D7B8218265140055A599 /* Seekbar.swift */, C9F6D7B3218264F10055A599 /* Views */, ); path = Seekbar; @@ -1921,7 +1917,6 @@ 571B7B2B2175015F005C0942 /* AVURLAssetStub.swift in Sources */, 571B7B292175013F005C0942 /* AVFoundationPlaybackTests.swift in Sources */, 32755E2421503A830088724E /* PlaybackTests.swift in Sources */, - 4807611B23046FF600B1BB0C /* MediaControlElementTests.swift in Sources */, 48A29BFA221C8F290004AD3B /* CoreStub.swift in Sources */, 48A29BF9221C8F1A0004AD3B /* AVFoundationPlaybackMock.swift in Sources */, 576786C12188A4C60046508C /* Array+appendOrReplaceTests.swift in Sources */, @@ -1971,7 +1966,6 @@ E7D0BD17218A389B00F5FDF2 /* SeekbarTests.swift in Sources */, C9EDF84D2162CEF500789E2F /* UIViewControllerMock.swift in Sources */, EDF652241D46829100627C48 /* UIContainerPluginTests.swift in Sources */, - C9EDF8482162C98D00789E2F /* MediaControlPluginTests.swift in Sources */, 5733D1BE21BAA6E4002107D2 /* Dictionary+ExtTests.swift in Sources */, 96912C3E1C21A1AF003A4AFD /* PosterPluginTests.swift in Sources */, FBE6A3E42163EEAE0083C9CC /* Loader+Plugins.swift in Sources */, @@ -2032,7 +2026,7 @@ 96D362CD1D41339400CCB866 /* Playback.swift in Sources */, 96D362D91D41339400CCB866 /* UIView+Ext.swift in Sources */, 96D362DD1D41339400CCB866 /* PlaybackFactory.swift in Sources */, - AB163506215AB97800635233 /* MediaControlPlugin.swift in Sources */, + AB163506215AB97800635233 /* MediaControlElement.swift in Sources */, 96D362E61D41339400CCB866 /* EventProtocol.swift in Sources */, CD57FCF122949BB300AB24CF /* SimpleContainerPlugin.swift in Sources */, C9F6D7B9218265140055A599 /* Seekbar.swift in Sources */, diff --git a/Sources/Clappr/Classes/Base/Core.swift b/Sources/Clappr/Classes/Base/Core.swift index 901971306..c6c9b6517 100644 --- a/Sources/Clappr/Classes/Base/Core.swift +++ b/Sources/Clappr/Classes/Base/Core.swift @@ -141,13 +141,13 @@ open class Core: UIObject, UIGestureRecognizerDelegate { let mediaControl = plugins.first { $0 is MediaControl } if let mediaControl = mediaControl as? MediaControl { - let mediaControlPlugins = plugins.compactMap { $0 as? MediaControlPlugin } + let mediaControlPlugins = plugins.compactMap { $0 as? MediaControl.Element } mediaControl.renderPlugins(mediaControlPlugins) } } private func isNotMediaControlPlugin(_ plugin: Plugin) -> Bool { - return !(plugin is MediaControlPlugin) + return !(plugin is MediaControl.Element) } #endif diff --git a/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/FullscreenButton.swift b/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/FullscreenButton.swift index 2ea64c711..7bf35c4a0 100644 --- a/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/FullscreenButton.swift +++ b/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/FullscreenButton.swift @@ -1,4 +1,4 @@ -open class FullscreenButton: MediaControlPlugin { +open class FullscreenButton: MediaControl.Element { public var fullscreenIcon = UIImage.fromName("fullscreen", for: FullscreenButton.self) public var windowedIcon = UIImage.fromName("fullscreen_exit", for: FullscreenButton.self) diff --git a/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControl.swift b/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControl.swift index 1e45088f0..e5a45f350 100644 --- a/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControl.swift +++ b/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControl.swift @@ -2,16 +2,6 @@ import Foundation open class MediaControl: UICorePlugin, UIGestureRecognizerDelegate { - open class Element: UICorePlugin, MediaControlPluginType { - open var panel: MediaControlPanel { - return .center - } - - open var position: MediaControlPosition { - return .left - } - } - public var tapGesture: UITapGestureRecognizer? var mediaControlView: MediaControlView = .fromNib() @@ -216,7 +206,7 @@ open class MediaControl: UICorePlugin, UIGestureRecognizerDelegate { view.bindFrameToSuperviewBounds() } - func renderPlugins(_ plugins: [MediaControlPlugin]) { + func renderPlugins(_ plugins: [MediaControl.Element]) { let orderedPlugins = sortPluginsIfNeeded(plugins) orderedPlugins.forEach { plugin in mediaControlView.addSubview(plugin.view, in: plugin.panel, at: plugin.position) @@ -231,9 +221,9 @@ open class MediaControl: UICorePlugin, UIGestureRecognizerDelegate { } } - private func sortPluginsIfNeeded(_ plugins: [MediaControlPlugin]) -> [MediaControlPlugin] { + private func sortPluginsIfNeeded(_ plugins: [MediaControl.Element]) -> [MediaControl.Element] { if let pluginsOrder = core?.options[kMediaControlPluginsOrder] as? [String] { - var orderedPlugins = [MediaControlPlugin]() + var orderedPlugins = [MediaControl.Element]() pluginsOrder.forEach { pluginName in if let selectedPlugin = plugins.first(where: { $0.pluginName == pluginName }) { orderedPlugins.append(selectedPlugin) diff --git a/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControlElement.swift b/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControlElement.swift new file mode 100644 index 000000000..e6be6da6f --- /dev/null +++ b/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControlElement.swift @@ -0,0 +1,30 @@ +public protocol MediaControlElementType { + var panel: MediaControlPanel { get } + var position: MediaControlPosition { get } +} + +public enum MediaControlPanel { + case top + case center + case bottom + case modal +} + +public enum MediaControlPosition { + case left + case center + case right + case none +} + +extension MediaControl { + open class Element: UICorePlugin, MediaControlElementType { + open var panel: MediaControlPanel { + return .center + } + + open var position: MediaControlPosition { + return .left + } + } +} diff --git a/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControlPlugin.swift b/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControlPlugin.swift deleted file mode 100644 index 430b8208b..000000000 --- a/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControlPlugin.swift +++ /dev/null @@ -1,28 +0,0 @@ -public protocol MediaControlPluginType { - var panel: MediaControlPanel { get } - var position: MediaControlPosition { get } -} - -public enum MediaControlPanel { - case top - case center - case bottom - case modal -} - -public enum MediaControlPosition { - case left - case center - case right - case none -} - -open class MediaControlPlugin: UICorePlugin, MediaControlPluginType { - open var panel: MediaControlPanel { - return .center - } - - open var position: MediaControlPosition { - return .left - } -} diff --git a/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/PlayButton.swift b/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/PlayButton.swift index e6a34e333..d43ffc4d7 100644 --- a/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/PlayButton.swift +++ b/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/PlayButton.swift @@ -1,4 +1,4 @@ -open class PlayButton: MediaControlPlugin { +open class PlayButton: MediaControl.Element { open class override var name: String { return "PlayButton" } diff --git a/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/QuickSeekMediaControlPlugin.swift b/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/QuickSeekMediaControlPlugin.swift index 7b6fad1b9..8cf81d070 100644 --- a/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/QuickSeekMediaControlPlugin.swift +++ b/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/QuickSeekMediaControlPlugin.swift @@ -36,7 +36,7 @@ public class QuickSeekMediaControlPlugin: QuickSeekPlugin { let pluginsWithoutMediaControl = core?.plugins.filter({ $0.pluginName != MediaControl.name }) return pluginsWithoutMediaControl? .compactMap({ $0 as? UICorePlugin }) - .filter({ ($0 as? MediaControlPlugin)?.panel != .modal }) + .filter({ ($0 as? MediaControl.Element)?.panel != .modal }) } override func shouldSeek(point: CGPoint) -> Bool { diff --git a/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/Seekbar.swift b/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/Seekbar/Seekbar.swift similarity index 98% rename from Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/Seekbar.swift rename to Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/Seekbar/Seekbar.swift index bf030a455..28b646e7d 100644 --- a/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/Seekbar.swift +++ b/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/Seekbar/Seekbar.swift @@ -1,4 +1,4 @@ -class Seekbar: MediaControlPlugin { +class Seekbar: MediaControl.Element { open override class var name: String { return "Seekbar" diff --git a/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/TimeIndicator.swift b/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/TimeIndicator.swift index 1faac3161..8fe3d5d7f 100644 --- a/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/TimeIndicator.swift +++ b/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/TimeIndicator.swift @@ -1,4 +1,4 @@ -open class TimeIndicator: MediaControlPlugin { +open class TimeIndicator: MediaControl.Element { open class override var name: String { return "TimeIndicator" } diff --git a/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/FullscreenButtonTests.swift b/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/FullscreenButtonTests.swift index d14af6d5a..96d2ef042 100644 --- a/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/FullscreenButtonTests.swift +++ b/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/FullscreenButtonTests.swift @@ -35,7 +35,7 @@ class FullscreenButtonTests: QuickSpec { describe("#init") { it("is an MediaControlPlugin type") { - expect(fullscreenButton).to(beAKindOf(MediaControlPlugin.self)) + expect(fullscreenButton).to(beAKindOf(MediaControl.Element.self)) } } diff --git a/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/MediaControlPluginTests.swift b/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/MediaControlPluginTests.swift deleted file mode 100644 index 597f367e8..000000000 --- a/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/MediaControlPluginTests.swift +++ /dev/null @@ -1,61 +0,0 @@ -import Quick -import Nimble - -@testable import Clappr - -class MediaControlPluginTests: QuickSpec { - override func spec() { - var mediaControlPlugin: MediaControlPlugin! - var core: Core! - - beforeEach { - core = CoreStub() - mediaControlPlugin = StubMediaControlPlugin(context: core) - } - - describe("MediaControlPlugin") { - it("is a UICorePlugin") { - expect(mediaControlPlugin).to(beAKindOf(UICorePlugin.self)) - } - - it("has a view") { - expect(mediaControlPlugin.view).to(beAKindOf(UIView.self)) - expect(mediaControlPlugin.view).toNot(beNil()) - } - } - - describe("panel") { - it("is a MediaControlPanel type") { - expect(mediaControlPlugin.panel).to(beAKindOf(MediaControlPanel.self)) - } - - it("has top, center, bottom and modal properties") { - expect(MediaControlPanel.top).to(beAKindOf(MediaControlPanel.self)) - expect(MediaControlPanel.center).to(beAKindOf(MediaControlPanel.self)) - expect(MediaControlPanel.bottom).to(beAKindOf(MediaControlPanel.self)) - expect(MediaControlPanel.modal).to(beAKindOf(MediaControlPanel.self)) - } - } - - describe("position") { - it("is a MediaControlPosition type") { - expect(mediaControlPlugin.position).to(beAKindOf(MediaControlPosition.self)) - } - - it("has left, center, right and none properties") { - expect(MediaControlPosition.left).to(beAKindOf(MediaControlPosition.self)) - expect(MediaControlPosition.center).to(beAKindOf(MediaControlPosition.self)) - expect(MediaControlPosition.right).to(beAKindOf(MediaControlPosition.self)) - expect(MediaControlPosition.none).to(beAKindOf(MediaControlPosition.self)) - } - } - } -} - -class StubMediaControlPlugin: MediaControlPlugin { - override class var name: String { - return "StubMediaControlPlugin" - } - - override func bindEvents() { } -} diff --git a/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/MediaControlTests.swift b/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/MediaControlTests.swift index b3755fa3a..09ff213ea 100644 --- a/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/MediaControlTests.swift +++ b/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/MediaControlTests.swift @@ -374,7 +374,7 @@ class MediaControlTests: QuickSpec { } describe("renderPlugins") { - var plugins: [MediaControlPlugin]! + var plugins: [MediaControl.Element]! var mediaControlViewMock: MediaControlViewMock! beforeEach { @@ -494,7 +494,7 @@ class MediaControlTests: QuickSpec { } } -class MediaControlPluginMock: MediaControlPlugin { +class MediaControlPluginMock: MediaControl.Element { static var _panel: MediaControlPanel = .top static var _position: MediaControlPosition = .left static var didCallRender = false @@ -546,7 +546,7 @@ class TimeIndicatorPluginMock: TimeIndicator { } -class FirstPlugin: MediaControlPlugin { +class FirstPlugin: MediaControl.Element { override class var name: String { return "FirstPlugin" } @@ -573,7 +573,7 @@ class FirstPlugin: MediaControlPlugin { } } -class SecondPlugin: MediaControlPlugin { +class SecondPlugin: MediaControl.Element { override class var name: String { return "SecondPlugin" } diff --git a/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/Seekbar/SeekbarTests.swift b/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/Seekbar/SeekbarTests.swift index 215292077..20b182420 100644 --- a/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/Seekbar/SeekbarTests.swift +++ b/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/Seekbar/SeekbarTests.swift @@ -16,7 +16,7 @@ class SeekbarTests: QuickSpec { describe("Seekbar") { it("is a MediaControlPlugin") { - expect(seekbar).to(beAKindOf(MediaControlPlugin.self)) + expect(seekbar).to(beAKindOf(MediaControl.Element.self)) } } diff --git a/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/TimeIndicatorTests.swift b/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/TimeIndicatorTests.swift index e036baf45..648332af0 100644 --- a/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/TimeIndicatorTests.swift +++ b/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/TimeIndicatorTests.swift @@ -15,7 +15,7 @@ class TimeIndicatorTests: QuickSpec { describe(".TimeIndicatorTests") { it("is a MediaControlPlugin") { - expect(timeIndicator).to(beAKindOf(MediaControlPlugin.self)) + expect(timeIndicator).to(beAKindOf(MediaControl.Element.self)) } describe("#pluginName") { diff --git a/Tests/Clappr_Tests/CoreTests.swift b/Tests/Clappr_Tests/CoreTests.swift index cd447961e..61ff744f8 100644 --- a/Tests/Clappr_Tests/CoreTests.swift +++ b/Tests/Clappr_Tests/CoreTests.swift @@ -812,7 +812,7 @@ class CorePluginMock: CorePlugin { private class MediaControlMock: MediaControl { var didCallRenderPlugins = false - override func renderPlugins(_ plugins: [MediaControlPlugin]) { + override func renderPlugins(_ plugins: [MediaControl.Element]) { didCallRenderPlugins = true } } diff --git a/Tests/Clappr_Tests/PlayButtonTests.swift b/Tests/Clappr_Tests/PlayButtonTests.swift index 52329909f..8d9a8896c 100644 --- a/Tests/Clappr_Tests/PlayButtonTests.swift +++ b/Tests/Clappr_Tests/PlayButtonTests.swift @@ -17,7 +17,7 @@ class PlayButtonTests: QuickSpec { describe("Plugin structure") { context("#init") { it("is an MediaControlPlugin type") { - expect(playButton).to(beAKindOf(MediaControlPlugin.self)) + expect(playButton).to(beAKindOf(MediaControl.Element.self)) } } From f06b5ac2f39ee21b6edd84d19c0f91e8885031cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Corre=CC=82a?= Date: Wed, 14 Aug 2019 14:46:00 -0300 Subject: [PATCH 03/11] docs: update readme file --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 58bf998e1..b72ea1a22 100644 --- a/README.md +++ b/README.md @@ -81,11 +81,11 @@ Clappr comes with four default components: play/pause button, seekbar, fullscree #### Media Control Plugins -You can add your own components into the `MediaControl` by creating your own Media Control Plugin. +You can add your own components into the `MediaControl` by creating your own Media Control Element. To do so, you must: -* Inherit from `MediaControlPlugin`; +* Inherit from `MediaControl.Element`; * Define in which `panel` and `position` the plugin will be rendered; * Have a unique name; From 54f9dd26a229b97db998548dd5ded65bb2ca69ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Corre=CC=82a?= Date: Wed, 14 Aug 2019 14:46:23 -0300 Subject: [PATCH 04/11] chore: mediaControl element options rename --- Sources/Clappr/Classes/Base/Options.swift | 8 ++++---- .../Plugin/Core/MediaControl/MediaControl.swift | 2 +- .../Plugins/Core/MediaControl/MediaControlTests.swift | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Sources/Clappr/Classes/Base/Options.swift b/Sources/Clappr/Classes/Base/Options.swift index dde2dd4cf..79b2ed693 100644 --- a/Sources/Clappr/Classes/Base/Options.swift +++ b/Sources/Clappr/Classes/Base/Options.swift @@ -14,10 +14,10 @@ public let kDefaultAudioSource = "defaultAudioSource" public let kMinDvrSize = "minDvrSize" public let kMediaControlAlwaysVisible = "mediaControlAlwaysVisible" -// List of MediaControl Plugins -public let kMediaControlPlugins = "mediaControlPlugins" -// Order of MediaControl Plugins -public let kMediaControlPluginsOrder = "mediaControlPluginsOrder" +// List of MediaControl Elements +public let kMediaControlElements = "mediaControlElements" +// Order of MediaControl Elements +public let kMediaControlElementsOrder = "mediaControlElementsOrder" public let kLoop = "loop" public let kMetaData = "metadata" diff --git a/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControl.swift b/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControl.swift index e5a45f350..82965d4bc 100644 --- a/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControl.swift +++ b/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControl.swift @@ -222,7 +222,7 @@ open class MediaControl: UICorePlugin, UIGestureRecognizerDelegate { } private func sortPluginsIfNeeded(_ plugins: [MediaControl.Element]) -> [MediaControl.Element] { - if let pluginsOrder = core?.options[kMediaControlPluginsOrder] as? [String] { + if let pluginsOrder = core?.options[kMediaControlElementsOrder] as? [String] { var orderedPlugins = [MediaControl.Element]() pluginsOrder.forEach { pluginName in if let selectedPlugin = plugins.first(where: { $0.pluginName == pluginName }) { diff --git a/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/MediaControlTests.swift b/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/MediaControlTests.swift index 09ff213ea..44fca7399 100644 --- a/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/MediaControlTests.swift +++ b/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/MediaControlTests.swift @@ -442,10 +442,10 @@ class MediaControlTests: QuickSpec { } } - context("when kMediaControlPluginsOrder is passed") { - it("renders the plugins following the kMediaControlPluginsOrder with all plugins specified in the option") { + context("when kMediaControlElementsOrder is passed") { + it("renders the plugins following the kMediaControlElementsOrder with all plugins specified in the option") { let core = Core() - core.options[kMediaControlPluginsOrder] = ["FullscreenButton", "TimeIndicatorPluginMock", "SecondPlugin", "FirstPlugin"] + core.options[kMediaControlElementsOrder] = ["FullscreenButton", "TimeIndicatorPluginMock", "SecondPlugin", "FirstPlugin"] let plugins = [FirstPlugin(context: core), SecondPlugin(context: core), TimeIndicatorPluginMock(context: core), FullscreenButton(context: core), ] let mediaControl = MediaControl(context: core) mediaControl.render() @@ -459,9 +459,9 @@ class MediaControlTests: QuickSpec { expect(bottomRightView?.subviews[3].subviews.first?.accessibilityIdentifier).to(equal("FirstPlugin")) } - it("renders the plugins following the kMediaControlPluginsOrder with only two plugins specified in the option") { + it("renders the plugins following the kMediaControlElementsOrder with only two plugins specified in the option") { let core = Core() - core.options[kMediaControlPluginsOrder] = ["FullscreenButton", "TimeIndicatorPluginMock"] + core.options[kMediaControlElementsOrder] = ["FullscreenButton", "TimeIndicatorPluginMock"] let plugins = [FirstPlugin(context: core), SecondPlugin(context: core), TimeIndicatorPluginMock(context: core), FullscreenButton(context: core), ] let mediaControl = MediaControl(context: core) mediaControl.render() From 56f85c34592841ec3c2782a74e160975602d5e9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Corre=CC=82a?= Date: Wed, 14 Aug 2019 14:54:50 -0300 Subject: [PATCH 05/11] refactor: rename mediacontrol rendering funcions --- Sources/Clappr/Classes/Base/Core.swift | 29 ++++++++++--------- .../Core/MediaControl/MediaControl.swift | 12 ++++---- .../Core/MediaControl/MediaControlTests.swift | 16 +++++----- Tests/Clappr_Tests/CoreTests.swift | 2 +- 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/Sources/Clappr/Classes/Base/Core.swift b/Sources/Clappr/Classes/Base/Core.swift index c6c9b6517..441e00a09 100644 --- a/Sources/Clappr/Classes/Base/Core.swift +++ b/Sources/Clappr/Classes/Base/Core.swift @@ -126,10 +126,6 @@ open class Core: UIObject, UIGestureRecognizerDelegate { #endif #if os(iOS) - private func renderCoreAndMediaControlPlugins() { - renderCorePlugins() - renderMediaControlPlugins() - } private func renderCorePlugins() { plugins.filter { isNotMediaControlPlugin($0) }.forEach { plugin in @@ -137,13 +133,16 @@ open class Core: UIObject, UIGestureRecognizerDelegate { } } - private func renderMediaControlPlugins() { - let mediaControl = plugins.first { $0 is MediaControl } + private var mediaControlPlugin: MediaControl? { + return plugins.first { $0 is MediaControl } as? MediaControl + } - if let mediaControl = mediaControl as? MediaControl { - let mediaControlPlugins = plugins.compactMap { $0 as? MediaControl.Element } - mediaControl.renderPlugins(mediaControlPlugins) - } + private var mediaControlElements: [MediaControl.Element] { + return plugins.compactMap { $0 as? MediaControl.Element } + } + + private func renderMediaControlElements() { + mediaControlPlugin?.renderElements(mediaControlElements) } private func isNotMediaControlPlugin(_ plugin: Plugin) -> Bool { @@ -164,14 +163,18 @@ open class Core: UIObject, UIGestureRecognizerDelegate { } } + private var shouldEnterInFullScreen: Bool { + return optionsUnboxer.fullscreen && !optionsUnboxer.fullscreenControledByApp + } + fileprivate func addToContainer() { #if os(iOS) - if optionsUnboxer.fullscreen && !optionsUnboxer.fullscreenControledByApp { - renderCoreAndMediaControlPlugins() + renderCorePlugins() + renderMediaControlElements() + if shouldEnterInFullScreen { fullscreenHandler?.enterInFullscreen() } else { renderInContainerView() - renderCoreAndMediaControlPlugins() } #else renderInContainerView() diff --git a/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControl.swift b/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControl.swift index 82965d4bc..6e02aaead 100644 --- a/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControl.swift +++ b/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControl.swift @@ -206,17 +206,17 @@ open class MediaControl: UICorePlugin, UIGestureRecognizerDelegate { view.bindFrameToSuperviewBounds() } - func renderPlugins(_ plugins: [MediaControl.Element]) { - let orderedPlugins = sortPluginsIfNeeded(plugins) - orderedPlugins.forEach { plugin in - mediaControlView.addSubview(plugin.view, in: plugin.panel, at: plugin.position) + func renderElements(_ elements: [MediaControl.Element]) { + let orderedElements = sortPluginsIfNeeded(elements) + orderedElements.forEach { element in + mediaControlView.addSubview(element.view, in: element.panel, at: element.position) do { try ObjC.catchException { - plugin.render() + element.render() } } catch { - Logger.logError("\((plugin as Plugin).pluginName) crashed during render (\(error.localizedDescription))", scope: "MediaControl") + Logger.logError("\((element as Plugin).pluginName) crashed during render (\(error.localizedDescription))", scope: "MediaControl") } } } diff --git a/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/MediaControlTests.swift b/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/MediaControlTests.swift index 44fca7399..6bd11e858 100644 --- a/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/MediaControlTests.swift +++ b/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/MediaControlTests.swift @@ -389,7 +389,7 @@ class MediaControlTests: QuickSpec { mediaControl.mediaControlView = mediaControlViewMock mediaControl.render() - mediaControl.renderPlugins(plugins) + mediaControl.renderElements(plugins) expect(mediaControlViewMock.didCallAddSubview).to(beTrue()) } @@ -398,7 +398,7 @@ class MediaControlTests: QuickSpec { mediaControl.mediaControlView = mediaControlViewMock mediaControl.render() - mediaControl.renderPlugins(plugins) + mediaControl.renderElements(plugins) expect(mediaControlViewMock.didCallAddSubviewWithView).to(equal(plugins.first?.view)) } @@ -408,7 +408,7 @@ class MediaControlTests: QuickSpec { mediaControl.mediaControlView = mediaControlViewMock mediaControl.render() - mediaControl.renderPlugins(plugins) + mediaControl.renderElements(plugins) expect(mediaControlViewMock.didCallAddSubviewWithPanel).to(equal(MediaControlPanel.center)) } @@ -418,7 +418,7 @@ class MediaControlTests: QuickSpec { mediaControl.mediaControlView = mediaControlViewMock mediaControl.render() - mediaControl.renderPlugins(plugins) + mediaControl.renderElements(plugins) expect(mediaControlViewMock.didCallAddSubviewWithPosition).to(equal(MediaControlPosition.left)) } @@ -427,7 +427,7 @@ class MediaControlTests: QuickSpec { MediaControlPluginMock._panel = .top mediaControl.render() - mediaControl.renderPlugins(plugins) + mediaControl.renderElements(plugins) expect(MediaControlPluginMock.didCallRender).to(beTrue()) } @@ -436,7 +436,7 @@ class MediaControlTests: QuickSpec { MediaControlPluginMock.crashOnRender = true mediaControl.render() - mediaControl.renderPlugins(plugins) + mediaControl.renderElements(plugins) expect(mediaControl).to(beAKindOf(MediaControl.self)) } @@ -450,7 +450,7 @@ class MediaControlTests: QuickSpec { let mediaControl = MediaControl(context: core) mediaControl.render() - mediaControl.renderPlugins(plugins) + mediaControl.renderElements(plugins) let bottomRightView = mediaControl.mediaControlView.bottomRight expect(bottomRightView?.subviews[0].subviews.first?.accessibilityIdentifier).to(equal("FullscreenButton")) @@ -466,7 +466,7 @@ class MediaControlTests: QuickSpec { let mediaControl = MediaControl(context: core) mediaControl.render() - mediaControl.renderPlugins(plugins) + mediaControl.renderElements(plugins) let bottomRightView = mediaControl.mediaControlView.bottomRight expect(bottomRightView?.subviews[0].subviews.first?.accessibilityIdentifier).to(equal("FullscreenButton")) diff --git a/Tests/Clappr_Tests/CoreTests.swift b/Tests/Clappr_Tests/CoreTests.swift index 61ff744f8..697ffac0c 100644 --- a/Tests/Clappr_Tests/CoreTests.swift +++ b/Tests/Clappr_Tests/CoreTests.swift @@ -812,7 +812,7 @@ class CorePluginMock: CorePlugin { private class MediaControlMock: MediaControl { var didCallRenderPlugins = false - override func renderPlugins(_ plugins: [MediaControl.Element]) { + override func renderElements(_ plugins: [MediaControl.Element]) { didCallRenderPlugins = true } } From e2ae797c34786fad853914f171ec82b9488a2e4a Mon Sep 17 00:00:00 2001 From: John Martins Date: Wed, 14 Aug 2019 16:08:43 -0300 Subject: [PATCH 06/11] refactor: core cleanup --- Sources/Clappr/Classes/Base/Core.swift | 57 ++++++++++++-------------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/Sources/Clappr/Classes/Base/Core.swift b/Sources/Clappr/Classes/Base/Core.swift index 441e00a09..ed6a789c3 100644 --- a/Sources/Clappr/Classes/Base/Core.swift +++ b/Sources/Clappr/Classes/Base/Core.swift @@ -32,20 +32,19 @@ open class Core: UIObject, UIGestureRecognizerDelegate { willSet { activeContainer?.stopListening() - trigger(Event.willChangeActiveContainer.rawValue) + trigger(.willChangeActiveContainer) } didSet { - activeContainer?.on( - Event.willChangePlayback.rawValue) { [weak self] (info: EventUserInfo) in + activeContainer?.on(Event.willChangePlayback.rawValue) { [weak self] info in self?.trigger(Event.willChangeActivePlayback.rawValue, userInfo: info) } - activeContainer?.on( - Event.didChangePlayback.rawValue) { [weak self] (info: EventUserInfo) in + activeContainer?.on(Event.didChangePlayback.rawValue) { [weak self] info in self?.trigger(Event.didChangeActivePlayback.rawValue, userInfo: info) } - trigger(Event.didChangeActiveContainer.rawValue) + + trigger(.didChangeActiveContainer) } } @@ -67,9 +66,7 @@ open class Core: UIObject, UIGestureRecognizerDelegate { addTapGestures() bindEventListeners() - Loader.shared.corePlugins.forEach { plugin in - self.addPlugin(plugin.init(context: self)) - } + Loader.shared.corePlugins.forEach { addPlugin($0.init(context: self)) } } func load() { @@ -109,7 +106,7 @@ open class Core: UIObject, UIGestureRecognizerDelegate { open func attach(to parentView: UIView, controller: UIViewController) { self.parentController = controller self.parentView = parentView - trigger(Event.didAttachView) + trigger(.didAttachView) } open override func render() { @@ -119,21 +116,17 @@ open class Core: UIObject, UIGestureRecognizerDelegate { #if os(tvOS) private func renderPlugins() { - plugins.forEach { plugin in - render(plugin) - } + plugins.forEach(render) } #endif #if os(iOS) private func renderCorePlugins() { - plugins.filter { isNotMediaControlPlugin($0) }.forEach { plugin in - render(plugin) - } + plugins.filter(isNotMediaControlElement).forEach(render) } - private var mediaControlPlugin: MediaControl? { + private var mediaControl: MediaControl? { return plugins.first { $0 is MediaControl } as? MediaControl } @@ -142,10 +135,10 @@ open class Core: UIObject, UIGestureRecognizerDelegate { } private func renderMediaControlElements() { - mediaControlPlugin?.renderElements(mediaControlElements) + mediaControl?.renderElements(mediaControlElements) } - private func isNotMediaControlPlugin(_ plugin: Plugin) -> Bool { + private func isNotMediaControlElement(_ plugin: Plugin) -> Bool { return !(plugin is MediaControl.Element) } #endif @@ -200,25 +193,17 @@ open class Core: UIObject, UIGestureRecognizerDelegate { @objc open func destroy() { Logger.logDebug("destroying", scope: "Core") - trigger(Event.willDestroy.rawValue) + trigger(.willDestroy) Logger.logDebug("destroying listeners", scope: "Core") stopListening() Logger.logDebug("destroying containers", scope: "Core") - containers.forEach { container in container.destroy() } + containers.forEach { $0.destroy() } containers.removeAll() Logger.logDebug("destroying plugins", scope: "Core") - plugins.forEach { plugin in - do { - try ObjC.catchException { - plugin.destroy() - } - } catch { - Logger.logError("\((plugin as Plugin).pluginName) crashed during destroy (\(error.localizedDescription))", scope: "Core") - } - } + plugins.forEach(safeDestroy) plugins.removeAll() Logger.logDebug("destroyed", scope: "Core") @@ -230,6 +215,16 @@ open class Core: UIObject, UIGestureRecognizerDelegate { #endif view.removeFromSuperview() - trigger(Event.didDestroy.rawValue) + trigger(.didDestroy) + } + + private func safeDestroy(_ plugin: Plugin) { + do { + try ObjC.catchException { + plugin.destroy() + } + } catch { + Logger.logError("\((plugin as Plugin).pluginName) crashed during destroy (\(error.localizedDescription))", scope: "Core") + } } } From 0daea35681fca975da5cdd5d9b587744694f02c7 Mon Sep 17 00:00:00 2001 From: John Martins Date: Thu, 15 Aug 2019 10:53:19 -0300 Subject: [PATCH 07/11] refactor: rename places where we used to call plugin insted of elements. --- .../Core/MediaControl/MediaControl.swift | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControl.swift b/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControl.swift index 6e02aaead..887864d18 100644 --- a/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControl.swift +++ b/Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/MediaControl.swift @@ -207,7 +207,7 @@ open class MediaControl: UICorePlugin, UIGestureRecognizerDelegate { } func renderElements(_ elements: [MediaControl.Element]) { - let orderedElements = sortPluginsIfNeeded(elements) + let orderedElements = sortElementsIfNeeded(elements) orderedElements.forEach { element in mediaControlView.addSubview(element.view, in: element.panel, at: element.position) @@ -221,22 +221,22 @@ open class MediaControl: UICorePlugin, UIGestureRecognizerDelegate { } } - private func sortPluginsIfNeeded(_ plugins: [MediaControl.Element]) -> [MediaControl.Element] { - if let pluginsOrder = core?.options[kMediaControlElementsOrder] as? [String] { - var orderedPlugins = [MediaControl.Element]() - pluginsOrder.forEach { pluginName in - if let selectedPlugin = plugins.first(where: { $0.pluginName == pluginName }) { - orderedPlugins.append(selectedPlugin) + private func sortElementsIfNeeded(_ elements: [MediaControl.Element]) -> [MediaControl.Element] { + if let elementsOrder = core?.options[kMediaControlElementsOrder] as? [String] { + var orderedElements = [MediaControl.Element]() + elementsOrder.forEach { elementName in + if let selectedElement = elements.first(where: { $0.pluginName == elementName }) { + orderedElements.append(selectedElement) } else { - Logger.logInfo("Plugin \(pluginName) not found.") + Logger.logInfo("Element \(elementName) not found.") } } - orderedPlugins.append(contentsOf: plugins.filter { !pluginsOrder.contains($0.pluginName) }) + orderedElements.append(contentsOf: elements.filter { !elementsOrder.contains($0.pluginName) }) - return orderedPlugins + return orderedElements } - return plugins + return elements } private func showIfAlwaysVisible() { From 0bdaae90eaa4714c2fdbb80a6e0b3b4807975e9a Mon Sep 17 00:00:00 2001 From: johnmartinstw <50424389+johnmartinstw@users.noreply.github.com> Date: Thu, 15 Aug 2019 11:50:37 -0300 Subject: [PATCH 08/11] Update README.md Co-Authored-By: Bruno Marinho --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b72ea1a22..617c6c1d9 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ You can add your own components into the `MediaControl` by creating your own Med To do so, you must: * Inherit from `MediaControl.Element`; -* Define in which `panel` and `position` the plugin will be rendered; + * Define in which `panel` and `position` the element will be rendered; * Have a unique name; If you provide the same name that an existing plugin (built-in), the plugin will override the existent plugin. From 6ba2368237df2597476a68efff3357745b1fd2c8 Mon Sep 17 00:00:00 2001 From: John Martins Date: Thu, 15 Aug 2019 13:17:42 -0300 Subject: [PATCH 09/11] refactor: minnor changes and replacing where it was plugin to element. --- Sources/Clappr/Classes/Base/Core.swift | 4 +- .../Core/MediaControl/MediaControlTests.swift | 60 +++++++++---------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Sources/Clappr/Classes/Base/Core.swift b/Sources/Clappr/Classes/Base/Core.swift index ed6a789c3..c0a46833a 100644 --- a/Sources/Clappr/Classes/Base/Core.swift +++ b/Sources/Clappr/Classes/Base/Core.swift @@ -37,11 +37,11 @@ open class Core: UIObject, UIGestureRecognizerDelegate { didSet { activeContainer?.on(Event.willChangePlayback.rawValue) { [weak self] info in - self?.trigger(Event.willChangeActivePlayback.rawValue, userInfo: info) + self?.trigger(.willChangeActivePlayback, userInfo: info) } activeContainer?.on(Event.didChangePlayback.rawValue) { [weak self] info in - self?.trigger(Event.didChangeActivePlayback.rawValue, userInfo: info) + self?.trigger(.didChangeActivePlayback, userInfo: info) } trigger(.didChangeActiveContainer) diff --git a/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/MediaControlTests.swift b/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/MediaControlTests.swift index 6bd11e858..9587fbb99 100644 --- a/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/MediaControlTests.swift +++ b/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/MediaControlTests.swift @@ -373,52 +373,52 @@ class MediaControlTests: QuickSpec { } } - describe("renderPlugins") { - var plugins: [MediaControl.Element]! + describe("renderElements") { + var elements: [MediaControl.Element]! var mediaControlViewMock: MediaControlViewMock! beforeEach { - plugins = [MediaControlPluginMock(context: coreStub)] + elements = [MediaControlPluginMock(context: coreStub)] mediaControlViewMock = MediaControlViewMock() MediaControlPluginMock.reset() } - context("for any plugin configuration") { + context("for any element configuration") { it("always calls the MediaControlView to position the view") { let mediaControl = MediaControl(context: coreStub) mediaControl.mediaControlView = mediaControlViewMock mediaControl.render() - mediaControl.renderElements(plugins) + mediaControl.renderElements(elements) expect(mediaControlViewMock.didCallAddSubview).to(beTrue()) } - it("always calls the MediaControlView passing the plugin's view") { + it("always calls the MediaControlView passing the element's view") { mediaControl.mediaControlView = mediaControlViewMock mediaControl.render() - mediaControl.renderElements(plugins) + mediaControl.renderElements(elements) - expect(mediaControlViewMock.didCallAddSubviewWithView).to(equal(plugins.first?.view)) + expect(mediaControlViewMock.didCallAddSubviewWithView).to(equal(elements.first?.view)) } - it("always calls the MediaControlView passing the plugin's panel") { + it("always calls the MediaControlView passing the element's panel") { MediaControlPluginMock._panel = .center mediaControl.mediaControlView = mediaControlViewMock mediaControl.render() - mediaControl.renderElements(plugins) + mediaControl.renderElements(elements) expect(mediaControlViewMock.didCallAddSubviewWithPanel).to(equal(MediaControlPanel.center)) } - it("always calls the MediaControlView passing the plugin's position") { + it("always calls the MediaControlView passing the element's position") { MediaControlPluginMock._position = .left mediaControl.mediaControlView = mediaControlViewMock mediaControl.render() - mediaControl.renderElements(plugins) + mediaControl.renderElements(elements) expect(mediaControlViewMock.didCallAddSubviewWithPosition).to(equal(MediaControlPosition.left)) } @@ -427,52 +427,52 @@ class MediaControlTests: QuickSpec { MediaControlPluginMock._panel = .top mediaControl.render() - mediaControl.renderElements(plugins) + mediaControl.renderElements(elements) expect(MediaControlPluginMock.didCallRender).to(beTrue()) } - it("protect the main thread when plugin crashes in render") { + it("protect the main thread when element crashes in render") { MediaControlPluginMock.crashOnRender = true mediaControl.render() - mediaControl.renderElements(plugins) + mediaControl.renderElements(elements) expect(mediaControl).to(beAKindOf(MediaControl.self)) } } context("when kMediaControlElementsOrder is passed") { - it("renders the plugins following the kMediaControlElementsOrder with all plugins specified in the option") { + it("renders the elements following the kMediaControlElementsOrder with all elements specified in the option") { let core = Core() - core.options[kMediaControlElementsOrder] = ["FullscreenButton", "TimeIndicatorPluginMock", "SecondPlugin", "FirstPlugin"] - let plugins = [FirstPlugin(context: core), SecondPlugin(context: core), TimeIndicatorPluginMock(context: core), FullscreenButton(context: core), ] + core.options[kMediaControlElementsOrder] = ["FullscreenButton", "TimeIndicatorPluginMock", "SecondElement", "FirstElement"] + let elements = [FirstElement(context: core), SecondElement(context: core), TimeIndicatorPluginMock(context: core), FullscreenButton(context: core), ] let mediaControl = MediaControl(context: core) mediaControl.render() - mediaControl.renderElements(plugins) + mediaControl.renderElements(elements) let bottomRightView = mediaControl.mediaControlView.bottomRight expect(bottomRightView?.subviews[0].subviews.first?.accessibilityIdentifier).to(equal("FullscreenButton")) expect(bottomRightView?.subviews[1].subviews.first?.accessibilityIdentifier).to(equal("timeIndicator")) - expect(bottomRightView?.subviews[2].subviews.first?.accessibilityIdentifier).to(equal("SecondPlugin")) - expect(bottomRightView?.subviews[3].subviews.first?.accessibilityIdentifier).to(equal("FirstPlugin")) + expect(bottomRightView?.subviews[2].subviews.first?.accessibilityIdentifier).to(equal("SecondElement")) + expect(bottomRightView?.subviews[3].subviews.first?.accessibilityIdentifier).to(equal("FirstElement")) } - it("renders the plugins following the kMediaControlElementsOrder with only two plugins specified in the option") { + it("renders the elements following the kMediaControlElementsOrder with only two elements specified in the option") { let core = Core() core.options[kMediaControlElementsOrder] = ["FullscreenButton", "TimeIndicatorPluginMock"] - let plugins = [FirstPlugin(context: core), SecondPlugin(context: core), TimeIndicatorPluginMock(context: core), FullscreenButton(context: core), ] + let elements = [FirstElement(context: core), SecondElement(context: core), TimeIndicatorPluginMock(context: core), FullscreenButton(context: core), ] let mediaControl = MediaControl(context: core) mediaControl.render() - mediaControl.renderElements(plugins) + mediaControl.renderElements(elements) let bottomRightView = mediaControl.mediaControlView.bottomRight expect(bottomRightView?.subviews[0].subviews.first?.accessibilityIdentifier).to(equal("FullscreenButton")) expect(bottomRightView?.subviews[1].subviews.first?.accessibilityIdentifier).to(equal("timeIndicator")) - expect(bottomRightView?.subviews[2].subviews.first?.accessibilityIdentifier).to(equal("FirstPlugin")) - expect(bottomRightView?.subviews[3].subviews.first?.accessibilityIdentifier).to(equal("SecondPlugin")) + expect(bottomRightView?.subviews[2].subviews.first?.accessibilityIdentifier).to(equal("FirstElement")) + expect(bottomRightView?.subviews[3].subviews.first?.accessibilityIdentifier).to(equal("SecondElement")) } } } @@ -546,9 +546,9 @@ class TimeIndicatorPluginMock: TimeIndicator { } -class FirstPlugin: MediaControl.Element { +class FirstElement: MediaControl.Element { override class var name: String { - return "FirstPlugin" + return "FirstElement" } var button: UIButton! { @@ -573,9 +573,9 @@ class FirstPlugin: MediaControl.Element { } } -class SecondPlugin: MediaControl.Element { +class SecondElement: MediaControl.Element { override class var name: String { - return "SecondPlugin" + return "SecondElement" } var button: UIButton! { From 01bb6b68dd04cd3729c0b519e730bdce96c18c84 Mon Sep 17 00:00:00 2001 From: John Martins Date: Thu, 15 Aug 2019 13:33:46 -0300 Subject: [PATCH 10/11] refactor: rename where was plugin to element. --- .../Core/MediaControl/MediaControlTests.swift | 40 +++++++++---------- Tests/Clappr_Tests/CoreTests.swift | 4 +- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/MediaControlTests.swift b/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/MediaControlTests.swift index 9587fbb99..01a53068d 100644 --- a/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/MediaControlTests.swift +++ b/Tests/Clappr_Tests/Classes/Plugins/Core/MediaControl/MediaControlTests.swift @@ -378,9 +378,9 @@ class MediaControlTests: QuickSpec { var mediaControlViewMock: MediaControlViewMock! beforeEach { - elements = [MediaControlPluginMock(context: coreStub)] + elements = [MediaControlElementMock(context: coreStub)] mediaControlViewMock = MediaControlViewMock() - MediaControlPluginMock.reset() + MediaControlElementMock.reset() } context("for any element configuration") { @@ -404,7 +404,7 @@ class MediaControlTests: QuickSpec { } it("always calls the MediaControlView passing the element's panel") { - MediaControlPluginMock._panel = .center + MediaControlElementMock._panel = .center mediaControl.mediaControlView = mediaControlViewMock mediaControl.render() @@ -414,7 +414,7 @@ class MediaControlTests: QuickSpec { } it("always calls the MediaControlView passing the element's position") { - MediaControlPluginMock._position = .left + MediaControlElementMock._position = .left mediaControl.mediaControlView = mediaControlViewMock mediaControl.render() @@ -424,16 +424,16 @@ class MediaControlTests: QuickSpec { } it("always calls the method render") { - MediaControlPluginMock._panel = .top + MediaControlElementMock._panel = .top mediaControl.render() mediaControl.renderElements(elements) - expect(MediaControlPluginMock.didCallRender).to(beTrue()) + expect(MediaControlElementMock.didCallRender).to(beTrue()) } it("protect the main thread when element crashes in render") { - MediaControlPluginMock.crashOnRender = true + MediaControlElementMock.crashOnRender = true mediaControl.render() mediaControl.renderElements(elements) @@ -445,8 +445,8 @@ class MediaControlTests: QuickSpec { context("when kMediaControlElementsOrder is passed") { it("renders the elements following the kMediaControlElementsOrder with all elements specified in the option") { let core = Core() - core.options[kMediaControlElementsOrder] = ["FullscreenButton", "TimeIndicatorPluginMock", "SecondElement", "FirstElement"] - let elements = [FirstElement(context: core), SecondElement(context: core), TimeIndicatorPluginMock(context: core), FullscreenButton(context: core), ] + core.options[kMediaControlElementsOrder] = ["FullscreenButton", "TimeIndicatorElementMock", "SecondElement", "FirstElement"] + let elements = [FirstElement(context: core), SecondElement(context: core), TimeIndicatorElementMock(context: core), FullscreenButton(context: core), ] let mediaControl = MediaControl(context: core) mediaControl.render() @@ -461,8 +461,8 @@ class MediaControlTests: QuickSpec { it("renders the elements following the kMediaControlElementsOrder with only two elements specified in the option") { let core = Core() - core.options[kMediaControlElementsOrder] = ["FullscreenButton", "TimeIndicatorPluginMock"] - let elements = [FirstElement(context: core), SecondElement(context: core), TimeIndicatorPluginMock(context: core), FullscreenButton(context: core), ] + core.options[kMediaControlElementsOrder] = ["FullscreenButton", "TimeIndicatorElementMock"] + let elements = [FirstElement(context: core), SecondElement(context: core), TimeIndicatorElementMock(context: core), FullscreenButton(context: core), ] let mediaControl = MediaControl(context: core) mediaControl.render() @@ -494,36 +494,36 @@ class MediaControlTests: QuickSpec { } } -class MediaControlPluginMock: MediaControl.Element { +class MediaControlElementMock: MediaControl.Element { static var _panel: MediaControlPanel = .top static var _position: MediaControlPosition = .left static var didCallRender = false static var crashOnRender = false override class var name: String { - return "MediaControlPluginMock" + return "MediaControlElementMock" } open override var panel: MediaControlPanel { - return MediaControlPluginMock._panel + return MediaControlElementMock._panel } open override var position: MediaControlPosition { - return MediaControlPluginMock._position + return MediaControlElementMock._position } override func bindEvents() { } override func render() { - MediaControlPluginMock.didCallRender = true + MediaControlElementMock.didCallRender = true - if MediaControlPluginMock.crashOnRender { + if MediaControlElementMock.crashOnRender { codeThatCrashes() } } static func reset() { - MediaControlPluginMock.didCallRender = false + MediaControlElementMock.didCallRender = false } private func codeThatCrashes() { @@ -531,9 +531,9 @@ class MediaControlPluginMock: MediaControl.Element { } } -class TimeIndicatorPluginMock: TimeIndicator { +class TimeIndicatorElementMock: TimeIndicator { override class var name: String { - return "TimeIndicatorPluginMock" + return "TimeIndicatorElementMock" } open override var panel: MediaControlPanel { diff --git a/Tests/Clappr_Tests/CoreTests.swift b/Tests/Clappr_Tests/CoreTests.swift index 697ffac0c..b0f9e121e 100644 --- a/Tests/Clappr_Tests/CoreTests.swift +++ b/Tests/Clappr_Tests/CoreTests.swift @@ -695,7 +695,7 @@ class CoreTests: QuickSpec { #if os(iOS) it("doesnt add plugin as subview if it is a MediaControlPlugin") { let core = Core() - let plugin = MediaControlPluginMock(context: core) + let plugin = MediaControlElementMock(context: core) core.addPlugin(plugin) core.render() @@ -706,7 +706,7 @@ class CoreTests: QuickSpec { it("calls the mediacontrol to add the plugins into the panels") { let core = CoreFactory.create(with: [:]) let mediaControlMock = MediaControlMock(context: core) - let mediaControlPluginMock = MediaControlPluginMock(context: core) + let mediaControlPluginMock = MediaControlElementMock(context: core) core.addPlugin(mediaControlMock) core.addPlugin(mediaControlPluginMock) From 6e6561e754fa2e76aa4e92c133ee7bdb3bbb08b3 Mon Sep 17 00:00:00 2001 From: John Martins Date: Thu, 15 Aug 2019 18:08:50 -0300 Subject: [PATCH 11/11] refactor: minnor changes --- Tests/Clappr_Tests/CoreTests.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/Clappr_Tests/CoreTests.swift b/Tests/Clappr_Tests/CoreTests.swift index b0f9e121e..6aed1244e 100644 --- a/Tests/Clappr_Tests/CoreTests.swift +++ b/Tests/Clappr_Tests/CoreTests.swift @@ -712,7 +712,7 @@ class CoreTests: QuickSpec { core.addPlugin(mediaControlPluginMock) core.render() - expect(mediaControlMock.didCallRenderPlugins).to(beTrue()) + expect(mediaControlMock.didCallRenderElements).to(beTrue()) } #endif @@ -810,10 +810,10 @@ class CorePluginMock: CorePlugin { #if os(iOS) private class MediaControlMock: MediaControl { - var didCallRenderPlugins = false + var didCallRenderElements = false override func renderElements(_ plugins: [MediaControl.Element]) { - didCallRenderPlugins = true + didCallRenderElements = true } } #endif