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