-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChatLogController.swift
105 lines (77 loc) · 3.79 KB
/
ChatLogController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//
// ChatLogController.swift
// Salisbury_Book_Exchange
//
// Created by Dean Kromer on 12/8/17.
// Copyright © 2017 Dean Kromer. All rights reserved.
//
import UIKit
import Firebase
class ChatLogController: UITableViewController {
var books = [Book]()
var users = [User]()
var messages = [Message]()
var messagesController: MessagesController?
let inputText: UITextField = {
let inputText = UITextField()
inputText.placeholder = "Enter Message"
inputText.translatesAutoresizingMaskIntoConstraints = false
return inputText
}()
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.title = "Messages"
setupInputComponents()
}
func setupInputComponents(){
let containerView = UIView()
containerView.backgroundColor = UIColor.white
containerView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(containerView)
containerView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
containerView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
containerView.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
containerView.heightAnchor.constraint(equalTo: view.heightAnchor).isActive = true
let sendButton = UIButton(type: .system)
sendButton.setTitle("Send", for: .normal)
sendButton.translatesAutoresizingMaskIntoConstraints = false
sendButton.addTarget(self, action: #selector(handleSend), for: .touchUpInside)
containerView.addSubview(sendButton)
sendButton.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
sendButton.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
sendButton.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
sendButton.heightAnchor.constraint(equalTo: view.heightAnchor).isActive = true
containerView.addSubview(inputText)
inputText.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
inputText.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
inputText.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
inputText.heightAnchor.constraint(equalTo: view.heightAnchor).isActive = true
let seperatorLineView = UIView()
seperatorLineView.backgroundColor = UIColor.blue
seperatorLineView.translatesAutoresizingMaskIntoConstraints = false
seperatorLineView.addSubview(seperatorLineView)
seperatorLineView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
seperatorLineView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
seperatorLineView.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
seperatorLineView.heightAnchor.constraint(equalTo: view.heightAnchor).isActive = true
}
@objc func handleSend() {
let ref = Database.database().reference().child("Messages")
let childRef = ref.childByAutoId()
let values = ["text": inputText.text]
childRef.updateChildValues(values)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 0
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return 0
}
}