| | |
| | | static var array = NSMutableArray() |
| | | static let cacheSearchPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent("search") |
| | | |
| | | static func readList()->NSMutableArray{ |
| | | static func readList(_ serchType:SearchVC.SearchType)->NSMutableArray{ |
| | | if !FileManager.default.fileExists(atPath: cacheSearchPath.absoluteString){ |
| | | try? FileManager.default.createDirectory(at: cacheSearchPath, withIntermediateDirectories: true) |
| | | } |
| | | |
| | | let searchPlistPath = cacheSearchPath.appendingPathComponent("search.plist") |
| | | let searchPlistPath = cacheSearchPath.appendingPathComponent(serchType.infoPlist) |
| | | if let tempArray = NSMutableArray(contentsOfFile: searchPlistPath.droppedScheme()!.absoluteString){ |
| | | array = tempArray |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | static func writeToPath(){ |
| | | let searchPlistPath = cacheSearchPath.appendingPathComponent("search.plist") |
| | | static func writeToPath(_ serchType:SearchVC.SearchType){ |
| | | let searchPlistPath = cacheSearchPath.appendingPathComponent(serchType.infoPlist) |
| | | array.write(to: searchPlistPath, atomically: true) |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | class SearchVC: BaseVC { |
| | | |
| | | enum SearchType { |
| | | case muse //疗愈 |
| | | case course //课程 |
| | | |
| | | var infoPlist:String{ |
| | | switch self { |
| | | case .muse:return "searchmuse.plist" |
| | | case .course:return "searchcourse.plist" |
| | | } |
| | | } |
| | | } |
| | | |
| | | @IBOutlet weak var cacheSearchCollectionView: UICollectionView! |
| | | @IBOutlet weak var cacheSearchHei: NSLayoutConstraint! |
| | | @IBOutlet weak var tf_search: UITextField! |
| | | @IBOutlet weak var tableView: UITableView! |
| | | |
| | | @IBOutlet weak var view_hotKeyword: UIView! |
| | | @IBOutlet weak var label_hotSearhTitle: UILabel! |
| | | |
| | | private var hotWords = [String]() |
| | | private var serchType:SearchType! |
| | | |
| | | init(serchType:SearchType) { |
| | | super.init(nibName: nil, bundle: nil) |
| | | self.serchType = serchType |
| | | } |
| | | |
| | | required init?(coder: NSCoder) { |
| | | fatalError("init(coder:) has not been implemented") |
| | | } |
| | | |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | | title = "心泉·疗愈" |
| | | |
| | | _ = SearchCache.readList() |
| | | view_hotKeyword.isHidden = serchType == .course |
| | | label_hotSearhTitle.isHidden = serchType == .course |
| | | |
| | | tf_search.placeholder = serchType == .course ? "搜索你喜欢的课程~":"请输入冥想搜索内容" |
| | | |
| | | _ = SearchCache.readList(serchType) |
| | | cacheSearchCollectionView.reloadData() |
| | | |
| | | Services.getHotWordList().subscribe(onNext: {data in |
| | |
| | | |
| | | override func viewDidDisappear(_ animated: Bool) { |
| | | super.viewDidDisappear(animated) |
| | | SearchCache.writeToPath() |
| | | SearchCache.writeToPath(serchType) |
| | | } |
| | | |
| | | override func setUI() { |
| | |
| | | tf_search.resignFirstResponder() |
| | | SearchCache.writeToList(tf_search.text!) |
| | | |
| | | let vc = SearchContentVC(content: tf_search.text!) |
| | | let vc = SearchContentVC(content: tf_search.text!, type: serchType) |
| | | jq_push(vc: vc) |
| | | } |
| | | } |