123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- //
- // TSDiscoverVC.swift
- // AIEmoji
- //
- // Created by 100Years on 2025/6/23.
- //
- class TSDiscoverVC: TSBaseVC {
-
- let viewModel = kTSDiscoverVM
- var hintBaseVC:TSAIListHintBaseVC = TSAIListHintBaseVC(config: .defaultConfig)
- lazy var photoPickerManager: TSPhotoPickerManager = TSPhotoPickerManager(viewController: self)
-
- lazy var vipBtn: UIButton = {
- let vipBtn = UIButton.createButton(image: UIImage(named: "nav_vip")) { [weak self] in
- guard let self = self else { return }
- TSPurchaseVC.show(target: self) {}
- }
- return vipBtn
- }()
-
- lazy var navBarView: TSBaseNavContentBarView = {
- let navBarView = TSBaseNavContentBarView()
- let label = UILabel.createLabel(text: "Discover",font: .font(name: .KelsiFill,size: 28))
- navBarView.barView.addSubview(label)
- label.snp.makeConstraints { make in
- make.centerY.equalToSuperview()
- make.leading.equalTo(17.0)
- }
-
- navBarView.barView.addSubview(vipBtn)
- vipBtn.snp.makeConstraints { make in
- make.centerY.equalToSuperview()
- make.trailing.equalTo(-16)
- make.width.height.equalTo(32)
- }
-
- kMainAsync {
- label.applyGradient(colors: ["#FA794F".uiColor,"#F8C32A".uiColor,"#FEFBF4".uiColor])
- }
-
- return navBarView
- }()
-
-
- lazy var collectionView: TSBaseCollectionView = {
- let collectionViewLayout = UICollectionViewFlowLayout()
- let collectionView = TSBaseCollectionView(frame: .zero, collectionViewLayout: collectionViewLayout)
- collectionView.delegate = self
- collectionView.dataSource = self
- for cases in TSDiscoverViewStyle.allCases {
- collectionView.register(cases.cell, forCellWithReuseIdentifier: String(describing: cases.cell))
- }
- collectionView.register(TSDiscoverHeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "TSDiscoverHeaderView")
-
- return collectionView
- }()
-
- override func createView() {
- addNormalNavBarView()
- navBarContentView.addSubview(navBarView)
- navBarView.snp.makeConstraints { make in
- make.edges.equalToSuperview()
- }
-
- contentView.addSubview(collectionView)
- collectionView.snp.makeConstraints { make in
- make.edges.equalToSuperview()
- }
- }
-
- override func dealThings() {
- NotificationCenter.default.addObserver(self, selector: #selector(updateVipView), name: .kPurchaseDidChanged, object: nil)
- updateVipView()
- }
-
- @objc func updateVipView() {
- kMainAsync{
- self.vipBtn.isHidden = PurchaseManager.default.isVip
- }
- }
- }
- extension TSDiscoverVC: UICollectionViewDataSource ,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout{
-
- func numberOfSections(in collectionView: UICollectionView) -> Int {
- return viewModel.discoverDatas.count
- }
-
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- if let secModel = viewModel.discoverDatas.safeObj(At:section){
- return secModel.items.count
- }
- return 0
- }
-
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
-
- if let secModel = viewModel.discoverDatas.safeObj(At:indexPath.section),let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing:secModel.style.cell), for: indexPath) as? TSDiscoverBaseCell, let item = secModel.items.safeObj(At:indexPath.row){
- cell.items = item
- cell.clickBlock = { [weak self] model in
- guard let self = self else { return }
- if let secModel = viewModel.discoverDatas.safeObj(At:indexPath.section) {
- TSDiscoverVC.clickCell(target: self,indexPath: indexPath, itemModel:model,secModel: secModel)
- }
- }
- return cell
- }
- return UICollectionViewCell()
- }
- func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
- if let secModel = viewModel.discoverDatas.safeObj(At:indexPath.section),
- kind == UICollectionView.elementKindSectionHeader,
- let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "TSDiscoverHeaderView", for: indexPath) as? TSDiscoverHeaderView{
- header.sectionModel = secModel
- header.clickBlock = { [weak self] model in
- guard let self = self else { return }
- clickHeader(indexPath: indexPath,model: model)
- }
- return header
- }
- return UICollectionReusableView()
- }
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize{
- if let secModel = viewModel.discoverDatas.safeObj(At:indexPath.section) {
- return secModel.style.itemSize
- }
- return .zero
- }
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets{
- if let secModel = viewModel.discoverDatas.safeObj(At:section) {
- var sectionEdge = UIEdgeInsets(top: 0, left: kDiscoverSection.left, bottom: 0, right: kDiscoverSection.right)
- if secModel.title.isEmpty {
- sectionEdge = UIEdgeInsets(top: 20, left: kDiscoverSection.left, bottom: 0, right: kDiscoverSection.right)
- }
- if section == viewModel.discoverDatas.count-1 {
- sectionEdge = UIEdgeInsets(top: sectionEdge.top, left: sectionEdge.left, bottom: sectionEdge.bottom+20, right: sectionEdge.right)
- }
- return sectionEdge
- }
- return .zero
- }
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
- if let secModel = viewModel.discoverDatas.safeObj(At:section),secModel.title.count > 0 {
- return CGSize(width: k_ScreenWidth, height: kDiscoverSectionH)
- }
- return .zero
- }
- }
- extension TSDiscoverVC {
-
- func clickHeader(indexPath:IndexPath,model:TSDiscoverSectionModel) {
- kPushVC(target: self, modelVC: TSDiscoverStyleMoreVC(sectionModel: model))
- }
-
- static func clickCell(target:UIViewController,indexPath:IndexPath,itemModel:TSDiscoverItemModel,secModel:TSDiscoverSectionModel) {
-
- if itemModel.style.isInterceptMultipleGenerations,
- TSGenerateBasePhotoOperationQueue.isAvailabilityHandle(view: target.view)
- { return }
-
-
- dePrint("\(itemModel.style)")
- switch itemModel.style {
- case .ageOld, .ageChild, .oldPhoto, .eyeOpen, .pretty, .photoLive, .photoQuality, .catTohuman,.process:
- kPushVC(target: target, modelVC: TSAIUploadPhotoBaseVC(titleString: itemModel.name, generatorStyle: itemModel.style,disCoverItemModel: itemModel))
- case .photoExpand:
- kPushVC(target: target, modelVC: TSAIExpandImageVC(upLoadImage: nil))
- case .futureBaby:
- kPushVC(target: target, modelVC: TSFutureBabyVC())
- case .changeEmote:
- TSDiscoverVC.enterSelectPhotos(target: target,style: itemModel.style) { image in
- kPushVC(target: target, modelVC: TSAIChangeEmoteVC(upLoadImage: image, style: .changeEmote))
- }
- break
- case .changehairColor:
- TSDiscoverVC.enterSelectPhotos(target: target,style: itemModel.style) { image in
- kPushVC(target: target, modelVC: TSAIChangeEmoteVC(upLoadImage: image, style: .changehairColor))
- }
- break
- case .changehair:
- TSDiscoverVC.enterSelectPhotos(target: target,style: itemModel.style) { image in
- kPushVC(target: target, modelVC: TSAIChangeEmoteVC(upLoadImage: image, style: .changehair))
- }
- case .ttp:
- kPushVC(target: target, modelVC: TSTTPInputVC())
- case .chat:
- let vc = TSChatViewController()
- vc.viewModel.uiStyle = .chat
- kPushVC(target: target, modelVC: vc)
- case .ptp:
- if let generateModel = itemModel.generateModel{
- kPushVC(target: target, modelVC: TSPTPUploadImageVC(generateModel: generateModel, sectionModel: secModel))
- }
- default:
-
- break
- }
- }
- }
- extension TSDiscoverVC{
- static func enterSelectPhotos(target:UIViewController,style:TSFuncStyle,complete: @escaping (UIImage)->Void){
- if style.userDefaultsKey.count == 0 {
- self.pickSinglePhoto(target:target,complete:complete)
- }else{
- TSAIListHintBaseVC.userDefaultsKey = style.userDefaultsKey
- if TSAIListHintBaseVC.isShowUploadImageHint{
- TSAIListHintBaseVC.isShowUploadImageHint = false
- self.presentModalHintVC(target:target,config:style.config,complete:complete)
- }else {
- self.pickSinglePhoto(target:target,complete:complete)
- }
- }
- }
- static func presentModalHintVC(target:UIViewController,config:TSAIListHintBaseVC.Config,complete:@escaping (UIImage)->Void){
- let hintBaseVC = TSAIListHintBaseVC(config: config)
- hintBaseVC.clickUpImageHandle = { image in
- if let image = image {
- complete(image)
- }else{
- dePrint("图片异常")
- }
- kDelayMainShort {
- hintBaseVC.dismissPageVC()
- }
- }
- kPresentModalVC(target: target, modelVC: hintBaseVC,transitionStyle: .crossDissolve)
- }
-
- static func pickSinglePhoto(target:UIViewController,complete: @escaping (UIImage)->Void) {
- let photoPickerManager = TSPhotoPickerManager(viewController: target)
- photoPickerManager.pickCustomSinglePhoto() { image, errorString in
- if let errorString = errorString {
- TSToastShared.showToast(text: errorString)
- }else if let image = image {
- complete(image)
- }else{
- dePrint("图片异常")
- }
- kDelayMainShort {
- photoPickerManager.dismissPageVC()
- }
-
- }
- }
- }
|