pEpForiOS/UI/Filter/ViewModel/FilterViewModel.swift
author Xavier Algarra <xavier@pep-project.org>
Mon, 13 Mar 2017 16:10:34 +0100
changeset 1832 8f9685564441
child 1836 908ef2563c5e
permissions -rw-r--r--
IOS-170 FilterView with diferents options
     1 //
     2 //  FilterViewModel.swift
     3 //  pEpForiOS
     4 //
     5 //  Created by Xavier Algarra on 13/03/2017.
     6 //  Copyright © 2017 p≡p Security S.A. All rights reserved.
     7 //
     8 
     9 import Foundation
    10 import MessageModel
    11 
    12 public enum FilterSectionType {
    13     case accouts, include, to, other
    14 }
    15 public class FilterViewModel {
    16 
    17     private var items: [FilterCellViewModel]
    18     public var title: String
    19 
    20     public init(type: FilterSectionType) {
    21 
    22         items = [FilterCellViewModel]()
    23         switch type {
    24         case .accouts:
    25             self.title = NSLocalizedString("INCLUDE MAIL FROM:", comment: "title for the accounts section")
    26             break
    27         case .include:
    28             self.title = NSLocalizedString("INCLUDE:", comment: "title for the include section")
    29             break
    30         case .to:
    31             self.title = NSLocalizedString("ADDRESSED TO:", comment: "title for the to section")
    32             break
    33         case .other:
    34             self.title = ""
    35             break
    36         }
    37 
    38         generateCells(type: type)
    39 
    40     }
    41 
    42     private func generateCells(type: FilterSectionType) {
    43         switch type {
    44         case .accouts:
    45             for account in Account.all() {
    46                 items.append(FilterCellViewModel(account: account))
    47             }
    48             break
    49         case .include:
    50             items.append(FilterCellViewModel(type: FilterCellType.unread))
    51             items.append(FilterCellViewModel(type: FilterCellType.indicate))
    52             break
    53         case .to:
    54             items.append(FilterCellViewModel(type: FilterCellType.forMe))
    55             items.append(FilterCellViewModel(type: FilterCellType.forMeCc))
    56             break
    57         case .other:
    58             //init de las celdas otros
    59             break
    60         }
    61     }
    62 
    63 
    64     subscript(index: Int) -> FilterCellViewModel {
    65         get {
    66             return self.items[index]
    67         }
    68     }
    69     var count : Int {
    70         return self.items.count
    71     }
    72 }