<commit_before>public class Core: UIBaseObject, UIGestureRecognizerDelegate {
    public private(set) var options: Options
    public private(set) var container: Container!
    public private(set) var mediaControl: MediaControl!
    public private(set) var plugins: [UICorePlugin] = []
    
    public var parentController: UIViewController?
    public var parentView: UIView?
    private var loader: Loader
    private lazy var fullscreenController = FullscreenController(nibName: nil, bundle: nil)
    
    required public init?(coder aDecoder: NSCoder) {
        fatalError("Should be using init(sources:[NSURL]) instead")
    }
    
    public required init(loader: Loader = Loader(), options: Options = [:]) {
        self.loader = loader
        self.options = options
        super.init(frame: CGRectZero)
        setup()
    }
    
    private func setup() {
        backgroundColor = UIColor.blackColor()
        createContainers()
        createMediaControl()
        bindEventListeners()
    }
    
    private func createContainers() {
        let factory = ContainerFactory(loader: loader, options: options)
        container = factory.createContainer()
    }
    
    private func createMediaControl() {
        mediaControl = loader.mediaControl.create()
        addTapRecognizer()
        
        if let container = container {
            mediaControl.setup(container)
        }
    }
    
    private func addTapRecognizer() {
        let tapRecognizer = UITapGestureRecognizer(target: mediaControl, action: #selector(MediaControl.toggleVisibility))
        tapRecognizer.delegate = self
        addGestureRecognizer(tapRecognizer)
    }
    
    private func bindEventListeners() {
        listenTo(mediaControl, eventName: MediaControlEvent.FullscreenEnter.rawValue, callback: enterFullscreen)
        listenTo(mediaControl, eventName: MediaControlEvent.FullscreenExit.rawValue, callback: exitFullscreen)
    }
    
    private func enterFullscreen(_: EventUserInfo) {
        mediaControl.fullscreen = true
        fullscreenController.view.backgroundColor = UIColor.blackColor()
        fullscreenController.modalPresentationStyle = .OverFullScreen
        parentController?.presentViewController(fullscreenController, animated: false, completion: nil)
        fullscreenController.view.addSubviewMatchingConstraints(self)
    }
    
    private func exitFullscreen(_: EventUserInfo) {
        renderInContainerView()
        fullscreenController.dismissViewControllerAnimated(false, completion: nil)
    }
    
    private func renderInContainerView() {
        mediaControl.fullscreen = false
        parentView?.addSubviewMatchingConstraints(self)
    }
    
    public override func render() {
        addToContainer()
        
        plugins.forEach(installPlugin)
        
        addSubviewMatchingConstraints(container)
        addSubviewMatchingConstraints(mediaControl)
        
        mediaControl.render()
        container.render()
    }
    
    private func addToContainer() {
        if let fullscreen = options[kFullscreen] as? Bool {
            fullscreen ? enterFullscreen([:]) : renderInContainerView()
        } else {
            renderInContainerView()
        }
    }
    
    private func installPlugin(plugin: UICorePlugin) {
        addSubview(plugin)
        plugin.render()
    }
    
    public func addPlugin(plugin: UICorePlugin) {
        plugin.core = self
        plugins.append(plugin)
    }
    
    public func hasPlugin(pluginClass: AnyClass) -> Bool {
        return plugins.filter({$0.isKindOfClass(pluginClass)}).count > 0
    }
    
    public func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
        return touch.view!.isKindOfClass(Container) || touch.view == mediaControl
    }
    
    public func setFullscreen(fullscreen: Bool) {
        fullscreen ? enterFullscreen(nil) : exitFullscreen([:])
    }
}<commit_msg>Core: prevent errors when calling setFullscreen to true when already on fullscreen<commit_after>public class Core: UIBaseObject, UIGestureRecognizerDelegate {
    public private(set) var options: Options
    public private(set) var container: Container!
    public private(set) var mediaControl: MediaControl!
    public private(set) var plugins: [UICorePlugin] = []
    
    public var parentController: UIViewController?
    public var parentView: UIView?
    private var loader: Loader
    private lazy var fullscreenController = FullscreenController(nibName: nil, bundle: nil)
    
    required public init?(coder aDecoder: NSCoder) {
        fatalError("Should be using init(sources:[NSURL]) instead")
    }
    
    public required init(loader: Loader = Loader(), options: Options = [:]) {
        self.loader = loader
        self.options = options
        super.init(frame: CGRectZero)
        setup()
    }
    
    private func setup() {
        backgroundColor = UIColor.blackColor()
        createContainers()
        createMediaControl()
        bindEventListeners()
    }
    
    private func createContainers() {
        let factory = ContainerFactory(loader: loader, options: options)
        container = factory.createContainer()
    }
    
    private func createMediaControl() {
        mediaControl = loader.mediaControl.create()
        addTapRecognizer()
        
        if let container = container {
            mediaControl.setup(container)
        }
    }
    
    private func addTapRecognizer() {
        let tapRecognizer = UITapGestureRecognizer(target: mediaControl, action: #selector(MediaControl.toggleVisibility))
        tapRecognizer.delegate = self
        addGestureRecognizer(tapRecognizer)
    }
    
    private func bindEventListeners() {
        listenTo(mediaControl, eventName: MediaControlEvent.FullscreenEnter.rawValue, callback: enterFullscreen)
        listenTo(mediaControl, eventName: MediaControlEvent.FullscreenExit.rawValue, callback: exitFullscreen)
    }
    
    private func enterFullscreen(_: EventUserInfo) {
        mediaControl.fullscreen = true
        fullscreenController.view.backgroundColor = UIColor.blackColor()
        fullscreenController.modalPresentationStyle = .OverFullScreen
        parentController?.presentViewController(fullscreenController, animated: false, completion: nil)
        fullscreenController.view.addSubviewMatchingConstraints(self)
    }
    
    private func exitFullscreen(_: EventUserInfo) {
        renderInContainerView()
        fullscreenController.dismissViewControllerAnimated(false, completion: nil)
    }
    
    private func renderInContainerView() {
        mediaControl.fullscreen = false
        parentView?.addSubviewMatchingConstraints(self)
    }
    
    public override func render() {
        addToContainer()
        
        plugins.forEach(installPlugin)
        
        addSubviewMatchingConstraints(container)
        addSubviewMatchingConstraints(mediaControl)
        
        mediaControl.render()
        container.render()
    }
    
    private func addToContainer() {
        if let fullscreen = options[kFullscreen] as? Bool {
            fullscreen ? enterFullscreen([:]) : renderInContainerView()
        } else {
            renderInContainerView()
        }
    }
    
    private func installPlugin(plugin: UICorePlugin) {
        addSubview(plugin)
        plugin.render()
    }
    
    public func addPlugin(plugin: UICorePlugin) {
        plugin.core = self
        plugins.append(plugin)
    }
    
    public func hasPlugin(pluginClass: AnyClass) -> Bool {
        return plugins.filter({$0.isKindOfClass(pluginClass)}).count > 0
    }
    
    public func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
        return touch.view!.isKindOfClass(Container) || touch.view == mediaControl
    }
    
    public func setFullscreen(fullscreen: Bool) {
        let isFullscreen = self.fullscreenController.presentingViewController != nil
        guard fullscreen != isFullscreen else {return}
        fullscreen ? enterFullscreen(nil) : exitFullscreen([:])
    }
}
{'fraction_non_alphanumeric': 0.0807108478341355, 'fraction_numerical': 0.0004936443292607676, 'mean_word_length': 2.896153846153846, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1975414', 'n_tokens_mistral': 2144, 'n_tokens_neox': 2093, 'n_words': 456}