<commit_before>/*
Copyright 2015-present Google Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import UIKit
import MaterialComponents

class MDCCatalogComponentsController: UICollectionViewController {

  let spacing = CGFloat(1)
  let inset = CGFloat(16)
  let node: CBCNode
  var headerViewController: MDCFlexibleHeaderViewController
  let imageNames = NSMutableArray()

  init(collectionViewLayout ignoredLayout: UICollectionViewLayout, node: CBCNode) {
    self.node = node

    let layout = UICollectionViewFlowLayout()
    let sectionInset:CGFloat = spacing
    layout.sectionInset = UIEdgeInsetsMake(sectionInset, sectionInset, sectionInset, sectionInset)
    layout.minimumInteritemSpacing = spacing
    layout.minimumLineSpacing = spacing

    self.headerViewController = MDCFlexibleHeaderViewController()

    super.init(collectionViewLayout: layout)

    self.title = "Material Design Components"

    self.addChildViewController(self.headerViewController)

    self.headerViewController.headerView.maximumHeight = 128
    self.headerViewController.headerView.minimumHeight = 72

    self.collectionView?.registerClass(MDCCatalogCollectionViewCell.self,
      forCellWithReuseIdentifier: "MDCCatalogCollectionViewCell")
    self.collectionView?.backgroundColor = UIColor(white: 0.9, alpha: 1)
  }

  convenience init(node: CBCNode) {
    self.init(collectionViewLayout: UICollectionViewLayout(), node: node)
  }

  required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }

  override func viewDidLoad() {
    super.viewDidLoad()

    let containerView = UIView(frame: self.headerViewController.headerView.bounds)
    containerView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]

    let titleLabel = UILabel()
    titleLabel.text = self.title!.uppercaseString
    titleLabel.textColor = UIColor(white: 0.46, alpha: 1)
    titleLabel.font = MDCTypography.titleFont()
    titleLabel.sizeToFit()
    if (inset + titleLabel.frame.size.width > containerView.frame.size.width) {
      titleLabel.font = MDCTypography.body2Font()
    }

    let titleInsets = UIEdgeInsets(top: 0, left: inset, bottom: inset, right: inset)
    let titleSize = titleLabel.sizeThatFits(containerView.bounds.size)
    titleLabel.frame = CGRect(
      x: titleInsets.left,
      y: containerView.bounds.size.height - titleSize.height - titleInsets.bottom,
      width: containerView.bounds.size.width,
      height: titleSize.height)
    titleLabel.autoresizingMask = [.FlexibleTopMargin, .FlexibleWidth]

    containerView.addSubview(titleLabel)

    self.headerViewController.headerView.addSubview(containerView)

    self.headerViewController.headerView.backgroundColor = UIColor.whiteColor()
    self.headerViewController.headerView.trackingScrollView = self.collectionView

    self.headerViewController.headerView.setShadowLayer(MDCShadowLayer()) { (layer, intensity) in
      let shadowLayer = layer as? MDCShadowLayer
      shadowLayer!.elevation = intensity * MDCShadowElevationAppBar
    }

    self.view.addSubview(self.headerViewController.view)
    self.headerViewController.didMoveToParentViewController(self)
  }

  override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)

    self.navigationController?.setNavigationBarHidden(true, animated: animated)
  }

  override func willAnimateRotationToInterfaceOrientation(
    toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
    collectionView?.collectionViewLayout.invalidateLayout()
  }

  override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
    return 1
  }<commit_msg>[Catalog] Forward touch events to the home screen's header.<commit_after>/*
Copyright 2015-present Google Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import UIKit
import MaterialComponents

class MDCCatalogComponentsController: UICollectionViewController {

  let spacing = CGFloat(1)
  let inset = CGFloat(16)
  let node: CBCNode
  var headerViewController: MDCFlexibleHeaderViewController
  let imageNames = NSMutableArray()

  init(collectionViewLayout ignoredLayout: UICollectionViewLayout, node: CBCNode) {
    self.node = node

    let layout = UICollectionViewFlowLayout()
    let sectionInset:CGFloat = spacing
    layout.sectionInset = UIEdgeInsetsMake(sectionInset, sectionInset, sectionInset, sectionInset)
    layout.minimumInteritemSpacing = spacing
    layout.minimumLineSpacing = spacing

    self.headerViewController = MDCFlexibleHeaderViewController()

    super.init(collectionViewLayout: layout)

    self.title = "Material Design Components"

    self.addChildViewController(self.headerViewController)

    self.headerViewController.headerView.maximumHeight = 128
    self.headerViewController.headerView.minimumHeight = 72

    self.collectionView?.registerClass(MDCCatalogCollectionViewCell.self,
      forCellWithReuseIdentifier: "MDCCatalogCollectionViewCell")
    self.collectionView?.backgroundColor = UIColor(white: 0.9, alpha: 1)
  }

  convenience init(node: CBCNode) {
    self.init(collectionViewLayout: UICollectionViewLayout(), node: node)
  }

  required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }

  override func viewDidLoad() {
    super.viewDidLoad()

    let containerView = UIView(frame: self.headerViewController.headerView.bounds)
    containerView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]

    let titleLabel = UILabel()
    titleLabel.text = self.title!.uppercaseString
    titleLabel.textColor = UIColor(white: 0.46, alpha: 1)
    titleLabel.font = MDCTypography.titleFont()
    titleLabel.sizeToFit()
    if (inset + titleLabel.frame.size.width > containerView.frame.size.width) {
      titleLabel.font = MDCTypography.body2Font()
    }

    let titleInsets = UIEdgeInsets(top: 0, left: inset, bottom: inset, right: inset)
    let titleSize = titleLabel.sizeThatFits(containerView.bounds.size)
    titleLabel.frame = CGRect(
      x: titleInsets.left,
      y: containerView.bounds.size.height - titleSize.height - titleInsets.bottom,
      width: containerView.bounds.size.width,
      height: titleSize.height)
    titleLabel.autoresizingMask = [.FlexibleTopMargin, .FlexibleWidth]

    containerView.addSubview(titleLabel)

    self.headerViewController.headerView.addSubview(containerView)

    self.headerViewController.headerView.forwardTouchEventsForView(containerView)

    self.headerViewController.headerView.backgroundColor = UIColor.whiteColor()
    self.headerViewController.headerView.trackingScrollView = self.collectionView

    self.headerViewController.headerView.setShadowLayer(MDCShadowLayer()) { (layer, intensity) in
      let shadowLayer = layer as? MDCShadowLayer
      shadowLayer!.elevation = intensity * MDCShadowElevationAppBar
    }

    self.view.addSubview(self.headerViewController.view)
    self.headerViewController.didMoveToParentViewController(self)
  }

  override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)

    self.navigationController?.setNavigationBarHidden(true, animated: animated)
  }

  override func willAnimateRotationToInterfaceOrientation(
    toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
    collectionView?.collectionViewLayout.invalidateLayout()
  }

  override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
    return 1
  }
{'fraction_non_alphanumeric': 0.07965439697005562, 'fraction_numerical': 0.006154574505858682, 'mean_word_length': 4.8075601374570445, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5392049', 'n_tokens_mistral': 2467, 'n_tokens_neox': 2305, 'n_words': 545}