123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- //
- // MessageView.swift
- // RainbowPlanet
- //
- // Created by 南鑫林 on 2019/4/24.
- // Copyright © 2019 南鑫林. All rights reserved.
- //
- import UIKit
- class MessageView: BaseView {
-
- let oneImages = ["my_message_system","my_message_active","my_message_indent"]
- let oneTitles = ["星球通知","活动公告","订单消息"]
-
- let twoImages = ["my_message_comment","my_message_like","my_message_attention","my_message_letter"]
- let twoTitles = ["评论和@","喜欢和赞","关注我的","私信"]
- let twoDetailTitles = ["暂未收到评论和@,多去互动吧","暂未收到喜欢和赞,多去互动吧","暂无关注,多去互动吧","暂无私信"]
-
- typealias DidSelectClosure = (_ indexPath: IndexPath) -> Void
- var didSelectClosure : DidSelectClosure?
-
- enum NotificationAuthorizationStatus {
- case authorized
- case notDetermined
- case denied
- }
-
- var authorizationStatus :NotificationAuthorizationStatus?
-
-
- override func setupViews() {
- addSubview(collectionView)
- if #available(iOS 10.0, *) {
- let unUserNotificationCenter = UNUserNotificationCenter.current()
- unUserNotificationCenter.getNotificationSettings {
- settings in
- switch settings.authorizationStatus {
- case .authorized:
- self.authorizationStatus = .authorized
- return
- case .notDetermined:
- self.authorizationStatus = .notDetermined
- // //请求授权
- // UNUserNotificationCenter.current()
- // .requestAuthorization(options: [.alert, .sound, .badge]) {
- // (accepted, error) in
- // if !accepted {
- // print("用户不允许消息通知。")
- // }
- // }
- break
- case .denied:
- self.authorizationStatus = .denied
- break
- default:
- break
- }
- }
- self.collectionView.reloadData()
- } else {
- // Fallback on earlier versions
- }
- }
-
- override func setupLayouts() {
- collectionView.snp.makeConstraints { (make) in
- make.edges.equalToSuperview()
- }
- }
-
- private lazy var collectionView: UICollectionView = {
- let collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: collectionViewLayout)
- collectionView.backgroundColor = kf7f8faColor
- collectionView.delegate = self;
- collectionView.dataSource = self;
- collectionView.showsVerticalScrollIndicator = false
- collectionView.showsHorizontalScrollIndicator = false
- collectionView.cornerRadius = 2.5
- collectionView.masksToBounds = true
- return collectionView
- }()
-
- private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
- let collectionViewLayout = UICollectionViewFlowLayout.init()
- // collectionViewLayout.estimatedItemSize = CGSize(width: kScaleWidth, height: 10)
- return collectionViewLayout
- }()
- }
- extension MessageView: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
- func numberOfSections(in collectionView: UICollectionView) -> Int {
- return 2
- }
-
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- switch section {
- case 0:
- return 3
- case 1:
- return 4
- default:
- return 0
- }
- }
-
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
- switch indexPath.section {
- case 0:
- let cell = MessageOneCollectionViewCell.cellWith(collectionView: collectionView, indexPath: indexPath)
- cell.setCell(titles: oneTitles, images: oneImages)
- return cell
- case 1:
- let cell = MessageTwoCollectionViewCell.cellWith(collectionView: collectionView, indexPath: indexPath)
- cell.setCell(titles: twoTitles, detailTitles: twoDetailTitles, images: twoImages)
- return cell
- default:
- return UICollectionViewCell()
- }
- }
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
- switch indexPath.section {
- case 0:
- return CGSize(width:kScreenWidth/3, height: kScaleValue(value: 40)+70)
- case 1:
- return CGSize(width:kScreenWidth, height: 91)
- default:
- return CGSize(width:0.0, height: 0.0)
- }
- }
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
- switch section {
- case 0:
- if self.authorizationStatus == .notDetermined || self.authorizationStatus == .denied {
- return UIEdgeInsets(top: 0, left: 0, bottom: 10, right: 0)
- }else if self.authorizationStatus == .authorized {
- return UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 0)
- }
- return UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 0)
- default:
- return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
- }
- }
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
- switch section {
- case 0:
- return 10
- default:
- return 0
- }
- }
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
- switch section {
- case 0:
- return 0
- default:
- return 0
- }
- }
-
- func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
- if kind == UICollectionView.elementKindSectionHeader {
- switch indexPath.section {
- case 0:
- let headerView = MessageNoticeHeaderCollectionReusableView.headerWith(collectionView: collectionView, kind: UICollectionView.elementKindSectionHeader, indexPath: indexPath)
- return headerView
- default:
- return UICollectionReusableView()
- }
-
- }
- return UICollectionReusableView()
- }
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
- switch section {
- case 0:
- if self.authorizationStatus == .notDetermined || self.authorizationStatus == .denied {
- return CGSize(width: kScreenWidth, height: kScaleValue(value: 36))
- }else if self.authorizationStatus == .authorized {
- return CGSize(width: kScreenWidth, height: 0)
- }
- return CGSize(width: kScreenWidth, height: 0)
- default:
- return CGSize(width: kScreenWidth, height: 0)
- }
- }
-
- func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
- if let didSelectClosure = self.didSelectClosure {
- didSelectClosure(indexPath)
- }
- }
-
- }
|