//

//  ViewController.swift

//  FreeTalk

//

//  Created by stayfoolish on 2018. 8. 30..

//  Copyright © 2018년 stayfoolish. All rights reserved.

//



import UIKit

import SnapKit

import Firebase


class ViewController: UIViewController {


    var box = UIImageView() 

    var remoteConfig: RemoteConfig!

    

    override func viewDidLoad() {

        super.viewDidLoad()

        

        remoteConfig = RemoteConfig.remoteConfig()

        let remoteConfigSettings = RemoteConfigSettings(developerModeEnabled: true)

        remoteConfig.configSettings = remoteConfigSettings!

        remoteConfig.setDefaults(fromPlist: "RemoteConfigDefaults")


        remoteConfig.fetch(withExpirationDuration: TimeInterval(0)) { (status, error) -> Void in

            if status == .success {

                print("Config fetched!")

                self.remoteConfig.activateFetched()

            } else {

                print("Config not fetched")

                print("Error: \(error!.localizedDescription)")

            }

            self.displayWelcome()

        }

        

        

        self.view.addSubview(box)

        box.snp.makeConstraints{(make) in

            make.center.equalTo(self.view)

        }

        box.image =  imageLiteral(resourceName: "loading_icon")

        self.view.backgroundColor = UIColor(hex: "#000000")

    }


    func displayWelcome(){

        let color = remoteConfig["splash_background"].stringValue

        let caps = remoteConfig["splash_message_caps"].boolValue

        let message = remoteConfig["splash_message"].stringValue

        

        if(caps){

            let alert = UIAlertController(title: "공지사항", message: message, preferredStyle: UIAlertControllerStyle.alert)

            alert.addAction(UIAlertAction(title: "확인", style: UIAlertActionStyle.default, handler: { (action) in

                exit(0)

            }))

            self.present(alert, animated: true, completion: nil)

        }else{

            let loginVC = self.storyboard?.instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController



            self.present(loginVC, animated: false, completion: nil)

        }

        self.view.backgroundColor = UIColor(hex: color!)

    }

    

    override func didReceiveMemoryWarning() {

        super.didReceiveMemoryWarning()

        // Dispose of any resources that can be recreated.

    }



}


extension UIColor {

    convenience init(hex: String) {

        let scanner = Scanner(string: hex)

        

        scanner.scanLocation = 1

        

        var rgbValue: UInt64 = 0

        

        scanner.scanHexInt64(&rgbValue)

        

        let r = (rgbValue & 0xff0000) >> 16

        let g = (rgbValue & 0xff00) >> 8

        let b = rgbValue & 0xff

        

        self.init(

            red: CGFloat(r) / 0xff,

            green: CGFloat(g) / 0xff,

            blue: CGFloat(b) / 0xff, alpha: 1

        )

    }

}





//

//  LoginViewController.swift

//  FreeTalk

//

//  Created by stayfoolish on 2018. 9. 5..

//  Copyright © 2018년 stayfoolish. All rights reserved.

//


import UIKit

import Firebase


class LoginViewController: UIViewController {


    @IBOutlet var loginButton: UIButton!

    @IBOutlet var signup: UIButton!

    let remoteConfig = RemoteConfig.remoteConfig()

    var color : String!

    override func viewDidLoad() {

        super.viewDidLoad()

        

        let statusBar = UIView()

        self.view.addSubview(statusBar)

        statusBar.snp.makeConstraints {(m) in

            m.right.top.left.equalTo(self.view)

            m.height.equalTo(20)

            

        }

        color = remoteConfig["splash_background"].stringValue

        

        statusBar.backgroundColor = UIColor(hex: color)

        loginButton.backgroundColor = UIColor(hex: color)

        signup.backgroundColor = UIColor(hex: color)

        

        signup.addTarget(self, action: #selector(presentsSignup), for: .touchUpInside)

        // Do any additional setup after loading the view.

    }

    

    @objc func presentsSignup(){

        let view = self.storyboard?.instantiateViewController(withIdentifier: "SignupViewController") as! SignupViewController

        self.present(view, animated: true, completion: nil)

    }


    override func didReceiveMemoryWarning() {

        super.didReceiveMemoryWarning()

        // Dispose of any resources that can be recreated.

    }

    


    /*

    // MARK: - Navigation


    // In a storyboard-based application, you will often want to do a little preparation before navigation

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

        // Get the new view controller using segue.destinationViewController.

        // Pass the selected object to the new view controller.

    }

    */


}





//

//  SignupViewController.swift

//  FreeTalk

//

//  Created by stayfoolish on 2018. 9. 5..

//  Copyright © 2018년 stayfoolish. All rights reserved.

//


import UIKit

import Firebase


class SignupViewController: UIViewController {

    

    

    @IBOutlet var email: UITextField!

    @IBOutlet var name: UITextField!

    

    @IBOutlet var password: UITextField!

   

    @IBOutlet var signup: UIButton!

    @IBOutlet var cancel: UIButton!

    

    let remoteConfig = RemoteConfig.remoteConfig()

    var color: String?


    override func viewDidLoad() {

        super.viewDidLoad()


        let statusBar = UIView()

        self.view.addSubview(statusBar)

        statusBar.snp.makeConstraints {(m) in

            m.right.top.left.equalTo(self.view)

            m.height.equalTo(20)

        }

        color = remoteConfig["splash_background"].stringValue

        

        statusBar.backgroundColor = UIColor(hex: color!)

        signup.backgroundColor = UIColor(hex: color!)

        cancel.backgroundColor = UIColor(hex: color!)

        

        signup.addTarget(self, action: #selector(signupEvent), for: .touchUpInside)

        cancel.addTarget(self, action: #selector(cancelevent), for: .touchUpInside)

        // Do any additional setup after loading the view.

    }

    

    @objc func signupEvent(){

        Auth.auth().createUser(withEmail: email.text!, password: password.text!) {(user, err) in

            let uid = user?.uid

            Database.database().reference().child("users").child(uid!).setValue(["name":self.name.text!])

        }

    }

    @objc func cancelevent(){

        self.dismiss(animated: true, completion: nil)

    }

    override func didReceiveMemoryWarning() {

        super.didReceiveMemoryWarning()

        // Dispose of any resources that can be recreated.

    }

    


    /*

    // MARK: - Navigation


    // In a storyboard-based application, you will often want to do a little preparation before navigation

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

        // Get the new view controller using segue.destinationViewController.

        // Pass the selected object to the new view controller.

    }

    */


}



















+ Recent posts