99 lines
3.6 KiB
Swift
99 lines
3.6 KiB
Swift
//
|
|
// StudentTableViewController.swift
|
|
// SchoolList8
|
|
//
|
|
// Created by Quentin Millardet on 14/10/2020.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class LightshowDownloadView: UITableViewController{
|
|
|
|
var model:LightshowModel?
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
model = (UIApplication.shared.delegate as! AppDelegate).model
|
|
}
|
|
|
|
// Return the number of rows for the table.
|
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
return model!.getStudentCount()
|
|
}
|
|
|
|
// Provide a cell object for each row.
|
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
// Fetch a cell of the appropriate type.
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: "lightshowDownloadCell")
|
|
let model = model?.getStudentAtIndex(indexPath.row);
|
|
|
|
let isOk : Bool = model?.isOkFiles() ?? false;
|
|
|
|
(cell as! LightshowDownloadCellSecond).LightshowName.text = model?.name
|
|
(cell as! LightshowDownloadCellSecond).warningIcon.isHidden = isOk;
|
|
var alertText = ""
|
|
if (!isOk){
|
|
alertText = "(Le fichcier mp3 ou fseq n'a pas été reconnu)"
|
|
}
|
|
(cell as! LightshowDownloadCellSecond).alertMessage.text = alertText
|
|
return cell!
|
|
}
|
|
|
|
override func tableView(_ tableView: UITableView,
|
|
leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
|
|
// Trash action
|
|
let trash = UIContextualAction(style: .destructive,
|
|
title: "Edit") { [weak self] (action, view, completionHandler) in
|
|
self?.handleMarkAsUnread()
|
|
completionHandler(true)
|
|
}
|
|
trash.backgroundColor = .systemGray
|
|
|
|
let configuration = UISwipeActionsConfiguration(actions: [trash])
|
|
|
|
return configuration
|
|
}
|
|
|
|
override func tableView(_ tableView: UITableView,
|
|
trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
|
|
// Trash action
|
|
let trash = UIContextualAction(style: .destructive,
|
|
title: "Trash") { [weak self] (action, view, completionHandler) in
|
|
self?.handleMoveToTrash()
|
|
completionHandler(true)
|
|
}
|
|
trash.backgroundColor = .systemRed
|
|
|
|
let configuration = UISwipeActionsConfiguration(actions: [trash])
|
|
|
|
return configuration
|
|
}
|
|
|
|
private func handleMarkAsUnread() {
|
|
print("Marked as unread")
|
|
}
|
|
|
|
private func handleMoveToTrash() {
|
|
print("Moved to trash")
|
|
}
|
|
|
|
// Permet de passer des informations à une vue avant que celle-ci ne soit créee
|
|
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
|
|
|
}
|
|
|
|
@IBAction func unwindFromCancel(_ unwindSegue: UIStoryboardSegue) {
|
|
//let sourceViewController : EditController = unwindSegue.source as! EditController
|
|
//NSLog(sourceViewController.nameField.text!)
|
|
// Use data from the view controller which initiated the unwind segue
|
|
}
|
|
|
|
@IBAction func unwindFromOk(_ unwindSegue: UIStoryboardSegue) {
|
|
//let sourceViewController : EditController = unwindSegue.source as! EditController
|
|
let newName : String = "sourceViewController.nameField.text!"
|
|
let row : Int = 1;
|
|
model?.setStudentAtIndex(row , withdraw: newName)
|
|
tableView.reloadData()
|
|
}
|
|
}
|