@@ -0,0 +1,81 @@
1+//
2+// SimplifiedChannelsList.swift
3+// GDproject
4+//
5+// Created by cstore on 13/03/2019.
6+// Copyright © 2019 drHSE. All rights reserved.
7+//
8+
9+
10+/// class for ADDing person to existing (or new) channel: like playlist in itunes
11+import UIKit
12+
13+class SimplifiedChannelsList: UITableViewController {
14+
15+ var user: Model.Users?
16+
17+ var dataSource: [Model.Channels]?{
18+ didSet{
19+ tableView.reloadData()
20+ }
21+ }
22+
23+ override func viewDidLoad() {
24+ super.viewDidLoad()
25+ setUpNavigationButtons()
26+ tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
27+ }
28+
29+ override func viewWillAppear(_ animated: Bool) {
30+ Model.channelsList { [weak self] (channels) in
31+ self?.dataSource = channels
32+ }
33+ }
34+
35+ func setUpNavigationButtons(){
36+ navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(cancelAction))
37+ }
38+
39+ func completedActions(with channel: Model.Channels){
40+ Model.updateChannel(with: channel)
41+ cancelAction()
42+ }
43+
44+ @objc func cancelAction(){
45+ let transition = CATransition()
46+ transition.duration = 0.5
47+ transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
48+ transition.type = CATransitionType.reveal
49+ transition.subtype = CATransitionSubtype.fromBottom
50+ navigationController?.view.layer.add(transition, forKey: nil)
51+ navigationController?.popViewController(animated: false)
52+ }
53+
54+ override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
55+ let viewHeader = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 30))
56+ return viewHeader
57+ }
58+
59+ override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
60+ return 30
61+ }
62+
63+ override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
64+ return dataSource?.count ?? 0
65+ }
66+
67+ override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
68+ var channel = dataSource![indexPath.row]
69+ channel.people.append(user!.id)
70+ completedActions(with: channel)
71+ }
72+
73+ override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
74+ let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
75+
76+ cell.textLabel?.text = dataSource![indexPath.row].name
77+ cell.detailTextLabel?.text = "\(dataSource![indexPath.row].id!)"
78+
79+ return cell
80+ }
81+}