123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- //
- // MeetingListViewController.swift
- // LMS
- //
- // Created by Suraj Kumar Mandal on 18/08/22.
- //
- import UIKit
- class MeetingListViewController: UIViewController {
-
- @IBOutlet var meetingListTableView: UITableView!
-
- var calendarData = [CalendarModel]()
- var meetingDate = String()
- var meetings = [CalendarModel]()
- var selectedDate = Date()
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view.
- executeRepeatedly()
- for data in calendarData {
- if data.date == meetingDate {
- meetings.append(data)
- }
- }
- // if let i = calendarData.firstIndex(where: { $0.date == meetingDate }) {
- // meetings.append(calendarData[i])
- // }
- meetingListTableView.delegate = self
- meetingListTableView.dataSource = self
- meetingListTableView.reloadData()
- }
-
- func formattedDateFromString(dateString: String, withFormat format: String) -> String? {
- let inputFormatter = DateFormatter()
- inputFormatter.dateFormat = "yyyy-MM-dd"
- if let date = inputFormatter.date(from: dateString) {
- let outputFormatter = DateFormatter()
- outputFormatter.dateFormat = format
- return outputFormatter.string(from: date)
- }
- return nil
- }
-
- func formattedTimeFromString(dateString: String, withFormat format: String) -> String? {
- let inputFormatter = DateFormatter()
- inputFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
- if let date = inputFormatter.date(from: dateString) {
- let outputFormatter = DateFormatter()
- outputFormatter.dateFormat = format
- outputFormatter.timeStyle = .short
- return outputFormatter.string(from: date)
- }
- return nil
- }
-
- private func executeRepeatedly() {
- // put your code here
- meetingListTableView.reloadData()
- DispatchQueue.main.asyncAfter(deadline: .now() + 60.0) { [weak self] in
- self?.executeRepeatedly()
- }
- }
-
- /*
- // 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.destination.
- // Pass the selected object to the new view controller.
- }
- */
- }
- extension MeetingListViewController: UITableViewDelegate, UITableViewDataSource {
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return meetings.count
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- if meetings[indexPath.row].offline == true {
- guard let cell = tableView.dequeueReusableCell(withIdentifier: "MeetingListTableViewCell", for: indexPath) as? MeetingListTableViewCell else {
- return UITableViewCell()
- }
- cell.customView.layer.cornerRadius = 10
- cell.customView.dropShadow()
- cell.meetingNameLabel.text = meetings[indexPath.row].scheduleTitle
- cell.dayDateLabel.text = formattedDateFromString(dateString: meetings[indexPath.row].date!, withFormat: "EEEE, MMM dd, yyyy")
- cell.timeLabel.text = "\(formattedTimeFromString(dateString: meetings[indexPath.row].startTime!, withFormat: "HH:mm") ?? "") - \(formattedTimeFromString(dateString: meetings[indexPath.row].endTime!, withFormat: "HH:mm") ?? "")"
- cell.joinClassButton.layer.cornerRadius = 5
-
- let date = Date()
- let format = DateFormatter()
- format.dateFormat = "yyyy-MM-dd HH:mm:ss"
- let time = format.string(from: date)
- let currentTime = format.date(from: time)
- let startTime = format.date(from: meetings[indexPath.row].startTime!)?.addingTimeInterval(TimeInterval(10.0 * 60.0))
- let endTime = format.date(from: meetings[indexPath.row].endTime!)?.addingTimeInterval(TimeInterval(20.0 * 60.0))
-
- if currentTime! > startTime! && currentTime! < endTime! {
- cell.joinClassButton.backgroundColor = #colorLiteral(red: 0.00400000019, green: 0.200000003, blue: 0.3919999897, alpha: 1)
- cell.joinClassButton.tag = indexPath.row
- cell.joinClassButton.addTarget(self, action: #selector(joinClass), for: .touchUpInside)
- } else {
- cell.joinClassButton.backgroundColor = UIColor.lightGray
- cell.joinClassButton.isUserInteractionEnabled = false
- }
-
- return cell
- } else {
- guard let cell = tableView.dequeueReusableCell(withIdentifier: "OfflineMeetingTableViewCell", for: indexPath) as? OfflineMeetingTableViewCell else {
- return UITableViewCell()
- }
- cell.customView.layer.cornerRadius = 10
- cell.customView.dropShadow()
- cell.meetingNameLabel.text = meetings[indexPath.row].scheduleTitle
- cell.dateLabel.text = formattedDateFromString(dateString: meetings[indexPath.row].date!, withFormat: "EEEE, MMM dd, yyyy")
- cell.timeLabel.text = "\(formattedTimeFromString(dateString: meetings[indexPath.row].startTime!, withFormat: "HH:mm") ?? "") - \(formattedTimeFromString(dateString: meetings[indexPath.row].endTime!, withFormat: "HH:mm") ?? "")"
-
- return cell
- }
- }
-
- @objc func joinClass(sender: UIButton){
- print(sender.tag)
- guard let url = URL(string: meetings[sender.tag].link ?? "") else { return }
- print(meetings[sender.tag].link ?? "")
- UIApplication.shared.open(url)
- }
- }
|