| | |
| | | |
| | | import UIKit |
| | | import JQTools |
| | | import RxSwift |
| | | import MediaPlayer |
| | | |
| | | let SetBGMSuccess_Noti = Notification.Name.init("SetBGMSuccess_Noti") |
| | | |
| | | struct TitleItem{ |
| | | var title = "" |
| | |
| | | var coverImage:String? |
| | | } |
| | | |
| | | class HomeViewModel{ |
| | | var homeTopMenuItems = [HomeTopMenuItem]() |
| | | var todyModel:MeditationModel? |
| | | var privateTodyModels = [MeditationModel]() |
| | | var meditationList = [MeditationListModel]() |
| | | } |
| | | |
| | | class HomeVC: BaseVC { |
| | | private var tableView:UITableView! |
| | | private let topMenuView = HomeTopMenuView.jq_loadNibView() |
| | | private var titleItems = [TitleItem]() |
| | | private var viewModel = HomeViewModel() |
| | | |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | | |
| | | titleItems.removeAll() |
| | | |
| | | titleItems.append(TitleItem(title: "每日疗愈", subTitle: "Daily Meditation")) |
| | | titleItems.append(TitleItem(title: "私人订制", subTitle: "Private Meditation",hasMore: true)) |
| | | titleItems.append(TitleItem(title: "新手冥想指南", subTitle: "Meditation guide")) |
| | | titleItems.append(TitleItem(title: "放松助眠", subTitle: "与内心的宁静与喜悦入睡",hasMore:true)) |
| | | titleItems.append(TitleItem(title: "放松助眠", subTitle: "与内心的宁静与喜悦入睡",hasMore:true)) |
| | | titleItems.append(TitleItem(title: "放松助眠", subTitle: "与内心的宁静与喜悦入睡",hasMore:true)) |
| | | |
| | | if let setting = UserDefaultSettingViewModel.getSetting(){ |
| | | if let audioFile = setting.bgm?.audioFile{ |
| | | AudioPlayer.getSharedInstance().playBGMAt(audioFile) |
| | | } |
| | | } |
| | | |
| | | getData() |
| | | } |
| | | |
| | | override func setUI() { |
| | |
| | | tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 40, right: 0) |
| | | tableView.showsVerticalScrollIndicator = false |
| | | DispatchQueue.main.async { |
| | | let height = self.topMenuView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).height |
| | | self.topMenuView.frame = CGRect(x: 0, y: 0, width: JQ_ScreenW, height: height - 70) |
| | | let h = 119 + 20.5 + JQ_ScreenW * 0.913 |
| | | self.topMenuView.frame = CGRect(x: 0, y: 0, width: JQ_ScreenW, height: h) |
| | | self.tableView.tableHeaderView = self.topMenuView |
| | | } |
| | | |
| | |
| | | tableView.register(UINib(nibName: "Home_Style_2_TCell", bundle: nil), forCellReuseIdentifier: "_Home_Style_2_TCell") |
| | | tableView.register(UINib(nibName: "Home_Style_3_TCell", bundle: nil), forCellReuseIdentifier: "_Home_Style_3_TCell") |
| | | tableView.register(UINib(nibName: "Home_Style_4_TCell", bundle: nil), forCellReuseIdentifier: "_Home_Style_4_TCell") |
| | | |
| | | tableView.register(UINib(nibName: "Home_Style_5_TCell", bundle: nil), forCellReuseIdentifier: "_Home_Style_5_TCell") |
| | | |
| | | tableView.separatorStyle = .none |
| | | tableView.delegate = self |
| | |
| | | let vc = HomeItemListVC(topTitle: item.title, id: item.id) |
| | | self.push(vc: vc) |
| | | } |
| | | |
| | | NotificationCenter.default.rx.notification(SetBGMSuccess_Noti).take(until: self.rx.deallocated).subscribe(onNext: {data in |
| | | self.topMenuView.resetTopImage() |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | private func getData(){ |
| | | |
| | | Services.getCategoryListByType(type: 1).subscribe(onNext: { data in |
| | | var items = [HomeTopMenuItem]() |
| | | for v in data.data ?? []{ |
| | | let model = HomeTopMenuItem(id: v.id, title: v.categoryName, image: v.firstIconUrl, imageFrom: .url) |
| | | items.append(model) |
| | | } |
| | | |
| | | self.viewModel.homeTopMenuItems = items |
| | | let h = ceil(Double(items.count) / 4.0) * 119 + 20.5 + JQ_ScreenW * 0.913 |
| | | self.topMenuView.menu_height.constant = ceil(Double(items.count) / 4.0) * 119 |
| | | self.tableView.tableHeaderView?.frame = CGRect(origin: .zero, size: CGSizeMake(JQ_ScreenW, h)) |
| | | self.topMenuView.resetItems(items) |
| | | self.topMenuView.menu_collectionView.reloadData() |
| | | }).disposed(by: disposeBag) |
| | | |
| | | Services.getTopdayMedita().subscribe(onNext: { data in |
| | | self.viewModel.todyModel = data.data?.clientMeditationVO |
| | | self.tableView.reloadRows(at: [IndexPath(row: 0, section: 0)], with: .none) |
| | | }).disposed(by: disposeBag) |
| | | |
| | | Services.getPersonalityPlan().subscribe(onNext: { data in |
| | | if let m = data.data{ |
| | | self.viewModel.privateTodyModels = m |
| | | self.tableView.reloadRows(at: [IndexPath(row: 1, section: 0)], with: .none) |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | |
| | | Services.getMeditationAndCateList().subscribe(onNext: { data in |
| | | if let m = data.data{ |
| | | self.viewModel.meditationList.removeAll() |
| | | self.viewModel.meditationList = m |
| | | for v in self.viewModel.meditationList{ |
| | | self.titleItems.append(TitleItem(title: v.clientMeditationCategoryVO?.categoryName ?? "", subTitle: v.clientMeditationCategoryVO?.description ?? "",hasMore:true)) |
| | | } |
| | | self.tableView.reloadData() |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | @objc func searchAction(){ |
| | |
| | | break |
| | | default: |
| | | let topTitle = titleItems[sender.tag - 200].title |
| | | let vc = HomeItemListVC(topTitle: topTitle, id: 0) |
| | | push(vc: vc) |
| | | let m = viewModel.meditationList[sender.tag - 200 - 3] |
| | | if let id = m.clientMeditationCategoryVO?.id{ |
| | | let vc = HomeItemListVC(topTitle: topTitle, id: id) |
| | | push(vc: vc) |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | extension HomeVC:UITableViewDelegate & UITableViewDataSource{ |
| | | |
| | | func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { |
| | | if indexPath.section == 2{ |
| | | let vc = HomeTyroGuideVC() |
| | | let vc = WebVC(type: .guide) |
| | | vc.title = "心泉·疗愈" |
| | | push(vc: vc) |
| | | } |
| | | } |
| | |
| | | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { |
| | | if indexPath.section == 0{ |
| | | let cell = tableView.dequeueReusableCell(withIdentifier: "_Home_Style_1_TCell") as! Home_Style_1_TCell |
| | | cell.model = viewModel.todyModel |
| | | return cell |
| | | } |
| | | |
| | | if indexPath.section == 1{ |
| | | }else if indexPath.section == 1{ |
| | | let cell = tableView.dequeueReusableCell(withIdentifier: "_Home_Style_4_TCell") as! Home_Style_4_TCell |
| | | cell.style = .style1 |
| | | cell.setModels(viewModel.privateTodyModels) |
| | | return cell |
| | | } |
| | | |
| | | if indexPath.section == 2{ |
| | | }else if indexPath.section == 2{ |
| | | let cell = tableView.dequeueReusableCell(withIdentifier: "_Home_Style_2_TCell") as! Home_Style_2_TCell |
| | | cell.view_shadow.isHidden = true |
| | | return cell |
| | | } |
| | | }else { |
| | | |
| | | if indexPath.section == 3{ |
| | | let cell = tableView.dequeueReusableCell(withIdentifier: "_Home_Style_3_TCell") as! Home_Style_3_TCell |
| | | return cell |
| | | let index = indexPath.section - 3 |
| | | if index == 0 && indexPath.row != 0{ |
| | | let cell = tableView.dequeueReusableCell(withIdentifier: "_Home_Style_5_TCell") as! Home_Style_5_TCell |
| | | return cell |
| | | }else{ |
| | | let m = viewModel.meditationList[index] |
| | | if m.clientMeditationCategoryVO!.showType == .horizontal{ |
| | | let cell = tableView.dequeueReusableCell(withIdentifier: "_Home_Style_4_TCell") as! Home_Style_4_TCell |
| | | cell.style = .style1 |
| | | cell.setModels(m.clientMeditationVOList) |
| | | return cell |
| | | }else if m.clientMeditationCategoryVO!.showType == .vertical{ |
| | | let cell = tableView.dequeueReusableCell(withIdentifier: "_Home_Style_3_TCell") as! Home_Style_3_TCell |
| | | cell.setModels(m.clientMeditationVOList) |
| | | return cell |
| | | } |
| | | } |
| | | return UITableViewCell() |
| | | } |
| | | |
| | | if indexPath.section == 4{ |
| | | let cell = tableView.dequeueReusableCell(withIdentifier: "_Home_Style_4_TCell") as! Home_Style_4_TCell |
| | | cell.style = .style2 |
| | | return cell |
| | | } |
| | | |
| | | if indexPath.section == 5{ |
| | | let cell = tableView.dequeueReusableCell(withIdentifier: "_Home_Style_4_TCell") as! Home_Style_4_TCell |
| | | cell.style = .style2 |
| | | return cell |
| | | } |
| | | |
| | | return UITableViewCell() |
| | | } |
| | | |
| | | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { |
| | | |
| | | if section - 3 == 0{ |
| | | return 2 |
| | | } |
| | | return 1 |
| | | } |
| | | |
| | | func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { |
| | | if indexPath.section == 0 || indexPath.section == 1 || indexPath.section == 2{ |
| | | return JQ_ScreenW * 0.551 |
| | | }else{ |
| | | let index = indexPath.section - 3 |
| | | let m = viewModel.meditationList[index] |
| | | |
| | | if index == 0 && indexPath.row != 0 { |
| | | return 236 |
| | | } |
| | | |
| | | if m.clientMeditationCategoryVO?.showType == .horizontal{ |
| | | return 328 |
| | | }else{ |
| | | return 213 |
| | | } |
| | | } |
| | | if indexPath.section == 3{ |
| | | return 397.3 |
| | | } |
| | | if indexPath.section == 4 || indexPath.section == 5{ |
| | | return 328 |
| | | } |
| | | return 0 |
| | | } |
| | | |
| | | func numberOfSections(in tableView: UITableView) -> Int { |
| | |
| | | }else{ |
| | | headerView.btn_more.setImage(UIImage(named: "icon_exchange"), for: .normal) |
| | | } |
| | | |
| | | return headerView |
| | | } |
| | | |