<commit_before>//
//  Copyright (c) 2016 Google Inc.
//
//  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 FirebaseUI

class StorageViewController: UIViewController {

  @IBOutlet fileprivate var imageView: UIImageView!
  @IBOutlet fileprivate var textField: UITextField!

  fileprivate var storageRef = Storage.storage().reference()
  
  override func viewDidLoad() {
    self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Clear Cache", style: .plain, target: self, action: #selector(flushCache))
  }

  override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    self.textField.autocorrectionType = .no
    self.textField.autocapitalizationType = .none
    self.imageView.contentMode = .scaleAspectFit

    // Notification boilerplate to handle keyboard appearance/disappearance
    NotificationCenter.default.addObserver(self,
                                                     selector: #selector(keyboardWillShow),
                                                     name: UIResponder.keyboardWillShowNotification,
                                                     object: nil)
    NotificationCenter.default.addObserver(self,
                                                     selector: #selector(keyboardWillHide),
                                                     name: UIResponder.keyboardWillHideNotification,
                                                     object: nil)
  }

  @IBAction fileprivate func loadButtonPressed(_ sender: AnyObject) {
    self.imageView.image = nil
    guard let text = self.textField.text else { return }
    guard let url = URL(string: text) else { return }

    self.storageRef = Storage.storage().reference(withPath: url.path)

    self.imageView.sd_setImage(with: self.storageRef,
                               maxImageSize: 10000000,
                               placeholderImage: nil,
                               options: [.progressiveLoad]) { (image, error, cacheType, storageRef) in
      if let error = error {
        print("Error loading image: \(error)")
      }
    }
  }
  
  @objc fileprivate func flushCache() {
    SDImageCache.shared.clearMemory()
    SDImageCache.shared.clearDisk()
  }

  // MARK: Keyboard boilerplate

  /// Used to shift textfield up when the keyboard appears.
  @IBOutlet fileprivate var bottomConstraint: NSLayoutConstraint!

  @objc fileprivate func keyboardWillShow(_ notification: Notification) {
    let userInfo = (notification as NSNotification).userInfo!
    let endFrameValue = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as! NSValue
    let endHeight = endFrameValue.cgRectValue.size.height<commit_msg>Review: change the Swift Demo's method into private<commit_after>//
//  Copyright (c) 2016 Google Inc.
//
//  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 FirebaseUI

class StorageViewController: UIViewController {

  @IBOutlet fileprivate var imageView: UIImageView!
  @IBOutlet fileprivate var textField: UITextField!

  fileprivate var storageRef = Storage.storage().reference()
  
  override func viewDidLoad() {
    self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Clear Cache", style: .plain, target: self, action: #selector(flushCache))
  }

  override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    self.textField.autocorrectionType = .no
    self.textField.autocapitalizationType = .none
    self.imageView.contentMode = .scaleAspectFit

    // Notification boilerplate to handle keyboard appearance/disappearance
    NotificationCenter.default.addObserver(self,
                                                     selector: #selector(keyboardWillShow),
                                                     name: UIResponder.keyboardWillShowNotification,
                                                     object: nil)
    NotificationCenter.default.addObserver(self,
                                                     selector: #selector(keyboardWillHide),
                                                     name: UIResponder.keyboardWillHideNotification,
                                                     object: nil)
  }

  @IBAction fileprivate func loadButtonPressed(_ sender: AnyObject) {
    self.imageView.image = nil
    guard let text = self.textField.text else { return }
    guard let url = URL(string: text) else { return }

    self.storageRef = Storage.storage().reference(withPath: url.path)

    self.imageView.sd_setImage(with: self.storageRef,
                               maxImageSize: 10000000,
                               placeholderImage: nil,
                               options: [.progressiveLoad]) { (image, error, cacheType, storageRef) in
      if let error = error {
        print("Error loading image: \(error)")
      }
    }
  }
  
  @objc private func flushCache() {
    SDImageCache.shared.clearMemory()
    SDImageCache.shared.clearDisk()
  }

  // MARK: Keyboard boilerplate

  /// Used to shift textfield up when the keyboard appears.
  @IBOutlet fileprivate var bottomConstraint: NSLayoutConstraint!

  @objc fileprivate func keyboardWillShow(_ notification: Notification) {
    let userInfo = (notification as NSNotification).userInfo!
    let endFrameValue = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as! NSValue
    let endHeight = endFrameValue.cgRectValue.size.height
{'fraction_non_alphanumeric': 0.07912772585669782, 'fraction_numerical': 0.004984423676012461, 'mean_word_length': 2.3830347734457322, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4231741', 'n_tokens_mistral': 1642, 'n_tokens_neox': 1569, 'n_words': 480}