pEpForiOS/UI/Folder/FolderTableViewController.swift
author Xavier Algarra <xavier@pep-project.org>
Thu, 20 Apr 2017 17:31:40 +0200
changeset 2041 eaac91f98aab
parent 2040 48f5e39c45a7
child 2045 01b83254d3de
permissions -rw-r--r--
IOS-328 animation on the folder select
xavier@1751
     1
//
xavier@1751
     2
//  FolderTableViewController.swift
xavier@1751
     3
//  pEpForiOS
xavier@1751
     4
//
xavier@1751
     5
//  Created by Xavier Algarra on 16/02/17.
xavier@1751
     6
//  Copyright © 2017 p≡p Security S.A. All rights reserved.
xavier@1751
     7
//
xavier@1751
     8
xavier@1751
     9
import UIKit
xavier@1751
    10
xavier@1966
    11
class FolderTableViewController: UITableViewController {
xavier@1751
    12
    var appConfig: AppConfig?
xavier@1751
    13
xavier@1883
    14
    var folderVM = FolderViewModel()
xavier@1751
    15
xavier@1751
    16
    override func viewDidLoad() {
xavier@1751
    17
        super.viewDidLoad()
xavier@1984
    18
        //initialConfig()
xavier@1984
    19
        tableView.estimatedRowHeight = 44.0
xavier@1984
    20
        tableView.rowHeight = UITableViewAutomaticDimension
xavier@1984
    21
        tableView.estimatedSectionHeaderHeight = 80.0
xavier@1984
    22
        tableView.sectionHeaderHeight = UITableViewAutomaticDimension
xavier@1997
    23
        //tableView.register(CollapsibleTableViewHeader.self, forHeaderFooterViewReuseIdentifier: "header")
xavier@1751
    24
    }
xavier@1751
    25
xavier@1751
    26
    override func viewWillAppear(_ animated: Bool) {
xavier@1751
    27
        super.viewWillAppear(animated)
xavier@1751
    28
xavier@1751
    29
    }
xavier@1751
    30
xavier@1751
    31
    override func didReceiveMemoryWarning() {
xavier@1751
    32
        super.didReceiveMemoryWarning()
xavier@1751
    33
        // Dispose of any resources that can be recreated.
xavier@1751
    34
    }
xavier@1751
    35
xavier@1751
    36
    // MARK: - Table view data source
xavier@1751
    37
xavier@1751
    38
    override func numberOfSections(in tableView: UITableView) -> Int {
xavier@1751
    39
        return folderVM.count
xavier@1751
    40
    }
xavier@1751
    41
xavier@1751
    42
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
xavier@1751
    43
        return folderVM[section].count
xavier@1751
    44
    }
xavier@1948
    45
xavier@1948
    46
    override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
xavier@1997
    47
        let header :CollapsibleTableViewHeader?
xavier@1997
    48
        if let head = tableView.dequeueReusableHeaderFooterView(withIdentifier: "header") as? CollapsibleTableViewHeader{
xavier@1997
    49
            header = head
xavier@1997
    50
        } else {
xavier@1997
    51
            header = CollapsibleTableViewHeader(reuseIdentifier: "header")
xavier@1997
    52
        }
xavier@1997
    53
        header!.configure(viewModel: folderVM[section], section: section)
xavier@1997
    54
        return header
xavier@1966
    55
    }
xavier@1997
    56
xavier@1966
    57
    override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
xavier@1966
    58
        return 0.0
xavier@1948
    59
    }
xavier@1948
    60
xavier@1751
    61
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
xavier@1772
    62
        let cell = tableView.dequeueReusableCell(withIdentifier: "Default", for: indexPath)
xavier@1751
    63
        let fcvm = folderVM[indexPath.section][indexPath.item]
xavier@1772
    64
        cell.detailTextLabel?.text = "\(fcvm.number)"
xavier@1772
    65
        cell.textLabel?.text = fcvm.title
xavier@1966
    66
        cell.accessoryType = .disclosureIndicator
xavier@1751
    67
        return cell
xavier@1751
    68
    }
xavier@1751
    69
xavier@1997
    70
    override func tableView(_ tableView: UITableView, indentationLevelForRowAt indexPath: IndexPath)
xavier@1997
    71
        -> Int {
xavier@1772
    72
        return folderVM[indexPath.section][indexPath.item].level
xavier@1772
    73
    }
xavier@1772
    74
xavier@2040
    75
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
xavier@1774
    76
xavier@2040
    77
        let sb = UIStoryboard(name: "Main", bundle: nil)
xavier@2040
    78
        if let vc = sb.instantiateViewController(withIdentifier: "EmailListViewController") as? EmailListViewController {
xavier@2040
    79
            let config = EmailListConfig(appConfig: appConfig, folder: folderVM[indexPath.section][indexPath.row].getFolder())
xavier@2040
    80
            vc.config = config
xavier@2041
    81
            self.navigationController?.pushViewController(vc, animated: true)
xavier@1774
    82
        }
xavier@1774
    83
    }
xavier@1774
    84
xavier@1968
    85
    @IBAction func addAccount(_ sender: Any) {
xavier@1968
    86
    }
xavier@1968
    87
xavier@1751
    88
    /*
xavier@1997
    89
     // Override to support conditional editing of the table view.
xavier@1997
    90
     override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
xavier@1997
    91
     // Return false if you do not want the specified item to be editable.
xavier@1997
    92
     return true
xavier@1997
    93
     }
xavier@1997
    94
     */
xavier@1751
    95
xavier@1751
    96
    /*
xavier@1997
    97
     // Override to support editing the table view.
xavier@1997
    98
     override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
xavier@1997
    99
     if editingStyle == .delete {
xavier@1997
   100
     // Delete the row from the data source
xavier@1997
   101
     tableView.deleteRows(at: [indexPath], with: .fade)
xavier@1997
   102
     } else if editingStyle == .insert {
xavier@1997
   103
     // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
xavier@1997
   104
     }
xavier@1997
   105
     }
xavier@1997
   106
     */
xavier@1751
   107
xavier@1751
   108
    /*
xavier@1997
   109
     // Override to support rearranging the table view.
xavier@1997
   110
     override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
xavier@1997
   111
xavier@1997
   112
     }
xavier@1997
   113
     */
xavier@1751
   114
xavier@1751
   115
    /*
xavier@1997
   116
     // Override to support conditional rearranging of the table view.
xavier@1997
   117
     override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
xavier@1997
   118
     // Return false if you do not want the item to be re-orderable.
xavier@1997
   119
     return true
xavier@1997
   120
     }
xavier@1997
   121
     */
xavier@1751
   122
xavier@1997
   123
    /*
xavier@1997
   124
     // MARK: - Navigation
xavier@1997
   125
xavier@1997
   126
     // In a storyboard-based application, you will often want to do a little preparation before navigation
xavier@1997
   127
     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
xavier@1997
   128
     // Get the new view controller using segue.destinationViewController.
xavier@1997
   129
     // Pass the selected object to the new view controller.
xavier@1997
   130
     }
xavier@1997
   131
     */
xavier@1751
   132
xavier@1751
   133
}